Skip to content

Commit

Permalink
Rename to maxDispatchGas
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed May 2, 2024
1 parent 7880d46 commit 27c14e9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions contracts/src/AgentExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ contract AgentExecutor {
}

/// @dev Call a contract at the given address, with provided bytes as payload.
function executeCall(address target, bytes memory payload, uint64 dynamicGas) external returns (bool) {
return target.safeCall(dynamicGas, 0, payload);
/// The safeCall here performs a low level call without copying any returndata for the return bomb attack
function executeCall(address target, bytes memory payload, uint64 maxDispatchGas) external returns (bool) {
return target.safeCall(maxDispatchGas, 0, payload);
}
}
2 changes: 1 addition & 1 deletion contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ contract Gateway is IGateway, IInitializable, IUpgradable {
TransactCallParams memory params = abi.decode(data, (TransactCallParams));
address agent = _ensureAgent(params.agentID);
bytes memory call =
abi.encodeCall(AgentExecutor.executeCall, (params.target, params.payload, params.dynamicGas));
abi.encodeCall(AgentExecutor.executeCall, (params.target, params.payload, params.maxDispatchGas));
(, bytes memory result) = Agent(payable(agent)).invoke(AGENT_EXECUTOR, call);
(bool success) = abi.decode(result, (bool));
if (!success) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/Params.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ struct TransactCallParams {
/// @dev Payload of the call
bytes payload;
/// @dev Max gas cost of the call
uint64 dynamicGas;
uint64 maxDispatchGas;
}
14 changes: 9 additions & 5 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ contract GatewayTest is Test {
agentID: assetHubAgentID,
target: address(helloWorld),
payload: payload,
dynamicGas: 100000
maxDispatchGas: 100000
});

// Expect the HelloWorld contract to emit `SaidHello`
Expand All @@ -890,7 +890,7 @@ contract GatewayTest is Test {
agentID: assetHubAgentID,
target: address(helloWorld),
payload: payload,
dynamicGas: 100000
maxDispatchGas: 100000
});

vm.expectRevert(abi.encodeWithSelector(Gateway.AgentTransactCallFailed.selector));
Expand All @@ -905,7 +905,7 @@ contract GatewayTest is Test {
agentID: assetHubAgentID,
target: address(helloWorld),
payload: payload,
dynamicGas: 100000
maxDispatchGas: 100000
});

vm.expectRevert(abi.encodeWithSelector(Gateway.AgentTransactCallFailed.selector));
Expand All @@ -923,8 +923,12 @@ contract GatewayTest is Test {
uint256 amount = 50;
bytes memory payload = abi.encodeCall(IERC20.transfer, (account1, amount));

TransactCallParams memory params =
TransactCallParams({agentID: assetHubAgentID, target: address(token), payload: payload, dynamicGas: 100000});
TransactCallParams memory params = TransactCallParams({
agentID: assetHubAgentID,
target: address(token),
payload: payload,
maxDispatchGas: 100000
});

MockGateway(address(gateway)).transactPublic(abi.encode(params));

Expand Down

0 comments on commit 27c14e9

Please sign in to comment.