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
df821cfb
Commit
df821cfb
authored
Sep 06, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `TestStateHash`
parent
7b68fe4d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
state_test.go
cannon/mipsevm/state_test.go
+47
-0
No files found.
cannon/mipsevm/state_test.go
View file @
df821cfb
...
@@ -82,6 +82,53 @@ func TestState(t *testing.T) {
...
@@ -82,6 +82,53 @@ func TestState(t *testing.T) {
}
}
}
}
// Run through all permutations of `exited` / `exitCode` and ensure that the
// correct witness, state hash, and VM Status is produced.
func
TestStateHash
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
exited
bool
exitCode
uint8
}{
{
exited
:
false
,
exitCode
:
0
},
{
exited
:
false
,
exitCode
:
1
},
{
exited
:
false
,
exitCode
:
2
},
{
exited
:
false
,
exitCode
:
3
},
{
exited
:
true
,
exitCode
:
0
},
{
exited
:
true
,
exitCode
:
1
},
{
exited
:
true
,
exitCode
:
2
},
{
exited
:
true
,
exitCode
:
3
},
}
exitedOffset
:=
32
*
2
+
4
*
6
for
_
,
c
:=
range
cases
{
state
:=
&
State
{
Memory
:
NewMemory
(),
Exited
:
c
.
exited
,
ExitCode
:
c
.
exitCode
,
}
actualWitness
:=
state
.
EncodeWitness
()
actualStateHash
,
err
:=
StateWitness
(
actualWitness
)
.
StateHash
()
require
.
NoError
(
t
,
err
,
"Error hashing witness"
)
require
.
Equal
(
t
,
len
(
actualWitness
),
StateWitnessSize
,
"Incorrect witness size"
)
expectedWitness
:=
make
(
StateWitness
,
226
)
memRoot
:=
state
.
Memory
.
MerkleRoot
()
copy
(
expectedWitness
[
:
32
],
memRoot
[
:
])
expectedWitness
[
exitedOffset
]
=
c
.
exitCode
var
exited
uint8
if
c
.
exited
{
exited
=
1
}
expectedWitness
[
exitedOffset
+
1
]
=
uint8
(
exited
)
require
.
Equal
(
t
,
expectedWitness
[
:
],
actualWitness
[
:
],
"Incorrect witness"
)
expectedStateHash
:=
crypto
.
Keccak256Hash
(
actualWitness
)
expectedStateHash
[
0
]
=
vmStatus
(
c
.
exited
,
c
.
exitCode
)
require
.
Equal
(
t
,
expectedStateHash
,
actualStateHash
,
"Incorrect state hash"
)
}
}
func
TestHello
(
t
*
testing
.
T
)
{
func
TestHello
(
t
*
testing
.
T
)
{
elfProgram
,
err
:=
elf
.
Open
(
"../example/bin/hello.elf"
)
elfProgram
,
err
:=
elf
.
Open
(
"../example/bin/hello.elf"
)
require
.
NoError
(
t
,
err
,
"open ELF file"
)
require
.
NoError
(
t
,
err
,
"open ELF file"
)
...
...
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