From 0a10d27dbcc7111deec062cb9cfb842e18d61701 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 17 May 2018 17:29:27 -0300 Subject: [PATCH] fix "stack too deep" problem by removing modifier --- contracts/identity/IdentityGasRelay.sol | 150 ++++++++++++++++++------ contracts/identity/IdentityKernel.sol | 6 +- 2 files changed, 118 insertions(+), 38 deletions(-) diff --git a/contracts/identity/IdentityGasRelay.sol b/contracts/identity/IdentityGasRelay.sol index 89d8269..3d8c7b3 100644 --- a/contracts/identity/IdentityGasRelay.sol +++ b/contracts/identity/IdentityGasRelay.sol @@ -68,6 +68,27 @@ contract IdentityGasRelay is Identity { } } + constructor( + bytes32[] _keys, + uint256[] _purposes, + uint256[] _types, + uint256 _managerThreshold, + uint256 _actorThreshold, + address _recoveryContract + ) + Identity( + _keys, + _purposes, + _types, + _managerThreshold, + _actorThreshold, + _recoveryContract + ) + public + { + + } + /** * @notice include ethereum signed callHash in return of gas proportional amount multiplied by `_gasPrice` of `_gasToken` * allows identity of being controlled without requiring ether in key balace @@ -91,7 +112,19 @@ contract IdentityGasRelay is Identity { bytes _messageSignatures ) external - executeGasRelayed( + returns (bool success) + { + + //query current gas available + uint startGas = gasleft(); + + //verify transaction parameters + require(startGas >= _gasLimit); + require(_nonce == nonce); + + //verify if signatures are valid and came from correct actors; + verifySignatures( + _to == address(this) ? MANAGEMENT_KEY : ACTION_KEY, callGasRelayHash( _to, _value, @@ -100,17 +133,27 @@ contract IdentityGasRelay is Identity { _gasPrice, _gasLimit, _gasToken - ), - _to == address(this) ? MANAGEMENT_KEY : ACTION_KEY, - _nonce, - _gasPrice, - _gasLimit, - _gasToken, + ), _messageSignatures - ) - returns (bool success) - { + ); + + //increase nonce + nonce++; + + //executes transaction success = _commitCall(_nonce, _to, _value, _data); + + //refund gas used using contract held ERC20 tokens or ETH + if (_gasPrice > 0) { + uint256 _amount = 21000 + (startGas - gasleft()); + _amount = _amount * _gasPrice; + if (_gasToken == address(0)) { + address(msg.sender).transfer(_amount); + } else { + ERC20Token(_gasToken).transfer(msg.sender, _amount); + } + } + } @@ -135,7 +178,19 @@ contract IdentityGasRelay is Identity { bytes _messageSignatures ) external - executeGasRelayed( + returns(address deployedAddress) + { + + //query current gas available + uint startGas = gasleft(); + + //verify transaction parameters + require(startGas >= _gasLimit); + require(_nonce == nonce); + + //verify if signatures are valid and came from correct actors; + verifySignatures( + ACTION_KEY, deployGasRelayHash( _value, keccak256(_data), @@ -143,19 +198,26 @@ contract IdentityGasRelay is Identity { _gasPrice, _gasLimit, _gasToken - ), - ACTION_KEY, - _nonce, - _gasPrice, - _gasLimit, - _gasToken, + ), _messageSignatures - ) - returns(address deployedAddress) - { + ); + + //increase nonce nonce++; + deployedAddress = doCreate(_value, _data); - emit ContractDeployed(deployedAddress); + emit ContractDeployed(deployedAddress); + + //refund gas used using contract held ERC20 tokens or ETH + if (_gasPrice > 0) { + uint256 _amount = 21000 + (startGas - gasleft()); + _amount = _amount * _gasPrice; + if (_gasToken == address(0)) { + address(msg.sender).transfer(_amount); + } else { + ERC20Token(_gasToken).transfer(msg.sender, _amount); + } + } } @@ -186,31 +248,49 @@ contract IdentityGasRelay is Identity { bytes _messageSignatures ) external - executeGasRelayed( - approveAndCallGasRelayHash( - _baseToken, - _to, + returns(bool success) + { + + //query current gas available + uint startGas = gasleft(); + + //verify transaction parameters + require(startGas >= _gasLimit); + require(_nonce == nonce); + + //verify if signatures are valid and came from correct actors; + verifySignatures( + ACTION_KEY, + deployGasRelayHash( _value, keccak256(_data), _nonce, _gasPrice, _gasLimit, - _gasToken - ), - ACTION_KEY, - _nonce, - _gasPrice, - _gasLimit, - _gasToken, + _gasToken + ), _messageSignatures - ) - returns(bool success) - { + ); + + //increase nonce + nonce++; + require(_baseToken != address(0)); //_baseToken should be something! require(_to != address(this)); //no management with approveAndCall require(_to != address(0)); //need valid destination ERC20Token(_baseToken).approve(_to, _value); success = _commitCall(_nonce, _to, 0, _data); + + //refund gas used using contract held ERC20 tokens or ETH + if (_gasPrice > 0) { + uint256 _amount = 21000 + (startGas - gasleft()); + _amount = _amount * _gasPrice; + if (_gasToken == address(0)) { + address(msg.sender).transfer(_amount); + } else { + ERC20Token(_gasToken).transfer(msg.sender, _amount); + } + } } /** diff --git a/contracts/identity/IdentityKernel.sol b/contracts/identity/IdentityKernel.sol index 568fb5f..9a1d4ba 100644 --- a/contracts/identity/IdentityKernel.sol +++ b/contracts/identity/IdentityKernel.sol @@ -1,12 +1,12 @@ pragma solidity ^0.4.17; import "../deploy/DelayedUpdatableInstanceStorage.sol"; -import "./Identity.sol"; +import "./IdentityGasRelay.sol"; -contract IdentityKernel is DelayedUpdatableInstanceStorage, Identity { +contract IdentityKernel is DelayedUpdatableInstanceStorage, IdentityGasRelay { constructor() - Identity( + IdentityGasRelay( new bytes32[](0), new uint256[](0), new uint256[](0),