-
Notifications
You must be signed in to change notification settings - Fork 246
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
delegatecall safety: Implement min return size in DelegateProxy #248
Conversation
test/TestDelegateProxy.sol
Outdated
} | ||
|
||
function testFailIfReverts() { | ||
TestDelegateProxy(throwProxy).revertIfReturnLessThanMinAndDie(); |
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.
Shouldn't this be revertCall
?
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.
Precisely
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.
👍
We could also replace 'throws' with 'reverts' since throw
is deprecated.
} | ||
|
||
function testMinReturn0WithReturn() { | ||
delegateFwd(target, target.returnSomething.selector.toBytes(), 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.
For these that don't fail, it'd be great if we could assert that their returns are the same as what Target
should've returned (or nothing). But doing this would probably be easier in a separate JS-based test for the DelegateProxy
.
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.
yep
Adds a new param to
delegateFwd(...)
to pass the minimum amount of bytes the underlying call must return, otherwise, it reverts. I kept the old function as a convenince method that just passes0
as the minimum return data size.This allows things such as always forcing to return something when calling a specific type of contract to avoid a
selfdesctruct
. Given that when aselfdestruct
occurs the context is exited returning1
(success) but always returns 0 bytes of data. Ideally this would be done at the protocol level, returning a different error code when itselfdestruct
s but we can't wait.This only works if you force the functions you forward to return something (setting the min to 32 and returning a boolean is enough).