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
2ca70b4e
Unverified
Commit
2ca70b4e
authored
Jan 23, 2024
by
Adrian Sutton
Committed by
GitHub
Jan 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: Wire fetcher into preimage validator (#9123)
parent
b4c313da
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
18 deletions
+58
-18
fetcher.go
op-challenger/game/keccak/fetcher/fetcher.go
+5
-5
fetcher_test.go
op-challenger/game/keccak/fetcher/fetcher_test.go
+4
-4
scheduler.go
op-challenger/game/keccak/scheduler.go
+4
-2
scheduler_test.go
op-challenger/game/keccak/scheduler_test.go
+11
-1
types.go
op-challenger/game/keccak/types/types.go
+3
-0
verifier.go
op-challenger/game/keccak/verifier.go
+18
-5
registry_test.go
op-challenger/game/registry/registry_test.go
+10
-0
service.go
op-challenger/game/service.go
+3
-1
No files found.
op-challenger/game/keccak/fetcher/fetcher.go
View file @
2ca70b4e
...
@@ -19,8 +19,8 @@ var (
...
@@ -19,8 +19,8 @@ var (
)
)
type
L1Source
interface
{
type
L1Source
interface
{
TxsByNumber
(
ctx
context
.
Context
,
number
uint64
)
(
types
.
Transactions
,
error
)
BlockByNumber
(
ctx
context
.
Context
,
number
*
big
.
Int
)
(
*
types
.
Block
,
error
)
Fetch
Receipt
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
*
types
.
Receipt
,
error
)
Transaction
Receipt
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
*
types
.
Receipt
,
error
)
ChainID
(
ctx
context
.
Context
)
(
*
big
.
Int
,
error
)
ChainID
(
ctx
context
.
Context
)
(
*
big
.
Int
,
error
)
}
}
...
@@ -48,11 +48,11 @@ func (f *InputFetcher) FetchInputs(ctx context.Context, blockHash common.Hash, o
...
@@ -48,11 +48,11 @@ func (f *InputFetcher) FetchInputs(ctx context.Context, blockHash common.Hash, o
var
inputs
[]
keccakTypes
.
InputData
var
inputs
[]
keccakTypes
.
InputData
for
_
,
blockNum
:=
range
blockNums
{
for
_
,
blockNum
:=
range
blockNums
{
foundRelevantTx
:=
false
foundRelevantTx
:=
false
txs
,
err
:=
f
.
source
.
TxsByNumber
(
ctx
,
blockNum
)
block
,
err
:=
f
.
source
.
BlockByNumber
(
ctx
,
new
(
big
.
Int
)
.
SetUint64
(
blockNum
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed getting tx for block %v: %w"
,
blockNum
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed getting tx for block %v: %w"
,
blockNum
,
err
)
}
}
for
_
,
tx
:=
range
txs
{
for
_
,
tx
:=
range
block
.
Transactions
()
{
inputData
,
err
:=
f
.
extractRelevantLeavesFromTx
(
ctx
,
oracle
,
signer
,
tx
,
ident
)
inputData
,
err
:=
f
.
extractRelevantLeavesFromTx
(
ctx
,
oracle
,
signer
,
tx
,
ident
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -97,7 +97,7 @@ func (f *InputFetcher) extractRelevantLeavesFromTx(ctx context.Context, oracle O
...
@@ -97,7 +97,7 @@ func (f *InputFetcher) extractRelevantLeavesFromTx(ctx context.Context, oracle O
f
.
log
.
Trace
(
"Skipping transaction with incorrect sender"
,
"tx"
,
tx
.
Hash
(),
"expected"
,
ident
.
Claimant
,
"actual"
,
sender
)
f
.
log
.
Trace
(
"Skipping transaction with incorrect sender"
,
"tx"
,
tx
.
Hash
(),
"expected"
,
ident
.
Claimant
,
"actual"
,
sender
)
return
nil
,
nil
return
nil
,
nil
}
}
rcpt
,
err
:=
f
.
source
.
Fetch
Receipt
(
ctx
,
tx
.
Hash
())
rcpt
,
err
:=
f
.
source
.
Transaction
Receipt
(
ctx
,
tx
.
Hash
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to retrieve receipt for tx %v: %w"
,
tx
.
Hash
(),
err
)
return
nil
,
fmt
.
Errorf
(
"failed to retrieve receipt for tx %v: %w"
,
tx
.
Hash
(),
err
)
}
}
...
...
op-challenger/game/keccak/fetcher/fetcher_test.go
View file @
2ca70b4e
...
@@ -283,15 +283,15 @@ func (s *stubL1Source) ChainID(_ context.Context) (*big.Int, error) {
...
@@ -283,15 +283,15 @@ func (s *stubL1Source) ChainID(_ context.Context) (*big.Int, error) {
return
chainID
,
nil
return
chainID
,
nil
}
}
func
(
s
*
stubL1Source
)
TxsByNumber
(
_
context
.
Context
,
number
uint64
)
(
types
.
Transactions
,
error
)
{
func
(
s
*
stubL1Source
)
BlockByNumber
(
_
context
.
Context
,
number
*
big
.
Int
)
(
*
types
.
Block
,
error
)
{
txs
,
ok
:=
s
.
txs
[
number
]
txs
,
ok
:=
s
.
txs
[
number
.
Uint64
()
]
if
!
ok
{
if
!
ok
{
return
nil
,
errors
.
New
(
"not found"
)
return
nil
,
errors
.
New
(
"not found"
)
}
}
return
txs
,
nil
return
(
&
types
.
Block
{})
.
WithBody
(
txs
,
nil
)
,
nil
}
}
func
(
s
*
stubL1Source
)
Fetch
Receipt
(
_
context
.
Context
,
txHash
common
.
Hash
)
(
*
types
.
Receipt
,
error
)
{
func
(
s
*
stubL1Source
)
Transaction
Receipt
(
_
context
.
Context
,
txHash
common
.
Hash
)
(
*
types
.
Receipt
,
error
)
{
rcptStatus
,
ok
:=
s
.
rcptStatus
[
txHash
]
rcptStatus
,
ok
:=
s
.
rcptStatus
[
txHash
]
if
!
ok
{
if
!
ok
{
rcptStatus
=
types
.
ReceiptStatusSuccessful
rcptStatus
=
types
.
ReceiptStatusSuccessful
...
...
op-challenger/game/keccak/scheduler.go
View file @
2ca70b4e
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
)
)
type
Verifier
interface
{
type
Verifier
interface
{
Verify
(
ctx
context
.
Context
,
oracle
keccakTypes
.
LargePreimageOracle
,
preimage
keccakTypes
.
LargePreimageMetaData
)
Verify
(
ctx
context
.
Context
,
blockHash
common
.
Hash
,
oracle
keccakTypes
.
LargePreimageOracle
,
preimage
keccakTypes
.
LargePreimageMetaData
)
error
}
}
type
LargePreimageScheduler
struct
{
type
LargePreimageScheduler
struct
{
...
@@ -80,7 +80,9 @@ func (s *LargePreimageScheduler) verifyOraclePreimages(ctx context.Context, orac
...
@@ -80,7 +80,9 @@ func (s *LargePreimageScheduler) verifyOraclePreimages(ctx context.Context, orac
preimages
,
err
:=
oracle
.
GetActivePreimages
(
ctx
,
blockHash
)
preimages
,
err
:=
oracle
.
GetActivePreimages
(
ctx
,
blockHash
)
for
_
,
preimage
:=
range
preimages
{
for
_
,
preimage
:=
range
preimages
{
if
preimage
.
ShouldVerify
()
{
if
preimage
.
ShouldVerify
()
{
s
.
verifier
.
Verify
(
ctx
,
oracle
,
preimage
)
if
err
:=
s
.
verifier
.
Verify
(
ctx
,
blockHash
,
oracle
,
preimage
);
err
!=
nil
{
s
.
log
.
Error
(
"Failed to verify large preimage"
,
"oracle"
,
oracle
.
Addr
(),
"claimant"
,
preimage
.
Claimant
,
"uuid"
,
preimage
.
UUID
,
"err"
,
err
)
}
}
}
}
}
return
err
return
err
...
...
op-challenger/game/keccak/scheduler_test.go
View file @
2ca70b4e
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"time"
"time"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
...
@@ -64,6 +65,14 @@ type stubOracle struct {
...
@@ -64,6 +65,14 @@ type stubOracle struct {
images
[]
keccakTypes
.
LargePreimageMetaData
images
[]
keccakTypes
.
LargePreimageMetaData
}
}
func
(
s
*
stubOracle
)
GetInputDataBlocks
(
_
context
.
Context
,
_
batching
.
Block
,
_
keccakTypes
.
LargePreimageIdent
)
([]
uint64
,
error
)
{
panic
(
"not supported"
)
}
func
(
s
*
stubOracle
)
DecodeInputData
(
_
[]
byte
)
(
*
big
.
Int
,
keccakTypes
.
InputData
,
error
)
{
panic
(
"not supported"
)
}
func
(
s
*
stubOracle
)
Addr
()
common
.
Address
{
func
(
s
*
stubOracle
)
Addr
()
common
.
Address
{
return
s
.
addr
return
s
.
addr
}
}
...
@@ -86,10 +95,11 @@ type stubVerifier struct {
...
@@ -86,10 +95,11 @@ type stubVerifier struct {
verified
[]
keccakTypes
.
LargePreimageMetaData
verified
[]
keccakTypes
.
LargePreimageMetaData
}
}
func
(
s
*
stubVerifier
)
Verify
(
_
context
.
Context
,
_
keccakTypes
.
LargePreimageOracle
,
image
keccakTypes
.
LargePreimageMetaData
)
{
func
(
s
*
stubVerifier
)
Verify
(
_
context
.
Context
,
_
common
.
Hash
,
_
keccakTypes
.
LargePreimageOracle
,
image
keccakTypes
.
LargePreimageMetaData
)
error
{
s
.
m
.
Lock
()
s
.
m
.
Lock
()
defer
s
.
m
.
Unlock
()
defer
s
.
m
.
Unlock
()
s
.
verified
=
append
(
s
.
verified
,
image
)
s
.
verified
=
append
(
s
.
verified
,
image
)
return
nil
}
}
func
(
s
*
stubVerifier
)
Verified
()
[]
keccakTypes
.
LargePreimageMetaData
{
func
(
s
*
stubVerifier
)
Verified
()
[]
keccakTypes
.
LargePreimageMetaData
{
...
...
op-challenger/game/keccak/types/types.go
View file @
2ca70b4e
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"context"
"context"
"math/big"
"math/big"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
)
)
...
@@ -59,4 +60,6 @@ func (m LargePreimageMetaData) ShouldVerify() bool {
...
@@ -59,4 +60,6 @@ func (m LargePreimageMetaData) ShouldVerify() bool {
type
LargePreimageOracle
interface
{
type
LargePreimageOracle
interface
{
Addr
()
common
.
Address
Addr
()
common
.
Address
GetActivePreimages
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
([]
LargePreimageMetaData
,
error
)
GetActivePreimages
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
([]
LargePreimageMetaData
,
error
)
GetInputDataBlocks
(
ctx
context
.
Context
,
block
batching
.
Block
,
ident
LargePreimageIdent
)
([]
uint64
,
error
)
DecodeInputData
(
data
[]
byte
)
(
*
big
.
Int
,
InputData
,
error
)
}
}
op-challenger/game/keccak/verifier.go
View file @
2ca70b4e
...
@@ -2,21 +2,34 @@ package keccak
...
@@ -2,21 +2,34 @@ package keccak
import
(
import
(
"context"
"context"
"fmt"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/fetcher"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
)
)
type
Fetcher
interface
{
FetchInputs
(
ctx
context
.
Context
,
blockHash
common
.
Hash
,
oracle
fetcher
.
Oracle
,
ident
keccakTypes
.
LargePreimageIdent
)
([]
keccakTypes
.
InputData
,
error
)
}
type
PreimageVerifier
struct
{
type
PreimageVerifier
struct
{
log
log
.
Logger
log
log
.
Logger
fetcher
Fetcher
}
}
func
NewPreimageVerifier
(
logger
log
.
Logger
)
*
PreimageVerifier
{
func
NewPreimageVerifier
(
logger
log
.
Logger
,
fetcher
Fetcher
)
*
PreimageVerifier
{
return
&
PreimageVerifier
{
return
&
PreimageVerifier
{
log
:
logger
,
log
:
logger
,
fetcher
:
fetcher
,
}
}
}
}
func
(
v
*
PreimageVerifier
)
Verify
(
ctx
context
.
Context
,
oracle
keccakTypes
.
LargePreimageOracle
,
preimage
keccakTypes
.
LargePreimageMetaData
)
{
func
(
v
*
PreimageVerifier
)
Verify
(
ctx
context
.
Context
,
blockHash
common
.
Hash
,
oracle
keccakTypes
.
LargePreimageOracle
,
preimage
keccakTypes
.
LargePreimageMetaData
)
error
{
// No verification currently performed.
_
,
err
:=
v
.
fetcher
.
FetchInputs
(
ctx
,
blockHash
,
oracle
,
preimage
.
LargePreimageIdent
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to fetch leaves: %w"
,
err
)
}
return
nil
}
}
op-challenger/game/registry/registry_test.go
View file @
2ca70b4e
...
@@ -2,12 +2,14 @@ package registry
...
@@ -2,12 +2,14 @@ package registry
import
(
import
(
"context"
"context"
"math/big"
"testing"
"testing"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/scheduler"
"github.com/ethereum-optimism/optimism/op-challenger/game/scheduler"
"github.com/ethereum-optimism/optimism/op-challenger/game/scheduler/test"
"github.com/ethereum-optimism/optimism/op-challenger/game/scheduler/test"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
...
@@ -60,6 +62,14 @@ func TestDeduplicateOracles(t *testing.T) {
...
@@ -60,6 +62,14 @@ func TestDeduplicateOracles(t *testing.T) {
type
stubPreimageOracle
common
.
Address
type
stubPreimageOracle
common
.
Address
func
(
s
stubPreimageOracle
)
GetInputDataBlocks
(
_
context
.
Context
,
_
batching
.
Block
,
_
keccakTypes
.
LargePreimageIdent
)
([]
uint64
,
error
)
{
panic
(
"not supported"
)
}
func
(
s
stubPreimageOracle
)
DecodeInputData
(
_
[]
byte
)
(
*
big
.
Int
,
keccakTypes
.
InputData
,
error
)
{
panic
(
"not supported"
)
}
func
(
s
stubPreimageOracle
)
Addr
()
common
.
Address
{
func
(
s
stubPreimageOracle
)
Addr
()
common
.
Address
{
return
common
.
Address
(
s
)
return
common
.
Address
(
s
)
}
}
...
...
op-challenger/game/service.go
View file @
2ca70b4e
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"sync/atomic"
"sync/atomic"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/fetcher"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
...
@@ -225,7 +226,8 @@ func (s *Service) initScheduler(cfg *config.Config) error {
...
@@ -225,7 +226,8 @@ func (s *Service) initScheduler(cfg *config.Config) error {
}
}
func
(
s
*
Service
)
initLargePreimages
()
error
{
func
(
s
*
Service
)
initLargePreimages
()
error
{
verifier
:=
keccak
.
NewPreimageVerifier
(
s
.
logger
)
fetcher
:=
fetcher
.
NewPreimageFetcher
(
s
.
logger
,
s
.
l1Client
)
verifier
:=
keccak
.
NewPreimageVerifier
(
s
.
logger
,
fetcher
)
s
.
preimages
=
keccak
.
NewLargePreimageScheduler
(
s
.
logger
,
s
.
registry
.
Oracles
(),
verifier
)
s
.
preimages
=
keccak
.
NewLargePreimageScheduler
(
s
.
logger
,
s
.
registry
.
Oracles
(),
verifier
)
return
nil
return
nil
}
}
...
...
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