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

Remove delegate executors #324

Merged
merged 3 commits into from
Jun 6, 2018
Merged
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
21 changes: 2 additions & 19 deletions contracts/common/DelegateProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,12 @@ contract DelegateProxy is ERCProxy, IsContract {
* @param _calldata Calldata for the delegatecall
*/
function delegatedFwd(address _dst, bytes _calldata) internal {
delegatedFwd(_dst, _calldata, 0);
}

/**
* @dev Performs a delegatecall and returns whatever the delegatecall returned (entire context execution will return!)
* @param _dst Destination address to perform the delegatecall
* @param _calldata Calldata for the delegatecall
* @param _minReturnSize Minimum size the call needs to return, if less than that it will revert
*/
function delegatedFwd(address _dst, bytes _calldata, uint256 _minReturnSize) internal {
require(isContract(_dst));
uint256 size;
uint256 result;
uint256 fwd_gas_limit = FWD_GAS_LIMIT;

assembly {
result := delegatecall(sub(gas, fwd_gas_limit), _dst, add(_calldata, 0x20), mload(_calldata), 0, 0)
size := returndatasize
}

require(size >= _minReturnSize);

assembly {
let result := delegatecall(sub(gas, fwd_gas_limit), _dst, add(_calldata, 0x20), mload(_calldata), 0, 0)
let size := returndatasize
let ptr := mload(0x40)
returndatacopy(ptr, 0, size)

Expand Down
8 changes: 2 additions & 6 deletions contracts/evmscript/EVMScriptRunner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ contract EVMScriptRunner is AppStorage, EVMScriptRegistryConstants {

require(executorAddr.delegatecall(sig, calldataArgs));

bytes memory ret = returnedDataDecoded();

require(ret.length > 0);

return ret;
return returnedDataDecoded();
}

function getExecutor(bytes _script) public view returns (IEVMScriptExecutor) {
Expand Down Expand Up @@ -61,4 +57,4 @@ contract EVMScriptRunner is AppStorage, EVMScriptRegistryConstants {
require(kernel == preKernel);
require(appId == preAppId);
}
}
}
5 changes: 0 additions & 5 deletions contracts/evmscript/executors/CallsScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,5 @@ contract CallsScript is IEVMScriptExecutor {
switch success case 0 { revert(0, 0) }
}
}

bytes memory ret = new bytes(1);
ret[0] = 0x01;

return ret;
}
}
63 changes: 0 additions & 63 deletions contracts/evmscript/executors/DelegateScript.sol

This file was deleted.

46 changes: 0 additions & 46 deletions contracts/evmscript/executors/DeployDelegateScript.sol

This file was deleted.

8 changes: 0 additions & 8 deletions contracts/factory/EVMScriptRegistryFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pragma solidity 0.4.18;
import "../evmscript/EVMScriptRegistry.sol";

import "../evmscript/executors/CallsScript.sol";
import "../evmscript/executors/DelegateScript.sol";
import "../evmscript/executors/DeployDelegateScript.sol";

import "./AppProxyFactory.sol";
import "../kernel/Kernel.sol";
Expand All @@ -14,14 +12,10 @@ import "../acl/ACL.sol";
contract EVMScriptRegistryFactory is AppProxyFactory, EVMScriptRegistryConstants {
address public baseReg;
address public baseCalls;
address public baseDel;
address public baseDeployDel;

function EVMScriptRegistryFactory() public {
baseReg = address(new EVMScriptRegistry());
baseCalls = address(new CallsScript());
baseDel = address(new DelegateScript());
baseDeployDel = address(new DeployDelegateScript());
}

function newEVMScriptRegistry(Kernel _dao, address _root) public returns (EVMScriptRegistry reg) {
Expand All @@ -33,8 +27,6 @@ contract EVMScriptRegistryFactory is AppProxyFactory, EVMScriptRegistryConstants
acl.createPermission(this, reg, reg.REGISTRY_MANAGER_ROLE(), this);

reg.addScriptExecutor(baseCalls); // spec 1 = CallsScript
reg.addScriptExecutor(baseDel); // spec 2 = DelegateScript
reg.addScriptExecutor(baseDeployDel); // spec 3 = DeployDelegateScript

acl.revokePermission(this, reg, reg.REGISTRY_MANAGER_ROLE());
acl.setPermissionManager(_root, reg, reg.REGISTRY_MANAGER_ROLE());
Expand Down
17 changes: 0 additions & 17 deletions docs/aragonOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,6 @@ A simple way to concatenate multiple calls. It cancels the operation if any of t
- **Output:** None.
- **Blacklist:** Entire script reverts if a call to one of the addresses in the blacklist is performed.

##### 5.2.1.1 DelegateScript
`delegatecalls` into a given contract, which basically allows for any arbitrary computation within the EVM in the caller’s context.

- **Script body:** Address of the contract to make the call to.
- **Input:** `calldata` for the `delegatecall` that will be performed.
- **Output:** raw return data of the call.
- **Blacklist:** impossible to enforce. If there are any addresses in the blacklist the script will revert as it is not possible to check whether a particular address will be called.

##### 5.2.1.3 DeployDelegateScript

Is a superset of the DelegateScript, but it takes a contract’s initcode bytecode as its script body instead of just an address. On execution, it deploys the contract to the blockchain and executes it with a `delegatecall`.

- **Script body:**: initcode for contract being created.
- **Input:** `calldata` for the `delegatecall` that will be performed after contract creation.
- **Output:** raw return data of the call.
- **Blacklist:** impossible to enforce. If there are any addresses in the blacklist the script will revert as it is not possible to check whether a particular address will be called.


### 5.3 Making an app a Forwarder

Expand Down
35 changes: 1 addition & 34 deletions test/TestDelegateProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import "../contracts/evmscript/ScriptHelpers.sol";


contract Target {
function returnSomething() public constant returns (bool) { return true; }
function dontReturn() public {}
function fail() public { revert(); }
function die() public { selfdestruct(0); }
Expand Down Expand Up @@ -39,34 +38,13 @@ contract TestDelegateProxy is DelegateProxy {
throwProxy = new ThrowProxy(address(this));
}

function testMinReturn0WithoutReturn() public {
delegatedFwd(target, target.dontReturn.selector.toBytes(), 0);
}

function testMinReturn0WithReturn() public {
delegatedFwd(target, target.returnSomething.selector.toBytes(), 0);
}

function testMinReturn32WithReturn() public {
delegatedFwd(target, target.returnSomething.selector.toBytes(), 32);
}

function testFailsIfReturnLessThanMin() public {
TestDelegateProxy(throwProxy).revertIfReturnLessThanMin();
throwProxy.assertThrows("should have reverted if return data was less than min");
}

function revertIfReturnLessThanMin() public {
delegatedFwd(target, target.dontReturn.selector.toBytes(), 32);
}

function testFailIfNoContract() public {
TestDelegateProxy(throwProxy).noContract();
throwProxy.assertThrows("should have reverted if target is not a contract");
}

function noContract() public {
delegatedFwd(address(0x1234), target.dontReturn.selector.toBytes(), 0);
delegatedFwd(address(0x1234), target.dontReturn.selector.toBytes());
}

function testFailIfReverts() public {
Expand All @@ -89,17 +67,6 @@ contract TestDelegateProxy is DelegateProxy {
Assert.isFalse(result, "should return false");
}

/* TODO: this test doesn't work with ganache. To be restablished when we use geth for tests
function testSelfdestructIsRevertedWithMinReturn() public {
TestDelegateProxy(throwProxy).revertIfReturnLessThanMinAndDie();
throwProxy.assertThrows("should have reverted to stop selfdestruct");
}

function revertIfReturnLessThanMinAndDie() public {
delegatedFwd(target, target.die.selector.toBytes(), 32);
}
*/

// keep as last test as it will kill this contract
function testDieIfMinReturn0() public {
delegatedFwd(target, target.die.selector.toBytes());
Expand Down
Loading