Skip to content

Commit

Permalink
chore(contracts/core): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhalliday committed Nov 5, 2024
1 parent cef8c92 commit ca1269f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
10 changes: 5 additions & 5 deletions contracts/core/.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions contracts/core/src/libraries/TypeMax.sol
Original file line number Diff line number Diff line change
@@ -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));
}
36 changes: 9 additions & 27 deletions contracts/core/src/solve/Outbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ca1269f

Please sign in to comment.