-
Notifications
You must be signed in to change notification settings - Fork 5
feat: reentrancy.Guard
for stateful precompiles
#212
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
PrecompileEnvironment.ReentrancyGuard()
reentrancy.Guard
reentrancy.Guard
reentrancy.Guard
for stateful precompiles
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.
Makes sense and seems intuitive to use from a developer perspective.
The only example use case I can think of that the existing test doesn't cover is having multiple guards with different keys protecting different functions within a single precompile, and confirming calls to the other function can still be made.
Not strictly necessary for this PR though.
It was trivial to add so I included it. Thanks for the review. |
Why this should be merged
The
vm.PrecompileEnvironment.Call()
method requires careful usage because of reentrancy vulnerabilities (this is common to all outgoingCALL
s in the EVM, not just stateful precompiles). This package provides a common method of protection, a reentrancy guard.How this works
Provides a function that returns
vm.ErrExecutionReverted
if called twice, by the same contract, in the same transaction, with the same identifier.How this was tested
Integration test.