Skip to content

Commit 213cfb7

Browse files
tedwu13Ted Wu
andauthored
Replace custom external call with native solidity .call (#204)
* Replace custom external call with native solidity .call * add return type of memory * Code review comments * Remove transaction failed event Co-authored-by: Ted Wu <[email protected]>
1 parent 52ca7be commit 213cfb7

File tree

1 file changed

+1
-38
lines changed

1 file changed

+1
-38
lines changed

contracts/Orchestrator.sol

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ contract Orchestrator is Ownable {
1616
bytes data;
1717
}
1818

19-
event TransactionFailed(address indexed destination, uint256 index, bytes data);
20-
2119
// Stable ordering is not guaranteed.
2220
Transaction[] public transactions;
2321

@@ -47,9 +45,8 @@ contract Orchestrator is Ownable {
4745
for (uint256 i = 0; i < transactions.length; i++) {
4846
Transaction storage t = transactions[i];
4947
if (t.enabled) {
50-
bool result = externalCall(t.destination, t.data);
48+
(bool result, ) = t.destination.call(t.data);
5149
if (!result) {
52-
emit TransactionFailed(t.destination, i, t.data);
5350
revert("Transaction Failed");
5451
}
5552
}
@@ -94,38 +91,4 @@ contract Orchestrator is Ownable {
9491
function transactionsSize() external view returns (uint256) {
9592
return transactions.length;
9693
}
97-
98-
/**
99-
* @dev wrapper to call the encoded transactions on downstream consumers.
100-
* @param destination Address of destination contract.
101-
* @param data The encoded data payload.
102-
* @return True on success
103-
*/
104-
function externalCall(address destination, bytes memory data) internal returns (bool) {
105-
bool result;
106-
assembly {
107-
// solhint-disable-line no-inline-assembly
108-
// "Allocate" memory for output
109-
// (0x40 is where "free memory" pointer is stored by convention)
110-
let outputAddress := mload(0x40)
111-
112-
// First 32 bytes are the padded length of data, so exclude that
113-
let dataAddress := add(data, 32)
114-
115-
result := call(
116-
// 34710 is the value that solidity is currently emitting
117-
// It includes callGas (700) + callVeryLow (3, to pay for SUB)
118-
// + callValueTransferGas (9000) + callNewAccountGas
119-
// (25000, in case the destination address does not exist and needs creating)
120-
sub(gas(), 34710),
121-
destination,
122-
0, // transfer value in wei
123-
dataAddress,
124-
mload(data), // Size of the input, in bytes. Stored in position 0 of the array.
125-
outputAddress,
126-
0 // Output is ignored, therefore the output size is zero
127-
)
128-
}
129-
return result;
130-
}
13194
}

0 commit comments

Comments
 (0)