From 5df7a603810f288adc0a66d6632315dd7c681b52 Mon Sep 17 00:00:00 2001 From: Ted Wu Date: Thu, 18 Feb 2021 23:59:20 -0800 Subject: [PATCH 1/4] Replace custom external call with native solidity .call --- contracts/Orchestrator.sol | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/contracts/Orchestrator.sol b/contracts/Orchestrator.sol index 551b8ab8..3f62a198 100644 --- a/contracts/Orchestrator.sol +++ b/contracts/Orchestrator.sol @@ -47,7 +47,7 @@ contract Orchestrator is Ownable { for (uint256 i = 0; i < transactions.length; i++) { Transaction storage t = transactions[i]; if (t.enabled) { - bool result = externalCall(t.destination, t.data); + bool result = t.destination.call(t.data); if (!result) { emit TransactionFailed(t.destination, i, t.data); revert("Transaction Failed"); @@ -94,38 +94,4 @@ contract Orchestrator is Ownable { function transactionsSize() external view returns (uint256) { return transactions.length; } - - /** - * @dev wrapper to call the encoded transactions on downstream consumers. - * @param destination Address of destination contract. - * @param data The encoded data payload. - * @return True on success - */ - function externalCall(address destination, bytes memory data) internal returns (bool) { - bool result; - assembly { - // solhint-disable-line no-inline-assembly - // "Allocate" memory for output - // (0x40 is where "free memory" pointer is stored by convention) - let outputAddress := mload(0x40) - - // First 32 bytes are the padded length of data, so exclude that - let dataAddress := add(data, 32) - - result := call( - // 34710 is the value that solidity is currently emitting - // It includes callGas (700) + callVeryLow (3, to pay for SUB) - // + callValueTransferGas (9000) + callNewAccountGas - // (25000, in case the destination address does not exist and needs creating) - sub(gas(), 34710), - destination, - 0, // transfer value in wei - dataAddress, - mload(data), // Size of the input, in bytes. Stored in position 0 of the array. - outputAddress, - 0 // Output is ignored, therefore the output size is zero - ) - } - return result; - } } From 07e229b2c3dd23b1b55ed871207196179fdfb5e6 Mon Sep 17 00:00:00 2001 From: Ted Wu Date: Fri, 19 Feb 2021 00:10:21 -0800 Subject: [PATCH 2/4] add return type of memory --- contracts/Orchestrator.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/Orchestrator.sol b/contracts/Orchestrator.sol index 3f62a198..d160ca33 100644 --- a/contracts/Orchestrator.sol +++ b/contracts/Orchestrator.sol @@ -47,7 +47,7 @@ contract Orchestrator is Ownable { for (uint256 i = 0; i < transactions.length; i++) { Transaction storage t = transactions[i]; if (t.enabled) { - bool result = t.destination.call(t.data); + (bool result, bytes memory reason) = t.destination.call(t.data); if (!result) { emit TransactionFailed(t.destination, i, t.data); revert("Transaction Failed"); From 8e0f30c50797e7a130b8659d098e42a99adcedc5 Mon Sep 17 00:00:00 2001 From: Ted Wu Date: Fri, 19 Feb 2021 10:26:17 -0800 Subject: [PATCH 3/4] Code review comments --- contracts/Orchestrator.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contracts/Orchestrator.sol b/contracts/Orchestrator.sol index d160ca33..0d3bf095 100644 --- a/contracts/Orchestrator.sol +++ b/contracts/Orchestrator.sol @@ -47,9 +47,8 @@ contract Orchestrator is Ownable { for (uint256 i = 0; i < transactions.length; i++) { Transaction storage t = transactions[i]; if (t.enabled) { - (bool result, bytes memory reason) = t.destination.call(t.data); + (bool result, ) = t.destination.call(t.data); if (!result) { - emit TransactionFailed(t.destination, i, t.data); revert("Transaction Failed"); } } From 8d1e556127cb6c748addb0d683d0e9861308cc77 Mon Sep 17 00:00:00 2001 From: Ted Wu Date: Fri, 19 Feb 2021 11:48:05 -0800 Subject: [PATCH 4/4] Remove transaction failed event --- contracts/Orchestrator.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/contracts/Orchestrator.sol b/contracts/Orchestrator.sol index 0d3bf095..801407ed 100644 --- a/contracts/Orchestrator.sol +++ b/contracts/Orchestrator.sol @@ -16,8 +16,6 @@ contract Orchestrator is Ownable { bytes data; } - event TransactionFailed(address indexed destination, uint256 index, bytes data); - // Stable ordering is not guaranteed. Transaction[] public transactions;