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
177d162f
Commit
177d162f
authored
Oct 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
faster and cleaner with profiler
parent
6e1f18fc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
18 deletions
+16
-18
MIPS.sol
contracts/MIPS.sol
+2
-0
main.go
mipsevm/main.go
+14
-18
No files found.
contracts/MIPS.sol
View file @
177d162f
...
...
@@ -96,6 +96,8 @@ contract MIPS {
// TODO: test ll and sc
function stepNextPC(bytes32 stateHash, uint32 pc, uint64 nextPC) internal view returns (bytes32) {
uint32 insn = m.ReadMemory(stateHash, pc);
//return stateHash;
uint32 opcode = insn >> 26; // 6-bits
uint32 func = insn & 0x3f; // 6-bits
...
...
mipsevm/main.go
View file @
177d162f
...
...
@@ -107,6 +107,8 @@ func bytesTo32(a []byte) uint32 {
return
binary
.
BigEndian
.
Uint32
(
a
[
28
:
])
}
var
mret
=
make
([]
byte
,
32
)
func
opStaticCall
(
pc
*
uint64
,
interpreter
*
vm
.
EVMInterpreter
,
scope
*
vm
.
ScopeContext
)
([]
byte
,
error
)
{
// Pop gas. The actual gas is in interpreter.evm.callGasTemp.
stack
:=
scope
.
Stack
...
...
@@ -127,8 +129,8 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
nret
:=
ram
[
addr
]
//scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
ret
:=
common
.
BigToHash
(
big
.
NewInt
(
int64
(
nret
)))
.
Bytes
()
binary
.
BigEndian
.
PutUint32
(
mret
[
0x1c
:
],
nret
)
//
ret := common.BigToHash(big.NewInt(int64(nret))).Bytes()
if
debug
>=
2
{
fmt
.
Println
(
"HOOKED READ! "
,
fmt
.
Sprintf
(
"%x = %x"
,
addr
,
nret
))
}
...
...
@@ -153,7 +155,7 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
}
pcCount
+=
1
}
scope
.
Memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
ret
)
scope
.
Memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
m
ret
)
}
else
if
args
[
0
]
==
184
{
addr
:=
bytesTo32
(
args
[
0x24
:
0x44
])
dat
:=
bytesTo32
(
args
[
0x44
:
0x64
])
...
...
@@ -169,18 +171,19 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
// ram access is free here
scope
.
Contract
.
Gas
=
returnGas
// what is the return value here?
return
common
.
Hash
{}
.
Bytes
()
,
nil
return
mret
,
nil
}
func
RunMinigeth
(
fn
string
,
interpreter
*
vm
.
EVMInterpreter
,
bytecode
[]
byte
,
steps
int
)
{
ram
=
make
(
map
[
uint32
](
uint32
))
func
LoadMappedFile
(
fn
string
,
ram
map
[
uint32
](
uint32
))
{
dat
,
_
:=
ioutil
.
ReadFile
(
fn
)
for
i
:=
0
;
i
<
len
(
dat
);
i
+=
4
{
ram
[
uint32
(
i
)]
=
uint32
(
dat
[
i
])
<<
24
|
uint32
(
dat
[
i
+
1
])
<<
16
|
uint32
(
dat
[
i
+
2
])
<<
8
|
uint32
(
dat
[
i
+
3
])
<<
0
ram
[
uint32
(
i
)]
=
binary
.
BigEndian
.
Uint32
(
dat
[
i
:
i
+
4
])
}
}
func
RunMinigeth
(
fn
string
,
interpreter
*
vm
.
EVMInterpreter
,
bytecode
[]
byte
,
steps
int
)
{
ram
=
make
(
map
[
uint32
](
uint32
))
LoadMappedFile
(
fn
,
ram
)
gas
:=
10000
*
uint64
(
steps
)
...
...
@@ -208,14 +211,7 @@ func RunMinigeth(fn string, interpreter *vm.EVMInterpreter, bytecode []byte, ste
func
runTest
(
fn
string
,
steps
int
,
interpreter
*
vm
.
EVMInterpreter
,
bytecode
[]
byte
,
gas
uint64
)
(
uint32
,
uint64
)
{
ram
=
make
(
map
[
uint32
](
uint32
))
ram
[
0xC000007C
]
=
0xDEAD0000
//fmt.Println("starting", fn)
dat
,
_
:=
ioutil
.
ReadFile
(
fn
)
for
i
:=
0
;
i
<
len
(
dat
);
i
+=
4
{
ram
[
uint32
(
i
)]
=
uint32
(
dat
[
i
])
<<
24
|
uint32
(
dat
[
i
+
1
])
<<
16
|
uint32
(
dat
[
i
+
2
])
<<
8
|
uint32
(
dat
[
i
+
3
])
<<
0
}
LoadMappedFile
(
fn
,
ram
)
// 0xdb7df598
from
:=
common
.
Address
{}
...
...
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