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
06f7503b
Commit
06f7503b
authored
Oct 16, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
failing on the 6th step
parent
6f7b2c8d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
75 deletions
+32
-75
MIPSMemory.sol
contracts/MIPSMemory.sol
+0
-52
full.go
mipsevm/full.go
+23
-20
minievm.go
mipsevm/minievm.go
+9
-3
No files found.
contracts/MIPSMemory.sol
View file @
06f7503b
...
@@ -2,12 +2,8 @@
...
@@ -2,12 +2,8 @@
pragma solidity ^0.7.3;
pragma solidity ^0.7.3;
import "./lib/Lib_Keccak256.sol";
import "./lib/Lib_Keccak256.sol";
//import "hardhat/console.sol";
import "./lib/Lib_MerkleTrie.sol";
import "./lib/Lib_MerkleTrie.sol";
//import { Lib_RLPReader } from "./lib/Lib_RLPReader.sol";
//import { Lib_BytesUtils } from "./lib/Lib_BytesUtils.sol";
contract MIPSMemory {
contract MIPSMemory {
// TODO: the trie library should read and write from this as appropriate
// TODO: the trie library should read and write from this as appropriate
mapping(bytes32 => bytes) public trie;
mapping(bytes32 => bytes) public trie;
...
@@ -74,14 +70,6 @@ contract MIPSMemory {
...
@@ -74,14 +70,6 @@ contract MIPSMemory {
return ret;
return ret;
}
}
/*mapping(bytes32 => mapping(uint32 => bytes)) proofs;
function AddMerkleProof(bytes32 stateHash, uint32 addr, bytes calldata proof) public {
// validate proof
Lib_MerkleTrie.get(tb(addr), proof, stateHash);
proofs[stateHash][addr] = proof;
}*/
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) public returns (bytes32) {
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) public returns (bytes32) {
require(addr & 3 == 0, "write memory must be 32-bit aligned");
require(addr & 3 == 0, "write memory must be 32-bit aligned");
return Lib_MerkleTrie.update(tb(addr>>2), tb(value), trie, stateHash);
return Lib_MerkleTrie.update(tb(addr>>2), tb(value), trie, stateHash);
...
@@ -140,46 +128,6 @@ contract MIPSMemory {
...
@@ -140,46 +128,6 @@ contract MIPSMemory {
} else {
} else {
return fb(value);
return fb(value);
}
}
/*bytes memory key = Lib_BytesUtils.toNibbles(tb(addr>>2));
bytes32 cnode = stateHash;
uint256 idx = 0;
while (true) {
Lib_RLPReader.RLPItem[] memory node = Lib_RLPReader.readList(trie[cnode]);
if (node.length == BRANCH_NODE_LENGTH) {
//revert("node length bnl");
uint8 branchKey = uint8(key[idx]);
if (idx == key.length-1) {
//if (addr != 0xc0000080) revert("here");
Lib_RLPReader.RLPItem[] memory lp = Lib_RLPReader.readList(node[branchKey]);
require(lp.length == 2, "wrong RLP list length");
return fb(Lib_RLPReader.readBytes(lp[1]));
} else {
cnode = Lib_RLPReader.readBytes32(node[branchKey]);
idx += 1;
}
} else if (node.length == LEAF_OR_EXTENSION_NODE_LENGTH) {
bytes memory path = Lib_BytesUtils.toNibbles(Lib_RLPReader.readBytes(node[0]));
uint8 prefix = uint8(path[0]);
if (prefix == PREFIX_LEAF_EVEN || prefix == PREFIX_LEAF_ODD) {
// TODO: check match
//return fb(Lib_RLPReader.readList(node[1]));
// broken
} else if (prefix == PREFIX_EXTENSION_EVEN || prefix == PREFIX_EXTENSION_ODD) {
// TODO: check match
if (prefix == PREFIX_EXTENSION_EVEN) {
idx += path.length - 2;
} else {
idx += path.length - 1;
}
cnode = Lib_RLPReader.readBytes32(node[1]);
}
} else {
revert("node in trie broken");
}
}*/
//return fb(get(tb(addr>>2), stateHash));
}
}
}
}
\ No newline at end of file
mipsevm/full.go
View file @
06f7503b
...
@@ -57,35 +57,38 @@ func RunFull() {
...
@@ -57,35 +57,38 @@ func RunFull() {
ZeroRegisters
(
ram
)
ZeroRegisters
(
ram
)
ram
[
0xC000007C
]
=
0x5EAD0000
ram
[
0xC000007C
]
=
0x5EAD0000
root
:=
RamToTrie
(
ram
)
root
:=
RamToTrie
(
ram
)
fmt
.
Println
(
"state root"
,
root
,
"nodes"
,
len
(
Preimages
))
//ParseNode(root, 0)
ParseNode
(
root
,
0
)
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
)
}
}
fmt
.
Println
(
"trie is ready, let's run"
)
fmt
.
Println
(
"trie is ready, let's run"
)
fmt
.
Println
(
"state root"
,
root
,
"nodes"
,
len
(
Preimages
))
// it's run o clock
for
step
:=
0
;
step
<
10
;
step
++
{
from
:=
common
.
Address
{}
// it's run o clock
to
:=
common
.
HexToAddress
(
"0x1337"
)
from
:=
common
.
Address
{}
bytecode
:=
statedb
.
Bytecodes
[
to
]
to
:=
common
.
HexToAddress
(
"0x1337"
)
gas
:=
uint64
(
100000000
)
bytecode
:=
statedb
.
Bytecodes
[
to
]
gas
:=
uint64
(
100000000
)
steps
:=
1
steps
:=
1
input
:=
crypto
.
Keccak256Hash
([]
byte
(
"Steps(bytes32,uint256)"
))
.
Bytes
()[
:
4
]
input
:=
crypto
.
Keccak256Hash
([]
byte
(
"Steps(bytes32,uint256)"
))
.
Bytes
()[
:
4
]
input
=
append
(
input
,
root
.
Bytes
()
...
)
input
=
append
(
input
,
root
.
Bytes
()
...
)
input
=
append
(
input
,
common
.
BigToHash
(
big
.
NewInt
(
int64
(
steps
)))
.
Bytes
()
...
)
input
=
append
(
input
,
common
.
BigToHash
(
big
.
NewInt
(
int64
(
steps
)))
.
Bytes
()
...
)
contract
:=
vm
.
NewContract
(
vm
.
AccountRef
(
from
),
vm
.
AccountRef
(
to
),
common
.
Big0
,
gas
)
contract
:=
vm
.
NewContract
(
vm
.
AccountRef
(
from
),
vm
.
AccountRef
(
to
),
common
.
Big0
,
gas
)
contract
.
SetCallCode
(
&
to
,
crypto
.
Keccak256Hash
(
bytecode
),
bytecode
)
contract
.
SetCallCode
(
&
to
,
crypto
.
Keccak256Hash
(
bytecode
),
bytecode
)
dat
,
err
:=
interpreter
.
Run
(
contract
,
input
,
false
)
dat
,
err
:=
interpreter
.
Run
(
contract
,
input
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
if
len
(
dat
)
>=
0x24
{
if
len
(
dat
)
>=
0x24
{
fmt
.
Println
(
string
(
dat
[
0x24
:
]))
fmt
.
Println
(
string
(
dat
[
0x24
:
]))
}
log
.
Fatal
(
err
)
}
else
{
root
=
common
.
BytesToHash
(
dat
)
fmt
.
Println
(
"new state root"
,
step
,
root
)
}
}
log
.
Fatal
(
err
)
}
else
{
fmt
.
Println
(
"exited"
,
common
.
BytesToHash
(
dat
))
}
}
}
}
mipsevm/minievm.go
View file @
06f7503b
...
@@ -56,7 +56,9 @@ func (b *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.
...
@@ -56,7 +56,9 @@ func (b *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.
}
}
func
(
s
*
StateDB
)
GetBalance
(
addr
common
.
Address
)
*
big
.
Int
{
return
common
.
Big0
}
func
(
s
*
StateDB
)
GetBalance
(
addr
common
.
Address
)
*
big
.
Int
{
return
common
.
Big0
}
func
(
s
*
StateDB
)
GetCode
(
addr
common
.
Address
)
[]
byte
{
func
(
s
*
StateDB
)
GetCode
(
addr
common
.
Address
)
[]
byte
{
fmt
.
Println
(
"GetCode"
,
addr
)
if
s
.
Debug
>=
1
{
fmt
.
Println
(
"GetCode"
,
addr
)
}
return
s
.
Bytecodes
[
addr
]
return
s
.
Bytecodes
[
addr
]
}
}
func
(
s
*
StateDB
)
GetCodeHash
(
addr
common
.
Address
)
common
.
Hash
{
return
common
.
Hash
{}
}
func
(
s
*
StateDB
)
GetCodeHash
(
addr
common
.
Address
)
common
.
Hash
{
return
common
.
Hash
{}
}
...
@@ -70,7 +72,9 @@ func (s *StateDB) GetRefund() uint64 { return 0 }
...
@@ -70,7 +72,9 @@ func (s *StateDB) GetRefund() uint64 { return 0 }
func
(
s
*
StateDB
)
GetState
(
fakeaddr
common
.
Address
,
hash
common
.
Hash
)
common
.
Hash
{
func
(
s
*
StateDB
)
GetState
(
fakeaddr
common
.
Address
,
hash
common
.
Hash
)
common
.
Hash
{
if
s
.
useRealState
{
if
s
.
useRealState
{
// TODO: fakeaddr?
// TODO: fakeaddr?
fmt
.
Println
(
"GetState"
,
fakeaddr
,
hash
)
if
s
.
Debug
>=
1
{
fmt
.
Println
(
"GetState"
,
fakeaddr
,
hash
)
}
return
s
.
RealState
[
hash
]
return
s
.
RealState
[
hash
]
}
}
ram
:=
s
.
Ram
ram
:=
s
.
Ram
...
@@ -147,7 +151,9 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
...
@@ -147,7 +151,9 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
func
(
s
*
StateDB
)
SetNonce
(
addr
common
.
Address
,
nonce
uint64
)
{}
func
(
s
*
StateDB
)
SetNonce
(
addr
common
.
Address
,
nonce
uint64
)
{}
func
(
s
*
StateDB
)
SetState
(
fakeaddr
common
.
Address
,
key
,
value
common
.
Hash
)
{
func
(
s
*
StateDB
)
SetState
(
fakeaddr
common
.
Address
,
key
,
value
common
.
Hash
)
{
if
s
.
useRealState
{
if
s
.
useRealState
{
fmt
.
Println
(
"SetState"
,
fakeaddr
,
key
,
value
)
if
s
.
Debug
>=
1
{
fmt
.
Println
(
"SetState"
,
fakeaddr
,
key
,
value
)
}
s
.
RealState
[
key
]
=
value
s
.
RealState
[
key
]
=
value
return
return
}
}
...
...
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