Skip to content
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

Merged
merged 4 commits into from
Mar 14, 2018

Conversation

izqui
Copy link
Contributor

@izqui izqui commented Mar 14, 2018

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 passes 0 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 a selfdestruct occurs the context is exited returning 1 (success) but always returns 0 bytes of data. Ideally this would be done at the protocol level, returning a different error code when it selfdestructs 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).

@coveralls
Copy link

coveralls commented Mar 14, 2018

Coverage Status

Coverage increased (+0.006%) to 99.476% when pulling aecd6f7 on min-return into 501a905 on dev.

}

function testFailIfReverts() {
TestDelegateProxy(throwProxy).revertIfReturnLessThanMinAndDie();
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisely

Copy link
Contributor

@sohkai sohkai left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@izqui izqui merged commit 8c915e1 into dev Mar 14, 2018
@izqui izqui deleted the min-return branch March 14, 2018 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants