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

Add check for invalid target. Closes #24 #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ contract DSProxy is DSAuth, DSNote {
returns (bytes memory response)
{
require(_target != address(0), "ds-proxy-target-address-required");
uint csize;
Copy link
Member

Choose a reason for hiding this comment

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

Let's use codesize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't use codesize as variable name in assembly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

codeSize or code_size work though. What do you prefer?

assembly {
csize := extcodesize(_target)
}
require(csize > 0, "ds-proxy-target-invalid-address");

// call contract in current context
assembly {
Expand Down
13 changes: 13 additions & 0 deletions src/proxy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,19 @@ contract DSProxyTest is DSTest {
assertEq(address(this).balance, myBalance + 5);
}

///test 14 - check failure when an address without code is used as target
function testFail_executeNonContract() public {
bytes memory data = abi.encodeWithSignature("test()");
proxy.execute(address(0x1), data);
}

///test 15 - check failure when a non existing function is called
function testFail_executeNonFunction() public {
address testContract = address(new TestContract());
bytes memory data = abi.encodeWithSignature("nonExistingFunction()");
proxy.execute(testContract, data);
}

function() external payable {
}
}