Skip to content

TaikoL2

TaikoL2 is a core smart contract for the Taiko Alethia rollup, responsible for cross-layer state synchronization, gas pricing via EIP-1559, and bridging support. It ensures L2 remains in sync with L1 and facilitates secure message verification.


Features

  • Anchor L1 State to L2: Ensures L2 block validity by referencing L1 state.
  • EIP-1559 Gas Pricing: Dynamically adjusts base fees and gas targets based on L1 data.
  • Cross-Layer Bridging: Enables state root anchoring for message verification between L1 and L2.
  • Optimized Block Processing: Ensures gas-efficient state transitions.

Contract Methods

anchorV2

Anchors L1 block details to L2, ensuring state synchronization.

ParameterTypeDescription
_anchorBlockIduint256L1 block ID to anchor.
_anchorStateRootbytes32State root of the specified L1 block.
_parentGasUseduint256Gas used in the parent block.
_baseFeeConfiguint256Configuration for base fee calculation.

Returns:

  • Updates publicInputHash and synchronizes chain data.
  • Computes gas parameters using getBasefeeV2.

getBasefeeV2

Calculates EIP-1559 base fee and updates gas parameters.

ParameterTypeDescription
_parentGasUseduint256Gas used in the parent block.
_baseFeeConfiguint256Configuration for EIP-1559 calculations.

Returns:

Return ValueTypeDescription
basefee_uint256Computed base fee per gas.
newGasTarget_uint256Updated gas target.
newGasExcess_uint256Updated gas excess.

Technical Details:

  • Uses LibEIP1559.calc1559BaseFee to compute the new base fee.
  • Adjusts gas targets dynamically using LibEIP1559.adjustExcess.

getBlockHash

Retrieves the block hash for a given block ID.

ParameterTypeDescription
_blockIduint256ID of the block to retrieve.

Returns:

Return ValueTypeDescription
blockHash_bytes32Hash of the requested block.

Technical Note:

  • If the block is older than 256 blocks, _blockhashes mapping is used instead of blockhash().

Events

Anchored

Emitted when L1 block details are successfully anchored to L2.

ParameterTypeDescription
parentHashbytes32Hash of the parent block.
parentGasExcessuint256Gas excess used for base fee calculations.

EIP1559Update

Emitted when gas parameters are updated.

ParameterTypeDescription
oldGasTargetuint256Previous gas target.
newGasTargetuint256Updated gas target.
oldGasExcessuint256Previous gas excess.
newGasExcessuint256Updated gas excess.
basefeeuint256Computed base fee.

State Variables

VariableTypeDescription
publicInputHashbytes32Ensures integrity of public inputs for block verification.
parentGasExcessuint256Tracks gas usage exceeding the target for fee adjustments.
lastSyncedBlockuint256Stores the most recent L1 block ID synced with L2.
l1ChainIduint256Chain ID of L1 (Ethereum).

Design Considerations

  1. State Synchronization

    • Ensures L1-L2 consistency via anchoring.
    • Uses public input hash validation to prevent state mismatches.
  2. Gas Efficiency

    • Implements EIP-1559 dynamic gas pricing.
    • Optimizes L2 execution costs based on L1 gas usage.
  3. Bridging & Interoperability

    • Stores verified state roots to facilitate cross-layer message verification.
    • Ensures compatibility with bridging mechanisms.