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
daada814
Commit
daada814
authored
Nov 05, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add broken trie test
parent
ce242d9f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
2 deletions
+52
-2
README.md
README.md
+1
-1
trie.go
mipsevm/trie.go
+14
-0
trie_test.go
mipsevm/trie_test.go
+29
-0
mips_test_memory.js
test/mips_test_memory.js
+8
-1
No files found.
README.md
View file @
daada814
...
...
@@ -22,7 +22,7 @@ mipsevm -- A MIPS runtime in the EVM (see also contracts/)
## TODO
*
Support fast generation of a specific state from the checkpoints
*
*
Load into Unicorn/evm from the trie
*
Load into Unicorn/evm from the trie
*
Write binary search "responder"
*
Deploy to cheapETH!
...
...
mipsevm/trie.go
View file @
daada814
...
...
@@ -29,6 +29,14 @@ func TrieToJson(root common.Hash, step int) []byte {
return
b
}
func
TrieFromJson
(
dat
[]
byte
)
(
common
.
Hash
,
int
)
{
var
j
Jtree
err
:=
json
.
Unmarshal
(
dat
,
&
j
)
check
(
err
)
Preimages
=
j
.
Preimages
return
j
.
Root
,
j
.
Step
}
// TODO: this is copied from the oracle
func
(
kw
PreimageKeyValueWriter
)
Put
(
key
[]
byte
,
value
[]
byte
)
error
{
hash
:=
crypto
.
Keccak256Hash
(
value
)
...
...
@@ -80,6 +88,12 @@ func ParseNode(node common.Hash, depth int, callback func(common.Hash) []byte) {
ParseNodeInternal
(
elems
,
depth
,
callback
)
}
func
RamFromTrie
(
root
common
.
Hash
)
map
[
uint32
](
uint32
)
{
ram
:=
make
(
map
[
uint32
](
uint32
))
// TODO: write this
return
ram
}
func
RamToTrie
(
ram
map
[
uint32
](
uint32
))
common
.
Hash
{
mt
:=
trie
.
NewStackTrie
(
PreimageKeyValueWriter
{})
...
...
mipsevm/trie_test.go
View file @
daada814
...
...
@@ -3,6 +3,7 @@ package main
import
(
"fmt"
"io/ioutil"
"reflect"
"testing"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -20,6 +21,21 @@ func TestTrie(t *testing.T) {
dat
:=
TrieToJson
(
root
,
-
1
)
fmt
.
Println
(
"serialized length is"
,
len
(
dat
))
ioutil
.
WriteFile
(
"/tmp/cannon/ramtrie.json"
,
dat
,
0644
)
// load the trie
oldPreLen
:=
len
(
Preimages
)
Preimages
=
make
(
map
[
common
.
Hash
][]
byte
)
dat
,
err
:=
ioutil
.
ReadFile
(
"/tmp/cannon/ramtrie.json"
)
check
(
err
)
newroot
,
_
:=
TrieFromJson
(
dat
)
if
root
!=
newroot
{
t
.
Fatal
(
"loaded root mismatch"
)
}
if
len
(
Preimages
)
!=
oldPreLen
{
t
.
Fatal
(
"preimage length mismatch"
)
}
// TODO: load memory when ready
}
func
printRoot
(
ram
map
[
uint32
](
uint32
))
{
...
...
@@ -35,6 +51,19 @@ func printTrie(ram map[uint32](uint32)) {
})
}
func
TestToFromTrie
(
t
*
testing
.
T
)
{
ram
:=
make
(
map
[
uint32
](
uint32
))
ram
[
0
]
=
1
ram
[
4
]
=
2
trie
:=
RamToTrie
(
ram
)
newram
:=
RamFromTrie
(
trie
)
if
!
reflect
.
DeepEqual
(
ram
,
newram
)
{
t
.
Fatal
(
"ram to/from mismatch"
)
}
}
func
TestBuggedTrie
(
t
*
testing
.
T
)
{
ram
:=
make
(
map
[
uint32
](
uint32
))
...
...
test/mips_test_memory.js
View file @
daada814
...
...
@@ -67,13 +67,20 @@ describe("MIPSMemory contract", function () {
for
(
var
i
=
0
;
i
<
100
;
i
++
)
{
const
keys
=
Object
.
keys
(
kv
)
const
choice
=
Math
.
random
()
if
(
choice
<
0.
5
||
keys
.
length
==
0
)
{
if
(
choice
<
0.
3
||
keys
.
length
==
0
)
{
// write new key
const
key
=
randint
(
0x100
)
*
4
const
value
=
randint
(
0x100000000
)
console
.
log
(
"
writing
"
,
key
,
value
)
root
=
await
write
(
mm
,
root
,
key
,
value
)
kv
[
key
]
=
value
}
else
if
(
choice
<
0.5
)
{
// write new high key
const
key
=
randint
(
0x100
)
*
4
+
0x10000000
const
value
=
randint
(
0x100000000
)
console
.
log
(
"
writing
"
,
key
,
value
)
root
=
await
write
(
mm
,
root
,
key
,
value
)
kv
[
key
]
=
value
}
else
if
(
choice
>
0.7
)
{
// read old key
const
idx
=
randint
(
keys
.
length
)
...
...
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