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

Replace custom external call with native solidity .call #204

Merged
Merged
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
39 changes: 1 addition & 38 deletions contracts/Orchestrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -47,9 +45,8 @@ 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");
}
}
Expand Down Expand Up @@ -94,38 +91,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;
}
}