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
b59b8710
Commit
b59b8710
authored
Sep 06, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add error to `StateWitness::StateHash`
parent
c04d3959
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
26 deletions
+51
-26
run.go
cannon/cmd/run.go
+8
-2
witness.go
cannon/cmd/witness.go
+4
-1
evm_test.go
cannon/mipsevm/evm_test.go
+2
-1
state.go
cannon/mipsevm/state.go
+21
-12
provider.go
op-challenger/game/fault/trace/cannon/provider.go
+15
-3
FaultDisputeGame.t.sol
packages/contracts-bedrock/test/FaultDisputeGame.t.sol
+1
-7
No files found.
cannon/cmd/run.go
View file @
b59b8710
...
...
@@ -330,12 +330,18 @@ func Run(ctx *cli.Context) error {
}
if
proofAt
(
state
)
{
preStateHash
:=
state
.
EncodeWitness
()
.
StateHash
()
preStateHash
,
err
:=
state
.
EncodeWitness
()
.
StateHash
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to hash prestate witness: %w"
,
err
)
}
witness
,
err
:=
stepFn
(
true
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed at proof-gen step %d (PC: %08x): %w"
,
step
,
state
.
PC
,
err
)
}
postStateHash
:=
state
.
EncodeWitness
()
.
StateHash
()
postStateHash
,
err
:=
state
.
EncodeWitness
()
.
StateHash
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to hash poststate witness: %w"
,
err
)
}
proof
:=
&
Proof
{
Step
:
step
,
Pre
:
preStateHash
,
...
...
cannon/cmd/witness.go
View file @
b59b8710
...
...
@@ -30,7 +30,10 @@ func Witness(ctx *cli.Context) error {
return
fmt
.
Errorf
(
"invalid input state (%v): %w"
,
input
,
err
)
}
witness
:=
state
.
EncodeWitness
()
h
:=
witness
.
StateHash
()
h
,
err
:=
witness
.
StateHash
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to compute witness hash: %w"
,
err
)
}
if
output
!=
""
{
if
err
:=
os
.
WriteFile
(
output
,
witness
,
0755
);
err
!=
nil
{
return
fmt
.
Errorf
(
"writing output to %v: %w"
,
output
,
err
)
...
...
cannon/mipsevm/evm_test.go
View file @
b59b8710
...
...
@@ -92,7 +92,8 @@ func (m *MIPSEVM) Step(t *testing.T, stepWitness *StepWitness) []byte {
require
.
Equal
(
t
,
1
,
len
(
logs
),
"expecting a log with post-state"
)
evmPost
:=
logs
[
0
]
.
Data
stateHash
:=
StateWitness
(
evmPost
)
.
StateHash
()
stateHash
,
err
:=
StateWitness
(
evmPost
)
.
StateHash
()
require
.
NoError
(
t
,
err
,
"state hash could not be computed"
)
require
.
Equal
(
t
,
stateHash
,
postHash
,
"logged state must be accurate"
)
m
.
env
.
StateDB
.
RevertToSnapshot
(
snap
)
...
...
cannon/mipsevm/state.go
View file @
b59b8710
...
...
@@ -2,12 +2,16 @@ package mipsevm
import
(
"encoding/binary"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
// StateWitnessSize is the size of the state witness encoding in bytes.
var
StateWitnessSize
=
226
type
State
struct
{
Memory
*
Memory
`json:"memory"`
...
...
@@ -75,18 +79,26 @@ const (
VMStatusUnfinished
=
3
)
func
(
sw
StateWitness
)
StateHash
()
common
.
Hash
{
func
(
sw
StateWitness
)
StateHash
()
(
common
.
Hash
,
error
)
{
hash
:=
crypto
.
Keccak256Hash
(
sw
)
offset
:=
32
*
2
+
4
*
6
if
len
(
sw
)
!=
226
{
return
common
.
Hash
{},
fmt
.
Errorf
(
"Invalid witness length. Got %d, expected at least 88"
,
len
(
sw
))
}
exitCode
:=
sw
[
offset
]
exited
:=
sw
[
offset
+
1
]
status
:=
vmStatus
(
exited
==
1
,
exitCode
)
hash
[
0
]
=
status
return
hash
return
hash
,
nil
}
func
vmStatus
(
exited
bool
,
exitCode
uint8
)
uint8
{
if
exited
{
if
!
exited
{
return
VMStatusUnfinished
}
switch
exitCode
{
case
0
:
return
VMStatusValid
...
...
@@ -95,7 +107,4 @@ func vmStatus(exited bool, exitCode uint8) uint8 {
default
:
return
VMStatusPanic
}
}
else
{
return
VMStatusUnfinished
}
}
op-challenger/game/fault/trace/cannon/provider.go
View file @
b59b8710
...
...
@@ -128,7 +128,11 @@ func (p *CannonTraceProvider) AbsolutePreStateCommitment(ctx context.Context) (c
if
err
!=
nil
{
return
common
.
Hash
{},
fmt
.
Errorf
(
"cannot load absolute pre-state: %w"
,
err
)
}
return
mipsevm
.
StateWitness
(
state
)
.
StateHash
(),
nil
hash
,
err
:=
mipsevm
.
StateWitness
(
state
)
.
StateHash
()
if
err
!=
nil
{
return
common
.
Hash
{},
fmt
.
Errorf
(
"cannot hash absolute pre-state: %w"
,
err
)
}
return
hash
,
nil
}
// loadProof will attempt to load or generate the proof data at the specified index
...
...
@@ -160,8 +164,12 @@ func (p *CannonTraceProvider) loadProof(ctx context.Context, i uint64) (*proofDa
// Extend the trace out to the full length using a no-op instruction that doesn't change any state
// No execution is done, so no proof-data or oracle values are required.
witness
:=
state
.
EncodeWitness
()
witnessHash
,
err
:=
mipsevm
.
StateWitness
(
witness
)
.
StateHash
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot hash witness: %w"
,
err
)
}
proof
:=
&
proofData
{
ClaimValue
:
witness
.
StateHash
()
,
ClaimValue
:
witness
Hash
,
StateData
:
hexutil
.
Bytes
(
witness
),
ProofData
:
[]
byte
{},
OracleKey
:
nil
,
...
...
@@ -188,5 +196,9 @@ func (p *CannonTraceProvider) loadProof(ctx context.Context, i uint64) (*proofDa
}
func
(
p
*
CannonTraceProvider
)
StateHash
(
ctx
context
.
Context
,
state
[]
byte
)
(
common
.
Hash
,
error
)
{
return
mipsevm
.
StateWitness
(
state
)
.
StateHash
(),
nil
hash
,
err
:=
mipsevm
.
StateWitness
(
state
)
.
StateHash
()
if
err
!=
nil
{
return
common
.
Hash
{},
fmt
.
Errorf
(
"cannot hash state: %w"
,
err
)
}
return
hash
,
nil
}
packages/contracts-bedrock/test/FaultDisputeGame.t.sol
View file @
b59b8710
...
...
@@ -633,13 +633,7 @@ contract OneVsOne_Arena is FaultDisputeGame_Init {
/// @dev The challenger.
GamePlayer internal challenger;
function init(
GamePlayer _defender,
GamePlayer _challenger,
uint256 _finalTraceIndex
)
public
{
function init(GamePlayer _defender, GamePlayer _challenger, uint256 _finalTraceIndex) public {
Claim rootClaim = _defender.claimAt(_finalTraceIndex);
super.init(rootClaim, ABSOLUTE_PRESTATE_CLAIM);
defender = _defender;
...
...
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