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
b2f33d71
Unverified
Commit
b2f33d71
authored
Apr 13, 2023
by
OptimismBot
Committed by
GitHub
Apr 13, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5433 from ethereum-optimism/aj/fpp-compute-output-root
op-program: Verify L2 output root
parents
a6e2b97f
9f62a1f8
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
180 additions
and
46 deletions
+180
-46
api.go
op-node/node/api.go
+1
-7
output_root.go
op-node/rollup/output_root.go
+10
-0
driver.go
op-program/client/driver/driver.go
+22
-5
driver_test.go
op-program/client/driver/driver_test.go
+30
-0
engine.go
op-program/client/l2/engine.go
+14
-0
main.go
op-program/host/cmd/main.go
+9
-1
main_test.go
op-program/host/cmd/main_test.go
+24
-2
config.go
op-program/host/config/config.go
+12
-1
config_test.go
op-program/host/config/config_test.go
+41
-17
flags.go
op-program/host/flags/flags.go
+16
-11
l2.go
op-program/host/l2/l2.go
+1
-2
No files found.
op-node/node/api.go
View file @
b2f33d71
...
@@ -9,7 +9,6 @@ import (
...
@@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"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-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup"
...
@@ -115,12 +114,7 @@ func (n *nodeAPI) OutputAtBlock(ctx context.Context, number hexutil.Uint64) (*et
...
@@ -115,12 +114,7 @@ func (n *nodeAPI) OutputAtBlock(ctx context.Context, number hexutil.Uint64) (*et
}
}
var
l2OutputRootVersion
eth
.
Bytes32
// it's zero for now
var
l2OutputRootVersion
eth
.
Bytes32
// it's zero for now
l2OutputRoot
,
err
:=
rollup
.
ComputeL2OutputRoot
(
&
bindings
.
TypesOutputRootProof
{
l2OutputRoot
,
err
:=
rollup
.
ComputeL2OutputRootV0
(
head
,
proof
.
StorageHash
)
Version
:
l2OutputRootVersion
,
StateRoot
:
head
.
Root
(),
MessagePasserStorageRoot
:
proof
.
StorageHash
,
LatestBlockhash
:
head
.
Hash
(),
})
if
err
!=
nil
{
if
err
!=
nil
{
n
.
log
.
Error
(
"Error computing L2 output root, nil ptr passed to hashing function"
)
n
.
log
.
Error
(
"Error computing L2 output root, nil ptr passed to hashing function"
)
return
nil
,
err
return
nil
,
err
...
...
op-node/rollup/output_root.go
View file @
b2f33d71
...
@@ -24,3 +24,13 @@ func ComputeL2OutputRoot(proofElements *bindings.TypesOutputRootProof) (eth.Byte
...
@@ -24,3 +24,13 @@ func ComputeL2OutputRoot(proofElements *bindings.TypesOutputRootProof) (eth.Byte
)
)
return
eth
.
Bytes32
(
digest
),
nil
return
eth
.
Bytes32
(
digest
),
nil
}
}
func
ComputeL2OutputRootV0
(
block
eth
.
BlockInfo
,
storageRoot
[
32
]
byte
)
(
eth
.
Bytes32
,
error
)
{
var
l2OutputRootVersion
eth
.
Bytes32
// it's zero for now
return
ComputeL2OutputRoot
(
&
bindings
.
TypesOutputRootProof
{
Version
:
l2OutputRootVersion
,
StateRoot
:
block
.
Root
(),
MessagePasserStorageRoot
:
storageRoot
,
LatestBlockhash
:
block
.
Hash
(),
})
}
op-program/client/driver/driver.go
View file @
b2f33d71
...
@@ -18,17 +18,24 @@ type Derivation interface {
...
@@ -18,17 +18,24 @@ type Derivation interface {
SafeL2Head
()
eth
.
L2BlockRef
SafeL2Head
()
eth
.
L2BlockRef
}
}
type
L2Source
interface
{
derive
.
Engine
L2OutputRoot
()
(
eth
.
Bytes32
,
error
)
}
type
Driver
struct
{
type
Driver
struct
{
logger
log
.
Logger
logger
log
.
Logger
pipeline
Derivation
pipeline
Derivation
l2OutputRoot
func
()
(
eth
.
Bytes32
,
error
)
}
}
func
NewDriver
(
logger
log
.
Logger
,
cfg
*
rollup
.
Config
,
l1Source
derive
.
L1Fetcher
,
l2Source
derive
.
Engin
e
)
*
Driver
{
func
NewDriver
(
logger
log
.
Logger
,
cfg
*
rollup
.
Config
,
l1Source
derive
.
L1Fetcher
,
l2Source
L2Sourc
e
)
*
Driver
{
pipeline
:=
derive
.
NewDerivationPipeline
(
logger
,
cfg
,
l1Source
,
l2Source
,
metrics
.
NoopMetrics
)
pipeline
:=
derive
.
NewDerivationPipeline
(
logger
,
cfg
,
l1Source
,
l2Source
,
metrics
.
NoopMetrics
)
pipeline
.
Reset
()
pipeline
.
Reset
()
return
&
Driver
{
return
&
Driver
{
logger
:
logger
,
logger
:
logger
,
pipeline
:
pipeline
,
pipeline
:
pipeline
,
l2OutputRoot
:
l2Source
.
L2OutputRoot
,
}
}
}
}
...
@@ -51,3 +58,13 @@ func (d *Driver) Step(ctx context.Context) error {
...
@@ -51,3 +58,13 @@ func (d *Driver) Step(ctx context.Context) error {
func
(
d
*
Driver
)
SafeHead
()
eth
.
L2BlockRef
{
func
(
d
*
Driver
)
SafeHead
()
eth
.
L2BlockRef
{
return
d
.
pipeline
.
SafeL2Head
()
return
d
.
pipeline
.
SafeL2Head
()
}
}
func
(
d
*
Driver
)
ValidateClaim
(
claimedOutputRoot
eth
.
Bytes32
)
bool
{
outputRoot
,
err
:=
d
.
l2OutputRoot
()
if
err
!=
nil
{
d
.
logger
.
Info
(
"Failed to calculate L2 output root"
,
"err"
,
err
)
return
false
}
d
.
logger
.
Info
(
"Derivation complete"
,
"head"
,
d
.
SafeHead
(),
"output"
,
outputRoot
,
"claim"
,
claimedOutputRoot
)
return
claimedOutputRoot
==
outputRoot
}
op-program/client/driver/driver_test.go
View file @
b2f33d71
...
@@ -45,6 +45,36 @@ func TestNoError(t *testing.T) {
...
@@ -45,6 +45,36 @@ func TestNoError(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
}
}
func
TestValidateClaim
(
t
*
testing
.
T
)
{
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
driver
:=
createDriver
(
t
,
io
.
EOF
)
expected
:=
eth
.
Bytes32
{
0x11
}
driver
.
l2OutputRoot
=
func
()
(
eth
.
Bytes32
,
error
)
{
return
expected
,
nil
}
valid
:=
driver
.
ValidateClaim
(
expected
)
require
.
True
(
t
,
valid
)
})
t
.
Run
(
"Invalid"
,
func
(
t
*
testing
.
T
)
{
driver
:=
createDriver
(
t
,
io
.
EOF
)
driver
.
l2OutputRoot
=
func
()
(
eth
.
Bytes32
,
error
)
{
return
eth
.
Bytes32
{
0x22
},
nil
}
valid
:=
driver
.
ValidateClaim
(
eth
.
Bytes32
{
0x11
})
require
.
False
(
t
,
valid
)
})
t
.
Run
(
"Error"
,
func
(
t
*
testing
.
T
)
{
driver
:=
createDriver
(
t
,
io
.
EOF
)
driver
.
l2OutputRoot
=
func
()
(
eth
.
Bytes32
,
error
)
{
return
eth
.
Bytes32
{},
errors
.
New
(
"boom"
)
}
valid
:=
driver
.
ValidateClaim
(
eth
.
Bytes32
{
0x11
})
require
.
False
(
t
,
valid
)
})
}
func
createDriver
(
t
*
testing
.
T
,
derivationResult
error
)
*
Driver
{
func
createDriver
(
t
*
testing
.
T
,
derivationResult
error
)
*
Driver
{
derivation
:=
&
stubDerivation
{
nextErr
:
derivationResult
}
derivation
:=
&
stubDerivation
{
nextErr
:
derivationResult
}
return
&
Driver
{
return
&
Driver
{
...
...
op-program/client/l2/engine.go
View file @
b2f33d71
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
...
@@ -33,6 +34,19 @@ func NewOracleEngine(rollupCfg *rollup.Config, logger log.Logger, backend engine
...
@@ -33,6 +34,19 @@ func NewOracleEngine(rollupCfg *rollup.Config, logger log.Logger, backend engine
}
}
}
}
func
(
o
*
OracleEngine
)
L2OutputRoot
()
(
eth
.
Bytes32
,
error
)
{
outBlock
:=
o
.
backend
.
CurrentHeader
()
stateDB
,
err
:=
o
.
backend
.
StateAt
(
outBlock
.
Root
)
if
err
!=
nil
{
return
eth
.
Bytes32
{},
fmt
.
Errorf
(
"failed to open L2 state db at block %s: %w"
,
outBlock
.
Hash
(),
err
)
}
withdrawalsTrie
,
err
:=
stateDB
.
StorageTrie
(
predeploys
.
L2ToL1MessagePasserAddr
)
if
err
!=
nil
{
return
eth
.
Bytes32
{},
fmt
.
Errorf
(
"withdrawals trie unavailable at block %v: %w"
,
outBlock
.
Hash
(),
err
)
}
return
rollup
.
ComputeL2OutputRootV0
(
eth
.
HeaderBlockInfo
(
outBlock
),
withdrawalsTrie
.
Hash
())
}
func
(
o
*
OracleEngine
)
GetPayload
(
ctx
context
.
Context
,
payloadId
eth
.
PayloadID
)
(
*
eth
.
ExecutionPayload
,
error
)
{
func
(
o
*
OracleEngine
)
GetPayload
(
ctx
context
.
Context
,
payloadId
eth
.
PayloadID
)
(
*
eth
.
ExecutionPayload
,
error
)
{
return
o
.
api
.
GetPayloadV1
(
ctx
,
payloadId
)
return
o
.
api
.
GetPayloadV1
(
ctx
,
payloadId
)
}
}
...
...
op-program/host/cmd/main.go
View file @
b2f33d71
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"time"
"time"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
cldr
"github.com/ethereum-optimism/optimism/op-program/client/driver"
cldr
"github.com/ethereum-optimism/optimism/op-program/client/driver"
"github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum-optimism/optimism/op-program/host/config"
...
@@ -41,6 +42,10 @@ var VersionWithMeta = func() string {
...
@@ -41,6 +42,10 @@ var VersionWithMeta = func() string {
return
v
return
v
}()
}()
var
(
ErrClaimNotValid
=
errors
.
New
(
"invalid claim"
)
)
func
main
()
{
func
main
()
{
args
:=
os
.
Args
args
:=
os
.
Args
err
:=
run
(
args
,
FaultProofProgram
)
err
:=
run
(
args
,
FaultProofProgram
)
...
@@ -124,6 +129,9 @@ func FaultProofProgram(logger log.Logger, cfg *config.Config) error {
...
@@ -124,6 +129,9 @@ func FaultProofProgram(logger log.Logger, cfg *config.Config) error {
return
err
return
err
}
}
}
}
logger
.
Info
(
"Derivation complete"
,
"head"
,
d
.
SafeHead
())
claim
:=
cfg
.
L2Claim
if
!
d
.
ValidateClaim
(
eth
.
Bytes32
(
claim
))
{
return
ErrClaimNotValid
}
return
nil
return
nil
}
}
op-program/host/cmd/main_test.go
View file @
b2f33d71
...
@@ -16,6 +16,7 @@ import (
...
@@ -16,6 +16,7 @@ import (
// Use HexToHash(...).Hex() to ensure the strings are the correct length for a hash
// Use HexToHash(...).Hex() to ensure the strings are the correct length for a hash
var
l1HeadValue
=
common
.
HexToHash
(
"0x111111"
)
.
Hex
()
var
l1HeadValue
=
common
.
HexToHash
(
"0x111111"
)
.
Hex
()
var
l2HeadValue
=
common
.
HexToHash
(
"0x222222"
)
.
Hex
()
var
l2HeadValue
=
common
.
HexToHash
(
"0x222222"
)
.
Hex
()
var
l2ClaimValue
=
common
.
HexToHash
(
"0x333333"
)
.
Hex
()
func
TestLogLevel
(
t
*
testing
.
T
)
{
func
TestLogLevel
(
t
*
testing
.
T
)
{
t
.
Run
(
"RejectInvalid"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"RejectInvalid"
,
func
(
t
*
testing
.
T
)
{
...
@@ -34,7 +35,12 @@ func TestLogLevel(t *testing.T) {
...
@@ -34,7 +35,12 @@ func TestLogLevel(t *testing.T) {
func
TestDefaultCLIOptionsMatchDefaultConfig
(
t
*
testing
.
T
)
{
func
TestDefaultCLIOptionsMatchDefaultConfig
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgs
())
cfg
:=
configForArgs
(
t
,
addRequiredArgs
())
defaultCfg
:=
config
.
NewConfig
(
&
chaincfg
.
Goerli
,
"genesis.json"
,
common
.
HexToHash
(
l1HeadValue
),
common
.
HexToHash
(
l2HeadValue
))
defaultCfg
:=
config
.
NewConfig
(
&
chaincfg
.
Goerli
,
"genesis.json"
,
common
.
HexToHash
(
l1HeadValue
),
common
.
HexToHash
(
l2HeadValue
),
common
.
HexToHash
(
l2ClaimValue
))
require
.
Equal
(
t
,
defaultCfg
,
cfg
)
require
.
Equal
(
t
,
defaultCfg
,
cfg
)
}
}
...
@@ -167,11 +173,26 @@ func TestL1RPCKind(t *testing.T) {
...
@@ -167,11 +173,26 @@ func TestL1RPCKind(t *testing.T) {
// Offline support will be added later, but for now it just bails out with an error
// Offline support will be added later, but for now it just bails out with an error
func
TestOfflineModeNotSupported
(
t
*
testing
.
T
)
{
func
TestOfflineModeNotSupported
(
t
*
testing
.
T
)
{
logger
:=
log
.
New
()
logger
:=
log
.
New
()
cfg
:=
config
.
NewConfig
(
&
chaincfg
.
Goerli
,
"genesis.json"
,
common
.
HexToHash
(
l1HeadValue
),
common
.
HexToHash
(
l2HeadValue
))
cfg
:=
config
.
NewConfig
(
&
chaincfg
.
Goerli
,
"genesis.json"
,
common
.
HexToHash
(
l1HeadValue
),
common
.
HexToHash
(
l2HeadValue
)
,
common
.
HexToHash
(
l2ClaimValue
)
)
err
:=
FaultProofProgram
(
logger
,
cfg
)
err
:=
FaultProofProgram
(
logger
,
cfg
)
require
.
ErrorContains
(
t
,
err
,
"offline mode not supported"
)
require
.
ErrorContains
(
t
,
err
,
"offline mode not supported"
)
}
}
func
TestL2Claim
(
t
*
testing
.
T
)
{
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag l2.claim is required"
,
addRequiredArgsExcept
(
"--l2.claim"
))
})
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
replaceRequiredArg
(
"--l2.claim"
,
l2ClaimValue
))
require
.
EqualValues
(
t
,
common
.
HexToHash
(
l2ClaimValue
),
cfg
.
L2Claim
)
})
t
.
Run
(
"Invalid"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
config
.
ErrInvalidL2Claim
.
Error
(),
replaceRequiredArg
(
"--l2.claim"
,
"something"
))
})
}
func
verifyArgsInvalid
(
t
*
testing
.
T
,
messageContains
string
,
cliArgs
[]
string
)
{
func
verifyArgsInvalid
(
t
*
testing
.
T
,
messageContains
string
,
cliArgs
[]
string
)
{
_
,
_
,
err
:=
runWithArgs
(
cliArgs
)
_
,
_
,
err
:=
runWithArgs
(
cliArgs
)
require
.
ErrorContains
(
t
,
err
,
messageContains
)
require
.
ErrorContains
(
t
,
err
,
messageContains
)
...
@@ -220,6 +241,7 @@ func requiredArgs() map[string]string {
...
@@ -220,6 +241,7 @@ func requiredArgs() map[string]string {
"--network"
:
"goerli"
,
"--network"
:
"goerli"
,
"--l1.head"
:
l1HeadValue
,
"--l1.head"
:
l1HeadValue
,
"--l2.head"
:
l2HeadValue
,
"--l2.head"
:
l2HeadValue
,
"--l2.claim"
:
l2ClaimValue
,
"--l2.genesis"
:
"genesis.json"
,
"--l2.genesis"
:
"genesis.json"
,
}
}
}
}
...
...
op-program/host/config/config.go
View file @
b2f33d71
...
@@ -17,6 +17,7 @@ var (
...
@@ -17,6 +17,7 @@ var (
ErrInvalidL1Head
=
errors
.
New
(
"invalid l1 head"
)
ErrInvalidL1Head
=
errors
.
New
(
"invalid l1 head"
)
ErrInvalidL2Head
=
errors
.
New
(
"invalid l2 head"
)
ErrInvalidL2Head
=
errors
.
New
(
"invalid l2 head"
)
ErrL1AndL2Inconsistent
=
errors
.
New
(
"l1 and l2 options must be specified together or both omitted"
)
ErrL1AndL2Inconsistent
=
errors
.
New
(
"l1 and l2 options must be specified together or both omitted"
)
ErrInvalidL2Claim
=
errors
.
New
(
"invalid l2 claim"
)
)
)
type
Config
struct
{
type
Config
struct
{
...
@@ -25,6 +26,7 @@ type Config struct {
...
@@ -25,6 +26,7 @@ type Config struct {
L2GenesisPath
string
L2GenesisPath
string
L1Head
common
.
Hash
L1Head
common
.
Hash
L2Head
common
.
Hash
L2Head
common
.
Hash
L2Claim
common
.
Hash
L1URL
string
L1URL
string
L1TrustRPC
bool
L1TrustRPC
bool
L1RPCKind
sources
.
RPCProviderKind
L1RPCKind
sources
.
RPCProviderKind
...
@@ -43,6 +45,9 @@ func (c *Config) Check() error {
...
@@ -43,6 +45,9 @@ func (c *Config) Check() error {
if
c
.
L2Head
==
(
common
.
Hash
{})
{
if
c
.
L2Head
==
(
common
.
Hash
{})
{
return
ErrInvalidL2Head
return
ErrInvalidL2Head
}
}
if
c
.
L2Claim
==
(
common
.
Hash
{})
{
return
ErrInvalidL2Claim
}
if
c
.
L2GenesisPath
==
""
{
if
c
.
L2GenesisPath
==
""
{
return
ErrMissingL2Genesis
return
ErrMissingL2Genesis
}
}
...
@@ -57,12 +62,13 @@ func (c *Config) FetchingEnabled() bool {
...
@@ -57,12 +62,13 @@ func (c *Config) FetchingEnabled() bool {
}
}
// NewConfig creates a Config with all optional values set to the CLI default value
// NewConfig creates a Config with all optional values set to the CLI default value
func
NewConfig
(
rollupCfg
*
rollup
.
Config
,
l2GenesisPath
string
,
l1Head
common
.
Hash
,
l2Head
common
.
Hash
)
*
Config
{
func
NewConfig
(
rollupCfg
*
rollup
.
Config
,
l2GenesisPath
string
,
l1Head
common
.
Hash
,
l2Head
common
.
Hash
,
l2Claim
common
.
Hash
)
*
Config
{
return
&
Config
{
return
&
Config
{
Rollup
:
rollupCfg
,
Rollup
:
rollupCfg
,
L2GenesisPath
:
l2GenesisPath
,
L2GenesisPath
:
l2GenesisPath
,
L1Head
:
l1Head
,
L1Head
:
l1Head
,
L2Head
:
l2Head
,
L2Head
:
l2Head
,
L2Claim
:
l2Claim
,
L1RPCKind
:
sources
.
RPCKindBasic
,
L1RPCKind
:
sources
.
RPCKindBasic
,
}
}
}
}
...
@@ -79,6 +85,10 @@ func NewConfigFromCLI(ctx *cli.Context) (*Config, error) {
...
@@ -79,6 +85,10 @@ func NewConfigFromCLI(ctx *cli.Context) (*Config, error) {
if
l2Head
==
(
common
.
Hash
{})
{
if
l2Head
==
(
common
.
Hash
{})
{
return
nil
,
ErrInvalidL2Head
return
nil
,
ErrInvalidL2Head
}
}
l2Claim
:=
common
.
HexToHash
(
ctx
.
GlobalString
(
flags
.
L2Claim
.
Name
))
if
l2Claim
==
(
common
.
Hash
{})
{
return
nil
,
ErrInvalidL2Claim
}
l1Head
:=
common
.
HexToHash
(
ctx
.
GlobalString
(
flags
.
L1Head
.
Name
))
l1Head
:=
common
.
HexToHash
(
ctx
.
GlobalString
(
flags
.
L1Head
.
Name
))
if
l1Head
==
(
common
.
Hash
{})
{
if
l1Head
==
(
common
.
Hash
{})
{
return
nil
,
ErrInvalidL1Head
return
nil
,
ErrInvalidL1Head
...
@@ -88,6 +98,7 @@ func NewConfigFromCLI(ctx *cli.Context) (*Config, error) {
...
@@ -88,6 +98,7 @@ func NewConfigFromCLI(ctx *cli.Context) (*Config, error) {
L2URL
:
ctx
.
GlobalString
(
flags
.
L2NodeAddr
.
Name
),
L2URL
:
ctx
.
GlobalString
(
flags
.
L2NodeAddr
.
Name
),
L2GenesisPath
:
ctx
.
GlobalString
(
flags
.
L2GenesisPath
.
Name
),
L2GenesisPath
:
ctx
.
GlobalString
(
flags
.
L2GenesisPath
.
Name
),
L2Head
:
l2Head
,
L2Head
:
l2Head
,
L2Claim
:
l2Claim
,
L1Head
:
l1Head
,
L1Head
:
l1Head
,
L1URL
:
ctx
.
GlobalString
(
flags
.
L1NodeAddr
.
Name
),
L1URL
:
ctx
.
GlobalString
(
flags
.
L1NodeAddr
.
Name
),
L1TrustRPC
:
ctx
.
GlobalBool
(
flags
.
L1TrustRPC
.
Name
),
L1TrustRPC
:
ctx
.
GlobalBool
(
flags
.
L1TrustRPC
.
Name
),
...
...
op-program/host/config/config_test.go
View file @
b2f33d71
...
@@ -11,58 +11,78 @@ import (
...
@@ -11,58 +11,78 @@ import (
var
validRollupConfig
=
&
chaincfg
.
Goerli
var
validRollupConfig
=
&
chaincfg
.
Goerli
var
validL2GenesisPath
=
"genesis.json"
var
validL2GenesisPath
=
"genesis.json"
var
validL1Head
=
common
.
HexToHash
(
"0x112233889988FF"
)
var
validL1Head
=
common
.
Hash
{
0xaa
}
var
validL2Head
=
common
.
HexToHash
(
"0x6303578b1fa9480389c51bbcef6fe045bb877da39740819e9eb5f36f94949bd0"
)
var
validL2Head
=
common
.
Hash
{
0xbb
}
var
validL2Claim
=
common
.
Hash
{
0xcc
}
func
TestDefaultConfigIsValid
(
t
*
testing
.
T
)
{
func
TestDefaultConfigIsValid
(
t
*
testing
.
T
)
{
err
:=
NewConfig
(
validRollupConfig
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
.
Check
()
err
:=
validConfig
(
)
.
Check
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
}
}
func
TestRollupConfig
(
t
*
testing
.
T
)
{
func
TestRollupConfig
(
t
*
testing
.
T
)
{
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
err
:=
NewConfig
(
nil
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
.
Check
()
config
:=
validConfig
()
config
.
Rollup
=
nil
err
:=
config
.
Check
()
require
.
ErrorIs
(
t
,
err
,
ErrMissingRollupConfig
)
require
.
ErrorIs
(
t
,
err
,
ErrMissingRollupConfig
)
})
})
t
.
Run
(
"Invalid"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Invalid"
,
func
(
t
*
testing
.
T
)
{
err
:=
NewConfig
(
&
rollup
.
Config
{},
validL2GenesisPath
,
validL1Head
,
validL2Head
)
.
Check
()
config
:=
validConfig
()
config
.
Rollup
=
&
rollup
.
Config
{}
err
:=
config
.
Check
()
require
.
ErrorIs
(
t
,
err
,
rollup
.
ErrBlockTimeZero
)
require
.
ErrorIs
(
t
,
err
,
rollup
.
ErrBlockTimeZero
)
})
})
}
}
func
TestL1HeadRequired
(
t
*
testing
.
T
)
{
func
TestL1HeadRequired
(
t
*
testing
.
T
)
{
err
:=
NewConfig
(
validRollupConfig
,
validL2GenesisPath
,
common
.
Hash
{},
validL2Head
)
.
Check
()
config
:=
validConfig
()
config
.
L1Head
=
common
.
Hash
{}
err
:=
config
.
Check
()
require
.
ErrorIs
(
t
,
err
,
ErrInvalidL1Head
)
require
.
ErrorIs
(
t
,
err
,
ErrInvalidL1Head
)
}
}
func
TestL2HeadRequired
(
t
*
testing
.
T
)
{
func
TestL2HeadRequired
(
t
*
testing
.
T
)
{
err
:=
NewConfig
(
validRollupConfig
,
validL2GenesisPath
,
validL1Head
,
common
.
Hash
{})
.
Check
()
config
:=
validConfig
()
config
.
L2Head
=
common
.
Hash
{}
err
:=
config
.
Check
()
require
.
ErrorIs
(
t
,
err
,
ErrInvalidL2Head
)
require
.
ErrorIs
(
t
,
err
,
ErrInvalidL2Head
)
}
}
func
TestL2ClaimRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
()
config
.
L2Claim
=
common
.
Hash
{}
err
:=
config
.
Check
()
require
.
ErrorIs
(
t
,
err
,
ErrInvalidL2Claim
)
}
func
TestL2GenesisRequired
(
t
*
testing
.
T
)
{
func
TestL2GenesisRequired
(
t
*
testing
.
T
)
{
err
:=
NewConfig
(
validRollupConfig
,
""
,
validL1Head
,
validL2Head
)
.
Check
()
config
:=
validConfig
()
config
.
L2GenesisPath
=
""
err
:=
config
.
Check
()
require
.
ErrorIs
(
t
,
err
,
ErrMissingL2Genesis
)
require
.
ErrorIs
(
t
,
err
,
ErrMissingL2Genesis
)
}
}
func
TestFetchingArgConsistency
(
t
*
testing
.
T
)
{
func
TestFetchingArgConsistency
(
t
*
testing
.
T
)
{
t
.
Run
(
"RequireL2WhenL1Set"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"RequireL2WhenL1Set"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
NewConfig
(
&
chaincfg
.
Beta1
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
cfg
:=
validConfig
(
)
cfg
.
L1URL
=
"https://example.com:1234"
cfg
.
L1URL
=
"https://example.com:1234"
require
.
ErrorIs
(
t
,
cfg
.
Check
(),
ErrL1AndL2Inconsistent
)
require
.
ErrorIs
(
t
,
cfg
.
Check
(),
ErrL1AndL2Inconsistent
)
})
})
t
.
Run
(
"RequireL1WhenL2Set"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"RequireL1WhenL2Set"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
NewConfig
(
&
chaincfg
.
Beta1
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
cfg
:=
validConfig
(
)
cfg
.
L2URL
=
"https://example.com:1234"
cfg
.
L2URL
=
"https://example.com:1234"
require
.
ErrorIs
(
t
,
cfg
.
Check
(),
ErrL1AndL2Inconsistent
)
require
.
ErrorIs
(
t
,
cfg
.
Check
(),
ErrL1AndL2Inconsistent
)
})
})
t
.
Run
(
"AllowNeitherSet"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"AllowNeitherSet"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
NewConfig
(
&
chaincfg
.
Beta1
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
cfg
:=
validConfig
()
cfg
.
L1URL
=
""
cfg
.
L2URL
=
""
require
.
NoError
(
t
,
cfg
.
Check
())
require
.
NoError
(
t
,
cfg
.
Check
())
})
})
t
.
Run
(
"AllowBothSet"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"AllowBothSet"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
NewConfig
(
&
chaincfg
.
Beta1
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
cfg
:=
validConfig
(
)
cfg
.
L1URL
=
"https://example.com:1234"
cfg
.
L1URL
=
"https://example.com:1234"
cfg
.
L2URL
=
"https://example.com:4678"
cfg
.
L2URL
=
"https://example.com:4678"
require
.
NoError
(
t
,
cfg
.
Check
())
require
.
NoError
(
t
,
cfg
.
Check
())
...
@@ -71,32 +91,36 @@ func TestFetchingArgConsistency(t *testing.T) {
...
@@ -71,32 +91,36 @@ func TestFetchingArgConsistency(t *testing.T) {
func
TestFetchingEnabled
(
t
*
testing
.
T
)
{
func
TestFetchingEnabled
(
t
*
testing
.
T
)
{
t
.
Run
(
"FetchingNotEnabledWhenNoFetcherUrlsSpecified"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"FetchingNotEnabledWhenNoFetcherUrlsSpecified"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
NewConfig
(
&
chaincfg
.
Beta1
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
cfg
:=
validConfig
(
)
require
.
False
(
t
,
cfg
.
FetchingEnabled
(),
"Should not enable fetching when node URL not supplied"
)
require
.
False
(
t
,
cfg
.
FetchingEnabled
(),
"Should not enable fetching when node URL not supplied"
)
})
})
t
.
Run
(
"FetchingEnabledWhenFetcherUrlsSpecified"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"FetchingEnabledWhenFetcherUrlsSpecified"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
NewConfig
(
&
chaincfg
.
Beta1
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
cfg
:=
validConfig
(
)
cfg
.
L2URL
=
"https://example.com:1234"
cfg
.
L2URL
=
"https://example.com:1234"
require
.
False
(
t
,
cfg
.
FetchingEnabled
(),
"Should not enable fetching when node URL not supplied"
)
require
.
False
(
t
,
cfg
.
FetchingEnabled
(),
"Should not enable fetching when node URL not supplied"
)
})
})
t
.
Run
(
"FetchingNotEnabledWhenNoL1UrlSpecified"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"FetchingNotEnabledWhenNoL1UrlSpecified"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
NewConfig
(
&
chaincfg
.
Beta1
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
cfg
:=
validConfig
(
)
cfg
.
L2URL
=
"https://example.com:1234"
cfg
.
L2URL
=
"https://example.com:1234"
require
.
False
(
t
,
cfg
.
FetchingEnabled
(),
"Should not enable L1 fetching when L1 node URL not supplied"
)
require
.
False
(
t
,
cfg
.
FetchingEnabled
(),
"Should not enable L1 fetching when L1 node URL not supplied"
)
})
})
t
.
Run
(
"FetchingNotEnabledWhenNoL2UrlSpecified"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"FetchingNotEnabledWhenNoL2UrlSpecified"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
NewConfig
(
&
chaincfg
.
Beta1
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
cfg
:=
validConfig
(
)
cfg
.
L1URL
=
"https://example.com:1234"
cfg
.
L1URL
=
"https://example.com:1234"
require
.
False
(
t
,
cfg
.
FetchingEnabled
(),
"Should not enable L2 fetching when L2 node URL not supplied"
)
require
.
False
(
t
,
cfg
.
FetchingEnabled
(),
"Should not enable L2 fetching when L2 node URL not supplied"
)
})
})
t
.
Run
(
"FetchingEnabledWhenBothFetcherUrlsSpecified"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"FetchingEnabledWhenBothFetcherUrlsSpecified"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
NewConfig
(
&
chaincfg
.
Beta1
,
validL2GenesisPath
,
validL1Head
,
validL2Head
)
cfg
:=
validConfig
(
)
cfg
.
L1URL
=
"https://example.com:1234"
cfg
.
L1URL
=
"https://example.com:1234"
cfg
.
L2URL
=
"https://example.com:5678"
cfg
.
L2URL
=
"https://example.com:5678"
require
.
True
(
t
,
cfg
.
FetchingEnabled
(),
"Should enable fetching when node URL supplied"
)
require
.
True
(
t
,
cfg
.
FetchingEnabled
(),
"Should enable fetching when node URL supplied"
)
})
})
}
}
func
validConfig
()
*
Config
{
return
NewConfig
(
validRollupConfig
,
validL2GenesisPath
,
validL1Head
,
validL2Head
,
validL2Claim
)
}
op-program/host/flags/flags.go
View file @
b2f33d71
...
@@ -41,6 +41,11 @@ var (
...
@@ -41,6 +41,11 @@ var (
Usage
:
"Hash of the agreed L2 block to start derivation from"
,
Usage
:
"Hash of the agreed L2 block to start derivation from"
,
EnvVar
:
service
.
PrefixEnvVar
(
envVarPrefix
,
"L2_HEAD"
),
EnvVar
:
service
.
PrefixEnvVar
(
envVarPrefix
,
"L2_HEAD"
),
}
}
L2Claim
=
cli
.
StringFlag
{
Name
:
"l2.claim"
,
Usage
:
"Claimed L2 output root to validate"
,
EnvVar
:
service
.
PrefixEnvVar
(
envVarPrefix
,
"L2_CLAIM"
),
}
L2GenesisPath
=
cli
.
StringFlag
{
L2GenesisPath
=
cli
.
StringFlag
{
Name
:
"l2.genesis"
,
Name
:
"l2.genesis"
,
Usage
:
"Path to the op-geth genesis file"
,
Usage
:
"Path to the op-geth genesis file"
,
...
@@ -71,13 +76,16 @@ var (
...
@@ -71,13 +76,16 @@ var (
// Flags contains the list of configuration options available to the binary.
// Flags contains the list of configuration options available to the binary.
var
Flags
[]
cli
.
Flag
var
Flags
[]
cli
.
Flag
var
requiredFlags
=
[]
cli
.
Flag
{
L1Head
,
L2Head
,
L2Claim
,
L2GenesisPath
,
}
var
programFlags
=
[]
cli
.
Flag
{
var
programFlags
=
[]
cli
.
Flag
{
RollupConfig
,
RollupConfig
,
Network
,
Network
,
L2NodeAddr
,
L2NodeAddr
,
L1Head
,
L2Head
,
L2GenesisPath
,
L1NodeAddr
,
L1NodeAddr
,
L1TrustRPC
,
L1TrustRPC
,
L1RPCProviderKind
,
L1RPCProviderKind
,
...
@@ -85,6 +93,7 @@ var programFlags = []cli.Flag{
...
@@ -85,6 +93,7 @@ var programFlags = []cli.Flag{
func
init
()
{
func
init
()
{
Flags
=
append
(
Flags
,
oplog
.
CLIFlags
(
envVarPrefix
)
...
)
Flags
=
append
(
Flags
,
oplog
.
CLIFlags
(
envVarPrefix
)
...
)
Flags
=
append
(
Flags
,
requiredFlags
...
)
Flags
=
append
(
Flags
,
programFlags
...
)
Flags
=
append
(
Flags
,
programFlags
...
)
}
}
...
@@ -97,14 +106,10 @@ func CheckRequired(ctx *cli.Context) error {
...
@@ -97,14 +106,10 @@ func CheckRequired(ctx *cli.Context) error {
if
rollupConfig
!=
""
&&
network
!=
""
{
if
rollupConfig
!=
""
&&
network
!=
""
{
return
fmt
.
Errorf
(
"cannot specify both %s and %s"
,
RollupConfig
.
Name
,
Network
.
Name
)
return
fmt
.
Errorf
(
"cannot specify both %s and %s"
,
RollupConfig
.
Name
,
Network
.
Name
)
}
}
if
ctx
.
GlobalString
(
L2GenesisPath
.
Name
)
==
""
{
for
_
,
flag
:=
range
requiredFlags
{
return
fmt
.
Errorf
(
"flag %s is required"
,
L2GenesisPath
.
Name
)
if
ctx
.
GlobalString
(
flag
.
GetName
())
==
""
{
}
return
fmt
.
Errorf
(
"flag %s is required"
,
flag
.
GetName
())
if
ctx
.
GlobalString
(
L2Head
.
Name
)
==
""
{
}
return
fmt
.
Errorf
(
"flag %s is required"
,
L2Head
.
Name
)
}
if
ctx
.
GlobalString
(
L1Head
.
Name
)
==
""
{
return
fmt
.
Errorf
(
"flag %s is required"
,
L1Head
.
Name
)
}
}
return
nil
return
nil
}
}
op-program/host/l2/l2.go
View file @
b2f33d71
...
@@ -6,7 +6,6 @@ import (
...
@@ -6,7 +6,6 @@ import (
"fmt"
"fmt"
"os"
"os"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
cll2
"github.com/ethereum-optimism/optimism/op-program/client/l2"
cll2
"github.com/ethereum-optimism/optimism/op-program/client/l2"
"github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core"
...
@@ -14,7 +13,7 @@ import (
...
@@ -14,7 +13,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params"
)
)
func
NewFetchingEngine
(
ctx
context
.
Context
,
logger
log
.
Logger
,
cfg
*
config
.
Config
)
(
derive
.
Engine
,
error
)
{
func
NewFetchingEngine
(
ctx
context
.
Context
,
logger
log
.
Logger
,
cfg
*
config
.
Config
)
(
*
cll2
.
Oracle
Engine
,
error
)
{
genesis
,
err
:=
loadL2Genesis
(
cfg
)
genesis
,
err
:=
loadL2Genesis
(
cfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
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