Commit 06f7503b authored by George Hotz's avatar George Hotz

failing on the 6th step

parent 6f7b2c8d
......@@ -2,12 +2,8 @@
pragma solidity ^0.7.3;
import "./lib/Lib_Keccak256.sol";
//import "hardhat/console.sol";
import "./lib/Lib_MerkleTrie.sol";
//import { Lib_RLPReader } from "./lib/Lib_RLPReader.sol";
//import { Lib_BytesUtils } from "./lib/Lib_BytesUtils.sol";
contract MIPSMemory {
// TODO: the trie library should read and write from this as appropriate
mapping(bytes32 => bytes) public trie;
......@@ -74,14 +70,6 @@ contract MIPSMemory {
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) {
require(addr & 3 == 0, "write memory must be 32-bit aligned");
return Lib_MerkleTrie.update(tb(addr>>2), tb(value), trie, stateHash);
......@@ -140,46 +128,6 @@ contract MIPSMemory {
} else {
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
......@@ -57,15 +57,16 @@ func RunFull() {
ZeroRegisters(ram)
ram[0xC000007C] = 0x5EAD0000
root := RamToTrie(ram)
fmt.Println("state root", root, "nodes", len(Preimages))
ParseNode(root, 0)
//ParseNode(root, 0)
for k, v := range Preimages {
fmt.Println("AddTrieNode", k)
addTrieNode(v, interpreter, statedb)
}
fmt.Println("trie is ready, let's run")
fmt.Println("state root", root, "nodes", len(Preimages))
for step := 0; step < 10; step++ {
// it's run o clock
from := common.Address{}
to := common.HexToAddress("0x1337")
......@@ -86,6 +87,8 @@ func RunFull() {
}
log.Fatal(err)
} else {
fmt.Println("exited", common.BytesToHash(dat))
root = common.BytesToHash(dat)
fmt.Println("new state root", step, root)
}
}
}
......@@ -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) GetCode(addr common.Address) []byte {
if s.Debug >= 1 {
fmt.Println("GetCode", addr)
}
return s.Bytecodes[addr]
}
func (s *StateDB) GetCodeHash(addr common.Address) common.Hash { return common.Hash{} }
......@@ -70,7 +72,9 @@ func (s *StateDB) GetRefund() uint64 { return 0 }
func (s *StateDB) GetState(fakeaddr common.Address, hash common.Hash) common.Hash {
if s.useRealState {
// TODO: fakeaddr?
if s.Debug >= 1 {
fmt.Println("GetState", fakeaddr, hash)
}
return s.RealState[hash]
}
ram := s.Ram
......@@ -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) SetState(fakeaddr common.Address, key, value common.Hash) {
if s.useRealState {
if s.Debug >= 1 {
fmt.Println("SetState", fakeaddr, key, value)
}
s.RealState[key] = value
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment