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