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
d3682d8a
Commit
d3682d8a
authored
Oct 16, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test MIPS stepping in javascript
parent
06f7503b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
3 deletions
+45
-3
MIPS.sol
contracts/MIPS.sol
+4
-2
full.go
mipsevm/full.go
+4
-1
trie.go
mipsevm/trie.go
+13
-0
mips_test_trie.js
test/mips_test_trie.js
+24
-0
No files found.
contracts/MIPS.sol
View file @
d3682d8a
...
@@ -121,12 +121,14 @@ contract MIPS {
...
@@ -121,12 +121,14 @@ contract MIPS {
return (stateHash, exit);
return (stateHash, exit);
}
}
function Step(bytes32 stateHash) public returns (bytes32) {
event Stepped(bytes32 stateHash);
function Step(bytes32 stateHash) public returns (bytes32 newStateHash) {
uint32 pc = ReadMemory(stateHash, REG_PC);
uint32 pc = ReadMemory(stateHash, REG_PC);
if (pc == 0x5ead0000) {
if (pc == 0x5ead0000) {
return stateHash;
return stateHash;
}
}
return stepPC(stateHash, pc, pc+4);
newStateHash = stepPC(stateHash, pc, pc+4);
emit Stepped(newStateHash);
}
}
// will revert if any required input state is missing
// will revert if any required input state is missing
...
...
mipsevm/full.go
View file @
d3682d8a
...
@@ -2,6 +2,7 @@ package main
...
@@ -2,6 +2,7 @@ package main
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"log"
"log"
"math/big"
"math/big"
...
@@ -59,6 +60,8 @@ func RunFull() {
...
@@ -59,6 +60,8 @@ func RunFull() {
root
:=
RamToTrie
(
ram
)
root
:=
RamToTrie
(
ram
)
//ParseNode(root, 0)
//ParseNode(root, 0)
ioutil
.
WriteFile
(
"/tmp/eth/trie.json"
,
TrieToJson
(
root
),
0644
)
for
k
,
v
:=
range
Preimages
{
for
k
,
v
:=
range
Preimages
{
fmt
.
Println
(
"AddTrieNode"
,
k
)
fmt
.
Println
(
"AddTrieNode"
,
k
)
addTrieNode
(
v
,
interpreter
,
statedb
)
addTrieNode
(
v
,
interpreter
,
statedb
)
...
@@ -88,7 +91,7 @@ func RunFull() {
...
@@ -88,7 +91,7 @@ func RunFull() {
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
else
{
}
else
{
root
=
common
.
BytesToHash
(
dat
)
root
=
common
.
BytesToHash
(
dat
)
fmt
.
Println
(
"new state root"
,
step
,
root
)
fmt
.
Println
(
"new state root"
,
step
,
root
,
"gas used"
,
(
gas
-
contract
.
Gas
)
)
}
}
}
}
}
}
mipsevm/trie.go
View file @
d3682d8a
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"bytes"
"bytes"
"encoding/binary"
"encoding/binary"
"encoding/gob"
"encoding/gob"
"encoding/json"
"fmt"
"fmt"
"sort"
"sort"
"strings"
"strings"
...
@@ -18,6 +19,12 @@ type PreimageKeyValueWriter struct{}
...
@@ -18,6 +19,12 @@ type PreimageKeyValueWriter struct{}
var
Preimages
=
make
(
map
[
common
.
Hash
][]
byte
)
var
Preimages
=
make
(
map
[
common
.
Hash
][]
byte
)
type
Jtree
struct
{
Root
common
.
Hash
`json:"root"`
Preimages
map
[
common
.
Hash
][]
byte
`json:"preimages"`
}
// TODO: replace with JSON
func
SerializeTrie
(
root
common
.
Hash
)
[]
byte
{
func
SerializeTrie
(
root
common
.
Hash
)
[]
byte
{
b
:=
new
(
bytes
.
Buffer
)
b
:=
new
(
bytes
.
Buffer
)
e
:=
gob
.
NewEncoder
(
b
)
e
:=
gob
.
NewEncoder
(
b
)
...
@@ -26,6 +33,12 @@ func SerializeTrie(root common.Hash) []byte {
...
@@ -26,6 +33,12 @@ func SerializeTrie(root common.Hash) []byte {
return
b
.
Bytes
()
return
b
.
Bytes
()
}
}
func
TrieToJson
(
root
common
.
Hash
)
[]
byte
{
b
,
err
:=
json
.
Marshal
(
Jtree
{
Preimages
:
Preimages
,
Root
:
root
})
check
(
err
)
return
b
}
// TODO: this is copied from the oracle
// TODO: this is copied from the oracle
func
(
kw
PreimageKeyValueWriter
)
Put
(
key
[]
byte
,
value
[]
byte
)
error
{
func
(
kw
PreimageKeyValueWriter
)
Put
(
key
[]
byte
,
value
[]
byte
)
error
{
hash
:=
crypto
.
Keccak256Hash
(
value
)
hash
:=
crypto
.
Keccak256Hash
(
value
)
...
...
test/mips_test_trie.js
0 → 100644
View file @
d3682d8a
const
{
expect
}
=
require
(
"
chai
"
);
const
trieAdd
=
{
"
root
"
:
"
0xe5200ed7c7b2cdd673574f8fe42c5e448ed248766d4456dfa0fa1fda5f5ef9c2
"
,
"
preimages
"
:{
"
0x02b8d50956bf99188941a96a6b62e5325e25fd361c64b9a5fdabcd096503f64c
"
:
"
+HHGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghF6tAADGIIQAAAAAgA==
"
,
"
0x1bcc822b269177eecb38ea1336f519ac32de68e9f90797e158998f4867c711eb
"
:
"
+HGgL4Jb+u0gEWM4e9G4lO/GsyUEY/heVoGOAfiI04qPXfSgArjVCVa/mRiJQalqa2LlMl4l/TYcZLml/avNCWUD9kygaNY/x30waJPsd6PWg76b094l8vUmmL6XB1XdUFy+xfWAgICAgICAgICAgICAgA==
"
,
"
0x2f825bfaed201163387bd1b894efc6b3250463f85e56818e01f888d38a8f5df4
"
:
"
+HHGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAgA==
"
,
"
0x3d95d160d966af02a751b950b626fe09a33cd20d4efd5e09605a1d77d6aea3b7
"
:
"
5YMQAACgG8yCKyaRd+7LOOoTNvUZrDLeaOn5B5fhWJmPSGfHEes=
"
,
"
0x4439d93a074b4edd5b54b01da1a2de393b7b56b6172aee5eb3b021a1a20bc991
"
:
"
5oQAAAAAoM6MuvdTbEcVOfd0sdLVE21XWGkXQyWTL4l5g0aHzGro
"
,
"
0x68d63fc77d306893ec77a3d683be9bd3de25f2f52698be970755dd505cbec5f5
"
:
"
6cYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAACAgICAgICAgICAgICA
"
,
"
0xce8cbaf7536c471539f774b1d2d5136d575869174325932f8979834687cc6ae8
"
:
"
+FPGIIQ2EP/wxiCENBEAAcYghDwI///GIIQ1CP/9xiCENAkAA8YghAEJUCDGIIQtQgABxiCErgIACMYghK4RAATGIIQD4AAIxiCEAAAAAICAgICAgA==
"
,
"
0xe5200ed7c7b2cdd673574f8fe42c5e448ed248766d4456dfa0fa1fda5f5ef9c2
"
:
"
+FGgRDnZOgdLTt1bVLAdoaLeOTt7VrYXKu5es7AhoaILyZGAgKA9ldFg2WavAqdRuVC2Jv4JozzSDU79XglgWh131q6jt4CAgICAgICAgICAgIA=
"
}};
describe
(
"
MIPS contract
"
,
function
()
{
it
(
"
add should work
"
,
async
function
()
{
const
MIPS
=
await
ethers
.
getContractFactory
(
"
MIPS
"
)
const
m
=
await
MIPS
.
deploy
()
const
mm
=
await
ethers
.
getContractAt
(
"
MIPSMemory
"
,
await
m
.
m
())
for
(
k
in
trieAdd
[
'
preimages
'
])
{
const
bin
=
Uint8Array
.
from
(
atob
(
trieAdd
[
'
preimages
'
][
k
]),
c
=>
c
.
charCodeAt
(
0
))
await
mm
.
AddTrieNode
(
bin
)
}
let
root
=
trieAdd
[
'
root
'
]
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
ret
=
await
m
.
Step
(
root
)
const
receipt
=
await
ret
.
wait
()
root
=
receipt
.
logs
[
0
].
data
console
.
log
(
i
,
root
)
}
});
});
\ No newline at end of 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