Skip to content
On this page

S2C11: Pre-Mint + RLP

1. Problem

Similar to S1C12, an RLP-encoded block header must be provided. However, a preMintFlag mechanism has been added — a commitment must be pre-submitted, and then the block header must be submitted within a specified time window.

2. Cause

The contract implements a Commit-Reveal pattern: first call preMintFlag to lock in the intent, then within a certain timeframe (within 256 blocks) submit the correct RLP block header to prove that the specified number of blocks have been "waited" for.

3. Solution

  1. Call preMintFlag multiple times (recommended 10 times to maximize success rate)
  2. Wait for at least 2 blocks to be mined
  3. Obtain the complete header information of the 2nd previous block from the current block number
  4. Use correct RLP encoding
  5. Submit within the 256-block window
bash
# Pre-commit (multiple times)
for i in $(seq 1 10); do
  cast send $CHALLENGE "preMintFlag()" --private-key $PK --rpc-url $RPC
done

# Wait 2 blocks
sleep 10

# Submit block header
BLOCK_NUM=$(($CURRENT_BLOCK - 2))
BLOCK_HEADER=$(cast rlp $BLOCK_NUM --rpc-url $RPC)
cast send $CHALLENGE "mintFlag(bytes)" $BLOCK_HEADER --private-key $PK

4. Pitfalls Encountered

RLP encoding correctness: The RLP encoding of OP Mainnet block headers may differ from standard Ethereum due to the Bedrock upgrade.

Commit-Reveal time window: Must complete within 256 blocks, and must wait at least 2 blocks.

Pre-mint count: A single preMintFlag may not be sufficient to lock in the correct block range; multiple calls improve the success rate.

5. Pitfall Causes

OP's block structure has minor differences from Ethereum mainnet (e.g., the difficulty field may differ on OP). The RLP encoder needs to correctly handle all 15+ fields of OP blocks.

6. How to Resolve

  • Use ethers.utils.RLP.encode() or cast rlp for RLP encoding
  • Confirm the block is within the range [block.number - 256, block.number - 2]
  • Call preMintFlag 10 times to ensure sufficient time window coverage

7. Key Technical Points

PointDescription
Commit-RevealTwo-phase commit pattern that prevents forward-computation attacks
RLP encodingEthereum's standard serialization; the 15+ fields of a block header require precise encoding
OP Bedrock blocksOptimism's Bedrock upgrade changed the block format
Time window managementpreMint + wait + mint must be within the correct block range

Built with AiAda