-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add protection against gas bombs in prize hooks #115
Add protection against gas bombs in prize hooks #115
Conversation
LCOV of commit
|
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.
Interesting case! Looks good, just feels like it might be not enough? Curious to hear your thoughts
src/abstract/Claimable.sol
Outdated
/// @dev Revert data for both hooks will also be limited to this size. | ||
/// @dev 128 bytes is enough for `beforeClaimPrize` to return the recipient address as well as 32 bytes of additional | ||
/// byte string data (32 for offset, 32 for length, 32 for data). | ||
uint16 public constant HOOK_DATA_LIMIT = 128; |
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.
Is three words enough? Do we have more examples to help inform this?
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.
3 words for the entire return data is enough for 32 bytes of _hookData
to be passed back from the beforeClaimPrize
call. We haven't seen a lot of uses for hook data yet, so it's a pretty arbitrary choice, but it's a way to keep gas costs low while still allowing some data to be passed through. In hindsight, the new transient storage opcodes will probably be used more than this hook data for any meaningful state storage across calls, but the prize vault should still keep this interface intact to be backwards-compatible with previous hooks.
LCOV of commit
|
Gas bombs in hooks can be triggered in two ways:
_hookData
forbeforeClaimPrize
which then gets copied to memorybeforeClaimPrize
orafterClaimPrize
hook callsGas bombs can be used to drain the remaining call gas and cause entire batch claims to revert, making it difficult for bots to detect, pinpoint, and mitigate the hook failure. To mitigate this behaviour, the
ExcessivelySafeCall
library is used to limit the return data that is copied to memory.The prize vault
claimPrize
function is modified to safely revert if thebeforeClaimPrize
function returns more than 32 bytes of additionalhookData
. In addition, if any revert messages are thrown by either hook calls that exceed the total allowed limit of 128 bytes, a generic error will be thrown instead.By limiting the return data of hook calls, the behaviour of
claimPrize
is more predictable and claimer bots will not be susceptible gas bombs.