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
3a6ed525
Commit
3a6ed525
authored
Oct 27, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repro issue in js
parent
e2e0b0f8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
9 deletions
+50
-9
MIPSMemory.sol
contracts/MIPSMemory.sol
+6
-0
hardhat.config.js
hardhat.config.js
+1
-1
compare_evmchain_test.go
mipsevm/compare_evmchain_test.go
+4
-4
minievm.go
mipsevm/minievm.go
+4
-4
mips_test_memory.js
test/mips_test_memory.js
+32
-0
mips_test_trie.js
test/mips_test_trie.js
+3
-0
No files found.
contracts/MIPSMemory.sol
View file @
3a6ed525
...
...
@@ -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)));
...
...
hardhat.config.js
View file @
3a6ed525
...
...
@@ -3,7 +3,7 @@
*/
require
(
"
@nomiclabs/hardhat-ethers
"
);
require
(
"
hardhat-gas-reporter
"
);
//
require("hardhat-gas-reporter");
module
.
exports
=
{
solidity
:
{
...
...
mipsevm/compare_evmchain_test.go
View file @
3a6ed525
...
...
@@ -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 TestCompare
Unicorn
Chain
// go test -run TestCompare
Evm
Chain
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
...
...
mipsevm/minievm.go
View file @
3a6ed525
...
...
@@ -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
...
...
test/mips_test_memory.js
0 → 100644
View file @
3a6ed525
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
)
})
})
test/mips_test_trie.js
View file @
3a6ed525
...
...
@@ -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
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