github.com/ethereum-optimism/optimism@v1.7.2/op-node/rollup/output_root.go (about) 1 package rollup 2 3 import ( 4 "errors" 5 6 "github.com/ethereum-optimism/optimism/op-bindings/bindings" 7 "github.com/ethereum-optimism/optimism/op-service/eth" 8 ) 9 10 var ErrNilProof = errors.New("output root proof is nil") 11 12 // ComputeL2OutputRoot computes the L2 output root by hashing an output root proof. 13 func ComputeL2OutputRoot(proofElements *bindings.TypesOutputRootProof) (eth.Bytes32, error) { 14 if proofElements == nil { 15 return eth.Bytes32{}, ErrNilProof 16 } 17 18 if eth.Bytes32(proofElements.Version) != eth.OutputVersionV0 { 19 return eth.Bytes32{}, errors.New("unsupported output root version") 20 } 21 l2Output := eth.OutputV0{ 22 StateRoot: eth.Bytes32(proofElements.StateRoot), 23 MessagePasserStorageRoot: proofElements.MessagePasserStorageRoot, 24 BlockHash: proofElements.LatestBlockhash, 25 } 26 return eth.OutputRoot(&l2Output), nil 27 } 28 29 func ComputeL2OutputRootV0(block eth.BlockInfo, storageRoot [32]byte) (eth.Bytes32, error) { 30 stateRoot := block.Root() 31 l2Output := eth.OutputV0{ 32 StateRoot: eth.Bytes32(stateRoot), 33 MessagePasserStorageRoot: storageRoot, 34 BlockHash: block.Hash(), 35 } 36 return eth.OutputRoot(&l2Output), nil 37 }