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
04ff70f6
Commit
04ff70f6
authored
Oct 16, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
i see the difference, this is a later problem
parent
027bcb41
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
17 deletions
+37
-17
full.go
mipsevm/full.go
+26
-12
full_test.go
mipsevm/full_test.go
+7
-1
trie.go
mipsevm/trie.go
+3
-3
trie_test.go
mipsevm/trie_test.go
+1
-1
No files found.
mipsevm/full.go
View file @
04ff70f6
...
...
@@ -27,6 +27,26 @@ func deploy(interpreter *vm.EVMInterpreter, statedb *StateDB) {
statedb
.
Bytecodes
[
common
.
HexToAddress
(
"0x1337"
)]
=
ret
}
func
getTrieNode
(
str
common
.
Hash
,
interpreter
*
vm
.
EVMInterpreter
,
statedb
*
StateDB
)
[]
byte
{
from
:=
common
.
Address
{}
to
:=
common
.
HexToAddress
(
"0xBd770416a3345F91E4B34576cb804a576fa48EB1"
)
gas
:=
uint64
(
100000000
)
input
:=
crypto
.
Keccak256Hash
([]
byte
(
"trie(bytes32)"
))
.
Bytes
()[
:
4
]
input
=
append
(
input
,
str
.
Bytes
()
...
)
bytecode
:=
statedb
.
Bytecodes
[
to
]
//fmt.Println("bytecode", len(bytecode))
contract
:=
vm
.
NewContract
(
vm
.
AccountRef
(
from
),
vm
.
AccountRef
(
to
),
common
.
Big0
,
gas
)
contract
.
SetCallCode
(
&
to
,
crypto
.
Keccak256Hash
(
bytecode
),
bytecode
)
ret
,
err
:=
interpreter
.
Run
(
contract
,
input
,
false
)
check
(
err
)
fmt
.
Println
(
"getTrieNode"
,
str
,
ret
)
return
ret
[
64
:
]
}
func
addTrieNode
(
str
[]
byte
,
interpreter
*
vm
.
EVMInterpreter
,
statedb
*
StateDB
)
{
from
:=
common
.
Address
{}
to
:=
common
.
HexToAddress
(
"0xBd770416a3345F91E4B34576cb804a576fa48EB1"
)
...
...
@@ -48,16 +68,6 @@ func addTrieNode(str []byte, interpreter *vm.EVMInterpreter, statedb *StateDB) {
check
(
err
)
}
func
RunTest
()
{
ram
:=
make
(
map
[
uint32
](
uint32
))
LoadMappedFile
(
"test/bin/add.bin"
,
ram
,
0
)
ZeroRegisters
(
ram
)
ram
[
0xC000007C
]
=
0x5EAD0000
RunWithRam
(
ram
,
1
,
0
,
nil
)
}
func
RunFull
()
{
interpreter
,
statedb
:=
GetInterpreter
(
0
,
true
)
deploy
(
interpreter
,
statedb
)
...
...
@@ -69,7 +79,7 @@ func RunFull() {
ZeroRegisters
(
ram
)
ram
[
0xC000007C
]
=
0x5EAD0000
root
:=
RamToTrie
(
ram
)
ParseNode
(
root
,
0
)
//
ParseNode(root, 0)
ioutil
.
WriteFile
(
"/tmp/eth/trie.json"
,
TrieToJson
(
root
),
0644
)
...
...
@@ -80,7 +90,7 @@ func RunFull() {
fmt
.
Println
(
"trie is ready, let's run"
)
fmt
.
Println
(
"state root"
,
root
,
"nodes"
,
len
(
Preimages
))
for
step
:=
0
;
step
<
40
;
step
++
{
for
step
:=
0
;
step
<
12
;
step
++
{
// it's run o clock
from
:=
common
.
Address
{}
to
:=
common
.
HexToAddress
(
"0x1337"
)
...
...
@@ -105,4 +115,8 @@ func RunFull() {
fmt
.
Println
(
"new state root"
,
step
,
root
,
"gas used"
,
(
gas
-
contract
.
Gas
))
}
}
ParseNode
(
root
,
0
,
func
(
t
common
.
Hash
)
[]
byte
{
return
getTrieNode
(
t
,
interpreter
,
statedb
)
})
}
mipsevm/full_test.go
View file @
04ff70f6
...
...
@@ -3,6 +3,8 @@ package main
import
(
"fmt"
"testing"
"github.com/ethereum/go-ethereum/common"
)
func
TestFull
(
t
*
testing
.
T
)
{
...
...
@@ -15,9 +17,13 @@ func TestFullEvm(t *testing.T) {
ZeroRegisters
(
ram
)
ram
[
0xC000007C
]
=
0x5EAD0000
root
:=
RamToTrie
(
ram
)
for
step
:=
0
;
step
<
12
;
step
++
{
RunWithRam
(
ram
,
1
,
0
,
nil
)
root
:
=
RamToTrie
(
ram
)
root
=
RamToTrie
(
ram
)
fmt
.
Println
(
step
,
root
)
}
ParseNode
(
root
,
0
,
func
(
t
common
.
Hash
)
[]
byte
{
return
Preimages
[
t
]
})
}
mipsevm/trie.go
View file @
04ff70f6
...
...
@@ -56,12 +56,12 @@ func (kw PreimageKeyValueWriter) Delete(key []byte) error {
// full nodes / BRANCH_NODE have 17 values, each a hash
// LEAF or EXTENSION nodes have 2 values, a path and value
func
ParseNode
(
node
common
.
Hash
,
depth
int
)
{
func
ParseNode
(
node
common
.
Hash
,
depth
int
,
callback
func
(
common
.
Hash
)
[]
byte
)
{
if
depth
>
3
{
return
}
sprefix
:=
strings
.
Repeat
(
" "
,
depth
)
buf
:=
Preimages
[
node
]
buf
:=
callback
(
node
)
elems
,
_
,
err
:=
rlp
.
SplitList
(
buf
)
check
(
err
)
c
,
_
:=
rlp
.
CountValues
(
elems
)
...
...
@@ -75,7 +75,7 @@ func ParseNode(node common.Hash, depth int) {
if
len
(
val
)
==
32
{
hh
:=
common
.
BytesToHash
(
val
)
fmt
.
Println
(
sprefix
,
"node found with len"
,
len
(
Preimages
[
hh
]))
ParseNode
(
hh
,
depth
+
1
)
ParseNode
(
hh
,
depth
+
1
,
callback
)
}
}
}
...
...
mipsevm/trie_test.go
View file @
04ff70f6
...
...
@@ -13,7 +13,7 @@ func TestTrie(t *testing.T) {
LoadMappedFile
(
"../mipigo/test/test.bin"
,
ram
,
0
)
ZeroRegisters
(
ram
)
root
:=
RamToTrie
(
ram
)
ParseNode
(
root
,
0
)
//
ParseNode(root, 0)
dat
:=
SerializeTrie
(
root
)
fmt
.
Println
(
"serialized length is"
,
len
(
dat
))
...
...
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