Skip to content

Commit

Permalink
Remove gas limits
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jun 12, 2023
1 parent f09ed28 commit 42cb91d
Show file tree
Hide file tree
Showing 20 changed files with 24 additions and 660 deletions.
10 changes: 2 additions & 8 deletions contracts/domain/BosonConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ string constant NO_SUCH_AGENT = "No such agent";
string constant WALLET_OWNS_VOUCHERS = "Wallet address owns vouchers";
string constant NO_SUCH_DISPUTE_RESOLVER = "No such dispute resolver";
string constant INVALID_ESCALATION_PERIOD = "Invalid escalation period";
string constant INVALID_AMOUNT_DISPUTE_RESOLVER_FEES = "Dispute resolver fees are not present or exceed maximum dispute resolver fees in a single transaction";
string constant INEXISTENT_DISPUTE_RESOLVER_FEES = "Dispute resolver fees are not present";
string constant DUPLICATE_DISPUTE_RESOLVER_FEES = "Duplicate dispute resolver fee";
string constant FEE_AMOUNT_NOT_YET_SUPPORTED = "Non-zero dispute resolver fees not yet supported";
string constant DISPUTE_RESOLVER_FEE_NOT_FOUND = "Dispute resolver fee not found";
string constant SELLER_ALREADY_APPROVED = "Seller id is approved already";
string constant SELLER_NOT_APPROVED = "Seller id is not approved";
string constant INVALID_AMOUNT_ALLOWED_SELLERS = "Allowed sellers are not present or exceed maximum allowed sellers in a single transaction";
string constant INEXISTENT_ALLOWED_SELLERS_LIST = "Allowed sellers are not present";
string constant INVALID_AUTH_TOKEN_TYPE = "Invalid AuthTokenType";
string constant ADMIN_OR_AUTH_TOKEN = "An admin address or an auth token is required";
string constant AUTH_TOKEN_MUST_BE_UNIQUE = "Auth token cannot be assigned to another entity of the same type";
Expand Down Expand Up @@ -97,7 +97,6 @@ string constant AGENT_FEE_AMOUNT_TOO_HIGH = "Sum of agent fee amount and protoco
// Revert Reasons: Group related
string constant NO_SUCH_GROUP = "No such group";
string constant OFFER_NOT_IN_GROUP = "Offer not part of the group";
string constant TOO_MANY_OFFERS = "Exceeded maximum offers in a single transaction";
string constant NOTHING_UPDATED = "Nothing updated";
string constant INVALID_CONDITION_PARAMETERS = "Invalid condition parameters";

Expand All @@ -108,7 +107,6 @@ string constant VOUCHER_NOT_REDEEMABLE = "Voucher not yet valid or already expir
string constant VOUCHER_EXTENSION_NOT_VALID = "Proposed date is not later than the current one";
string constant VOUCHER_STILL_VALID = "Voucher still valid";
string constant VOUCHER_HAS_EXPIRED = "Voucher has expired";
string constant TOO_MANY_EXCHANGES = "Exceeded maximum exchanges in a single transaction";
string constant EXCHANGE_IS_NOT_IN_A_FINAL_STATE = "Exchange is not in a final state";
string constant EXCHANGE_ALREADY_EXISTS = "Exchange already exists";
string constant INVALID_RANGE_LENGTH = "Range length is too large or zero";
Expand All @@ -129,7 +127,6 @@ string constant INVALID_TOKEN_ADDRESS = "Token address is a contract that doesn'
string constant NO_SUCH_BUNDLE = "No such bundle";
string constant TWIN_NOT_IN_BUNDLE = "Twin not part of the bundle";
string constant OFFER_NOT_IN_BUNDLE = "Offer not part of the bundle";
string constant TOO_MANY_TWINS = "Exceeded maximum twins in a single transaction";
string constant BUNDLE_OFFER_MUST_BE_UNIQUE = "Offer must be unique to a bundle";
string constant BUNDLE_TWIN_MUST_BE_UNIQUE = "Twin must be unique to a bundle";
string constant EXCHANGE_FOR_BUNDLED_OFFERS_EXISTS = "Exchange for the bundled offers exists";
Expand All @@ -141,7 +138,6 @@ string constant NATIVE_WRONG_ADDRESS = "Native token address must be 0";
string constant NATIVE_WRONG_AMOUNT = "Transferred value must match amount";
string constant TOKEN_NAME_UNSPECIFIED = "Token name unspecified";
string constant NATIVE_CURRENCY = "Native currency";
string constant TOO_MANY_TOKENS = "Too many tokens";
string constant TOKEN_AMOUNT_MISMATCH = "Number of amounts should match number of tokens";
string constant NOTHING_TO_WITHDRAW = "Nothing to withdraw";
string constant NOT_AUTHORIZED = "Not authorized to withdraw";
Expand All @@ -164,7 +160,6 @@ string constant DISPUTE_HAS_EXPIRED = "Dispute has expired";
string constant INVALID_BUYER_PERCENT = "Invalid buyer percent";
string constant DISPUTE_STILL_VALID = "Dispute still valid";
string constant INVALID_DISPUTE_TIMEOUT = "Invalid dispute timeout";
string constant TOO_MANY_DISPUTES = "Exceeded maximum disputes in a single transaction";
string constant ESCALATION_NOT_ALLOWED = "Disputes without dispute resolver cannot be escalated";

// Revert Reasons: Config related
Expand All @@ -187,7 +182,6 @@ string constant OFFER_RANGE_ALREADY_RESERVED = "Offer id already associated with
string constant INVALID_RANGE_START = "Range start too low";
string constant INVALID_AMOUNT_TO_MINT = "Amount to mint is greater than remaining un-minted in range";
string constant NO_SILENT_MINT_ALLOWED = "Only owner's mappings can be updated without event";
string constant TOO_MANY_TO_MINT = "Exceeded maximum amount to mint in a single transaction";
string constant OFFER_EXPIRED_OR_VOIDED = "Offer expired or voided";
string constant OFFER_STILL_VALID = "Offer still valid";
string constant NOTHING_TO_BURN = "Nothing to burn";
Expand Down
4 changes: 0 additions & 4 deletions contracts/mock/MockExchangeHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ contract MockExchangeHandlerFacet is BuyerBase, DisputeBase {
*
* Reverts if:
* - The exchanges region of protocol is paused
* - Number of exchanges exceeds maximum allowed number per batch
* - For any exchange:
* - Exchange does not exist
* - Exchange is not in Redeemed state
Expand All @@ -109,9 +108,6 @@ contract MockExchangeHandlerFacet is BuyerBase, DisputeBase {
* @param _exchangeIds - the array of exchanges ids
*/
function completeExchangeBatch(uint256[] calldata _exchangeIds) external exchangesNotPaused {
// limit maximum number of exchanges to avoid running into block gas limit in a loop
require(_exchangeIds.length <= protocolLimits().maxExchangesPerBatch, TOO_MANY_EXCHANGES);

for (uint256 i = 0; i < _exchangeIds.length; i++) {
// complete the exchange
completeExchange(_exchangeIds[i]);
Expand Down
10 changes: 0 additions & 10 deletions contracts/protocol/bases/GroupBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ contract GroupBase is ProtocolBase, IBosonGroupEvents {
* - Any of offers belongs to different seller
* - Any of offers does not exist
* - Offer exists in a different group
* - Number of offers exceeds maximum allowed number per group
*
* @param _group - the fully populated struct with group id set to 0x0
* @param _condition - the fully populated condition struct
Expand All @@ -38,9 +37,6 @@ contract GroupBase is ProtocolBase, IBosonGroupEvents {
(bool exists, uint256 sellerId) = getSellerIdByAssistant(sender);
require(exists, NOT_ASSISTANT);

// limit maximum number of offers to avoid running into block gas limit in a loop
require(_group.offerIds.length <= protocolLimits().maxOffersPerGroup, TOO_MANY_OFFERS);

// condition must be valid
require(validateCondition(_condition), INVALID_CONDITION_PARAMETERS);

Expand Down Expand Up @@ -129,7 +125,6 @@ contract GroupBase is ProtocolBase, IBosonGroupEvents {
* Reverts if:
* - Caller is not the seller
* - Offer ids param is an empty list
* - Current number of offers plus number of offers added exceeds maximum allowed number per group
* - Group does not exist
* - Any of offers belongs to different seller
* - Any of offers does not exist
Expand All @@ -146,10 +141,6 @@ contract GroupBase is ProtocolBase, IBosonGroupEvents {
// check if group can be updated
(uint256 sellerId, Group storage group) = preUpdateChecks(_groupId, _offerIds);

// limit maximum number of total offers to avoid running into block gas limit in a loop
// and make sure total number of offers in group does not exceed max
require(group.offerIds.length + _offerIds.length <= protocolLimits().maxOffersPerGroup, TOO_MANY_OFFERS);

for (uint256 i = 0; i < _offerIds.length; i++) {
uint256 offerId = _offerIds[i];
// make sure offer exist and belong to the seller
Expand Down Expand Up @@ -183,7 +174,6 @@ contract GroupBase is ProtocolBase, IBosonGroupEvents {
* Reverts if:
* - Caller is not the seller
* - Offer ids param is an empty list
* - Number of offers exceeds maximum allowed number per group
* - Group does not exist
*
* @param _groupId - the id of the group to be updated
Expand Down
1 change: 1 addition & 0 deletions contracts/protocol/facets/ConfigHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase {
setBeaconProxyAddress(_addresses.beaconProxy);
setProtocolFeePercentage(_fees.percentage);
setProtocolFeeFlatBoson(_fees.flatBoson);
setMaxEscalationResponsePeriod(_limits.maxEscalationResponsePeriod);
setBuyerEscalationDepositPercentage(_fees.buyerEscalationDepositPercentage);
setMaxTotalOfferFeePercentage(_limits.maxTotalOfferFeePercentage);
setMaxRoyaltyPecentage(_limits.maxRoyaltyPecentage);
Expand Down
4 changes: 0 additions & 4 deletions contracts/protocol/facets/DisputeHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ contract DisputeHandlerFacet is DisputeBase, IBosonDisputeHandler {
*
* Reverts if:
* - The disputes region of protocol is paused
* - Number of disputes exceeds maximum allowed number per batch
* - For any dispute:
* - Exchange does not exist
* - Exchange is not in a Disputed state
Expand All @@ -198,9 +197,6 @@ contract DisputeHandlerFacet is DisputeBase, IBosonDisputeHandler {
* @param _exchangeIds - the array of ids of the associated exchanges
*/
function expireDisputeBatch(uint256[] calldata _exchangeIds) external override {
// limit maximum number of disputes to avoid running into block gas limit in a loop
require(_exchangeIds.length <= protocolLimits().maxDisputesPerBatch, TOO_MANY_DISPUTES);

for (uint256 i = 0; i < _exchangeIds.length; i++) {
// create offer and update structs values to represent true state
expireDispute(_exchangeIds[i]);
Expand Down
39 changes: 8 additions & 31 deletions contracts/protocol/facets/DisputeResolverHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ contract DisputeResolverHandlerFacet is IBosonAccountEvents, ProtocolBase {
* - Any address is zero address
* - Any address is not unique to this dispute resolver
* - EscalationResponsePeriod is invalid
* - Number of seller ids in _sellerAllowList array exceeds max
* - Some seller does not exist
* - Some seller id is duplicated
* - DisputeResolver is not active (if active == false)
Expand Down Expand Up @@ -93,15 +92,6 @@ contract DisputeResolverHandlerFacet is IBosonAccountEvents, ProtocolBase {
// Cache protocol limits for reference
ProtocolLib.ProtocolLimits storage limits = protocolLimits();

// Make sure the gas block limit is not hit
require(_sellerAllowList.length <= limits.maxAllowedSellers, INVALID_AMOUNT_ALLOWED_SELLERS);

// The number of fees cannot exceed the maximum number of dispute resolver fees to avoid running into block gas limit in a loop
require(
_disputeResolverFees.length <= limits.maxFeesPerDisputeResolver,
INVALID_AMOUNT_DISPUTE_RESOLVER_FEES
);

// Escalation period must be greater than zero and less than or equal to the max allowed
require(
_disputeResolver.escalationResponsePeriod > 0 &&
Expand Down Expand Up @@ -412,12 +402,8 @@ contract DisputeResolverHandlerFacet is IBosonAccountEvents, ProtocolBase {
// Check that msg.sender is the admin address for this dispute resolver
require(disputeResolver.admin == sender, NOT_ADMIN);

// At least one fee must be specified and the number of fees cannot exceed the maximum number of dispute resolver fees to avoid running into block gas limit in a loop
require(
_disputeResolverFees.length > 0 &&
_disputeResolverFees.length <= protocolLimits().maxFeesPerDisputeResolver,
INVALID_AMOUNT_DISPUTE_RESOLVER_FEES
);
// At least one fee must be specified
require(_disputeResolverFees.length > 0, INEXISTENT_DISPUTE_RESOLVER_FEES);

// Set dispute resolver fees. Must loop because calldata structs cannot be converted to storage structs
for (uint256 i = 0; i < _disputeResolverFees.length; i++) {
Expand Down Expand Up @@ -476,11 +462,8 @@ contract DisputeResolverHandlerFacet is IBosonAccountEvents, ProtocolBase {
// Check that msg.sender is the admin address for this dispute resolver
require(disputeResolver.admin == sender, NOT_ADMIN);

// At least one fee must be specified and the number of fees cannot exceed the maximum number of dispute resolver fees to avoid running into block gas limit in a loop
require(
_feeTokenAddresses.length > 0 && _feeTokenAddresses.length <= protocolLimits().maxFeesPerDisputeResolver,
INVALID_AMOUNT_DISPUTE_RESOLVER_FEES
);
// At least one fee must be specified and
require(_feeTokenAddresses.length > 0, INEXISTENT_DISPUTE_RESOLVER_FEES);

// Set dispute resolver fees. Must loop because calldata structs cannot be converted to storage structs
for (uint256 i = 0; i < _feeTokenAddresses.length; i++) {
Expand Down Expand Up @@ -530,11 +513,8 @@ contract DisputeResolverHandlerFacet is IBosonAccountEvents, ProtocolBase {
uint256 _disputeResolverId,
uint256[] calldata _sellerAllowList
) external disputeResolversNotPaused nonReentrant {
// At least one seller id must be specified and the number of ids cannot exceed the maximum number of seller ids to avoid running into block gas limit in a loop
require(
_sellerAllowList.length > 0 && _sellerAllowList.length <= protocolLimits().maxAllowedSellers,
INVALID_AMOUNT_ALLOWED_SELLERS
);
// At least one seller id must be specified
require(_sellerAllowList.length > 0, INEXISTENT_ALLOWED_SELLERS_LIST);
bool exists;
DisputeResolver storage disputeResolver;

Expand Down Expand Up @@ -578,11 +558,8 @@ contract DisputeResolverHandlerFacet is IBosonAccountEvents, ProtocolBase {
// Cache protocol lookups for reference
ProtocolLib.ProtocolLookups storage lookups = protocolLookups();

// At least one seller id must be specified and the number of ids cannot exceed the maximum number of seller ids to avoid running into block gas limit in a loop
require(
_sellerAllowList.length > 0 && _sellerAllowList.length <= protocolLimits().maxAllowedSellers,
INVALID_AMOUNT_ALLOWED_SELLERS
);
// At least one seller id must be specified
require(_sellerAllowList.length > 0, INEXISTENT_ALLOWED_SELLERS_LIST);

bool exists;
DisputeResolver storage disputeResolver;
Expand Down
5 changes: 0 additions & 5 deletions contracts/protocol/facets/FundsHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ contract FundsHandlerFacet is IBosonFundsHandler, ProtocolBase {
* Reverts if:
* - Caller is not associated with the entity id
* - Token list length does not match amount list length
* - Token list length exceeds the maximum allowed number of tokens
* - Caller tries to withdraw more that they have in available funds
* - There is nothing to withdraw
* - Transfer of funds is not successful
Expand All @@ -221,10 +220,6 @@ contract FundsHandlerFacet is IBosonFundsHandler, ProtocolBase {
// Make sure that the data is complete
require(_tokenList.length == _tokenAmounts.length, TOKEN_AMOUNT_MISMATCH);

// Limit maximum number of tokens to avoid running into block gas limit in a loop
uint256 maxTokensPerWithdrawal = protocolLimits().maxTokensPerWithdrawal;
require(_tokenList.length <= maxTokensPerWithdrawal, TOO_MANY_TOKENS);

// Two possible options: withdraw all, or withdraw only specified tokens and amounts
if (_tokenList.length == 0) {
// Withdraw everything
Expand Down
9 changes: 0 additions & 9 deletions contracts/protocol/facets/OfferHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ contract OfferHandlerFacet is IBosonOfferHandler, OfferBase {
*
* Reverts if:
* - The offers region of protocol is paused
* - Number of offers exceeds maximum allowed number per batch
* - Number of elements in offers, offerDates and offerDurations do not match
* - For any offer:
* - Caller is not an assistant
Expand Down Expand Up @@ -106,8 +105,6 @@ contract OfferHandlerFacet is IBosonOfferHandler, OfferBase {
uint256[] calldata _disputeResolverIds,
uint256[] calldata _agentIds
) external override offersNotPaused nonReentrant {
// Limit maximum number of offers to avoid running into block gas limit in a loop
require(_offers.length <= protocolLimits().maxOffersPerBatch, TOO_MANY_OFFERS);
// Number of offer dates structs, offer durations structs and _disputeResolverIds must match the number of offers
require(
_offers.length == _offerDates.length &&
Expand Down Expand Up @@ -182,16 +179,13 @@ contract OfferHandlerFacet is IBosonOfferHandler, OfferBase {
*
* Reverts if, for any offer:
* - The offers region of protocol is paused
* - Number of offers exceeds maximum allowed number per batch
* - Offer id is invalid
* - Caller is not the assistant of the offer
* - Offer has already been voided
*
* @param _offerIds - list of ids of offers to void
*/
function voidOfferBatch(uint256[] calldata _offerIds) external override offersNotPaused {
// limit maximum number of offers to avoid running into block gas limit in a loop
require(_offerIds.length <= protocolLimits().maxOffersPerBatch, TOO_MANY_OFFERS);
for (uint256 i = 0; i < _offerIds.length; i++) {
voidOffer(_offerIds[i]);
}
Expand Down Expand Up @@ -241,7 +235,6 @@ contract OfferHandlerFacet is IBosonOfferHandler, OfferBase {
*
* Reverts if:
* - The offers region of protocol is paused
* - Number of offers exceeds maximum allowed number per batch
* - For any of the offers:
* - Offer does not exist
* - Caller is not the assistant of the offer
Expand All @@ -252,8 +245,6 @@ contract OfferHandlerFacet is IBosonOfferHandler, OfferBase {
* @param _validUntilDate - new valid until date
*/
function extendOfferBatch(uint256[] calldata _offerIds, uint256 _validUntilDate) external override offersNotPaused {
// Limit maximum number of offers to avoid running into block gas limit in a loop
require(_offerIds.length <= protocolLimits().maxOffersPerBatch, TOO_MANY_OFFERS);
for (uint256 i = 0; i < _offerIds.length; i++) {
extendOffer(_offerIds[i], _validUntilDate);
}
Expand Down
Loading

0 comments on commit 42cb91d

Please sign in to comment.