Commit 3a6ed525 authored by George Hotz's avatar George Hotz

repro issue in js

parent e2e0b0f8
......@@ -75,6 +75,12 @@ contract MIPSMemory {
return Lib_MerkleTrie.update(tb(addr>>2), tb(value), trie, stateHash);
}
event DidStep(bytes32 stateHash);
function WriteMemoryWithReceipt(bytes32 stateHash, uint32 addr, uint32 value) public {
bytes32 newStateHash = WriteMemory(stateHash, addr, value);
emit DidStep(newStateHash);
}
function WriteBytes32(bytes32 stateHash, uint32 addr, bytes32 val) public returns (bytes32) {
for (uint32 i = 0; i < 32; i += 4) {
uint256 tv = uint256(val>>(224-(i*8)));
......
......@@ -3,7 +3,7 @@
*/
require("@nomiclabs/hardhat-ethers");
require("hardhat-gas-reporter");
//require("hardhat-gas-reporter");
module.exports = {
solidity: {
......
......@@ -12,8 +12,8 @@ import (
func LoadRam() map[uint32](uint32) {
ram := make(map[uint32](uint32))
//fn := "../mipigo/test/test.bin"
fn := "test/bin/add.bin"
fn := "../mipigo/test/test.bin"
//fn := "test/bin/add.bin"
LoadMappedFile(fn, ram, 0)
ZeroRegisters(ram)
ram[0xC000007C] = 0x5EAD0000
......@@ -24,7 +24,7 @@ func LoadRam() map[uint32](uint32) {
RunFull()
}*/
// go test -run TestCompareUnicornChain
// go test -run TestCompareEvmChain
func TestCompareEvmChain(t *testing.T) {
totalSteps := 20
......@@ -39,7 +39,7 @@ func TestCompareEvmChain(t *testing.T) {
fmt.Println("state root", root, "nodes", len(Preimages))
// deploy chain
interpreter, statedb := GetInterpreter(0, true)
interpreter, statedb := GetInterpreter(1, true)
DeployChain(interpreter, statedb)
// load chain trie node
......
......@@ -50,7 +50,7 @@ func (s *StateDB) AddLog(log *types.Log) {
} else if log.Topics[0] == common.HexToHash("0x486ca368095cbbef9046ac7858bec943e866422cc388f49da1aa3aa77c10aa35") {
fmt.Printf("W: %x <- %x\n", bytesTo32(log.Data[0:32]), bytesTo32(log.Data[32:]))
} else {
fmt.Println("AddLog", log.Topics, log.Data)
//fmt.Println("AddLog", log.Topics, log.Data)
}
}
}
......@@ -66,7 +66,7 @@ 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 {
if s.Debug >= 2 {
fmt.Println("GetCode", addr)
}
return s.Bytecodes[addr]
......@@ -82,7 +82,7 @@ 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 {
if s.Debug >= 2 {
fmt.Println("GetState", fakeaddr, hash)
}
return s.RealState[hash]
......@@ -161,7 +161,7 @@ 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 {
if s.Debug >= 2 {
fmt.Println("SetState", fakeaddr, key, value)
}
s.RealState[key] = value
......
const { expect } = require("chai");
const trieAdd = {"root":"0x22ffce7c56d926c2d8d6337d8917fa0e1880e1869e189c15385ead63c6c45b93","preimages":{"0x044371dc86fb8c621bc84b69dce16de366de1126777250888b17416d0bd11279":"+FPGIIQ8EL//xiCENhD/8MYghDQRAAHGIIQ8CP//xiCENQj//cYghDQJAAPGIIQBCVAgxiCELUIAAcYghK4CAAjGIISuEQAExiCEA+AACICAgICAgA==","0x0fdfcc24b1b21d78ef2b7c6503eb9354677743685c2d00a14a8b502a177911b0":"+HGgL4Jb+u0gEWM4e9G4lO/GsyUEY/heVoGOAfiI04qPXfSgLCZprT7WBOLipiwJxxI0vy09rw9iPR+x0p/Xz1p3X5WgaNY/x30waJPsd6PWg76b094l8vUmmL6XB1XdUFy+xfWAgICAgICAgICAgICAgA==","0x11228d4f4a028a9088e6ec0aa6513e0d4731d9dc488e2af1957e46ba80624a69":"5oQAAAAAoARDcdyG+4xiG8hLadzhbeNm3hEmd3JQiIsXQW0L0RJ5","0x22ffce7c56d926c2d8d6337d8917fa0e1880e1869e189c15385ead63c6c45b93":"+FGgESKNT0oCipCI5uwKplE+DUcx2dxIjirxlX5GuoBiSmmAgKBv5gezlmGtxjQAs8Du76D93mAxExw5qWgAZjJQp1xmfICAgICAgICAgICAgIA=","0x2c2669ad3ed604e2e2a62c09c71234bf2d3daf0f623d1fb1d29fd7cf5a775f95":"+HHGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIRerQAAgA==","0x2f825bfaed201163387bd1b894efc6b3250463f85e56818e01f888d38a8f5df4":"+HHGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAgA==","0x68d63fc77d306893ec77a3d683be9bd3de25f2f52698be970755dd505cbec5f5":"6cYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAACAgICAgICAgICAgICA","0x6fe607b39661adc63400b3c0eeefa0fdde6031131c39a96800663250a75c667c":"5YMQAACgD9/MJLGyHXjvK3xlA+uTVGd3Q2hcLQChSotQKhd5EbA="}};
async function write(mm, root, addr, data) {
ret = await mm.WriteMemoryWithReceipt(root, addr, data)
const receipt = await ret.wait()
for (l of receipt.logs) {
if (l.topics[0] == "0x86b89b5c9818dbbf520dd979a5f250d357508fe11b9511d4a43fd9bc6aa1be70") {
root = l.data
}
}
console.log("new hash", root)
return root
}
describe("MIPSMemory contract", function () {
it("reads and write should work", async function() {
const MIPSMemory = await ethers.getContractFactory("MIPSMemory")
const mm = await MIPSMemory.deploy()
for (k in trieAdd['preimages']) {
const bin = Uint8Array.from(Buffer.from(trieAdd['preimages'][k], 'base64').toString('binary'), c => c.charCodeAt(0))
await mm.AddTrieNode(bin)
}
let root = trieAdd['root']
root = await write(mm, root, 0x7fffd010, 1000)
root = await write(mm, root, 0x7fffd00c, 6)
root = await write(mm, root, 0x7fffcffc, 0x85a24)
})
})
......@@ -26,4 +26,7 @@ describe("MIPS contract", function () {
console.log(i, root)
}
});
it("reads and write should work", async function() {
const mm = await ethers.getContractFactory("MIPSMemory")
})
});
\ No newline at end of file
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