Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion src/proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ contract DSProxy is DSAuth, DSNote {
returns (bytes memory response)
{
require(_target != address(0), "ds-proxy-target-address-required");
uint size;
assembly {
size := extcodesize(_target)
}
require(size > 0, "ds-proxy-target-invalid-address");

// call contract in current context
assembly {
let succeeded := delegatecall(sub(gas, 5000), _target, add(_data, 0x20), mload(_data), 0, 0)
let size := returndatasize
size := returndatasize

response := mload(0x40)
mstore(0x40, add(response, and(add(add(size, 0x20), 0x1f), not(0x1f))))
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 {
}
}