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
93b59bf7
Commit
93b59bf7
authored
Oct 11, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom type for `LocalContext` - @tynes review
Co-Authored-By:
Mark Tyneway
<
mark.tyneway@gmail.com
>
parent
330c2f74
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
28 deletions
+25
-28
evm.go
cannon/mipsevm/evm.go
+15
-23
witness.go
cannon/mipsevm/witness.go
+6
-4
updater_test.go
op-challenger/game/fault/trace/cannon/updater_test.go
+4
-1
No files found.
cannon/mipsevm/evm.go
View file @
93b59bf7
...
@@ -28,6 +28,21 @@ var (
...
@@ -28,6 +28,21 @@ var (
LoadLocalDataBytes4
[]
byte
LoadLocalDataBytes4
[]
byte
)
)
func
init
()
{
mipsAbi
,
err
:=
bindings
.
MIPSMetaData
.
GetAbi
()
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"failed to load MIPS ABI: %w"
,
err
))
}
StepBytes4
=
mipsAbi
.
Methods
[
"step"
]
.
ID
[
:
4
]
preimageAbi
,
err
:=
bindings
.
PreimageOracleMetaData
.
GetAbi
()
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"failed to load pre-image oracle ABI: %w"
,
err
))
}
LoadKeccak256PreimagePartBytes4
=
preimageAbi
.
Methods
[
"loadKeccak256PreimagePart"
]
.
ID
[
:
4
]
LoadLocalDataBytes4
=
preimageAbi
.
Methods
[
"loadLocalData"
]
.
ID
[
:
4
]
}
// LoadContracts loads the Cannon contracts, from op-bindings package
// LoadContracts loads the Cannon contracts, from op-bindings package
func
LoadContracts
()
(
*
Contracts
,
error
)
{
func
LoadContracts
()
(
*
Contracts
,
error
)
{
var
mips
,
oracle
Contract
var
mips
,
oracle
Contract
...
@@ -35,9 +50,6 @@ func LoadContracts() (*Contracts, error) {
...
@@ -35,9 +50,6 @@ func LoadContracts() (*Contracts, error) {
mips
.
DeployedBytecode
.
SourceMap
=
bindings
.
MIPSDeployedSourceMap
mips
.
DeployedBytecode
.
SourceMap
=
bindings
.
MIPSDeployedSourceMap
oracle
.
DeployedBytecode
.
Object
=
hexutil
.
MustDecode
(
bindings
.
PreimageOracleDeployedBin
)
oracle
.
DeployedBytecode
.
Object
=
hexutil
.
MustDecode
(
bindings
.
PreimageOracleDeployedBin
)
oracle
.
DeployedBytecode
.
SourceMap
=
bindings
.
PreimageOracleDeployedSourceMap
oracle
.
DeployedBytecode
.
SourceMap
=
bindings
.
PreimageOracleDeployedSourceMap
if
err
:=
InitSelectors
();
err
!=
nil
{
return
nil
,
err
}
return
&
Contracts
{
return
&
Contracts
{
MIPS
:
&
mips
,
MIPS
:
&
mips
,
Oracle
:
&
oracle
,
Oracle
:
&
oracle
,
...
@@ -54,32 +66,12 @@ func LoadContractsFromFiles() (*Contracts, error) {
...
@@ -54,32 +66,12 @@ func LoadContractsFromFiles() (*Contracts, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
err
:=
InitSelectors
();
err
!=
nil
{
return
nil
,
err
}
return
&
Contracts
{
return
&
Contracts
{
MIPS
:
mips
,
MIPS
:
mips
,
Oracle
:
oracle
,
Oracle
:
oracle
,
},
nil
},
nil
}
}
func
InitSelectors
()
error
{
mipsAbi
,
err
:=
bindings
.
MIPSMetaData
.
GetAbi
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to load MIPS ABI: %w"
,
err
)
}
StepBytes4
=
mipsAbi
.
Methods
[
"step"
]
.
ID
[
:
4
]
preimageAbi
,
err
:=
bindings
.
PreimageOracleMetaData
.
GetAbi
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to load pre-image oracle ABI: %w"
,
err
)
}
LoadKeccak256PreimagePartBytes4
=
preimageAbi
.
Methods
[
"loadKeccak256PreimagePart"
]
.
ID
[
:
4
]
LoadLocalDataBytes4
=
preimageAbi
.
Methods
[
"loadLocalData"
]
.
ID
[
:
4
]
return
nil
}
func
LoadContract
(
name
string
)
(
*
Contract
,
error
)
{
func
LoadContract
(
name
string
)
(
*
Contract
,
error
)
{
dat
,
err
:=
os
.
ReadFile
(
fmt
.
Sprintf
(
"../../packages/contracts-bedrock/forge-artifacts/%s.sol/%s.json"
,
name
,
name
))
dat
,
err
:=
os
.
ReadFile
(
fmt
.
Sprintf
(
"../../packages/contracts-bedrock/forge-artifacts/%s.sol/%s.json"
,
name
,
name
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
cannon/mipsevm/witness.go
View file @
93b59bf7
...
@@ -8,6 +8,8 @@ import (
...
@@ -8,6 +8,8 @@ import (
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
)
)
type
LocalContext
uint64
type
StepWitness
struct
{
type
StepWitness
struct
{
// encoded state witness
// encoded state witness
State
[]
byte
State
[]
byte
...
@@ -25,7 +27,7 @@ func uint32ToBytes32(v uint32) []byte {
...
@@ -25,7 +27,7 @@ func uint32ToBytes32(v uint32) []byte {
return
out
[
:
]
return
out
[
:
]
}
}
func
(
wit
*
StepWitness
)
EncodeStepInput
(
localContext
uint32
)
[]
byte
{
func
(
wit
*
StepWitness
)
EncodeStepInput
(
localContext
LocalContext
)
[]
byte
{
abiStateLen
:=
len
(
wit
.
State
)
abiStateLen
:=
len
(
wit
.
State
)
if
abiStateLen
%
32
!=
0
{
if
abiStateLen
%
32
!=
0
{
abiStateLen
+=
32
-
(
abiStateLen
%
32
)
abiStateLen
+=
32
-
(
abiStateLen
%
32
)
...
@@ -38,7 +40,7 @@ func (wit *StepWitness) EncodeStepInput(localContext uint32) []byte {
...
@@ -38,7 +40,7 @@ func (wit *StepWitness) EncodeStepInput(localContext uint32) []byte {
input
=
append
(
input
,
StepBytes4
...
)
input
=
append
(
input
,
StepBytes4
...
)
input
=
append
(
input
,
uint32ToBytes32
(
32
*
3
)
...
)
// state data offset in bytes
input
=
append
(
input
,
uint32ToBytes32
(
32
*
3
)
...
)
// state data offset in bytes
input
=
append
(
input
,
uint32ToBytes32
(
32
*
3
+
32
+
uint32
(
len
(
abiState
)))
...
)
// proof data offset in bytes
input
=
append
(
input
,
uint32ToBytes32
(
32
*
3
+
32
+
uint32
(
len
(
abiState
)))
...
)
// proof data offset in bytes
input
=
append
(
input
,
uint32ToBytes32
(
localContext
)
...
)
// local context in bytes
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
localContext
))
...
)
// local context in bytes
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
len
(
wit
.
State
)))
...
)
// state data length in bytes
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
len
(
wit
.
State
)))
...
)
// state data length in bytes
input
=
append
(
input
,
abiState
[
:
]
...
)
input
=
append
(
input
,
abiState
[
:
]
...
)
...
@@ -51,7 +53,7 @@ func (wit *StepWitness) HasPreimage() bool {
...
@@ -51,7 +53,7 @@ func (wit *StepWitness) HasPreimage() bool {
return
wit
.
PreimageKey
!=
([
32
]
byte
{})
return
wit
.
PreimageKey
!=
([
32
]
byte
{})
}
}
func
(
wit
*
StepWitness
)
EncodePreimageOracleInput
(
localContext
uint32
)
([]
byte
,
error
)
{
func
(
wit
*
StepWitness
)
EncodePreimageOracleInput
(
localContext
LocalContext
)
([]
byte
,
error
)
{
if
wit
.
PreimageKey
==
([
32
]
byte
{})
{
if
wit
.
PreimageKey
==
([
32
]
byte
{})
{
return
nil
,
errors
.
New
(
"cannot encode pre-image oracle input, witness has no pre-image to proof"
)
return
nil
,
errors
.
New
(
"cannot encode pre-image oracle input, witness has no pre-image to proof"
)
}
}
...
@@ -64,7 +66,7 @@ func (wit *StepWitness) EncodePreimageOracleInput(localContext uint32) ([]byte,
...
@@ -64,7 +66,7 @@ func (wit *StepWitness) EncodePreimageOracleInput(localContext uint32) ([]byte,
var
input
[]
byte
var
input
[]
byte
input
=
append
(
input
,
LoadLocalDataBytes4
...
)
input
=
append
(
input
,
LoadLocalDataBytes4
...
)
input
=
append
(
input
,
wit
.
PreimageKey
[
:
]
...
)
input
=
append
(
input
,
wit
.
PreimageKey
[
:
]
...
)
input
=
append
(
input
,
uint32ToBytes32
(
localContext
)
...
)
// local context in bytes
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
localContext
)
)
...
)
// local context in bytes
preimagePart
:=
wit
.
PreimageValue
[
8
:
]
preimagePart
:=
wit
.
PreimageValue
[
8
:
]
var
tmp
[
32
]
byte
var
tmp
[
32
]
byte
...
...
op-challenger/game/fault/trace/cannon/updater_test.go
View file @
93b59bf7
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"math/big"
"math/big"
"testing"
"testing"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum-optimism/optimism/op-service/testlog"
...
@@ -104,7 +105,9 @@ func TestCannonUpdater_BuildLocalOracleData(t *testing.T) {
...
@@ -104,7 +105,9 @@ func TestCannonUpdater_BuildLocalOracleData(t *testing.T) {
txData
,
err
:=
updater
.
BuildLocalOracleData
(
oracleData
)
txData
,
err
:=
updater
.
BuildLocalOracleData
(
oracleData
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
var
addLocalDataBytes4
=
crypto
.
Keccak256
([]
byte
(
"addLocalData(uint256,uint256,uint256)"
))[
:
4
]
fdgAbi
,
err
:=
bindings
.
FaultDisputeGameMetaData
.
GetAbi
()
require
.
NoError
(
t
,
err
)
addLocalDataBytes4
:=
fdgAbi
.
Methods
[
"addLocalData"
]
.
ID
[
:
4
]
// Pack the tx data manually.
// Pack the tx data manually.
var
expected
[]
byte
var
expected
[]
byte
...
...
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