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
09846e7c
Unverified
Commit
09846e7c
authored
Jul 20, 2023
by
inphi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cannon: Remove unicorn references
parent
a5793665
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
57 deletions
+57
-57
evm_test.go
cannon/mipsevm/evm_test.go
+21
-21
fuzz_evm_test.go
cannon/mipsevm/fuzz_evm_test.go
+36
-36
No files found.
cannon/mipsevm/evm_test.go
View file @
09846e7c
...
...
@@ -126,31 +126,31 @@ func TestEVM(t *testing.T) {
// set the return address ($ra) to jump into when test completes
state
.
Registers
[
31
]
=
endAddr
us
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
goState
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
for
i
:=
0
;
i
<
1000
;
i
++
{
if
us
.
state
.
PC
==
endAddr
{
if
goState
.
state
.
PC
==
endAddr
{
break
}
if
exitGroup
&&
us
.
state
.
Exited
{
if
exitGroup
&&
goState
.
state
.
Exited
{
break
}
insn
:=
state
.
Memory
.
GetMemory
(
state
.
PC
)
t
.
Logf
(
"step: %4d pc: 0x%08x insn: 0x%08x"
,
state
.
Step
,
state
.
PC
,
insn
)
stepWitness
,
err
:=
us
.
Step
(
true
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
// verify the post-state matches.
// TODO: maybe more readable to decode the evmPost state, and do attribute-wise comparison.
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
}
if
exitGroup
{
require
.
NotEqual
(
t
,
uint32
(
endAddr
),
us
.
state
.
PC
,
"must not reach end"
)
require
.
True
(
t
,
us
.
state
.
Exited
,
"must set exited state"
)
require
.
Equal
(
t
,
uint8
(
1
),
us
.
state
.
ExitCode
,
"must exit with 1"
)
require
.
NotEqual
(
t
,
uint32
(
endAddr
),
goState
.
state
.
PC
,
"must not reach end"
)
require
.
True
(
t
,
goState
.
state
.
Exited
,
"must set exited state"
)
require
.
Equal
(
t
,
uint8
(
1
),
goState
.
state
.
ExitCode
,
"must exit with 1"
)
}
else
{
require
.
Equal
(
t
,
uint32
(
endAddr
),
state
.
PC
,
"must reach end"
)
// inspect test result
...
...
@@ -180,8 +180,8 @@ func TestEVMFault(t *testing.T) {
// set the return address ($ra) to jump into when test completes
state
.
Registers
[
31
]
=
endAddr
us
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
require
.
Panics
(
t
,
func
()
{
_
,
_
=
us
.
Step
(
true
)
},
"must panic on illegal instruction"
)
goState
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
require
.
Panics
(
t
,
func
()
{
_
,
_
=
goState
.
Step
(
true
)
},
"must panic on illegal instruction"
)
insnProof
:=
initialState
.
Memory
.
MerkleProof
(
0
)
stepWitness
:=
&
StepWitness
{
...
...
@@ -213,11 +213,11 @@ func TestHelloEVM(t *testing.T) {
require
.
NoError
(
t
,
PatchStack
(
state
),
"add initial stack"
)
var
stdOutBuf
,
stdErrBuf
bytes
.
Buffer
us
:=
NewInstrumentedState
(
state
,
nil
,
io
.
MultiWriter
(
&
stdOutBuf
,
os
.
Stdout
),
io
.
MultiWriter
(
&
stdErrBuf
,
os
.
Stderr
))
goState
:=
NewInstrumentedState
(
state
,
nil
,
io
.
MultiWriter
(
&
stdOutBuf
,
os
.
Stdout
),
io
.
MultiWriter
(
&
stdErrBuf
,
os
.
Stderr
))
start
:=
time
.
Now
()
for
i
:=
0
;
i
<
400
_000
;
i
++
{
if
us
.
state
.
Exited
{
if
goState
.
state
.
Exited
{
break
}
insn
:=
state
.
Memory
.
GetMemory
(
state
.
PC
)
...
...
@@ -228,13 +228,13 @@ func TestHelloEVM(t *testing.T) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evm
.
SetTracer
(
tracer
)
stepWitness
,
err
:=
us
.
Step
(
true
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
// verify the post-state matches.
// TODO: maybe more readable to decode the evmPost state, and do attribute-wise comparison.
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
}
end
:=
time
.
Now
()
...
...
@@ -266,10 +266,10 @@ func TestClaimEVM(t *testing.T) {
oracle
,
expectedStdOut
,
expectedStdErr
:=
claimTestOracle
(
t
)
var
stdOutBuf
,
stdErrBuf
bytes
.
Buffer
us
:=
NewInstrumentedState
(
state
,
oracle
,
io
.
MultiWriter
(
&
stdOutBuf
,
os
.
Stdout
),
io
.
MultiWriter
(
&
stdErrBuf
,
os
.
Stderr
))
goState
:=
NewInstrumentedState
(
state
,
oracle
,
io
.
MultiWriter
(
&
stdOutBuf
,
os
.
Stdout
),
io
.
MultiWriter
(
&
stdErrBuf
,
os
.
Stderr
))
for
i
:=
0
;
i
<
2000
_000
;
i
++
{
if
us
.
state
.
Exited
{
if
goState
.
state
.
Exited
{
break
}
...
...
@@ -278,15 +278,15 @@ func TestClaimEVM(t *testing.T) {
t
.
Logf
(
"step: %4d pc: 0x%08x insn: 0x%08x"
,
state
.
Step
,
state
.
PC
,
insn
)
}
stepWitness
,
err
:=
us
.
Step
(
true
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evm
.
SetTracer
(
tracer
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
}
...
...
cannon/mipsevm/fuzz_evm_test.go
View file @
09846e7c
...
...
@@ -37,8 +37,8 @@ func FuzzStateSyscallBrk(f *testing.F) {
expectedRegisters
:=
state
.
Registers
expectedRegisters
[
2
]
=
0x4000
_0000
us
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
us
.
Step
(
true
)
goState
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
stepWitness
.
HasPreimage
())
...
...
@@ -57,8 +57,8 @@ func FuzzStateSyscallBrk(f *testing.F) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
})
}
...
...
@@ -86,8 +86,8 @@ func FuzzStateSyscallClone(f *testing.F) {
expectedRegisters
:=
state
.
Registers
expectedRegisters
[
2
]
=
0x1
us
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
us
.
Step
(
true
)
goState
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
stepWitness
.
HasPreimage
())
...
...
@@ -106,8 +106,8 @@ func FuzzStateSyscallClone(f *testing.F) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
})
}
...
...
@@ -132,8 +132,8 @@ func FuzzStateSyscallMmap(f *testing.F) {
preStateRoot
:=
state
.
Memory
.
MerkleRoot
()
preStateRegisters
:=
state
.
Registers
us
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
us
.
Step
(
true
)
goState
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
stepWitness
.
HasPreimage
())
...
...
@@ -165,8 +165,8 @@ func FuzzStateSyscallMmap(f *testing.F) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
})
}
...
...
@@ -193,8 +193,8 @@ func FuzzStateSyscallExitGroup(f *testing.F) {
preStateRoot
:=
state
.
Memory
.
MerkleRoot
()
preStateRegisters
:=
state
.
Registers
us
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
us
.
Step
(
true
)
goState
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
stepWitness
.
HasPreimage
())
...
...
@@ -213,8 +213,8 @@ func FuzzStateSyscallExitGroup(f *testing.F) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
})
}
...
...
@@ -239,8 +239,8 @@ func FuzzStateSyscallFnctl(f *testing.F) {
preStateRoot
:=
state
.
Memory
.
MerkleRoot
()
preStateRegisters
:=
state
.
Registers
us
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
us
.
Step
(
true
)
goState
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
stepWitness
.
HasPreimage
())
...
...
@@ -276,8 +276,8 @@ func FuzzStateSyscallFnctl(f *testing.F) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
})
}
...
...
@@ -307,8 +307,8 @@ func FuzzStateHintRead(f *testing.F) {
expectedRegisters
[
2
]
=
count
oracle
:=
staticOracle
(
t
,
preimageData
)
// only used for hinting
us
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
us
.
Step
(
true
)
goState
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
stepWitness
.
HasPreimage
())
...
...
@@ -325,8 +325,8 @@ func FuzzStateHintRead(f *testing.F) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
})
}
...
...
@@ -364,8 +364,8 @@ func FuzzStatePreimageRead(f *testing.F) {
}
oracle
:=
staticOracle
(
t
,
preimageData
)
us
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
us
.
Step
(
true
)
goState
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
stepWitness
.
HasPreimage
())
...
...
@@ -389,8 +389,8 @@ func FuzzStatePreimageRead(f *testing.F) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
})
}
...
...
@@ -424,8 +424,8 @@ func FuzzStateHintWrite(f *testing.F) {
expectedRegisters
[
2
]
=
count
oracle
:=
staticOracle
(
t
,
preimageData
)
// only used for hinting
us
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
us
.
Step
(
true
)
goState
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
stepWitness
.
HasPreimage
())
...
...
@@ -442,8 +442,8 @@ func FuzzStateHintWrite(f *testing.F) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
})
}
...
...
@@ -476,8 +476,8 @@ func FuzzStatePreimageWrite(f *testing.F) {
expectedRegisters
[
2
]
=
sz
oracle
:=
staticOracle
(
t
,
preimageData
)
us
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
us
.
Step
(
true
)
goState
:=
NewInstrumentedState
(
state
,
oracle
,
os
.
Stdout
,
os
.
Stderr
)
stepWitness
,
err
:=
goState
.
Step
(
true
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
stepWitness
.
HasPreimage
())
...
...
@@ -494,8 +494,8 @@ func FuzzStatePreimageWrite(f *testing.F) {
evm
:=
NewMIPSEVM
(
contracts
,
addrs
)
evmPost
:=
evm
.
Step
(
t
,
stepWitness
)
uniPost
:=
us
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
uni
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
goPost
:=
goState
.
state
.
EncodeWitness
()
require
.
Equal
(
t
,
hexutil
.
Bytes
(
go
Post
)
.
String
(),
hexutil
.
Bytes
(
evmPost
)
.
String
(),
"mipsevm produced different state than EVM"
)
})
}
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