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
c20dde6b
Commit
c20dde6b
authored
3 years ago
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mips is running
parent
854d220a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
4 deletions
+29
-4
MIPS.sol
contracts/MIPS.sol
+17
-1
MIPSMemory.sol
contracts/MIPSMemory.sol
+8
-2
main.go
mipsevm/main.go
+4
-1
No files found.
contracts/MIPS.sol
View file @
c20dde6b
...
...
@@ -57,6 +57,10 @@ contract MIPS {
// R-type (stores rd)
rt = m.ReadMemory(stateHash, REG_OFFSET + ((insn >> 14) & 0x7C));
storeAddr = REG_OFFSET + ((insn >> 9) & 0x7C);
} else {
// rt is SignExtImm
uint32 SignExtImm = insn&0xFFFF | (insn&0x8000 != 0 ? 0xFFFF0000 : 0);
rt = SignExtImm;
}
}
...
...
@@ -66,7 +70,12 @@ contract MIPS {
if (opcode >= 0x20) {
// M[R[rs]+SignExtImm]
uint32 SignExtImm = insn&0xFFFF | (insn&0x8000 != 0 ? 0xFFFF0000 : 0);
mem = m.ReadMemory(stateHash, (rs + SignExtImm) & 0xFFFFFFFC);
uint32 addr = (rs + SignExtImm) & 0xFFFFFFFC;
mem = m.ReadMemory(stateHash, addr);
if (opcode >= 0x28) {
// store
storeAddr = addr;
}
}
// execute
...
...
@@ -84,6 +93,13 @@ contract MIPS {
uint32 opcode = insn >> 26; // 6-bits
uint32 func = insn & 0x3f; // 6-bits
// TODO: deref the immed into a register
// transform ArithLogI
// TODO: replace with table
if (opcode == 8) { opcode = 0; func = 0x20; }
else if (opcode == 9) { opcode = 0; func = 0x21; }
else if (opcode == 0xc) { opcode = 0; func = 0x24; }
if (opcode == 0) {
uint32 shamt = (insn >> 6) & 0x1f;
// R-type (ArithLog)
...
...
This diff is collapsed.
Click to expand it.
contracts/MIPSMemory.sol
View file @
c20dde6b
...
...
@@ -15,9 +15,15 @@ contract MIPSMemory {
state[stateHash][addr] = (1 << 32) | value;
}
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 val) public pure returns (bytes32) {
// TODO: does the stateHash mutation
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) public pure returns (bytes32) {
require(addr & 3 == 0, "write memory must be 32-bit aligned");
// TODO: do the real stateHash mutation
bytes32 newstateHash = keccak256(abi.encodePacked(stateHash));
// no proof required, this is obviously right
//state[newstateHash][addr] = (1 << 32) | value;
return newstateHash;
}
// needed for preimage oracle
...
...
This diff is collapsed.
Click to expand it.
mipsevm/main.go
View file @
c20dde6b
...
...
@@ -124,6 +124,9 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
dat
:=
common
.
BytesToHash
(
args
[
0x44
:
0x64
])
.
Big
()
.
Uint64
()
fmt
.
Println
(
"HOOKED WRITE!"
,
fmt
.
Sprintf
(
"%x = %x"
,
addr
,
dat
))
ram
[
addr
]
=
uint32
(
dat
)
// pass through stateRoot
scope
.
Memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
args
[
0x4
:
0x24
])
}
scope
.
Contract
.
Gas
+=
returnGas
...
...
@@ -185,7 +188,7 @@ func main() {
// 0xdb7df598
input
:=
[]
byte
{
0xdb
,
0x7d
,
0xf5
,
0x98
}
// Steps(bytes32, uint256)
input
=
append
(
input
,
common
.
Hash
{}
.
Bytes
()
...
)
input
=
append
(
input
,
common
.
BigToHash
(
common
.
Big0
)
.
Bytes
()
...
)
input
=
append
(
input
,
common
.
BigToHash
(
big
.
NewInt
(
int64
(
steps
)))
.
Bytes
()
...
)
contract
:=
vm
.
NewContract
(
vm
.
AccountRef
(
from
),
vm
.
AccountRef
(
to
),
common
.
Big0
,
20000000
)
//fmt.Println(bytecodehash, bytecode)
...
...
This diff is collapsed.
Click to expand it.
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