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
710ca379
Unverified
Commit
710ca379
authored
Aug 03, 2023
by
OptimismBot
Committed by
GitHub
Aug 03, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6569 from ethereum-optimism/refcell/oracleprovider
feat(op-challenger): OracleUpdater Component
parents
a9dcc0b1
622b636b
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
307 additions
and
36 deletions
+307
-36
charlie.sh
op-challenger/charlie.sh
+3
-0
main_test.go
op-challenger/cmd/main_test.go
+34
-12
config.go
op-challenger/config/config.go
+9
-2
config_test.go
op-challenger/config/config_test.go
+8
-1
updater.go
op-challenger/fault/alphabet/updater.go
+27
-0
updater_test.go
op-challenger/fault/alphabet/updater_test.go
+19
-0
executor_test.go
op-challenger/fault/cannon/executor_test.go
+1
-1
updater.go
op-challenger/fault/cannon/updater.go
+59
-0
updater_test.go
op-challenger/fault/cannon/updater_test.go
+87
-0
service.go
op-challenger/fault/service.go
+27
-16
types.go
op-challenger/fault/types/types.go
+6
-0
flags.go
op-challenger/flags/flags.go
+24
-4
mallory.sh
op-challenger/mallory.sh
+3
-0
No files found.
op-challenger/charlie.sh
View file @
710ca379
...
@@ -14,11 +14,14 @@ MALLORY_KEY="28d7045146193f5f4eeb151c4843544b1b0d30a7ac1680c845a416fac65a7715"
...
@@ -14,11 +14,14 @@ MALLORY_KEY="28d7045146193f5f4eeb151c4843544b1b0d30a7ac1680c845a416fac65a7715"
FAULT_GAME_ADDRESS
=
"0x8daf17a20c9dba35f005b6324f493785d239719d"
FAULT_GAME_ADDRESS
=
"0x8daf17a20c9dba35f005b6324f493785d239719d"
PREIMAGE_ORACLE_ADDRESS
=
"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
./bin/op-challenger
\
./bin/op-challenger
\
--l1-eth-rpc
http://localhost:8545
\
--l1-eth-rpc
http://localhost:8545
\
--trace-type
=
"alphabet"
\
--trace-type
=
"alphabet"
\
--alphabet
"abcdefgh"
\
--alphabet
"abcdefgh"
\
--game-address
$FAULT_GAME_ADDRESS
\
--game-address
$FAULT_GAME_ADDRESS
\
--preimage-oracle-address
$PREIMAGE_ORACLE_ADDRESS
\
--private-key
$CHARLIE_KEY
\
--private-key
$CHARLIE_KEY
\
--num-confirmations
1
\
--num-confirmations
1
\
--game-depth
4
\
--game-depth
4
\
...
...
op-challenger/cmd/main_test.go
View file @
710ca379
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
var
(
var
(
l1EthRpc
=
"http://example.com:8545"
l1EthRpc
=
"http://example.com:8545"
gameAddressValue
=
"0xaa00000000000000000000000000000000000000"
gameAddressValue
=
"0xaa00000000000000000000000000000000000000"
preimageOracleAddressValue
=
"0xbb00000000000000000000000000000000000000"
cannonBin
=
"./bin/cannon"
cannonBin
=
"./bin/cannon"
cannonServer
=
"./bin/op-program"
cannonServer
=
"./bin/op-program"
cannonPreState
=
"./pre.json"
cannonPreState
=
"./pre.json"
...
@@ -42,14 +43,14 @@ func TestLogLevel(t *testing.T) {
...
@@ -42,14 +43,14 @@ func TestLogLevel(t *testing.T) {
func
TestDefaultCLIOptionsMatchDefaultConfig
(
t
*
testing
.
T
)
{
func
TestDefaultCLIOptionsMatchDefaultConfig
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
config
.
TraceTypeAlphabet
))
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
config
.
TraceTypeAlphabet
))
defaultCfg
:=
config
.
NewConfig
(
l1EthRpc
,
common
.
HexToAddress
(
gameAddressValue
),
config
.
TraceTypeAlphabet
,
true
,
4
)
defaultCfg
:=
config
.
NewConfig
(
l1EthRpc
,
common
.
HexToAddress
(
gameAddressValue
),
co
mmon
.
HexToAddress
(
preimageOracleAddressValue
),
co
nfig
.
TraceTypeAlphabet
,
true
,
4
)
// Add in the extra CLI options required when using alphabet trace type
// Add in the extra CLI options required when using alphabet trace type
defaultCfg
.
AlphabetTrace
=
alphabetTrace
defaultCfg
.
AlphabetTrace
=
alphabetTrace
require
.
Equal
(
t
,
defaultCfg
,
cfg
)
require
.
Equal
(
t
,
defaultCfg
,
cfg
)
}
}
func
TestDefaultConfigIsValid
(
t
*
testing
.
T
)
{
func
TestDefaultConfigIsValid
(
t
*
testing
.
T
)
{
cfg
:=
config
.
NewConfig
(
l1EthRpc
,
common
.
HexToAddress
(
gameAddressValue
),
config
.
TraceTypeAlphabet
,
true
,
4
)
cfg
:=
config
.
NewConfig
(
l1EthRpc
,
common
.
HexToAddress
(
gameAddressValue
),
co
mmon
.
HexToAddress
(
preimageOracleAddressValue
),
co
nfig
.
TraceTypeAlphabet
,
true
,
4
)
// Add in options that are required based on the specific trace type
// Add in options that are required based on the specific trace type
// To avoid needing to specify unused options, these aren't included in the params for NewConfig
// To avoid needing to specify unused options, these aren't included in the params for NewConfig
cfg
.
AlphabetTrace
=
alphabetTrace
cfg
.
AlphabetTrace
=
alphabetTrace
...
@@ -139,6 +140,26 @@ func TestGameDepth(t *testing.T) {
...
@@ -139,6 +140,26 @@ func TestGameDepth(t *testing.T) {
})
})
}
}
func
TestPreimageOracleAddress
(
t
*
testing
.
T
)
{
t
.
Run
(
"NotRequiredForAlphabetTrace"
,
func
(
t
*
testing
.
T
)
{
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--preimage-oracle-address"
))
})
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag preimage-oracle-address is required"
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--preimage-oracle-address"
))
})
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
addr
:=
common
.
Address
{
0xbb
,
0xcc
,
0xdd
}
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--preimage-oracle-address"
,
"--preimage-oracle-address="
+
addr
.
Hex
()))
require
.
Equal
(
t
,
addr
,
cfg
.
PreimageOracleAddress
)
})
t
.
Run
(
"Invalid"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"invalid address: foo"
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--preimage-oracle-address"
,
"--preimage-oracle-address=foo"
))
})
}
func
TestCannonBin
(
t
*
testing
.
T
)
{
func
TestCannonBin
(
t
*
testing
.
T
)
{
t
.
Run
(
"NotRequiredForAlphabetTrace"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"NotRequiredForAlphabetTrace"
,
func
(
t
*
testing
.
T
)
{
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--cannon-bin"
))
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--cannon-bin"
))
...
@@ -267,6 +288,7 @@ func requiredArgs(traceType config.TraceType) map[string]string {
...
@@ -267,6 +288,7 @@ func requiredArgs(traceType config.TraceType) map[string]string {
"--agree-with-proposed-output"
:
agreeWithProposedOutput
,
"--agree-with-proposed-output"
:
agreeWithProposedOutput
,
"--l1-eth-rpc"
:
l1EthRpc
,
"--l1-eth-rpc"
:
l1EthRpc
,
"--game-address"
:
gameAddressValue
,
"--game-address"
:
gameAddressValue
,
"--preimage-oracle-address"
:
preimageOracleAddressValue
,
"--trace-type"
:
traceType
.
String
(),
"--trace-type"
:
traceType
.
String
(),
}
}
switch
traceType
{
switch
traceType
{
...
...
op-challenger/config/config.go
View file @
710ca379
...
@@ -18,6 +18,7 @@ var (
...
@@ -18,6 +18,7 @@ var (
ErrMissingAlphabetTrace
=
errors
.
New
(
"missing alphabet trace"
)
ErrMissingAlphabetTrace
=
errors
.
New
(
"missing alphabet trace"
)
ErrMissingL1EthRPC
=
errors
.
New
(
"missing l1 eth rpc url"
)
ErrMissingL1EthRPC
=
errors
.
New
(
"missing l1 eth rpc url"
)
ErrMissingGameAddress
=
errors
.
New
(
"missing game address"
)
ErrMissingGameAddress
=
errors
.
New
(
"missing game address"
)
ErrMissingPreimageOracleAddress
=
errors
.
New
(
"missing pre-image oracle address"
)
ErrMissingCannonSnapshotFreq
=
errors
.
New
(
"missing cannon snapshot freq"
)
ErrMissingCannonSnapshotFreq
=
errors
.
New
(
"missing cannon snapshot freq"
)
)
)
...
@@ -60,6 +61,7 @@ const DefaultCannonSnapshotFreq = uint(10_000)
...
@@ -60,6 +61,7 @@ const DefaultCannonSnapshotFreq = uint(10_000)
type
Config
struct
{
type
Config
struct
{
L1EthRpc
string
// L1 RPC Url
L1EthRpc
string
// L1 RPC Url
GameAddress
common
.
Address
// Address of the fault game
GameAddress
common
.
Address
// Address of the fault game
PreimageOracleAddress
common
.
Address
// Address of the pre-image oracle
AgreeWithProposedOutput
bool
// Temporary config if we agree or disagree with the posted output
AgreeWithProposedOutput
bool
// Temporary config if we agree or disagree with the posted output
GameDepth
int
// Depth of the game tree
GameDepth
int
// Depth of the game tree
...
@@ -82,6 +84,7 @@ type Config struct {
...
@@ -82,6 +84,7 @@ type Config struct {
func
NewConfig
(
func
NewConfig
(
l1EthRpc
string
,
l1EthRpc
string
,
gameAddress
common
.
Address
,
gameAddress
common
.
Address
,
preimageOracleAddress
common
.
Address
,
traceType
TraceType
,
traceType
TraceType
,
agreeWithProposedOutput
bool
,
agreeWithProposedOutput
bool
,
gameDepth
int
,
gameDepth
int
,
...
@@ -89,6 +92,7 @@ func NewConfig(
...
@@ -89,6 +92,7 @@ func NewConfig(
return
Config
{
return
Config
{
L1EthRpc
:
l1EthRpc
,
L1EthRpc
:
l1EthRpc
,
GameAddress
:
gameAddress
,
GameAddress
:
gameAddress
,
PreimageOracleAddress
:
preimageOracleAddress
,
AgreeWithProposedOutput
:
agreeWithProposedOutput
,
AgreeWithProposedOutput
:
agreeWithProposedOutput
,
GameDepth
:
gameDepth
,
GameDepth
:
gameDepth
,
...
@@ -112,6 +116,9 @@ func (c Config) Check() error {
...
@@ -112,6 +116,9 @@ func (c Config) Check() error {
return
ErrMissingTraceType
return
ErrMissingTraceType
}
}
if
c
.
TraceType
==
TraceTypeCannon
{
if
c
.
TraceType
==
TraceTypeCannon
{
if
c
.
PreimageOracleAddress
==
(
common
.
Address
{})
{
return
ErrMissingPreimageOracleAddress
}
if
c
.
CannonBin
==
""
{
if
c
.
CannonBin
==
""
{
return
ErrMissingCannonBin
return
ErrMissingCannonBin
}
}
...
...
op-challenger/config/config_test.go
View file @
710ca379
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
var
(
var
(
validL1EthRpc
=
"http://localhost:8545"
validL1EthRpc
=
"http://localhost:8545"
validGameAddress
=
common
.
HexToAddress
(
"0x7bdd3b028C4796eF0EAf07d11394d0d9d8c24139"
)
validGameAddress
=
common
.
HexToAddress
(
"0x7bdd3b028C4796eF0EAf07d11394d0d9d8c24139"
)
validPreimageOracleAddress
=
common
.
HexToAddress
(
"0x7bdd3b028C4796eF0EAf07d11394d0d9d8c24139"
)
validAlphabetTrace
=
"abcdefgh"
validAlphabetTrace
=
"abcdefgh"
validCannonBin
=
"./bin/cannon"
validCannonBin
=
"./bin/cannon"
validCannonOpProgramBin
=
"./bin/op-program"
validCannonOpProgramBin
=
"./bin/op-program"
...
@@ -22,7 +23,7 @@ var (
...
@@ -22,7 +23,7 @@ var (
)
)
func
validConfig
(
traceType
TraceType
)
Config
{
func
validConfig
(
traceType
TraceType
)
Config
{
cfg
:=
NewConfig
(
validL1EthRpc
,
validGameAddress
,
traceType
,
agreeWithProposedOutput
,
gameDepth
)
cfg
:=
NewConfig
(
validL1EthRpc
,
validGameAddress
,
validPreimageOracleAddress
,
traceType
,
agreeWithProposedOutput
,
gameDepth
)
switch
traceType
{
switch
traceType
{
case
TraceTypeAlphabet
:
case
TraceTypeAlphabet
:
cfg
.
AlphabetTrace
=
validAlphabetTrace
cfg
.
AlphabetTrace
=
validAlphabetTrace
...
@@ -73,6 +74,12 @@ func TestAlphabetTraceRequired(t *testing.T) {
...
@@ -73,6 +74,12 @@ func TestAlphabetTraceRequired(t *testing.T) {
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingAlphabetTrace
)
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingAlphabetTrace
)
}
}
func
TestCannonPreimageOracleAddressRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
PreimageOracleAddress
=
common
.
Address
{}
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingPreimageOracleAddress
)
}
func
TestCannonBinRequired
(
t
*
testing
.
T
)
{
func
TestCannonBinRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
:=
validConfig
(
TraceTypeCannon
)
config
.
CannonBin
=
""
config
.
CannonBin
=
""
...
...
op-challenger/fault/alphabet/updater.go
0 → 100644
View file @
710ca379
package
alphabet
import
(
"context"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
"github.com/ethereum/go-ethereum/log"
)
// alphabetUpdater is a [types.OracleUpdater] that exposes a
// method to update onchain oracles with required data.
type
alphabetUpdater
struct
{
logger
log
.
Logger
}
// NewOracleUpdater returns a new updater.
func
NewOracleUpdater
(
logger
log
.
Logger
)
*
alphabetUpdater
{
return
&
alphabetUpdater
{
logger
:
logger
,
}
}
// UpdateOracle updates the oracle with the given data.
func
(
u
*
alphabetUpdater
)
UpdateOracle
(
ctx
context
.
Context
,
data
types
.
PreimageOracleData
)
error
{
u
.
logger
.
Info
(
"alphabet oracle updater called"
)
return
nil
}
op-challenger/fault/alphabet/updater_test.go
0 → 100644
View file @
710ca379
package
alphabet
import
(
"context"
"testing"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)
// TestAlphabetUpdater tests the [alphabetUpdater].
func
TestAlphabetUpdater
(
t
*
testing
.
T
)
{
logger
:=
testlog
.
Logger
(
t
,
log
.
LvlInfo
)
updater
:=
NewOracleUpdater
(
logger
)
require
.
Nil
(
t
,
updater
.
UpdateOracle
(
context
.
Background
(),
types
.
PreimageOracleData
{}))
}
op-challenger/fault/cannon/executor_test.go
View file @
710ca379
...
@@ -19,7 +19,7 @@ const execTestCannonPrestate = "/foo/pre.json"
...
@@ -19,7 +19,7 @@ const execTestCannonPrestate = "/foo/pre.json"
func
TestGenerateProof
(
t
*
testing
.
T
)
{
func
TestGenerateProof
(
t
*
testing
.
T
)
{
input
:=
"starting.json"
input
:=
"starting.json"
cfg
:=
config
.
NewConfig
(
"http://localhost:8888"
,
common
.
Address
{
0xaa
},
config
.
TraceTypeCannon
,
true
,
5
)
cfg
:=
config
.
NewConfig
(
"http://localhost:8888"
,
common
.
Address
{
0xaa
},
co
mmon
.
Address
{
0xbb
},
co
nfig
.
TraceTypeCannon
,
true
,
5
)
cfg
.
CannonDatadir
=
t
.
TempDir
()
cfg
.
CannonDatadir
=
t
.
TempDir
()
cfg
.
CannonAbsolutePreState
=
"pre.json"
cfg
.
CannonAbsolutePreState
=
"pre.json"
cfg
.
CannonBin
=
"./bin/cannon"
cfg
.
CannonBin
=
"./bin/cannon"
...
...
op-challenger/fault/cannon/updater.go
0 → 100644
View file @
710ca379
package
cannon
import
(
"context"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
// cannonUpdater is a [types.OracleUpdater] that exposes a method
// to update onchain cannon oracles with required data.
type
cannonUpdater
struct
{
logger
log
.
Logger
txMgr
txmgr
.
TxManager
fdgAbi
abi
.
ABI
fdgAddr
common
.
Address
preimageOracleAbi
abi
.
ABI
preimageOracleAddr
common
.
Address
}
// NewOracleUpdater returns a new updater.
func
NewOracleUpdater
(
logger
log
.
Logger
,
txMgr
txmgr
.
TxManager
,
fdgAddr
common
.
Address
,
preimageOracleAddr
common
.
Address
,
)
(
*
cannonUpdater
,
error
)
{
fdgAbi
,
err
:=
bindings
.
FaultDisputeGameMetaData
.
GetAbi
()
if
err
!=
nil
{
return
nil
,
err
}
preimageOracleAbi
,
err
:=
bindings
.
PreimageOracleMetaData
.
GetAbi
()
if
err
!=
nil
{
return
nil
,
err
}
return
&
cannonUpdater
{
logger
:
logger
,
txMgr
:
txMgr
,
fdgAbi
:
*
fdgAbi
,
fdgAddr
:
fdgAddr
,
preimageOracleAbi
:
*
preimageOracleAbi
,
preimageOracleAddr
:
preimageOracleAddr
,
},
nil
}
// UpdateOracle updates the oracle with the given data.
func
(
u
*
cannonUpdater
)
UpdateOracle
(
ctx
context
.
Context
,
data
types
.
PreimageOracleData
)
error
{
panic
(
"oracle updates not implemented"
)
}
op-challenger/fault/cannon/updater_test.go
0 → 100644
View file @
710ca379
package
cannon
import
(
"context"
"errors"
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum"
ethtypes
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)
var
(
mockFdgAddress
=
common
.
HexToAddress
(
"0x1234"
)
mockPreimageOracleAddress
=
common
.
HexToAddress
(
"0x12345"
)
mockSendError
=
errors
.
New
(
"mock send error"
)
)
type
mockTxManager
struct
{
from
common
.
Address
sends
int
calls
int
sendFails
bool
}
func
(
m
*
mockTxManager
)
Send
(
ctx
context
.
Context
,
candidate
txmgr
.
TxCandidate
)
(
*
ethtypes
.
Receipt
,
error
)
{
if
m
.
sendFails
{
return
nil
,
mockSendError
}
m
.
sends
++
return
ethtypes
.
NewReceipt
(
[]
byte
{},
false
,
0
,
),
nil
}
func
(
m
*
mockTxManager
)
Call
(
_
context
.
Context
,
_
ethereum
.
CallMsg
,
_
*
big
.
Int
)
([]
byte
,
error
)
{
if
m
.
sendFails
{
return
nil
,
mockSendError
}
m
.
calls
++
return
[]
byte
{},
nil
}
func
(
m
*
mockTxManager
)
BlockNumber
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
panic
(
"not implemented"
)
}
func
(
m
*
mockTxManager
)
From
()
common
.
Address
{
return
m
.
from
}
func
newTestCannonUpdater
(
t
*
testing
.
T
,
sendFails
bool
)
(
*
cannonUpdater
,
*
mockTxManager
)
{
logger
:=
testlog
.
Logger
(
t
,
log
.
LvlInfo
)
txMgr
:=
&
mockTxManager
{
from
:
mockFdgAddress
,
sendFails
:
sendFails
,
}
updater
,
err
:=
NewOracleUpdater
(
logger
,
txMgr
,
mockFdgAddress
,
mockPreimageOracleAddress
)
require
.
NoError
(
t
,
err
)
return
updater
,
txMgr
}
// TestCannonUpdater_UpdateOracle tests the [cannonUpdater]
// UpdateOracle function.
func
TestCannonUpdater_UpdateOracle
(
t
*
testing
.
T
)
{
t
.
Run
(
"succeeds"
,
func
(
t
*
testing
.
T
)
{
_
,
_
=
newTestCannonUpdater
(
t
,
false
)
// require.Nil(t, updater.UpdateOracle(context.Background(), types.PreimageOracleData{}))
// require.Equal(t, 1, mockTxMgr.calls)
})
t
.
Run
(
"send fails"
,
func
(
t
*
testing
.
T
)
{
_
,
_
=
newTestCannonUpdater
(
t
,
true
)
// require.Error(t, updater.UpdateOracle(context.Background(), types.PreimageOracleData{}))
// require.Equal(t, 1, mockTxMgr.calls)
})
}
op-challenger/fault/service.go
View file @
710ca379
...
@@ -31,14 +31,35 @@ type service struct {
...
@@ -31,14 +31,35 @@ type service struct {
// NewService creates a new Service.
// NewService creates a new Service.
func
NewService
(
ctx
context
.
Context
,
logger
log
.
Logger
,
cfg
*
config
.
Config
)
(
*
service
,
error
)
{
func
NewService
(
ctx
context
.
Context
,
logger
log
.
Logger
,
cfg
*
config
.
Config
)
(
*
service
,
error
)
{
client
,
err
:=
ethclient
.
Dial
(
cfg
.
L1EthRpc
)
txMgr
,
err
:=
txmgr
.
NewSimpleTxManager
(
"challenger"
,
logger
,
&
metrics
.
NoopTxMetrics
{},
cfg
.
TxMgrConfig
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to
dial L1
: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to
create the transaction manager
: %w"
,
err
)
}
}
txMgr
,
err
:=
txmgr
.
NewSimpleTxManager
(
"challenger"
,
logger
,
&
metrics
.
NoopTxMetrics
{},
cfg
.
TxMgrConfig
)
var
trace
types
.
TraceProvider
var
updater
types
.
OracleUpdater
switch
cfg
.
TraceType
{
case
config
.
TraceTypeCannon
:
trace
=
cannon
.
NewTraceProvider
(
logger
,
cfg
)
updater
,
err
=
cannon
.
NewOracleUpdater
(
logger
,
txMgr
,
cfg
.
GameAddress
,
cfg
.
PreimageOracleAddress
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to create the transaction manager: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to create the cannon updater: %w"
,
err
)
}
case
config
.
TraceTypeAlphabet
:
trace
=
alphabet
.
NewTraceProvider
(
cfg
.
AlphabetTrace
,
uint64
(
cfg
.
GameDepth
))
updater
=
alphabet
.
NewOracleUpdater
(
logger
)
default
:
return
nil
,
fmt
.
Errorf
(
"unsupported trace type: %v"
,
cfg
.
TraceType
)
}
return
newTypedService
(
ctx
,
logger
,
cfg
,
trace
,
updater
,
txMgr
)
}
// newTypedService creates a new Service from a provided trace provider.
func
newTypedService
(
ctx
context
.
Context
,
logger
log
.
Logger
,
cfg
*
config
.
Config
,
provider
types
.
TraceProvider
,
uploader
types
.
OracleUpdater
,
txMgr
txmgr
.
TxManager
)
(
*
service
,
error
)
{
client
,
err
:=
ethclient
.
Dial
(
cfg
.
L1EthRpc
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to dial L1: %w"
,
err
)
}
}
contract
,
err
:=
bindings
.
NewFaultDisputeGameCaller
(
cfg
.
GameAddress
,
client
)
contract
,
err
:=
bindings
.
NewFaultDisputeGameCaller
(
cfg
.
GameAddress
,
client
)
...
@@ -53,23 +74,13 @@ func NewService(ctx context.Context, logger log.Logger, cfg *config.Config) (*se
...
@@ -53,23 +74,13 @@ func NewService(ctx context.Context, logger log.Logger, cfg *config.Config) (*se
return
nil
,
fmt
.
Errorf
(
"failed to create the responder: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to create the responder: %w"
,
err
)
}
}
var
trace
types
.
TraceProvider
switch
cfg
.
TraceType
{
case
config
.
TraceTypeCannon
:
trace
=
cannon
.
NewTraceProvider
(
logger
,
cfg
)
case
config
.
TraceTypeAlphabet
:
trace
=
alphabet
.
NewTraceProvider
(
cfg
.
AlphabetTrace
,
uint64
(
cfg
.
GameDepth
))
default
:
return
nil
,
fmt
.
Errorf
(
"unsupported trace type: %v"
,
cfg
.
TraceType
)
}
agent
:=
NewAgent
(
loader
,
cfg
.
GameDepth
,
trace
,
responder
,
cfg
.
AgreeWithProposedOutput
,
gameLogger
)
caller
,
err
:=
NewFaultCallerFromBindings
(
cfg
.
GameAddress
,
client
,
gameLogger
)
caller
,
err
:=
NewFaultCallerFromBindings
(
cfg
.
GameAddress
,
client
,
gameLogger
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to bind the fault contract: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to bind the fault contract: %w"
,
err
)
}
}
agent
:=
NewAgent
(
loader
,
cfg
.
GameDepth
,
provider
,
responder
,
cfg
.
AgreeWithProposedOutput
,
gameLogger
)
return
&
service
{
return
&
service
{
agent
:
agent
,
agent
:
agent
,
agreeWithProposedOutput
:
cfg
.
AgreeWithProposedOutput
,
agreeWithProposedOutput
:
cfg
.
AgreeWithProposedOutput
,
...
...
op-challenger/fault/types/types.go
View file @
710ca379
...
@@ -44,6 +44,12 @@ type StepCallData struct {
...
@@ -44,6 +44,12 @@ type StepCallData struct {
Proof
[]
byte
Proof
[]
byte
}
}
// OracleUpdater is a generic interface for updating oracles.
type
OracleUpdater
interface
{
// UpdateOracle updates the oracle with the given data.
UpdateOracle
(
ctx
context
.
Context
,
data
PreimageOracleData
)
error
}
// TraceProvider is a generic way to get a claim value at a specific step in the trace.
// TraceProvider is a generic way to get a claim value at a specific step in the trace.
type
TraceProvider
interface
{
type
TraceProvider
interface
{
// Get returns the claim value at the requested index.
// Get returns the claim value at the requested index.
...
...
op-challenger/flags/flags.go
View file @
710ca379
...
@@ -5,12 +5,13 @@ import (
...
@@ -5,12 +5,13 @@ import (
"strings"
"strings"
"github.com/ethereum-optimism/optimism/op-challenger/config"
"github.com/ethereum-optimism/optimism/op-challenger/config"
openum
"github.com/ethereum-optimism/optimism/op-service/enum"
"github.com/urfave/cli/v2"
opservice
"github.com/ethereum-optimism/optimism/op-service"
opservice
"github.com/ethereum-optimism/optimism/op-service"
openum
"github.com/ethereum-optimism/optimism/op-service/enum"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
txmgr
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/urfave/cli/v2"
)
)
const
(
const
(
...
@@ -58,6 +59,11 @@ var (
...
@@ -58,6 +59,11 @@ var (
Usage
:
"Correct Alphabet Trace (alphabet trace type only)"
,
Usage
:
"Correct Alphabet Trace (alphabet trace type only)"
,
EnvVars
:
prefixEnvVars
(
"ALPHABET"
),
EnvVars
:
prefixEnvVars
(
"ALPHABET"
),
}
}
PreimageOracleAddressFlag
=
&
cli
.
StringFlag
{
Name
:
"preimage-oracle-address"
,
Usage
:
"Address of the Preimage Oracle contract (only required for cannon)."
,
EnvVars
:
prefixEnvVars
(
"PREIMAGE_ORACLE_ADDRESS"
),
}
CannonBinFlag
=
&
cli
.
StringFlag
{
CannonBinFlag
=
&
cli
.
StringFlag
{
Name
:
"cannon-bin"
,
Name
:
"cannon-bin"
,
Usage
:
"Path to cannon executable to use when generating trace data (cannon trace type only)"
,
Usage
:
"Path to cannon executable to use when generating trace data (cannon trace type only)"
,
...
@@ -103,6 +109,7 @@ var requiredFlags = []cli.Flag{
...
@@ -103,6 +109,7 @@ var requiredFlags = []cli.Flag{
// optionalFlags is a list of unchecked cli flags
// optionalFlags is a list of unchecked cli flags
var
optionalFlags
=
[]
cli
.
Flag
{
var
optionalFlags
=
[]
cli
.
Flag
{
AlphabetFlag
,
AlphabetFlag
,
PreimageOracleAddressFlag
,
CannonBinFlag
,
CannonBinFlag
,
CannonServerFlag
,
CannonServerFlag
,
CannonPreStateFlag
,
CannonPreStateFlag
,
...
@@ -130,6 +137,9 @@ func CheckRequired(ctx *cli.Context) error {
...
@@ -130,6 +137,9 @@ func CheckRequired(ctx *cli.Context) error {
gameType
:=
config
.
TraceType
(
strings
.
ToLower
(
ctx
.
String
(
TraceTypeFlag
.
Name
)))
gameType
:=
config
.
TraceType
(
strings
.
ToLower
(
ctx
.
String
(
TraceTypeFlag
.
Name
)))
switch
gameType
{
switch
gameType
{
case
config
.
TraceTypeCannon
:
case
config
.
TraceTypeCannon
:
if
!
ctx
.
IsSet
(
PreimageOracleAddressFlag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
PreimageOracleAddressFlag
.
Name
)
}
if
!
ctx
.
IsSet
(
CannonBinFlag
.
Name
)
{
if
!
ctx
.
IsSet
(
CannonBinFlag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonBinFlag
.
Name
)
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonBinFlag
.
Name
)
}
}
...
@@ -169,11 +179,21 @@ func NewConfigFromCLI(ctx *cli.Context) (*config.Config, error) {
...
@@ -169,11 +179,21 @@ func NewConfigFromCLI(ctx *cli.Context) (*config.Config, error) {
traceTypeFlag
:=
config
.
TraceType
(
strings
.
ToLower
(
ctx
.
String
(
TraceTypeFlag
.
Name
)))
traceTypeFlag
:=
config
.
TraceType
(
strings
.
ToLower
(
ctx
.
String
(
TraceTypeFlag
.
Name
)))
preimageOracleAddress
:=
common
.
Address
{}
preimageOracleValue
:=
ctx
.
String
(
PreimageOracleAddressFlag
.
Name
)
if
traceTypeFlag
==
config
.
TraceTypeCannon
||
preimageOracleValue
!=
""
{
preimageOracleAddress
,
err
=
opservice
.
ParseAddress
(
preimageOracleValue
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
&
config
.
Config
{
return
&
config
.
Config
{
// Required Flags
// Required Flags
L1EthRpc
:
ctx
.
String
(
L1EthRpcFlag
.
Name
),
L1EthRpc
:
ctx
.
String
(
L1EthRpcFlag
.
Name
),
TraceType
:
traceTypeFlag
,
TraceType
:
traceTypeFlag
,
GameAddress
:
dgfAddress
,
GameAddress
:
dgfAddress
,
PreimageOracleAddress
:
preimageOracleAddress
,
AlphabetTrace
:
ctx
.
String
(
AlphabetFlag
.
Name
),
AlphabetTrace
:
ctx
.
String
(
AlphabetFlag
.
Name
),
CannonBin
:
ctx
.
String
(
CannonBinFlag
.
Name
),
CannonBin
:
ctx
.
String
(
CannonBinFlag
.
Name
),
CannonServer
:
ctx
.
String
(
CannonServerFlag
.
Name
),
CannonServer
:
ctx
.
String
(
CannonServerFlag
.
Name
),
...
...
op-challenger/mallory.sh
View file @
710ca379
...
@@ -14,11 +14,14 @@ MALLORY_KEY="28d7045146193f5f4eeb151c4843544b1b0d30a7ac1680c845a416fac65a7715"
...
@@ -14,11 +14,14 @@ MALLORY_KEY="28d7045146193f5f4eeb151c4843544b1b0d30a7ac1680c845a416fac65a7715"
FAULT_GAME_ADDRESS
=
"0x8daf17a20c9dba35f005b6324f493785d239719d"
FAULT_GAME_ADDRESS
=
"0x8daf17a20c9dba35f005b6324f493785d239719d"
PREIMAGE_ORACLE_ADDRESS
=
"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
./bin/op-challenger
\
./bin/op-challenger
\
--l1-eth-rpc
http://localhost:8545
\
--l1-eth-rpc
http://localhost:8545
\
--trace-type
=
"alphabet"
\
--trace-type
=
"alphabet"
\
--alphabet
"abcdexyz"
\
--alphabet
"abcdexyz"
\
--game-address
$FAULT_GAME_ADDRESS
\
--game-address
$FAULT_GAME_ADDRESS
\
--preimage-oracle-address
$PREIMAGE_ORACLE_ADDRESS
\
--private-key
$MALLORY_KEY
\
--private-key
$MALLORY_KEY
\
--num-confirmations
1
\
--num-confirmations
1
\
--game-depth
4
\
--game-depth
4
\
...
...
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