From f16dcea86bfae6a6504e3d0ce23ee32a90f16552 Mon Sep 17 00:00:00 2001 From: zajck Date: Fri, 4 Aug 2023 08:37:41 +0200 Subject: [PATCH] fix #734 --- .../protocol/facets/ExchangeHandlerFacet.sol | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/contracts/protocol/facets/ExchangeHandlerFacet.sol b/contracts/protocol/facets/ExchangeHandlerFacet.sol index 01dca6bab..811c2e943 100644 --- a/contracts/protocol/facets/ExchangeHandlerFacet.sol +++ b/contracts/protocol/facets/ExchangeHandlerFacet.sol @@ -989,8 +989,13 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase { ProtocolLib.ProtocolLookups storage lookups = protocolLookups(); if (_condition.method == EvaluationMethod.SpecificToken) { + // Cache conditionalCommitsByTokenId mapping for reference + mapping(uint256 => uint256) storage conditionalCommitsByTokenId = lookups.conditionalCommitsByTokenId[ + _tokenId + ]; + // How many times has this token id been used to commit to offers in the group? - uint256 commitCount = lookups.conditionalCommitsByTokenId[_tokenId][_groupId]; + uint256 commitCount = conditionalCommitsByTokenId[_groupId]; require(commitCount < _condition.maxCommits, MAX_COMMITS_TOKEN_REACHED); @@ -998,11 +1003,16 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase { if (allow) { // Increment number of commits to the group for this token id if they are allowed to commit - lookups.conditionalCommitsByTokenId[_tokenId][_groupId] = ++commitCount; + conditionalCommitsByTokenId[_groupId] = ++commitCount; } } else if (_condition.method == EvaluationMethod.Threshold) { + // Cache conditionalCommitsByAddress mapping for reference + mapping(uint256 => uint256) storage conditionalCommitsByAddress = lookups.conditionalCommitsByAddress[ + _buyer + ]; + // How many times has this address committed to offers in the group? - uint256 commitCount = lookups.conditionalCommitsByAddress[_buyer][_groupId]; + uint256 commitCount = conditionalCommitsByAddress[_groupId]; require(commitCount < _condition.maxCommits, MAX_COMMITS_ADDRESS_REACHED); @@ -1010,7 +1020,7 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase { if (allow) { // Increment number of commits to the group for this address if they are allowed to commit - lookups.conditionalCommitsByAddress[_buyer][_groupId] = ++commitCount; + conditionalCommitsByAddress[_groupId] = ++commitCount; } } else { allow = true;