[audit] #12 : Same address can use multiple discounts through reentrancy #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reorder transactions to prevent reentrancy attack.
From Spearbit:
Description
The
discountRegistrants
mapping is used to keep track of which addresses have already used a discount and block them from registering with another or the same discount again.The mapping is checked in the
validDiscount
modifier and updated after_registration
function. The user can specify a custom resolver address in the request on whichmulticallWithNodeCheck
is called in the_registration
function. This can be used to reenter the contract and use the same or a different discount before thediscountRegistrants
updated.Note that as the
validDiscounts
checks the discount eligbility against themsg.sender
the specified resolver must be the address that is eligible for the discount. This could be the case for smart contract wallets that can provide the neededmulticallWithNodeCheck
function to perform this exploit.Recommendation
Move the update to the
discountRegistrants
state variable before doing the call to the resolver. This could be just before the_register
statement or even in thevalidDiscount
modifier.