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
61d19312
Commit
61d19312
authored
Aug 08, 2023
by
inphi
Committed by
clabby
Aug 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(ctb): Cannon contracts VM tests
parent
d6dcb1f4
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1472 additions
and
3 deletions
+1472
-3
differential-testing.go
...rock/scripts/differential-testing/differential-testing.go
+44
-0
CommonTest.t.sol
packages/contracts-bedrock/test/CommonTest.t.sol
+40
-0
MIPS.t.sol
packages/contracts-bedrock/test/MIPS.t.sol
+1388
-3
No files found.
packages/contracts-bedrock/scripts/differential-testing/differential-testing.go
View file @
61d19312
...
@@ -5,7 +5,9 @@ import (
...
@@ -5,7 +5,9 @@ import (
"fmt"
"fmt"
"math/big"
"math/big"
"os"
"os"
"strconv"
"github.com/ethereum-optimism/optimism/cannon/mipsevm"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-chain-ops/crossdomain"
"github.com/ethereum-optimism/optimism/op-chain-ops/crossdomain"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi"
...
@@ -60,6 +62,15 @@ var (
...
@@ -60,6 +62,15 @@ var (
proveWithdrawalInputsArgs
=
abi
.
Arguments
{
proveWithdrawalInputsArgs
=
abi
.
Arguments
{
{
Name
:
"inputs"
,
Type
:
proveWithdrawalInputs
},
{
Name
:
"inputs"
,
Type
:
proveWithdrawalInputs
},
}
}
// cannonMemoryProof inputs tuple (bytes32, bytes)
cannonMemoryProof
,
_
=
abi
.
NewType
(
"tuple"
,
"CannonMemoryProof"
,
[]
abi
.
ArgumentMarshaling
{
{
Name
:
"memRoot"
,
Type
:
"bytes32"
},
{
Name
:
"proof"
,
Type
:
"bytes"
},
})
cannonMemoryProofArgs
=
abi
.
Arguments
{
{
Name
:
"encodedCannonMemoryProof"
,
Type
:
cannonMemoryProof
},
}
)
)
func
main
()
{
func
main
()
{
...
@@ -312,6 +323,39 @@ func main() {
...
@@ -312,6 +323,39 @@ func main() {
// Print the output
// Print the output
fmt
.
Print
(
hexutil
.
Encode
(
packed
[
32
:
]))
fmt
.
Print
(
hexutil
.
Encode
(
packed
[
32
:
]))
case
"cannonMemoryProof"
:
// <pc, insn, [memAddr, memValue]>
mem
:=
mipsevm
.
NewMemory
()
if
len
(
args
)
!=
3
&&
len
(
args
)
!=
5
{
panic
(
"Error: cannonMemoryProofWithProof requires 2 or 4 arguments"
)
}
pc
,
err
:=
strconv
.
ParseUint
(
args
[
1
],
10
,
32
)
checkErr
(
err
,
"Error decocding addr"
)
insn
,
err
:=
strconv
.
ParseUint
(
args
[
2
],
10
,
32
)
checkErr
(
err
,
"Error decocding insn"
)
mem
.
SetMemory
(
uint32
(
pc
),
uint32
(
insn
))
var
insnProof
,
memProof
[
896
]
byte
if
len
(
args
)
==
5
{
memAddr
,
err
:=
strconv
.
ParseUint
(
args
[
3
],
10
,
32
)
checkErr
(
err
,
"Error decocding memAddr"
)
memValue
,
err
:=
strconv
.
ParseUint
(
args
[
4
],
10
,
32
)
checkErr
(
err
,
"Error decocding memValue"
)
mem
.
SetMemory
(
uint32
(
memAddr
),
uint32
(
memValue
))
memProof
=
mem
.
MerkleProof
(
uint32
(
memAddr
))
}
insnProof
=
mem
.
MerkleProof
(
uint32
(
pc
))
output
:=
struct
{
MemRoot
common
.
Hash
Proof
[]
byte
}{
MemRoot
:
mem
.
MerkleRoot
(),
Proof
:
append
(
insnProof
[
:
],
memProof
[
:
]
...
),
}
packed
,
err
:=
cannonMemoryProofArgs
.
Pack
(
&
output
)
checkErr
(
err
,
"Error encoding output"
)
fmt
.
Print
(
hexutil
.
Encode
(
packed
[
32
:
]))
default
:
default
:
panic
(
fmt
.
Errorf
(
"Unknown command: %s"
,
args
[
0
]))
panic
(
fmt
.
Errorf
(
"Unknown command: %s"
,
args
[
0
]))
}
}
...
...
packages/contracts-bedrock/test/CommonTest.t.sol
View file @
61d19312
...
@@ -678,6 +678,46 @@ contract FFIInterface is Test {
...
@@ -678,6 +678,46 @@ contract FFIInterface is Test {
return abi.decode(vm.ffi(cmds), (bytes32, bytes, bytes, bytes[]));
return abi.decode(vm.ffi(cmds), (bytes32, bytes, bytes, bytes[]));
}
}
function getCannonMemoryProof(uint32 pc, uint32 insn)
external
returns (
bytes32,
bytes memory
) {
string[] memory cmds = new string[](4);
cmds[0] = "scripts/differential-testing/differential-testing";
cmds[1] = "cannonMemoryProof";
cmds[2] = vm.toString(pc);
cmds[3] = vm.toString(insn);
bytes memory result = vm.ffi(cmds);
(
bytes32 memRoot,
bytes memory proof
) = abi.decode(result, (bytes32, bytes));
return (memRoot, proof);
}
function getCannonMemoryProof(uint32 pc, uint32 insn, uint32 memAddr, uint32 memVal)
external
returns (
bytes32,
bytes memory
) {
string[] memory cmds = new string[](6);
cmds[0] = "scripts/differential-testing/differential-testing";
cmds[1] = "cannonMemoryProof";
cmds[2] = vm.toString(pc);
cmds[3] = vm.toString(insn);
cmds[4] = vm.toString(memAddr);
cmds[5] = vm.toString(memVal);
bytes memory result = vm.ffi(cmds);
(
bytes32 memRoot,
bytes memory proof
) = abi.decode(result, (bytes32, bytes));
return (memRoot, proof);
}
}
}
// Used for testing a future upgrade beyond the current implementations.
// Used for testing a future upgrade beyond the current implementations.
...
...
packages/contracts-bedrock/test/MIPS.t.sol
View file @
61d19312
This diff is collapsed.
Click to expand it.
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