Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
26868d3a
Commit
26868d3a
authored
Mar 15, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use binding for `ComputeL2OutputRoot`
parent
90ade85a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
24 deletions
+36
-24
api.go
op-node/node/api.go
+11
-1
output_root.go
op-node/rollup/output_root.go
+15
-18
differential-testing.go
...rock/scripts/differential-testing/differential-testing.go
+4
-2
utils.go
...s/contracts-bedrock/scripts/differential-testing/utils.go
+6
-3
No files found.
op-node/node/api.go
View file @
26868d3a
...
...
@@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"
...
...
@@ -114,7 +115,16 @@ func (n *nodeAPI) OutputAtBlock(ctx context.Context, number hexutil.Uint64) (*et
}
var
l2OutputRootVersion
eth
.
Bytes32
// it's zero for now
l2OutputRoot
:=
rollup
.
ComputeL2OutputRoot
(
l2OutputRootVersion
,
head
.
Root
(),
proof
.
StorageHash
,
head
.
Hash
())
l2OutputRoot
,
err
:=
rollup
.
ComputeL2OutputRoot
(
&
bindings
.
TypesOutputRootProof
{
Version
:
l2OutputRootVersion
,
StateRoot
:
head
.
Root
(),
MessagePasserStorageRoot
:
proof
.
StorageHash
,
LatestBlockhash
:
head
.
Hash
(),
})
if
err
!=
nil
{
n
.
log
.
Error
(
"Error computing L2 output root, nil ptr passed to hashing function"
)
return
nil
,
err
}
return
&
eth
.
OutputResponse
{
Version
:
l2OutputRootVersion
,
...
...
op-node/rollup/output_root.go
View file @
26868d3a
package
rollup
import
(
"errors"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
// ComputeL2OutputRoot computes the L2 output root
func
ComputeL2OutputRoot
(
l2OutputRootVersion
eth
.
Bytes32
,
blockRoot
common
.
Hash
,
storageRoot
common
.
Hash
,
blockHash
common
.
Hash
)
eth
.
Bytes32
{
digest
:=
crypto
.
Keccak256Hash
(
l2OutputRootVersion
[
:
],
blockRoot
.
Bytes
(),
storageRoot
[
:
],
blockHash
.
Bytes
(),
)
return
eth
.
Bytes32
(
digest
)
}
var
NilProof
=
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
{},
NilProof
}
// HashOutputRootProof computes the hash of the output root proof
func
HashOutputRootProof
(
proof
*
bindings
.
TypesOutputRootProof
)
eth
.
Bytes32
{
return
ComputeL2OutputRoot
(
proof
.
Version
,
proof
.
StateRoot
,
proof
.
MessagePasserStorageRoot
,
proof
.
LatestBlockhash
,
digest
:=
crypto
.
Keccak256Hash
(
proofElements
.
Version
[
:
],
proofElements
.
StateRoot
[
:
],
proofElements
.
MessagePasserStorageRoot
[
:
],
proofElements
.
LatestBlockhash
[
:
],
)
return
eth
.
Bytes32
(
digest
),
nil
}
packages/contracts-bedrock/scripts/differential-testing/differential-testing.go
View file @
26868d3a
...
...
@@ -221,7 +221,8 @@ func main() {
latestBlockHash
:=
common
.
HexToHash
(
args
[
4
])
// Hash the output root proof
hash
:=
hashOutputRootProof
(
version
,
stateRoot
,
messagePasserStorageRoot
,
latestBlockHash
)
hash
,
err
:=
hashOutputRootProof
(
version
,
stateRoot
,
messagePasserStorageRoot
,
latestBlockHash
)
checkErr
(
err
,
"Error hashing output root proof"
)
// Pack hash
packed
,
err
:=
fixedBytesArgs
.
Pack
(
&
hash
)
...
...
@@ -289,7 +290,8 @@ func main() {
checkErr
(
state
.
Prove
(
predeploys
.
L2ToL1MessagePasserAddr
.
Bytes
(),
0
,
&
proof
),
"Error getting proof"
)
// Get the output root
outputRoot
:=
hashOutputRootProof
(
common
.
Hash
{},
world
.
Hash
(),
state
.
Hash
(),
common
.
Hash
{})
outputRoot
,
err
:=
hashOutputRootProof
(
common
.
Hash
{},
world
.
Hash
(),
state
.
Hash
(),
common
.
Hash
{})
checkErr
(
err
,
"Error hashing output root proof"
)
// Pack the output
output
:=
struct
{
...
...
packages/contracts-bedrock/scripts/differential-testing/utils.go
View file @
26868d3a
...
...
@@ -64,14 +64,17 @@ func hashWithdrawal(nonce *big.Int, sender common.Address, target common.Address
}
// hashOutputRootProof hashes an output root proof.
func
hashOutputRootProof
(
version
common
.
Hash
,
stateRoot
common
.
Hash
,
messagePasserStorageRoot
common
.
Hash
,
latestBlockHash
common
.
Hash
)
common
.
Hash
{
proof
:=
bindings
.
TypesOutputRootProof
{
func
hashOutputRootProof
(
version
common
.
Hash
,
stateRoot
common
.
Hash
,
messagePasserStorageRoot
common
.
Hash
,
latestBlockHash
common
.
Hash
)
(
common
.
Hash
,
error
)
{
hash
,
err
:=
rollup
.
ComputeL2OutputRoot
(
&
bindings
.
TypesOutputRootProof
{
Version
:
version
,
StateRoot
:
stateRoot
,
MessagePasserStorageRoot
:
messagePasserStorageRoot
,
LatestBlockhash
:
latestBlockHash
,
})
if
err
!=
nil
{
return
common
.
Hash
{},
err
}
return
common
.
Hash
(
rollup
.
HashOutputRootProof
(
&
proof
))
return
common
.
Hash
(
hash
),
nil
}
// makeDepositTx creates a deposit transaction type.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment