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
176478d7
Unverified
Commit
176478d7
authored
Mar 06, 2024
by
Adrian Sutton
Committed by
GitHub
Mar 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-e2e: Add e2e test that checks steps that load local preimages. (#9687)
Co-authored-by:
refcell
<
abigger87@gmail.com
>
parent
beff72f8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
213 additions
and
80 deletions
+213
-80
run.go
cannon/cmd/run.go
+54
-26
instrumented.go
cannon/mipsevm/instrumented.go
+2
-2
provider.go
op-challenger/game/fault/trace/cannon/provider.go
+20
-21
output_cannon_helper.go
op-e2e/e2eutils/disputegame/output_cannon_helper.go
+75
-5
preimages_test.go
op-e2e/faultproofs/preimages_test.go
+53
-0
call.go
op-service/sources/batching/call.go
+7
-25
call_test.go
op-service/sources/batching/call_test.go
+2
-1
No files found.
cannon/cmd/run.go
View file @
176478d7
...
...
@@ -5,6 +5,9 @@ import (
"fmt"
"os"
"os/exec"
"slices"
"strconv"
"strings"
"time"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -65,6 +68,11 @@ var (
Value
:
new
(
StepMatcherFlag
),
Required
:
false
,
}
RunStopAtPreimageFlag
=
&
cli
.
StringFlag
{
Name
:
"stop-at-preimage"
,
Usage
:
"stop at the first preimage request matching this key"
,
Required
:
false
,
}
RunStopAtPreimageTypeFlag
=
&
cli
.
StringFlag
{
Name
:
"stop-at-preimage-type"
,
Usage
:
"stop at the first preimage request matching this type"
,
...
...
@@ -247,18 +255,34 @@ func Run(ctx *cli.Context) error {
errLog
:=
&
mipsevm
.
LoggingWriter
{
Name
:
"program std-err"
,
Log
:
l
}
stopAtAnyPreimage
:=
false
var
stopAtPreimageTypeByte
preimage
.
KeyType
var
stopAtPreimageKeyPrefix
[]
byte
stopAtPreimageOffset
:=
uint32
(
0
)
if
ctx
.
IsSet
(
RunStopAtPreimageFlag
.
Name
)
{
val
:=
ctx
.
String
(
RunStopAtPreimageFlag
.
Name
)
parts
:=
strings
.
Split
(
val
,
"@"
)
if
len
(
parts
)
>
2
{
return
fmt
.
Errorf
(
"invalid %v: %v"
,
RunStopAtPreimageFlag
.
Name
,
val
)
}
stopAtPreimageKeyPrefix
=
common
.
FromHex
(
parts
[
0
])
if
len
(
parts
)
==
2
{
x
,
err
:=
strconv
.
ParseUint
(
parts
[
1
],
10
,
32
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid preimage offset: %w"
,
err
)
}
stopAtPreimageOffset
=
uint32
(
x
)
}
}
else
{
switch
ctx
.
String
(
RunStopAtPreimageTypeFlag
.
Name
)
{
case
"local"
:
stopAtPreimageTypeByte
=
preimage
.
LocalKeyType
stopAtPreimageKeyPrefix
=
[]
byte
{
byte
(
preimage
.
LocalKeyType
)}
case
"keccak"
:
stopAtPreimageTypeByte
=
preimage
.
Keccak256KeyType
stopAtPreimageKeyPrefix
=
[]
byte
{
byte
(
preimage
.
Keccak256KeyType
)}
case
"sha256"
:
stopAtPreimageTypeByte
=
preimage
.
Sha256KeyType
stopAtPreimageKeyPrefix
=
[]
byte
{
byte
(
preimage
.
Sha256KeyType
)}
case
"blob"
:
stopAtPreimageTypeByte
=
preimage
.
BlobKeyType
stopAtPreimageKeyPrefix
=
[]
byte
{
byte
(
preimage
.
BlobKeyType
)}
case
"precompile"
:
stopAtPreimageTypeByte
=
preimage
.
PrecompileKeyType
stopAtPreimageKeyPrefix
=
[]
byte
{
byte
(
preimage
.
PrecompileKeyType
)}
case
"any"
:
stopAtAnyPreimage
=
true
case
""
:
...
...
@@ -266,6 +290,7 @@ func Run(ctx *cli.Context) error {
default
:
return
fmt
.
Errorf
(
"invalid preimage type %q"
,
ctx
.
String
(
RunStopAtPreimageTypeFlag
.
Name
))
}
}
stopAtPreimageLargerThan
:=
ctx
.
Int
(
RunStopAtPreimageLargerThanFlag
.
Name
)
// split CLI args after first '--'
...
...
@@ -362,8 +387,6 @@ func Run(ctx *cli.Context) error {
}
}
prevPreimageOffset
:=
state
.
PreimageOffset
if
proofAt
(
state
)
{
preStateHash
,
err
:=
state
.
EncodeWitness
()
.
StateHash
()
if
err
!=
nil
{
...
...
@@ -399,17 +422,21 @@ func Run(ctx *cli.Context) error {
}
}
if
preimageRead
:=
state
.
PreimageOffset
>
prevPreimageOffset
;
preimageRead
{
lastPreimageKey
,
lastPreimageValue
,
lastPreimageOffset
:=
us
.
LastPreimage
()
if
lastPreimageOffset
!=
^
uint32
(
0
)
{
if
stopAtAnyPreimage
{
l
.
Info
(
"Stopping at preimage read"
)
break
}
if
state
.
PreimageKey
.
Bytes
()[
0
]
==
byte
(
stopAtPreimageTypeByte
)
{
l
.
Info
(
"Stopping at preimage read"
,
"type"
,
stopAtPreimageTypeByte
)
if
len
(
stopAtPreimageKeyPrefix
)
>
0
&&
slices
.
Equal
(
lastPreimageKey
[
:
len
(
stopAtPreimageKeyPrefix
)],
stopAtPreimageKeyPrefix
)
{
if
stopAtPreimageOffset
==
lastPreimageOffset
{
l
.
Info
(
"Stopping at preimage read"
,
"keyPrefix"
,
common
.
Bytes2Hex
(
stopAtPreimageKeyPrefix
),
"offset"
,
lastPreimageOffset
)
break
}
if
stopAtPreimageLargerThan
!=
0
&&
len
(
us
.
LastPreimage
())
>
stopAtPreimageLargerThan
{
l
.
Info
(
"Stopping at preimage read"
,
"size"
,
len
(
us
.
LastPreimage
()),
"min"
,
stopAtPreimageLargerThan
)
}
if
stopAtPreimageLargerThan
!=
0
&&
len
(
lastPreimageValue
)
>
stopAtPreimageLargerThan
{
l
.
Info
(
"Stopping at preimage read"
,
"size"
,
len
(
lastPreimageValue
),
"min"
,
stopAtPreimageLargerThan
)
break
}
}
...
...
@@ -435,6 +462,7 @@ var RunCommand = &cli.Command{
RunSnapshotAtFlag
,
RunSnapshotFmtFlag
,
RunStopAtFlag
,
RunStopAtPreimageFlag
,
RunStopAtPreimageTypeFlag
,
RunStopAtPreimageLargerThanFlag
,
RunMetaFlag
,
...
...
cannon/mipsevm/instrumented.go
View file @
176478d7
...
...
@@ -81,6 +81,6 @@ func (m *InstrumentedState) Step(proof bool) (wit *StepWitness, err error) {
return
}
func
(
m
*
InstrumentedState
)
LastPreimage
()
[]
byte
{
return
m
.
lastPreimage
func
(
m
*
InstrumentedState
)
LastPreimage
()
([
32
]
byte
,
[]
byte
,
uint32
)
{
return
m
.
lastPreimage
Key
,
m
.
lastPreimage
,
m
.
lastPreimageOffset
}
op-challenger/game/fault/trace/cannon/provider.go
View file @
176478d7
...
...
@@ -13,6 +13,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/config"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-program/host/kvstore"
"github.com/ethereum-optimism/optimism/op-service/ioutil"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -255,6 +256,12 @@ type preimageOpts []string
type
PreimageOpt
func
()
preimageOpts
func
PreimageLoad
(
key
preimage
.
Key
,
offset
uint32
)
PreimageOpt
{
return
func
()
preimageOpts
{
return
[]
string
{
"--stop-at-preimage"
,
fmt
.
Sprintf
(
"%v@%v"
,
common
.
Hash
(
key
.
PreimageKey
())
.
Hex
(),
offset
)}
}
}
func
FirstPreimageLoadOfType
(
preimageType
string
)
PreimageOpt
{
return
func
()
preimageOpts
{
return
[]
string
{
"--stop-at-preimage-type"
,
preimageType
}
...
...
@@ -287,28 +294,20 @@ func NewTraceProviderForTest(logger log.Logger, m CannonMetricer, cfg *config.Co
return
&
CannonTraceProviderForTest
{
p
}
}
func
(
p
*
CannonTraceProviderForTest
)
FindStep
(
ctx
context
.
Context
,
start
uint64
,
preimage
PreimageOpt
)
(
uint64
,
common
.
Hash
,
error
)
{
// First generate a snapshot of the starting state, so we can snap to it later for the full trace search
prestateProof
,
err
:=
p
.
loadProof
(
ctx
,
start
)
if
err
!=
nil
{
return
0
,
common
.
Hash
{},
err
}
start
+=
1
for
{
func
(
p
*
CannonTraceProviderForTest
)
FindStep
(
ctx
context
.
Context
,
start
uint64
,
preimage
PreimageOpt
)
(
uint64
,
error
)
{
// Run cannon to find the step that meets the preimage conditions
if
err
:=
p
.
generator
.
(
*
Executor
)
.
generateProof
(
ctx
,
p
.
dir
,
start
,
math
.
MaxUint64
,
preimage
()
...
);
err
!=
nil
{
return
0
,
common
.
Hash
{},
fmt
.
Errorf
(
"generate cannon trace (until preimage read) with proof at %d: %w"
,
start
,
err
)
return
0
,
fmt
.
Errorf
(
"generate cannon trace (until preimage read): %w"
,
err
)
}
// Load the step from the state cannon finished with
state
,
err
:=
p
.
finalState
()
if
err
!=
nil
{
return
0
,
common
.
Hash
{},
err
return
0
,
fmt
.
Errorf
(
"failed to load final state: %w"
,
err
)
}
// Check we didn't get to the end of the trace without finding the preimage read we were looking for
if
state
.
Exited
{
break
}
if
state
.
PreimageOffset
!=
0
&&
state
.
PreimageOffset
!=
prestateProof
.
OracleOffset
{
return
state
.
Step
-
1
,
state
.
PreimageKey
,
nil
}
start
=
state
.
Step
return
0
,
fmt
.
Errorf
(
"preimage read not found: %w"
,
io
.
EOF
)
}
return
0
,
common
.
Hash
{},
io
.
EOF
// The state is the post-state so the step we want to execute to read the preimage is step - 1.
return
state
.
Step
-
1
,
nil
}
op-e2e/e2eutils/disputegame/output_cannon_helper.go
View file @
176478d7
...
...
@@ -3,10 +3,14 @@ package disputegame
import
(
"context"
"crypto/ecdsa"
"errors"
"io"
"math/big"
"path/filepath"
"time"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-chain-ops/deployer"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/cannon"
...
...
@@ -16,8 +20,10 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/metrics"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/challenger"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
...
...
@@ -124,8 +130,8 @@ func (g *OutputCannonGameHelper) CreateStepPreimageLoadCheck(ctx context.Context
// This expects an odd execution game depth in order for the honest challenger to step on our leaf claim
func
(
g
*
OutputCannonGameHelper
)
ChallengeToPreimageLoad
(
ctx
context
.
Context
,
outputRootClaim
*
ClaimHelper
,
challengerKey
*
ecdsa
.
PrivateKey
,
preimage
cannon
.
PreimageOpt
,
preimageCheck
PreimageLoadCheck
,
preloadPreimage
bool
)
{
// Identifying the first state transition that loads a global preimage
provider
:=
g
.
createCannonTraceProvider
(
ctx
,
"sequencer"
,
outputRootClaim
,
challenger
.
WithPrivKey
(
challengerKey
))
targetTraceIndex
,
_
,
err
:=
provider
.
FindStep
(
ctx
,
0
,
preimage
)
provider
,
_
:=
g
.
createCannonTraceProvider
(
ctx
,
"sequencer"
,
outputRootClaim
,
challenger
.
WithPrivKey
(
challengerKey
))
targetTraceIndex
,
err
:=
provider
.
FindStep
(
ctx
,
0
,
preimage
)
g
.
require
.
NoError
(
err
)
splitDepth
:=
g
.
SplitDepth
(
ctx
)
...
...
@@ -213,7 +219,70 @@ func (g *OutputCannonGameHelper) ChallengeToPreimageLoad(ctx context.Context, ou
g
.
LogGameData
(
ctx
)
}
func
(
g
*
OutputCannonGameHelper
)
createCannonTraceProvider
(
ctx
context
.
Context
,
l2Node
string
,
outputRootClaim
*
ClaimHelper
,
options
...
challenger
.
Option
)
*
cannon
.
CannonTraceProviderForTest
{
func
(
g
*
OutputCannonGameHelper
)
VerifyPreimage
(
ctx
context
.
Context
,
outputRootClaim
*
ClaimHelper
,
preimageKey
preimage
.
Key
)
{
execDepth
:=
g
.
ExecDepth
(
ctx
)
// Identifying the first state transition that loads a global preimage
provider
,
localContext
:=
g
.
createCannonTraceProvider
(
ctx
,
"sequencer"
,
outputRootClaim
,
challenger
.
WithPrivKey
(
deployer
.
TestKey
))
start
:=
uint64
(
0
)
found
:=
false
for
offset
:=
uint32
(
0
);
;
offset
+=
4
{
preimageOpt
:=
cannon
.
PreimageLoad
(
preimageKey
,
offset
)
g
.
t
.
Logf
(
"Searching for step with key %x and offset %v"
,
preimageKey
.
PreimageKey
(),
offset
)
targetTraceIndex
,
err
:=
provider
.
FindStep
(
ctx
,
start
,
preimageOpt
)
if
errors
.
Is
(
err
,
io
.
EOF
)
{
// Did not find any more reads
g
.
require
.
True
(
found
,
"Should have found at least one preimage read"
)
g
.
t
.
Logf
(
"Searching for step with key %x and offset %v did not find another read"
,
preimageKey
.
PreimageKey
(),
offset
)
return
}
g
.
require
.
NoError
(
err
,
"Failed to find step that loads requested preimage"
)
start
=
targetTraceIndex
found
=
true
g
.
t
.
Logf
(
"Target trace index: %v"
,
targetTraceIndex
)
pos
:=
types
.
NewPosition
(
execDepth
,
new
(
big
.
Int
)
.
SetUint64
(
targetTraceIndex
))
g
.
require
.
Equal
(
targetTraceIndex
,
pos
.
TraceIndex
(
execDepth
)
.
Uint64
())
prestate
,
proof
,
oracleData
,
err
:=
provider
.
GetStepData
(
ctx
,
pos
)
g
.
require
.
NoError
(
err
,
"Failed to get step data"
)
g
.
require
.
NotNil
(
oracleData
,
"Should have had required preimage oracle data"
)
g
.
require
.
Equal
(
common
.
Hash
(
preimageKey
.
PreimageKey
())
.
Bytes
(),
oracleData
.
OracleKey
,
"Must have correct preimage key"
)
tx
,
err
:=
g
.
game
.
AddLocalData
(
g
.
opts
,
oracleData
.
GetIdent
(),
big
.
NewInt
(
outputRootClaim
.
index
),
new
(
big
.
Int
)
.
SetUint64
(
uint64
(
oracleData
.
OracleOffset
)))
g
.
require
.
NoError
(
err
)
_
,
err
=
wait
.
ForReceiptOK
(
ctx
,
g
.
client
,
tx
.
Hash
())
g
.
require
.
NoError
(
err
)
expectedPostState
,
err
:=
provider
.
Get
(
ctx
,
pos
)
g
.
require
.
NoError
(
err
,
"Failed to get expected post state"
)
callOpts
:=
&
bind
.
CallOpts
{
Context
:
ctx
}
vmAddr
,
err
:=
g
.
game
.
Vm
(
callOpts
)
g
.
require
.
NoError
(
err
,
"Failed to get VM address"
)
abi
,
err
:=
bindings
.
MIPSMetaData
.
GetAbi
()
g
.
require
.
NoError
(
err
,
"Failed to load MIPS ABI"
)
caller
:=
batching
.
NewMultiCaller
(
g
.
client
.
Client
(),
batching
.
DefaultBatchSize
)
result
,
err
:=
caller
.
SingleCall
(
ctx
,
batching
.
BlockLatest
,
&
batching
.
ContractCall
{
Abi
:
abi
,
Addr
:
vmAddr
,
Method
:
"step"
,
Args
:
[]
interface
{}{
prestate
,
proof
,
localContext
,
},
From
:
g
.
addr
,
})
g
.
require
.
NoError
(
err
,
"Failed to call step"
)
actualPostState
:=
result
.
GetBytes32
(
0
)
g
.
require
.
Equal
(
expectedPostState
,
common
.
Hash
(
actualPostState
))
}
}
func
(
g
*
OutputCannonGameHelper
)
createCannonTraceProvider
(
ctx
context
.
Context
,
l2Node
string
,
outputRootClaim
*
ClaimHelper
,
options
...
challenger
.
Option
)
(
*
cannon
.
CannonTraceProviderForTest
,
common
.
Hash
)
{
splitDepth
:=
g
.
SplitDepth
(
ctx
)
g
.
require
.
EqualValues
(
outputRootClaim
.
Depth
(),
splitDepth
+
1
,
"outputRootClaim must be the root of an execution game"
)
...
...
@@ -234,13 +303,14 @@ func (g *OutputCannonGameHelper) createCannonTraceProvider(ctx context.Context,
l1Head
:=
g
.
getL1Head
(
ctx
)
outputProvider
:=
outputs
.
NewTraceProvider
(
logger
,
prestateProvider
,
rollupClient
,
l1Head
,
splitDepth
,
prestateBlock
,
poststateBlock
)
var
localContext
common
.
Hash
selector
:=
split
.
NewSplitProviderSelector
(
outputProvider
,
splitDepth
,
func
(
ctx
context
.
Context
,
depth
types
.
Depth
,
pre
types
.
Claim
,
post
types
.
Claim
)
(
types
.
TraceProvider
,
error
)
{
agreed
,
disputed
,
err
:=
outputs
.
FetchProposals
(
ctx
,
outputProvider
,
pre
,
post
)
g
.
require
.
NoError
(
err
)
g
.
t
.
Logf
(
"Using trace between blocks %v and %v
\n
"
,
agreed
.
L2BlockNumber
,
disputed
.
L2BlockNumber
)
localInputs
,
err
:=
cannon
.
FetchLocalInputsFromProposals
(
ctx
,
l1Head
.
Hash
,
l2Client
,
agreed
,
disputed
)
g
.
require
.
NoError
(
err
,
"Failed to fetch local inputs"
)
localContext
:
=
outputs
.
CreateLocalContext
(
pre
,
post
)
localContext
=
outputs
.
CreateLocalContext
(
pre
,
post
)
dir
:=
filepath
.
Join
(
cfg
.
Datadir
,
"cannon-trace"
)
subdir
:=
filepath
.
Join
(
dir
,
localContext
.
Hex
())
return
cannon
.
NewTraceProviderForTest
(
logger
,
metrics
.
NoopMetrics
,
cfg
,
localInputs
,
subdir
,
g
.
MaxDepth
(
ctx
)
-
splitDepth
-
1
),
nil
...
...
@@ -253,7 +323,7 @@ func (g *OutputCannonGameHelper) createCannonTraceProvider(ctx context.Context,
provider
,
err
:=
selector
(
ctx
,
game
,
game
.
Claims
()[
outputRootClaim
.
parentIndex
],
outputRootClaim
.
position
)
g
.
require
.
NoError
(
err
)
translatingProvider
:=
provider
.
(
*
trace
.
TranslatingProvider
)
return
translatingProvider
.
Original
()
.
(
*
cannon
.
CannonTraceProviderForTest
)
return
translatingProvider
.
Original
()
.
(
*
cannon
.
CannonTraceProviderForTest
)
,
localContext
}
func
(
g
*
OutputCannonGameHelper
)
defaultChallengerOptions
(
l2Node
string
)
[]
challenger
.
Option
{
...
...
op-e2e/faultproofs/preimages_test.go
0 → 100644
View file @
176478d7
package
faultproofs
import
(
"context"
"fmt"
"testing"
op_e2e
"github.com/ethereum-optimism/optimism/op-e2e"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-program/client"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func
TestLocalPreimages
(
t
*
testing
.
T
)
{
op_e2e
.
InitParallel
(
t
,
op_e2e
.
UsesCannon
)
tests
:=
[]
struct
{
key
preimage
.
Key
}{
{
key
:
client
.
L1HeadLocalIndex
},
{
key
:
client
.
L2OutputRootLocalIndex
},
{
key
:
client
.
L2ClaimLocalIndex
},
{
key
:
client
.
L2ClaimBlockNumberLocalIndex
},
// We don't check client.L2ChainIDLocalIndex because e2e tests use a custom chain configuration
// which requires using a custom chain ID indicator so op-program will load the full rollup config and
// genesis from the preimage oracle
}
for
_
,
test
:=
range
tests
{
test
:=
test
t
.
Run
(
fmt
.
Sprintf
(
"preimage-%v"
,
test
.
key
),
func
(
t
*
testing
.
T
)
{
op_e2e
.
InitParallel
(
t
,
op_e2e
.
UsesCannon
)
ctx
:=
context
.
Background
()
sys
,
_
:=
startFaultDisputeSystem
(
t
)
t
.
Cleanup
(
sys
.
Close
)
disputeGameFactory
:=
disputegame
.
NewFactoryHelper
(
t
,
ctx
,
sys
)
game
:=
disputeGameFactory
.
StartOutputCannonGame
(
ctx
,
"sequencer"
,
3
,
common
.
Hash
{
0x01
,
0xaa
})
require
.
NotNil
(
t
,
game
)
claim
:=
game
.
DisputeLastBlock
(
ctx
)
// Create the root of the cannon trace.
claim
=
claim
.
Attack
(
ctx
,
common
.
Hash
{
0x01
})
game
.
LogGameData
(
ctx
)
game
.
VerifyPreimage
(
ctx
,
claim
,
test
.
key
)
game
.
LogGameData
(
ctx
)
})
}
}
op-service/sources/batching/call.go
View file @
176478d7
...
...
@@ -5,7 +5,6 @@ import (
"math/big"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
...
...
@@ -16,6 +15,7 @@ type ContractCall struct {
Addr
common
.
Address
Method
string
Args
[]
interface
{}
From
common
.
Address
}
func
NewContractCall
(
abi
*
abi
.
ABI
,
addr
common
.
Address
,
method
string
,
args
...
interface
{})
*
ContractCall
{
...
...
@@ -36,11 +36,13 @@ func (c *ContractCall) ToCallArgs() (interface{}, error) {
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to pack arguments: %w"
,
err
)
}
msg
:=
ethereum
.
CallMsg
{
To
:
&
c
.
Addr
,
Data
:
data
,
arg
:=
map
[
string
]
interface
{}{
"from"
:
c
.
From
,
"to"
:
&
c
.
Addr
,
"input"
:
hexutil
.
Bytes
(
data
),
}
return
toCallArg
(
msg
)
,
nil
return
arg
,
nil
}
func
(
c
*
ContractCall
)
Unpack
(
hex
hexutil
.
Bytes
)
(
*
CallResult
,
error
)
{
...
...
@@ -51,26 +53,6 @@ func (c *ContractCall) Unpack(hex hexutil.Bytes) (*CallResult, error) {
return
&
CallResult
{
out
:
out
},
nil
}
func
toCallArg
(
msg
ethereum
.
CallMsg
)
interface
{}
{
arg
:=
map
[
string
]
interface
{}{
"from"
:
msg
.
From
,
"to"
:
msg
.
To
,
}
if
len
(
msg
.
Data
)
>
0
{
arg
[
"input"
]
=
hexutil
.
Bytes
(
msg
.
Data
)
}
if
msg
.
Value
!=
nil
{
arg
[
"value"
]
=
(
*
hexutil
.
Big
)(
msg
.
Value
)
}
if
msg
.
Gas
!=
0
{
arg
[
"gas"
]
=
hexutil
.
Uint64
(
msg
.
Gas
)
}
if
msg
.
GasPrice
!=
nil
{
arg
[
"gasPrice"
]
=
(
*
hexutil
.
Big
)(
msg
.
GasPrice
)
}
return
arg
}
func
(
c
*
ContractCall
)
ToTxCandidate
()
(
txmgr
.
TxCandidate
,
error
)
{
data
,
err
:=
c
.
Pack
()
if
err
!=
nil
{
...
...
op-service/sources/batching/call_test.go
View file @
176478d7
...
...
@@ -15,11 +15,12 @@ func TestContractCall_ToCallArgs(t *testing.T) {
testAbi
,
err
:=
bindings
.
ERC20MetaData
.
GetAbi
()
require
.
NoError
(
t
,
err
)
call
:=
NewContractCall
(
testAbi
,
addr
,
"approve"
,
common
.
Address
{
0xcc
},
big
.
NewInt
(
1234444
))
call
.
From
=
common
.
Address
{
0xab
}
args
,
err
:=
call
.
ToCallArgs
()
require
.
NoError
(
t
,
err
)
argMap
,
ok
:=
args
.
(
map
[
string
]
interface
{})
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
argMap
[
"from"
],
c
ommon
.
Address
{}
)
require
.
Equal
(
t
,
argMap
[
"from"
],
c
all
.
From
)
require
.
Equal
(
t
,
argMap
[
"to"
],
&
addr
)
expectedData
,
err
:=
call
.
Pack
()
require
.
NoError
(
t
,
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