Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remediate [EHF-01C] Inefficient mapping Lookups #752

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions contracts/protocol/facets/ExchangeHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -989,28 +989,38 @@ 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);

allow = holdsSpecificToken(_buyer, _condition, _tokenId);

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);

allow = holdsThreshold(_buyer, _condition, _tokenId);

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;
Expand Down