-
Notifications
You must be signed in to change notification settings - Fork 65
Updated ERC1155 Discount Validator #100
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
Conversation
✅ Heimdall Review Status
|
Review Error for abdulla-cb @ 2024-11-04 23:14:04 UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good other than the potential reentrancy in the balance call. Made a suggestion on a potential fix.
uint256[] memory ids = abi.decode(validationData, (uint256[])); | ||
for (uint256 i; i < ids.length; i++) { | ||
uint256 id = ids[i]; | ||
if (approvedTokenIds[id] && token.balanceOf(claimer, id) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This technically adds a reentrancy risk, which should be mitigated by the fact that this a token that we are specifying.
Can we wrap this external call in a staticcall to remove any risk? It will also make it easier when we want to add more validators, nobody will have to review the balance function beforehand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, updated to include a staticcall helper method for balance checks.
Review Error for cb-elileers @ 2024-11-04 23:40:11 UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the change! Looks good to me :)
} | ||
|
||
/// @notice Helper for staticcalling getBalance to avoid reentrancy vector. | ||
function _getBalance(address claimer, uint256 id) internal view returns (uint256) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. I like that you pulled in the OZ Address library for this instead of writing a new implementation.
In this version of the ERC1155 discount validator, we accept an array of uints upon initialization, setting the approved token Ids for the token collection.
Upon calling the
isValidDiscountRegistration
, an integrator should pack the token Ids in an array and pass this as thevalidationData
bytes. For example, to check for token ids 0, 1 and 2, an integrator would setvalidationData
usingabi.encode([0,1,2])
.The token Ids are decoded into an
uint[] ids
object and each is checked forclaimer
The validator returns
true
if both criteria are true for a single tokenId, elsefalse
.