Skip to content

Commit

Permalink
Use engine API that matches hardfork version (#9253)
Browse files Browse the repository at this point in the history
* Use engine API that matches HF

* Simplify engine client code by using EngineAPIVersion

* Return full method string from engine api version methods

* FCUVersion takes payload attributes

* Use a proper method

* Handle switch default case explicitly

* Return fcuV3 if attrs is nil

* Add test cases for engine api version methods
  • Loading branch information
ImTei authored and spacesailor24 committed Feb 8, 2024
1 parent 71cefdb commit bd44da1
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 44 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,10 @@ workflows:
name: op-challenger-tests
module: op-challenger
requires: ["go-mod-download"]
- go-test:
name: op-dispute-mon-tests
module: op-dispute-mon
requires: ["go-mod-download"]
- go-test:
name: op-conductor-tests
module: op-conductor
Expand Down
9 changes: 6 additions & 3 deletions op-chain-ops/cmd/check-ecotone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,10 @@ func execTx(ctx context.Context, to *common.Address, data []byte, expectRevert b
if err != nil {
return fmt.Errorf("failed to get chainID: %w", err)
}
tx := types.NewTx(&types.DynamicFeeTx{ChainID: chainID, Nonce: nonce,
GasTipCap: tip, GasFeeCap: maxFee, Gas: 500000, To: to, Data: data})
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: chainID, Nonce: nonce,
GasTipCap: tip, GasFeeCap: maxFee, Gas: 500000, To: to, Data: data,
})
signer := types.NewCancunSigner(chainID)
signedTx, err := types.SignTx(tx, signer, env.key)
if err != nil {
Expand Down Expand Up @@ -657,8 +659,9 @@ func checkL1Fees(ctx context.Context, env *actionEnv) error {
return fmt.Errorf("failed to retrieve matching L1 block %s: %w", headRef, err)
}
gasTip := big.NewInt(2 * params.GWei)
baseFee := (*uint256.Int)(&payload.ExecutionPayload.BaseFeePerGas).ToBig()
gasMaxFee := new(big.Int).Add(
new(big.Int).Mul(big.NewInt(2), payload.ExecutionPayload.BaseFeePerGas.ToBig()), gasTip)
new(big.Int).Mul(big.NewInt(2), baseFee), gasTip)
to := common.Address{1, 2, 3, 5}
txData := &types.DynamicFeeTx{
ChainID: rollupCfg.L2ChainID,
Expand Down
5 changes: 4 additions & 1 deletion op-chain-ops/cmd/receipt-reference-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (

"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
"golang.org/x/exp/slog"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"

opservice "github.com/ethereum-optimism/optimism/op-service"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
)

const EnvPrefix = "OP_CHAIN_OPS_RECEIPT_REFERENCE_BUILDER"
Expand Down Expand Up @@ -75,7 +77,8 @@ var (
)

func main() {
log.Root().SetHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(isatty.IsTerminal(os.Stderr.Fd()))))
color := isatty.IsTerminal(os.Stderr.Fd())
oplog.SetGlobalLogHandler(log.NewTerminalHandlerWithLevel(os.Stdout, slog.LevelDebug, color))

app := &cli.App{
Name: "receipt-reference-builder",
Expand Down
3 changes: 0 additions & 3 deletions op-e2e/faultproofs/output_cannon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ func TestOutputCannonDefendStep(t *testing.T) {
}

func TestOutputCannonStepWithLargePreimage(t *testing.T) {
// TODO(client-pod#525): Investigate and fix flakiness
t.Skip("Skipping until the flakiness can be resolved")

op_e2e.InitParallel(t, op_e2e.UsesCannon)

ctx := context.Background()
Expand Down
6 changes: 1 addition & 5 deletions op-e2e/faultproofs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ type faultDisputeConfigOpts func(cfg *op_e2e.SystemConfig)

func withBatcherStopped() faultDisputeConfigOpts {
return func(cfg *op_e2e.SystemConfig) {
maxTxDataSize := uint64(131072) // As per the Ethereum spec.
// Allow the batcher to produce really huge calldata transactions.
// Make the max deliberately bigger than the target but still with some padding below the actual limit
cfg.BatcherTargetL1TxSizeBytes = maxTxDataSize - 5000
cfg.BatcherMaxL1TxSizeBytes = maxTxDataSize - 1000
cfg.DisableBatcher = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"baseFeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000",
"l1FeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000",
"sequencerFeeVaultMinimumWithdrawalAmount": "0x8ac7230489e80000",
"baseFeeVaultWithdrawalNetwork": "remote",
"l1FeeVaultWithdrawalNetwork": "remote",
"sequencerFeeVaultWithdrawalNetwork": "remote",
"baseFeeVaultWithdrawalNetwork": 0,
"l1FeeVaultWithdrawalNetwork": 0,
"sequencerFeeVaultWithdrawalNetwork": 0,
"proxyAdminOwner": "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720",
"finalSystemOwner": "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720",
"superchainConfigGuardian": "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720",
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts-bedrock/deploy-config/hardhat.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@
"proofMaturityDelaySeconds": 12,
"disputeGameFinalityDelaySeconds": 6,
"respectedGameType": 0,
"useFaultProofs": false
"useFaultProofs": false,
"fundDevAccounts": true
}
4 changes: 4 additions & 0 deletions packages/contracts-bedrock/scripts/DeployConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ contract DeployConfig is Script {
address public l2OutputOracleProposer;
address public l2OutputOracleChallenger;
uint256 public finalizationPeriodSeconds;
bool public fundDevAccounts;
address public proxyAdminOwner;
address public baseFeeVaultRecipient;
uint256 public baseFeeVaultMinimumWithdrawalAmount;
address public l1FeeVaultRecipient;
uint256 public l1FeeVaultMinimumWithdrawalAmount;
address public sequencerFeeVaultRecipient;
uint256 public sequencerFeeVaultMinimumWithdrawalAmount;
uint256 public sequencerFeeVaultWithdrawalNetwork;
string public governanceTokenName;
string public governanceTokenSymbol;
address public governanceTokenOwner;
Expand Down Expand Up @@ -95,13 +97,15 @@ contract DeployConfig is Script {
l2OutputOracleProposer = stdJson.readAddress(_json, "$.l2OutputOracleProposer");
l2OutputOracleChallenger = stdJson.readAddress(_json, "$.l2OutputOracleChallenger");
finalizationPeriodSeconds = stdJson.readUint(_json, "$.finalizationPeriodSeconds");
fundDevAccounts = stdJson.readBool(_json, "$.fundDevAccounts");
proxyAdminOwner = stdJson.readAddress(_json, "$.proxyAdminOwner");
baseFeeVaultRecipient = stdJson.readAddress(_json, "$.baseFeeVaultRecipient");
baseFeeVaultMinimumWithdrawalAmount = stdJson.readUint(_json, "$.baseFeeVaultMinimumWithdrawalAmount");
l1FeeVaultRecipient = stdJson.readAddress(_json, "$.l1FeeVaultRecipient");
l1FeeVaultMinimumWithdrawalAmount = stdJson.readUint(_json, "$.l1FeeVaultMinimumWithdrawalAmount");
sequencerFeeVaultRecipient = stdJson.readAddress(_json, "$.sequencerFeeVaultRecipient");
sequencerFeeVaultMinimumWithdrawalAmount = stdJson.readUint(_json, "$.sequencerFeeVaultMinimumWithdrawalAmount");
sequencerFeeVaultWithdrawalNetwork = stdJson.readUint(_json, "$.sequencerFeeVaultWithdrawalNetwork");
governanceTokenName = stdJson.readString(_json, "$.governanceTokenName");
governanceTokenSymbol = stdJson.readString(_json, "$.governanceTokenSymbol");
governanceTokenOwner = stdJson.readAddress(_json, "$.governanceTokenOwner");
Expand Down
79 changes: 62 additions & 17 deletions packages/contracts-bedrock/scripts/L2Genesis.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,35 @@ import { OptimismMintableERC20Factory } from "src/universal/OptimismMintableERC2
import { L1Block } from "src/L2/L1Block.sol";
import { GovernanceToken } from "src/governance/GovernanceToken.sol";
import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

interface IInitializable {
function initialize(address _addr) external;
}

/// @dev The general flow of adding a predeploy is:
/// 1. _setProxies uses vm.etch to set the Proxy.sol deployed bytecode for proxy address `0x420...000` to `0x420...000 + PROXY_COUNT - 1`.
/// 1. _setPredeployProxies uses vm.etch to set the Proxy.sol deployed bytecode for proxy address `0x420...000` to
/// `0x420...000 + PROXY_COUNT - 1`.
/// Additionally, the PROXY_ADMIN_ADDRESS and PROXY_IMPLEMENTATION_ADDRESS storage slots are set for the proxy
/// address.
/// 2. vm.etch sets the deployed bytecode for each predeploy at the implementation address (i.e. `0xc0d3` namespace).
/// 3. The `initialize` method is called at the implementation address with zero/dummy vaules if it exists.
/// 4. The `initialize` method is called at the proxy address with actual vaules if it exists.
/// 2. `vm.etch` sets the deployed bytecode for each predeploy at the implementation address (i.e. `0xc0d3`
/// namespace).
/// 3. The `initialize` method is called at the implementation address with zero/dummy vaules if the method exists.
/// 4. The `initialize` method is called at the proxy address with actual vaules if the method exists.
/// 5. A `require` check to verify the expected implementation address is set for the proxy.
/// @notice The following safety invariants are used when setting state:
/// 1. `vm.getDeployedBytecode` can only be used with `vm.etch` when there are no side
/// effects in the constructor and no immutables in the bytecode.
/// 2. A contract must be deployed using the `new` syntax if there are immutables in the code.
/// Any other side effects from the init code besides setting the immutables must be cleaned up afterwards.
/// 3. A contract is deployed using the `new` syntax because it's not proxied, but still needs to be set
/// at a specific address. Because just deploying a new instance doesn't give us the contract at our desired
/// address,
/// we must use `vm.etch` to set the deployed bytecode, and `vm.store` to set any storage slots. Lastly, we reset
/// the account the contract was initially deployed by so it's not included in the `vm.dumpState`.
/// 3. A contract is deployed using the `new` syntax, however it's not proxied and is still expected to exist at
/// a
/// specific implementation address (i.e. `0xc0d3` namespace). In this case we deploy an instance of the
/// contract
/// using `new` syntax, use `contract.code` to retrieve it's deployed bytecode, `vm.etch` the bytecode at the
/// expected implementation address, and `vm.store` to set any storage slots that are
/// expected to be set after a new deployment. Lastly, we reset the account code and storage slots the contract
/// was initially deployed to so it's not included in the `vm.dumpState`.
contract L2Genesis is Script, Artifacts {
uint256 constant PROXY_COUNT = 2048;
uint256 constant PRECOMPILE_COUNT = 256;
Expand All @@ -54,6 +60,20 @@ contract L2Genesis is Script, Artifacts {
/// @notice The storage slot that holds the address of the owner.
/// @dev `bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)`
bytes32 internal constant PROXY_ADMIN_ADDRESS = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
uint80 internal constant DEV_ACCOUNT_FUND_AMT = 10_000 ether;
/// @notice Default Anvil dev accounts. Only funded if `cfg.fundDevAccounts == true`.
address[10] internal devAccounts = [
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266,
0x70997970C51812dc3A010C7d01b50e0d17dc79C8,
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC,
0x90F79bf6EB2c4f870365E785982E1f101E93b906,
0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65,
0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc,
0x976EA74026E726554dB657fA54763abd0C3a0aa9,
0x14dC79964da2C08b23698B3D3cc7Ca32193d9955,
0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f,
0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
];

string internal outfile;

Expand All @@ -77,9 +97,13 @@ contract L2Genesis is Script, Artifacts {
/// to generate a L2 genesis alloc.
/// @notice The alloc object is sorted numerically by address.
function run() public {
_setPrecompiles();
_setProxies();
_setImplementations();
_dealEthToPrecompiles();
_setPredeployProxies();
_setPredeployImplementations();

if (cfg.fundDevAccounts()) {
_fundDevAccounts();
}

/// Reset so its not included state dump
vm.etch(address(cfg), "");
Expand All @@ -90,7 +114,7 @@ contract L2Genesis is Script, Artifacts {

/// @notice Give all of the precompiles 1 wei so that they are
/// not considered empty accounts.
function _setPrecompiles() internal {
function _dealEthToPrecompiles() internal {
for (uint256 i; i < PRECOMPILE_COUNT; i++) {
vm.deal(address(uint160(i)), 1);
}
Expand All @@ -100,7 +124,7 @@ contract L2Genesis is Script, Artifacts {
/// The Proxy bytecode should be set. All proxied predeploys should have
/// the 1967 admin slot set to the ProxyAdmin predeploy. All defined predeploys
/// should have their implementations set.
function _setProxies() internal {
function _setPredeployProxies() internal {
bytes memory code = vm.getDeployedCode("Proxy.sol:Proxy");
uint160 prefix = uint160(0x420) << 148;

Expand Down Expand Up @@ -129,7 +153,7 @@ contract L2Genesis is Script, Artifacts {
/// @notice LEGACY_ERC20_ETH is not being predeployed since it's been deprecated.
/// @dev Sets all the implementations for the predeploy proxies. For contracts without proxies,
/// sets the deployed bytecode at their expected predeploy address.
function _setImplementations() internal {
function _setPredeployImplementations() internal {
_setLegacyMessagePasser();
_setDeployerWhitelist();
_setWETH9();
Expand Down Expand Up @@ -228,7 +252,7 @@ contract L2Genesis is Script, Artifacts {
SequencerFeeVault vault = new SequencerFeeVault({
_recipient: cfg.sequencerFeeVaultRecipient(),
_minWithdrawalAmount: cfg.sequencerFeeVaultMinimumWithdrawalAmount(),
_withdrawalNetwork: FeeVault.WithdrawalNetwork.L1
_withdrawalNetwork: FeeVault.WithdrawalNetwork(cfg.sequencerFeeVaultWithdrawalNetwork())
});

address impl = _predeployToCodeNamespace(Predeploys.SEQUENCER_FEE_WALLET);
Expand Down Expand Up @@ -350,7 +374,7 @@ contract L2Genesis is Script, Artifacts {
/// @notice There isn't a good way to know if the resulting revering is due to abi mismatch
/// or because it's already been initialized
function _verifyCantReinitialize(address _contract, address _arg) internal {
vm.expectRevert();
vm.expectRevert("Initializable: contract is already initialized");
IInitializable(_contract).initialize(_arg);
}

Expand All @@ -363,6 +387,15 @@ contract L2Genesis is Script, Artifacts {
vm.ffi(commands);
}

function _fundDevAccounts() internal {
for (uint256 i; i < devAccounts.length; i++) {
console.log("Funding dev account %s with %s ETH", devAccounts[i], DEV_ACCOUNT_FUND_AMT / 1e18);
vm.deal(devAccounts[i], DEV_ACCOUNT_FUND_AMT);
}

_checkDevAccountsFunded();
}

//////////////////////////////////////////////////////
/// Post Checks
//////////////////////////////////////////////////////
Expand All @@ -384,4 +417,16 @@ contract L2Genesis is Script, Artifacts {
_verifyCantReinitialize(_impl, address(0));
_verifyCantReinitialize(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY, Predeploys.L2_STANDARD_BRIDGE);
}

function _checkDevAccountsFunded() internal view {
for (uint256 i; i < devAccounts.length; i++) {
if (devAccounts[i].balance != DEV_ACCOUNT_FUND_AMT) {
revert(
string.concat(
"Dev account not funded with expected amount of ETH: ", Strings.toHexString(devAccounts[i])
)
);
}
}
}
}
22 changes: 11 additions & 11 deletions packages/contracts-bedrock/snapshots/state-diff/Kontrol-Deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@
"newValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"previousValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"reverted": false,
"slot": "0x0000000000000000000000000000000000000000000000000000000000000039"
"slot": "0x000000000000000000000000000000000000000000000000000000000000003a"
}
],
"value": 0
Expand All @@ -1980,7 +1980,7 @@
"newValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"previousValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"reverted": false,
"slot": "0x000000000000000000000000000000000000000000000000000000000000003a"
"slot": "0x000000000000000000000000000000000000000000000000000000000000003b"
}
],
"value": 0
Expand Down Expand Up @@ -2441,7 +2441,7 @@
"newValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"previousValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"reverted": false,
"slot": "0x0000000000000000000000000000000000000000000000000000000000000039"
"slot": "0x000000000000000000000000000000000000000000000000000000000000003a"
}
],
"value": 0
Expand Down Expand Up @@ -2519,7 +2519,7 @@
"newValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"previousValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"reverted": false,
"slot": "0x000000000000000000000000000000000000000000000000000000000000003a"
"slot": "0x000000000000000000000000000000000000000000000000000000000000003b"
}
],
"value": 0
Expand Down Expand Up @@ -6011,7 +6011,7 @@
"newValue": "0x0000000000000000000000000000000000000000000000000000000000000834",
"previousValue": "0x0000000000000000000000000000000000000000000000000000000000000834",
"reverted": false,
"slot": "0x000000000000000000000000000000000000000000000000000000000000002a"
"slot": "0x000000000000000000000000000000000000000000000000000000000000002b"
}
],
"value": 0
Expand All @@ -6037,7 +6037,7 @@
"newValue": "0x00000000000000000000000000000000000000000000000000000000000f4240",
"previousValue": "0x00000000000000000000000000000000000000000000000000000000000f4240",
"reverted": false,
"slot": "0x000000000000000000000000000000000000000000000000000000000000002b"
"slot": "0x000000000000000000000000000000000000000000000000000000000000002c"
}
],
"value": 0
Expand All @@ -6063,7 +6063,7 @@
"newValue": "0x00000000000000000000000000000000000000000000000000000000017d7840",
"previousValue": "0x00000000000000000000000000000000000000000000000000000000017d7840",
"reverted": false,
"slot": "0x0000000000000000000000000000000000000000000000000000000000000028"
"slot": "0x0000000000000000000000000000000000000000000000000000000000000029"
}
],
"value": 0
Expand Down Expand Up @@ -6772,7 +6772,7 @@
"newValue": "0x0000000000000000000000000000000000000000000000000000000000000834",
"previousValue": "0x0000000000000000000000000000000000000000000000000000000000000834",
"reverted": false,
"slot": "0x000000000000000000000000000000000000000000000000000000000000002a"
"slot": "0x000000000000000000000000000000000000000000000000000000000000002b"
}
],
"value": 0
Expand Down Expand Up @@ -6850,7 +6850,7 @@
"newValue": "0x00000000000000000000000000000000000000000000000000000000000f4240",
"previousValue": "0x00000000000000000000000000000000000000000000000000000000000f4240",
"reverted": false,
"slot": "0x000000000000000000000000000000000000000000000000000000000000002b"
"slot": "0x000000000000000000000000000000000000000000000000000000000000002c"
}
],
"value": 0
Expand Down Expand Up @@ -7006,7 +7006,7 @@
"newValue": "0x00000000000000000000000000000000000000000000000000000000017d7840",
"previousValue": "0x00000000000000000000000000000000000000000000000000000000017d7840",
"reverted": false,
"slot": "0x0000000000000000000000000000000000000000000000000000000000000028"
"slot": "0x0000000000000000000000000000000000000000000000000000000000000029"
}
],
"value": 0
Expand Down Expand Up @@ -7162,7 +7162,7 @@
"newValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"previousValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
"reverted": false,
"slot": "0x0000000000000000000000000000000000000000000000000000000000000038"
"slot": "0x0000000000000000000000000000000000000000000000000000000000000039"
}
],
"value": 0
Expand Down

0 comments on commit bd44da1

Please sign in to comment.