ethereum-optimism / op-geth

GNU Lesser General Public License v3.0
255 stars 654 forks source link

Snap Sync: DepositNonce Data Correction #237

Closed axelKingsley closed 4 months ago

axelKingsley commented 4 months ago

What

Enables snap sync with untrusted parties by supplying a data source for DepositNonces.

Prior to Canyon Hard Fork, Deposit Nonces were not cryptographically verified. This PR supplies the Deposit Nonce data for most Superchain Registered Chains for the affected time period, and implements a correction function.

Why

We want Snap Sync to work without concern about trusting your peers. Today, a user could supply blocks with incorrect Deposit Nonces, and Snap Sync would not have a way of verifying. With this PR, nodes will be able to repair blocks with incorrect data, closing the attack vector.

How

If at any point the deposit nonces are not as expected, warnings are emitted to logs. More detailed activity is emitted to Trace Logs.

Testing

A unit test set is included to demonstrate that Nonces are Corrected when they are wrong.

I also Snap Synced Goerli with this code (a version with louder logs), and observed that over the range of blocks, Deposit Nonces were all checked.

Extending

This PR includes the required data for [OP, Base, Lyra, Mode, Orderly, Zora] Mainnet, as well as OP Goerli. To extend this correction to more chains, all that is required is that a new gob be checked into the data directory.

The file format created by the receipt reference tool should be used, as each gob is prefixed by its chainID, which is used to only load required files, keeping memory low.