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
6e1f18fc
Commit
6e1f18fc
authored
Oct 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
now all in evm interp
parent
036648b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
main.go
mipsevm/main.go
+16
-6
No files found.
mipsevm/main.go
View file @
6e1f18fc
...
...
@@ -2,6 +2,7 @@ package main
import
(
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
...
...
@@ -101,6 +102,11 @@ var debug int = 0
// TODO: why is ram uint64 -> uint32 and not uint32 -> uint32
var
ram
map
[
uint32
](
uint32
)
func
bytesTo32
(
a
[]
byte
)
uint32
{
//return uint32(common.BytesToHash(a).Big().Uint64())
return
binary
.
BigEndian
.
Uint32
(
a
[
28
:
])
}
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
...
...
@@ -117,7 +123,7 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
args
:=
scope
.
Memory
.
GetPtr
(
int64
(
inOffset
.
Uint64
()),
int64
(
inSize
.
Uint64
()))
if
args
[
0
]
==
98
{
// read
addr
:=
uint32
(
common
.
BytesToHash
(
args
[
4
:
])
.
Big
()
.
Uint64
()
)
addr
:=
bytesTo32
(
args
[
0x24
:
0x44
]
)
nret
:=
ram
[
addr
]
//scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
...
...
@@ -149,8 +155,8 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
}
scope
.
Memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
ret
)
}
else
if
args
[
0
]
==
184
{
addr
:=
uint32
(
common
.
BytesToHash
(
args
[
0x24
:
0x44
])
.
Big
()
.
Uint64
()
)
dat
:=
uint32
(
common
.
BytesToHash
(
args
[
0x44
:
0x64
])
.
Big
()
.
Uint64
()
)
addr
:=
bytesTo32
(
args
[
0x24
:
0x44
]
)
dat
:=
bytesTo32
(
args
[
0x44
:
0x64
]
)
if
debug
>=
2
{
fmt
.
Println
(
"HOOKED WRITE! "
,
fmt
.
Sprintf
(
"%x = %x"
,
addr
,
dat
))
}
...
...
@@ -199,7 +205,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
{
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)
...
...
@@ -230,7 +236,7 @@ func runTest(fn string, steps int, interpreter *vm.EVMInterpreter, bytecode []by
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
return
ram
[
0xbffffff4
]
&
ram
[
0xbffffff8
]
return
ram
[
0xbffffff4
]
&
ram
[
0xbffffff8
]
,
(
gas
-
contract
.
Gas
)
}
func
GetInterpreterAndBytecode
()
(
*
vm
.
EVMInterpreter
,
[]
byte
)
{
...
...
@@ -295,11 +301,15 @@ func main() {
log
.
Fatal
(
err
)
}
good
:=
true
gas
:=
uint64
(
0
)
for
_
,
f
:=
range
files
{
good
=
good
&&
(
runTest
(
"test/bin/"
+
f
.
Name
(),
100
,
interpreter
,
bytecode
,
1000000
)
==
1
)
ret
,
lgas
:=
runTest
(
"test/bin/"
+
f
.
Name
(),
100
,
interpreter
,
bytecode
,
1000000
)
good
=
good
&&
(
ret
==
1
)
gas
+=
lgas
}
if
!
good
{
panic
(
"some tests failed"
)
}
fmt
.
Println
(
"used"
,
gas
,
"gas"
)
}
}
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