From ca1269fb106a139dfc43ca07fc3fedeeba339697 Mon Sep 17 00:00:00 2001 From: Kevin Halliday Date: Tue, 5 Nov 2024 18:06:35 -0500 Subject: [PATCH] chore(contracts/core): cleanup --- contracts/core/.gas-snapshot | 10 +++---- contracts/core/src/libraries/TypeMax.sol | 12 ++++++++ contracts/core/src/solve/Outbox.sol | 36 ++++++------------------ 3 files changed, 26 insertions(+), 32 deletions(-) create mode 100644 contracts/core/src/libraries/TypeMax.sol diff --git a/contracts/core/.gas-snapshot b/contracts/core/.gas-snapshot index 23afc7e1e..0607eaa1d 100644 --- a/contracts/core/.gas-snapshot +++ b/contracts/core/.gas-snapshot @@ -140,11 +140,11 @@ OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle5_10validators_succeeds() (gas: 2 OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle5_25validators_succeeds() (gas: 3510011) OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle5_succeeds() (gas: 948663) Omni_Test:test_constructor() (gas: 1008119) -Outbox_fulfill_Test:test_fulfillFee() (gas: 48793) -Outbox_fulfill_Test:test_fulfill_succeeds() (gas: 280816) -Outbox_fulfill_Test:test_markFulfilled_nativeMultiToken() (gas: 1138839) -Outbox_fulfill_Test:test_markFulfilled_singleNative() (gas: 925092) -Outbox_fulfill_Test:test_markFulfilled_singleToken() (gas: 1047544) +Outbox_fulfill_Test:test_fulfillFee() (gas: 48377) +Outbox_fulfill_Test:test_fulfill_succeeds() (gas: 280505) +Outbox_fulfill_Test:test_markFulfilled_nativeMultiToken() (gas: 1137619) +Outbox_fulfill_Test:test_markFulfilled_singleNative() (gas: 923872) +Outbox_fulfill_Test:test_markFulfilled_singleToken() (gas: 1046324) PortalRegistry_Test:test_register() (gas: 1092038) PortalRegistry_Test:test_stub() (gas: 143) Preinstalls_Test:test_createX_deployCreate2_succeeds() (gas: 132705) diff --git a/contracts/core/src/libraries/TypeMax.sol b/contracts/core/src/libraries/TypeMax.sol new file mode 100644 index 000000000..982b637eb --- /dev/null +++ b/contracts/core/src/libraries/TypeMax.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-3.0-only +pragma solidity ^0.8.12; + +/** + * @title TypeMax + * @dev Util lib with type maximum values + */ +library TypeMax { + uint256 internal constant Uint256 = type(uint256).max; + bytes32 internal constant Bytes32 = bytes32(Uint256); + address internal constant Address = address(uint160(Uint256)); +} diff --git a/contracts/core/src/solve/Outbox.sol b/contracts/core/src/solve/Outbox.sol index a3688a98c..a70299039 100644 --- a/contracts/core/src/solve/Outbox.sol +++ b/contracts/core/src/solve/Outbox.sol @@ -8,6 +8,7 @@ import { XAppBase } from "../pkg/XAppBase.sol"; import { SafeTransferLib } from "solady/src/utils/SafeTransferLib.sol"; import { ConfLevel } from "../libraries/ConfLevel.sol"; +import { TypeMax } from "../libraries/TypeMax.sol"; import { Solve } from "./Solve.sol"; import { IInbox } from "./interfaces/IInbox.sol"; @@ -43,35 +44,16 @@ contract Outbox is OwnableRoles, ReentrancyGuard, Initializable, XAppBase { uint256 internal constant SOLVER = _ROLE_0; /** - * @notice Gas limit for the callback. + * @notice Gas limit for Inbox.markFulfilled callback. */ - uint64 internal constant CALLBACK_GAS_LIMIT = 200_000; + uint64 internal constant MARK_FULFILLED_GAS_LIMIT = 100_000; /** - * @notice Placeholder for request ID. + * @notice Stubbed calldata for Inbox.markFulfilled. Used to estimate the gas cost. + * @dev Type maxes used to ensure no non-zero bytes in fee estimation. */ - bytes32 internal constant ID_PLACEHOLDER = bytes32(type(uint256).max); - - /** - * @notice Placeholder for call hash. - */ - bytes32 internal constant CALLHASH_PLACEHOLDER = bytes32(type(uint256).max); - - /** - * @notice Placeholder for solver address. - */ - address internal constant SOLVER_PLACEHOLDER = address(type(uint160).max); - - /** - * @notice Signature of the markFulfilled function. - */ - string internal constant MARK_FULFILLED_SIGNATURE = "markFulfilled(bytes32,bytes32,address)"; - - /** - * @notice Encoded call data for the markFulfilled function. - */ - bytes internal constant MARK_FULFILLED_CALLDATA = - abi.encodeWithSignature(MARK_FULFILLED_SIGNATURE, ID_PLACEHOLDER, CALLHASH_PLACEHOLDER, SOLVER_PLACEHOLDER); + bytes internal constant MARK_FULFILLED_STUB_CDATA = + abi.encodeCall(IInbox.markFulfilled, (TypeMax.Bytes32, TypeMax.Bytes32, TypeMax.Address)); /** * @notice Address of the inbox contract. @@ -111,7 +93,7 @@ contract Outbox is OwnableRoles, ReentrancyGuard, Initializable, XAppBase { * @param sourceChainId ID of the source chain. */ function fulfillFee(uint64 sourceChainId) public view returns (uint256) { - return feeFor(sourceChainId, MARK_FULFILLED_CALLDATA, CALLBACK_GAS_LIMIT); + return feeFor(sourceChainId, MARK_FULFILLED_STUB_CDATA, MARK_FULFILLED_GAS_LIMIT); } /** @@ -176,7 +158,7 @@ contract Outbox is OwnableRoles, ReentrancyGuard, Initializable, XAppBase { // Send the fulfillment call to the inbox bytes memory data = abi.encodeCall(IInbox.markFulfilled, (reqId, callHash, creditTo)); - uint256 fee = xcall(sourceChainId, ConfLevel.Finalized, _inbox, data, CALLBACK_GAS_LIMIT); + uint256 fee = xcall(sourceChainId, ConfLevel.Finalized, _inbox, data, MARK_FULFILLED_GAS_LIMIT); if (msg.value - call.value < fee) revert InsufficientFee(); emit Fulfilled(reqId, callHash, creditTo);