Skip to content

Commit

Permalink
feat(contracts): make portal xmsg params configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhalliday committed Apr 23, 2024
1 parent 8876c55 commit e905e9f
Show file tree
Hide file tree
Showing 15 changed files with 1,273 additions and 382 deletions.
90 changes: 45 additions & 45 deletions contracts/.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -60,55 +60,55 @@ OmniAVS_canRegister_Test:test_canRegister_minStakeNotMet() (gas: 328620)
OmniAVS_canRegister_Test:test_canRegister_notAllowed() (gas: 222863)
OmniAVS_canRegister_Test:test_canRegister_notOperator() (gas: 119994)
OmniAVS_initialize_Test:test_initialize_defaultParams_succeeds() (gas: 3588147)
OmniAVS_syncWithOmni_Test:test_depositBeaconEth_succeeds() (gas: 628669)
OmniAVS_syncWithOmni_Test:test_depositBeaconEth_succeeds() (gas: 630918)
OmniAVS_syncWithOmni_Test:test_unsupportedStrategyDeposit_succeeds() (gas: 1532940)
OmniPortal_admin_Test:test_setFeeOracle_nonOwner_reverts() (gas: 20389)
OmniPortal_admin_Test:test_setFeeOracle_succeeds() (gas: 31888)
OmniPortal_admin_Test:test_setFeeOracle_zero_reverts() (gas: 20442)
OmniPortal_exec_Test:test_execSys_forwardsRevert() (gas: 23154)
OmniPortal_exec_Test:test_exec_aheadOffset_reverts() (gas: 26126)
OmniPortal_exec_Test:test_exec_behindOffset_reverts() (gas: 110502)
OmniPortal_exec_Test:test_exec_errorBytes() (gas: 71922017)
OmniPortal_exec_Test:test_exec_wrongChainId_reverts() (gas: 23660)
OmniPortal_exec_Test:test_exec_xmsgRevert_succeeds() (gas: 68033)
OmniPortal_exec_Test:test_exec_xmsg_succeeds() (gas: 125967)
OmniPortal_feeFor_Test:test_feeFor_defaultGasLimit_succeeds() (gas: 33934)
OmniPortal_feeFor_Test:test_feeFor_succeeds() (gas: 32581)
OmniPortal_xcall_Test:test_xcall_defaultGasLimit_succeeds() (gas: 85171)
OmniPortal_xcall_Test:test_xcall_explicitGasLimit_succeeds() (gas: 85623)
OmniPortal_xcall_Test:test_xcall_gasLimitTooHigh_reverts() (gas: 51417)
OmniPortal_xcall_Test:test_xcall_gasLimitTooLow_reverts() (gas: 51451)
OmniPortal_xcall_Test:test_xcall_insufficientFee_reverts() (gas: 49807)
OmniPortal_xcall_Test:test_xcall_sameChain_reverts() (gas: 51446)
OmniPortal_xsubmit_Test:test_xsubmit_addValidatorSet_succeeds() (gas: 64347247)
OmniPortal_xsubmit_Test:test_xsubmit_duplicateValidator_reverts() (gas: 63337231)
OmniPortal_xsubmit_Test:test_xsubmit_invalidAttestationRoot_reverts() (gas: 63382434)
OmniPortal_xsubmit_Test:test_xsubmit_invalidMsgs_reverts() (gas: 63369436)
OmniPortal_xsubmit_Test:test_xsubmit_noQuorum_reverts() (gas: 63344031)
OmniPortal_xsubmit_Test:test_xsubmit_noXmsgs_reverts() (gas: 63319316)
OmniPortal_xsubmit_Test:test_xsubmit_notNewValSet_succeeds() (gas: 64319277)
OmniPortal_xsubmit_Test:test_xsubmit_oldValSet_reverts() (gas: 64894485)
OmniPortal_xsubmit_Test:test_xsubmit_uknownValSetId_reverts() (gas: 63327512)
OmniPortal_xsubmit_Test:test_xsubmit_wrongChainId_reverts() (gas: 63424788)
OmniPortal_xsubmit_Test:test_xsubmit_wrongStreamOffset_reverts() (gas: 63416285)
OmniPortal_xsubmit_Test:test_xsubmit_xblock1_chainB_succeeds() (gas: 63596411)
OmniPortal_xsubmit_Test:test_xsubmit_xblock1_succeeds() (gas: 63596502)
OmniPortal_xsubmit_Test:test_xsubmit_xblock2_chainB_succeeds() (gas: 64246010)
OmniPortal_xsubmit_Test:test_xsubmit_xblock2_succeeds() (gas: 64247638)
OmniPortal_xsubmit_gas_Test:test_singleExec() (gas: 63902182)
OmniPortal_xsubmit_gas_Test:test_xsubmi_addValidator_succeeds() (gas: 63516313)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle10_succeeds() (gas: 64561408)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle1_succeeds() (gas: 63531960)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle25_succeeds() (gas: 66277467)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle50_succeeds() (gas: 69138267)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle5_succeeds() (gas: 63989542)
OmniPortal_admin_Test:test_setFeeOracle_nonOwner_reverts() (gas: 20367)
OmniPortal_admin_Test:test_setFeeOracle_succeeds() (gas: 31954)
OmniPortal_admin_Test:test_setFeeOracle_zero_reverts() (gas: 20420)
OmniPortal_exec_Test:test_execSys_forwardsRevert() (gas: 23242)
OmniPortal_exec_Test:test_exec_aheadOffset_reverts() (gas: 28315)
OmniPortal_exec_Test:test_exec_behindOffset_reverts() (gas: 113060)
OmniPortal_exec_Test:test_exec_errorBytes() (gas: 71926230)
OmniPortal_exec_Test:test_exec_wrongChainId_reverts() (gas: 25849)
OmniPortal_exec_Test:test_exec_xmsgRevert_succeeds() (gas: 70458)
OmniPortal_exec_Test:test_exec_xmsg_succeeds() (gas: 128414)
OmniPortal_feeFor_Test:test_feeFor_defaultGasLimit_succeeds() (gas: 36157)
OmniPortal_feeFor_Test:test_feeFor_succeeds() (gas: 32669)
OmniPortal_xcall_Test:test_xcall_defaultGasLimit_succeeds() (gas: 87843)
OmniPortal_xcall_Test:test_xcall_explicitGasLimit_succeeds() (gas: 88102)
OmniPortal_xcall_Test:test_xcall_gasLimitTooHigh_reverts() (gas: 53827)
OmniPortal_xcall_Test:test_xcall_gasLimitTooLow_reverts() (gas: 53970)
OmniPortal_xcall_Test:test_xcall_insufficientFee_reverts() (gas: 51973)
OmniPortal_xcall_Test:test_xcall_sameChain_reverts() (gas: 53825)
OmniPortal_xsubmit_Test:test_xsubmit_addValidatorSet_succeeds() (gas: 64350986)
OmniPortal_xsubmit_Test:test_xsubmit_duplicateValidator_reverts() (gas: 63337208)
OmniPortal_xsubmit_Test:test_xsubmit_invalidAttestationRoot_reverts() (gas: 63382411)
OmniPortal_xsubmit_Test:test_xsubmit_invalidMsgs_reverts() (gas: 63369413)
OmniPortal_xsubmit_Test:test_xsubmit_noQuorum_reverts() (gas: 63344008)
OmniPortal_xsubmit_Test:test_xsubmit_noXmsgs_reverts() (gas: 63319293)
OmniPortal_xsubmit_Test:test_xsubmit_notNewValSet_succeeds() (gas: 64322840)
OmniPortal_xsubmit_Test:test_xsubmit_oldValSet_reverts() (gas: 64898025)
OmniPortal_xsubmit_Test:test_xsubmit_uknownValSetId_reverts() (gas: 63327489)
OmniPortal_xsubmit_Test:test_xsubmit_wrongChainId_reverts() (gas: 63424765)
OmniPortal_xsubmit_Test:test_xsubmit_wrongStreamOffset_reverts() (gas: 63416262)
OmniPortal_xsubmit_Test:test_xsubmit_xblock1_chainB_succeeds() (gas: 63599788)
OmniPortal_xsubmit_Test:test_xsubmit_xblock1_succeeds() (gas: 63599879)
OmniPortal_xsubmit_Test:test_xsubmit_xblock2_chainB_succeeds() (gas: 64250787)
OmniPortal_xsubmit_Test:test_xsubmit_xblock2_succeeds() (gas: 64252370)
OmniPortal_xsubmit_gas_Test:test_singleExec() (gas: 63905872)
OmniPortal_xsubmit_gas_Test:test_xsubmi_addValidator_succeeds() (gas: 63518521)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle10_succeeds() (gas: 64565987)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle1_succeeds() (gas: 63534217)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle25_succeeds() (gas: 66285916)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle50_succeeds() (gas: 69153166)
OmniPortal_xsubmit_gas_Test:test_xsubmit_guzzle5_succeeds() (gas: 63992831)
OmniStake_Test:test_deposit_aboveMaxUint64_reverts() (gas: 17671)
OmniStake_Test:test_deposit_below1Ether_reverts() (gas: 17460)
OmniStake_Test:test_deposit_invalidLength_reverts() (gas: 18042)
OmniStake_Test:test_deposit_succeeds() (gas: 22429)
OmniStake_Test:test_deposit_wrongPubkey_reverts() (gas: 18350)
Omni_Test:test_constructor() (gas: 1006927)
PingPong_Test:test_pingpong_norecv_gas() (gas: 84609)
PingPong_Test:test_pingpong_norecv_twice_gas() (gas: 109503)
PingPong_Test:test_pingpong_recv_gas() (gas: 87250)
PingPong_Test:test_pingpong_recv_twice_gas() (gas: 117948)
PingPong_Test:test_pingpong_norecv_gas() (gas: 87047)
PingPong_Test:test_pingpong_norecv_twice_gas() (gas: 112379)
PingPong_Test:test_pingpong_recv_gas() (gas: 89688)
PingPong_Test:test_pingpong_recv_twice_gas() (gas: 120248)
2 changes: 1 addition & 1 deletion contracts/bindings/omniavs.go

Large diffs are not rendered by default.

1,082 changes: 889 additions & 193 deletions contracts/bindings/omniportal.go

Large diffs are not rendered by default.

29 changes: 24 additions & 5 deletions contracts/src/interfaces/IOmniPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ interface IOmniPortal {
*/
event ValidatorSetAdded(uint64 indexed setId);

/**
* @notice Default xmsg execution gas limit, enforced on destination chain
*/
function xmsgDefaultGasLimit() external view returns (uint64);

/**
* @notice Maximum allowed xmsg gas limit
*/
function xmsgMaxGasLimit() external view returns (uint64);

/**
* @notice Minimum allowed xmsg gas limit
*/
function xmsgMinGasLimit() external view returns (uint64);

/**
* @notice Maxium number of bytes allowed in xreceipt result
*/
function xreceiptMaxErrorBytes() external view returns (uint64);

/**
* @notice Returns Chain ID of the chain to which this portal is deployed
*/
Expand Down Expand Up @@ -87,8 +107,8 @@ interface IOmniPortal {
function isXCall() external view returns (bool);

/**
* @notice Calculate the fee for calling a contract on another chain. Uses
* OmniPortal.XMSG_DEFAULT_GAS_LIMIT. Fees denominated in wei.
* @notice Calculate the fee for calling a contract on another chain. Uses xmsgDefaultGasLimit.
* Fees denominated in wei.
* @param destChainId Destination chain ID
* @param data Encoded function calldata
*/
Expand All @@ -104,7 +124,7 @@ interface IOmniPortal {
function feeFor(uint64 destChainId, bytes calldata data, uint64 gasLimit) external view returns (uint256);

/**
* @notice Call a contract on another chain Uses OmniPortal.XMSG_DEFAULT_GAS_LIMIT as execution
* @notice Call a contract on another chain Uses xmsgDefaultGasLimit as execution
* gas limit on destination chain
* @param destChainId Destination chain ID
* @param to Address of contract to call on destination chain
Expand All @@ -114,8 +134,7 @@ interface IOmniPortal {

/**
* @notice Call a contract on another chain Uses provide gasLimit as execution gas limit on
* destination chain. Reverts if gasLimit < XMSG_MAX_GAS_LIMIT or gasLimit >
* XMSG_MAX_GAS_LIMIT
* destination chain. Reverts if gasLimit < xmsgMinGasLimit or gasLimit > xmsgMaxGasLimit.
* @param destChainId Destination chain ID
* @param to Address of contract to call on destination chain
* @param data ABI Encoded function calldata
Expand Down
54 changes: 51 additions & 3 deletions contracts/src/interfaces/IOmniPortalAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pragma solidity ^0.8.12;
interface IOmniPortalAdmin {
/**
* @notice Emitted when the fee oracle is changed
* @param oldFeeOracle The old fee oracle
* @param newFeeOracle The new fee oracle
* @param oldOracle The old fee oracle
* @param newOrcale The new fee oracle
*/
event FeeOracleChanged(address indexed oldFeeOracle, address indexed newFeeOracle);
event FeeOracleChanged(address indexed oldOracle, address indexed newOrcale);

/**
* @notice Emited when fees are collected
Expand All @@ -20,6 +20,34 @@ interface IOmniPortalAdmin {
*/
event FeesCollected(address indexed to, uint256 amount);

/**
* @notice Emitted when the xmsgDefaultGasLimit is changed.
* @param oldDefault The old xmsgDefaultGasLimit
* @param newDefault The new xmsgDefaultGasLimit
*/
event XMsgDefaultGasLimitChanged(uint64 indexed oldDefault, uint64 indexed newDefault);

/**
* @notice Emitted when xmsgMinGasLimit is changed.
* @param oldMin The old xmsgMinGasLimit
* @param newMin The new xmsgMinGasLimit
*/
event XMsgMinGasLimitChanged(uint64 indexed oldMin, uint64 indexed newMin);

/**
* @notice Emitted when xmsgMaxGasLimit is changed.
* @param oldMax The old xmsgMaxGasLimit
* @param newMax The new xmsgMaxGasLimit
*/
event XMsgMaxGasLimitChanged(uint64 indexed oldMax, uint64 indexed newMax);

/**
* @notice Emitted when xreceiptMaxErrorBytes is changed.
* @param oldMax The old xreceiptMaxErrorBytes
* @param newMax The new xreceiptMaxErrorBytes
*/
event XReceiptMaxErrorBytesChanged(uint64 indexed oldMax, uint64 indexed newMax);

/**
* @notice Returns the current fee oracle address
*/
Expand All @@ -35,4 +63,24 @@ interface IOmniPortalAdmin {
* @param to The address to transfer the fees to
*/
function collectFees(address to) external;

/**
* @notice Set the default gas limit for xmsg
*/
function setXMsgDefaultGasLimit(uint64 gasLimit) external;

/**
* @notice Set the minimum gas limit for xmsg
*/
function setXMsgMinGasLimit(uint64 gasLimit) external;

/**
* @notice Set the maximum gas limit for xmsg
*/
function setXMsgMaxGasLimit(uint64 gasLimit) external;

/**
* @notice Set the maximum error bytes for xreceipt
*/
function setXReceiptMaxErrorBytes(uint64 maxErrorBytes) external;
}
18 changes: 12 additions & 6 deletions contracts/src/pkg/XApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ import { XTypes } from "../libraries/XTypes.sol";

/**
* @title XApp
* @dev Base contract for Omni cross-chain applications
* @notice Base contract for Omni cross-chain applications
*/
contract XApp {
/// @notice The OmniPortal contract
/**
* @notice The OmniPortal contract
*/
IOmniPortal internal immutable omni;

/// @notice Transient storage for the current xmsg
/**
* @notice Transient storage for the current xmsg
*/
XTypes.MsgShort internal xmsg;

/// @notice Read current xmsg into storage before execution, delete it afterwards
/**
* @notice Read current xmsg into storage before execution, delete it afterwards
*/
modifier xrecv() {
xmsg = omni.xmsg();
_;
Expand All @@ -34,7 +40,7 @@ contract XApp {
}

/**
* @notice Returns the fee for calling a contract on another chain. Uses OmniPortal.XMSG_DEFAULT_GAS_LIMIT
* @notice Returns the fee for calling a contract on another chain. Uses OmniPortal.xmsgDefaultGasLimit
*/
function feeFor(uint64 destChainId, bytes memory data) internal view returns (uint256) {
return omni.feeFor(destChainId, data);
Expand All @@ -48,7 +54,7 @@ contract XApp {
}

/**
* @notice Call a contract on another chain. Uses OmniPortal.XMSG_DEFAULT_GAS_LIMIT
* @notice Call a contract on another chain. Uses OmniPortal.xmsgDefaultGasLimit
* @return fee The fee for the xcall
*/
function xcall(uint64 destChainId, address to, bytes memory data) internal returns (uint256) {
Expand Down
Loading

0 comments on commit e905e9f

Please sign in to comment.