Commit 2bd5143f authored by Kelvin Fichter's avatar Kelvin Fichter

feat(ctb): add gas estimation logic to portal

Adds the same special gas estimation logic that we just added to the
CrossDomainMessenger into the OptimismPortal.
parent 710aba90
This diff is collapsed.
This diff is collapsed.
......@@ -13,9 +13,9 @@ CrossDomainOwnableThroughPortal_Test:test_depositTransaction_crossDomainOwner_su
CrossDomainOwnable_Test:test_onlyOwner_notOwner_reverts() (gas: 10530)
CrossDomainOwnable_Test:test_onlyOwner_succeeds() (gas: 34861)
CrossDomainOwnable2_Test:test_onlyOwner_notMessenger_reverts() (gas: 8416)
CrossDomainOwnable2_Test:test_onlyOwner_notOwner2_reverts() (gas: 61776)
CrossDomainOwnable2_Test:test_onlyOwner_notOwner_reverts() (gas: 16610)
CrossDomainOwnable2_Test:test_onlyOwner_succeeds() (gas: 77804)
CrossDomainOwnable2_Test:test_onlyOwner_notOwner2_reverts() (gas: 61754)
CrossDomainOwnable2_Test:test_onlyOwner_notOwner_reverts() (gas: 16588)
CrossDomainOwnable2_Test:test_onlyOwner_succeeds() (gas: 77782)
DeployerWhitelist_Test:test_owner_succeeds() (gas: 7538)
DeployerWhitelist_Test:test_storageSlots_succeeds() (gas: 33395)
FeeVault_Test:test_constructor_succeeds() (gas: 10601)
......@@ -38,9 +38,9 @@ L1BlockNumberTest:test_fallback_succeeds() (gas: 18633)
L1BlockNumberTest:test_getL1BlockNumber_succeeds() (gas: 10603)
L1BlockNumberTest:test_receive_succeeds() (gas: 25340)
L1CrossDomainMessenger_Test:test_messageVersion_succeeds() (gas: 24716)
L1CrossDomainMessenger_Test:test_pause_callerIsNotOwner_reverts() (gas: 24561)
L1CrossDomainMessenger_Test:test_pause_succeeds() (gas: 53008)
L1CrossDomainMessenger_Test:test_relayMessage_paused_reverts() (gas: 60520)
L1CrossDomainMessenger_Test:test_pause_callerIsNotOwner_reverts() (gas: 24539)
L1CrossDomainMessenger_Test:test_pause_succeeds() (gas: 52964)
L1CrossDomainMessenger_Test:test_relayMessage_paused_reverts() (gas: 60498)
L1CrossDomainMessenger_Test:test_relayMessage_reentrancy_reverts() (gas: 190902)
L1CrossDomainMessenger_Test:test_relayMessage_retryAfterFailure_succeeds() (gas: 197256)
L1CrossDomainMessenger_Test:test_relayMessage_succeeds() (gas: 73617)
......@@ -50,9 +50,9 @@ L1CrossDomainMessenger_Test:test_replayMessage_withValue_reverts() (gas: 38214)
L1CrossDomainMessenger_Test:test_sendMessage_succeeds() (gas: 299523)
L1CrossDomainMessenger_Test:test_sendMessage_twice_succeeds() (gas: 1490457)
L1CrossDomainMessenger_Test:test_unpause_callerIsNotOwner_reverts() (gas: 24472)
L1CrossDomainMessenger_Test:test_unpause_succeeds() (gas: 45202)
L1CrossDomainMessenger_Test:test_xDomainMessageSender_reset_succeeds() (gas: 84080)
L1CrossDomainMessenger_Test:test_xDomainSender_notSet_reverts() (gas: 24274)
L1CrossDomainMessenger_Test:test_unpause_succeeds() (gas: 45149)
L1CrossDomainMessenger_Test:test_xDomainMessageSender_reset_succeeds() (gas: 84036)
L1CrossDomainMessenger_Test:test_xDomainSender_notSet_reverts() (gas: 24252)
L1StandardBridge_DepositERC20To_Test:test_depositERC20To_succeeds() (gas: 575962)
L1StandardBridge_DepositERC20_Test:test_depositERC20_succeeds() (gas: 573786)
L1StandardBridge_DepositERC20_TestFail:test_depositERC20_notEoa_reverts() (gas: 22320)
......@@ -70,9 +70,9 @@ L1StandardBridge_Getter_Test:test_getters_succeeds() (gas: 31449)
L1StandardBridge_Initialize_Test:test_initialize_succeeds() (gas: 22005)
L1StandardBridge_Receive_Test:test_receive_succeeds() (gas: 514475)
L2CrossDomainMessenger_Test:test_messageVersion_succeeds() (gas: 8367)
L2CrossDomainMessenger_Test:test_pause_notOwner_reverts() (gas: 10881)
L2CrossDomainMessenger_Test:test_pause_succeeds() (gas: 31823)
L2CrossDomainMessenger_Test:test_relayMessage_paused_reverts() (gas: 41618)
L2CrossDomainMessenger_Test:test_pause_notOwner_reverts() (gas: 10859)
L2CrossDomainMessenger_Test:test_pause_succeeds() (gas: 31846)
L2CrossDomainMessenger_Test:test_relayMessage_paused_reverts() (gas: 41596)
L2CrossDomainMessenger_Test:test_relayMessage_reentrancy_reverts() (gas: 167787)
L2CrossDomainMessenger_Test:test_relayMessage_retry_succeeds() (gas: 168313)
L2CrossDomainMessenger_Test:test_relayMessage_succeeds() (gas: 53183)
......@@ -80,8 +80,8 @@ L2CrossDomainMessenger_Test:test_relayMessage_toSystemContract_reverts() (gas: 3
L2CrossDomainMessenger_Test:test_relayMessage_v0_reverts() (gas: 18870)
L2CrossDomainMessenger_Test:test_sendMessage_succeeds() (gas: 122533)
L2CrossDomainMessenger_Test:test_sendMessage_twice_succeeds() (gas: 134671)
L2CrossDomainMessenger_Test:test_xDomainMessageSender_reset_succeeds() (gas: 52638)
L2CrossDomainMessenger_Test:test_xDomainSender_senderNotSet_reverts() (gas: 10546)
L2CrossDomainMessenger_Test:test_xDomainMessageSender_reset_succeeds() (gas: 52594)
L2CrossDomainMessenger_Test:test_xDomainSender_senderNotSet_reverts() (gas: 10524)
L2OutputOracleTest:test_computeL2Timestamp_succeeds() (gas: 37184)
L2OutputOracleTest:test_constructor_badTimestamp_reverts() (gas: 70717)
L2OutputOracleTest:test_constructor_succeeds() (gas: 33760)
......@@ -177,10 +177,10 @@ OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_ifWith
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_ifWithdrawalProofNotOldEnough_reverts() (gas: 196155)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_onInsufficientGas_reverts() (gas: 196877)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_onRecentWithdrawal_reverts() (gas: 176869)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_onReentrancy_reverts() (gas: 235280)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_onReplay_reverts() (gas: 236890)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_provenWithdrawalHash_succeeds() (gas: 228571)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_targetFails_fails() (gas: 8797746687696163587)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_onReentrancy_reverts() (gas: 235323)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_onReplay_reverts() (gas: 236933)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_provenWithdrawalHash_succeeds() (gas: 228614)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_targetFails_fails() (gas: 8797746687696163640)
OptimismPortal_FinalizeWithdrawal_Test:test_finalizeWithdrawalTransaction_timestampLessThanL2OracleStart_reverts() (gas: 192879)
OptimismPortal_FinalizeWithdrawal_Test:test_proveWithdrawalTransaction_onInvalidOutputRootProof_reverts() (gas: 83498)
OptimismPortal_FinalizeWithdrawal_Test:test_proveWithdrawalTransaction_onInvalidWithdrawalProof_reverts() (gas: 135228)
......
......@@ -4,6 +4,7 @@ pragma solidity 0.8.15;
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import { SafeCall } from "../libraries/SafeCall.sol";
import { L2OutputOracle } from "./L2OutputOracle.sol";
import { Constants } from "../libraries/Constants.sol";
import { Types } from "../libraries/Types.sol";
import { Hashing } from "../libraries/Hashing.sol";
import { SecureMerkleTrie } from "../libraries/trie/SecureMerkleTrie.sol";
......@@ -319,6 +320,13 @@ contract OptimismPortal is Initializable, ResourceMetering, Semver {
// All withdrawals are immediately finalized. Replayability can
// be achieved through contracts built on top of this contract
emit WithdrawalFinalized(withdrawalHash, success);
// Reverting here is useful for determining the exact gas cost to successfully execute the
// sub call to the target contract if the minimum gas limit specified by the user would not
// be sufficient to execute the sub call.
if (success == false && tx.origin == Constants.ESTIMATION_ADDRESS) {
revert("OptimismPortal: withdrawal failed");
}
}
/**
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title Constants
* @notice Constants is a library for storing constants. Simple! Don't put everything in here, just
* the stuff used in multiple contracts. Constants that only apply to a single contract
* should be defined in that contract instead.
*/
library Constants {
/**
* @notice Special address to be used as the tx origin for gas estimation calls in the
* OptimismPortal and CrossDomainMessenger calls. You only need to use this address if
* the minimum gas limit specified by the user is not actually enough to execute the
* given message and you're attempting to estimate the actual necessary gas limit. We
* use address(1) because it's the ecrecover precompile and therefore guaranteed to
* never have any code on any EVM chain.
*/
address internal constant ESTIMATION_ADDRESS = address(1);
}
......@@ -13,6 +13,7 @@ import {
import { SafeCall } from "../libraries/SafeCall.sol";
import { Hashing } from "../libraries/Hashing.sol";
import { Encoding } from "../libraries/Encoding.sol";
import { Constants } from "../libraries/Constants.sol";
/**
* @custom:legacy
......@@ -70,14 +71,6 @@ abstract contract CrossDomainMessenger is
*/
uint64 public constant MIN_GAS_CALLDATA_OVERHEAD = 16;
/**
* @notice Address to use when estimating gas for a message where the minimum gas limit on the
* message would not be sufficient to successfully execute the message. We use
* address(1) because we want to guarantee that the estimation address will never have
* code and address(1) is the ecrecover precompile on all EVM-equivalent chains.
*/
address public constant ESTIMATION_ADDRESS = address(1);
/**
* @notice Minimum amount of gas required to relay a message.
*/
......@@ -343,7 +336,7 @@ abstract contract CrossDomainMessenger is
// here will make the behavior of gas estimation change such that the gas limit
// computed will be the amount required to relay the message, even if that amount is
// greater than the minimum gas limit specified by the user.
if (tx.origin == ESTIMATION_ADDRESS) {
if (tx.origin == Constants.ESTIMATION_ADDRESS) {
revert("CrossDomainMessenger: failed to relay message");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment