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
d34f78a0
Unverified
Commit
d34f78a0
authored
Jun 16, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mipsevm,contracts: reduce step arguments
parent
f9bcb588
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
13 deletions
+9
-13
MIPS.sol
contracts/src/MIPS.sol
+6
-6
evm.go
mipsevm/evm.go
+1
-1
witness.go
mipsevm/witness.go
+2
-6
No files found.
contracts/src/MIPS.sol
View file @
d34f78a0
...
@@ -310,8 +310,8 @@ contract MIPS {
...
@@ -310,8 +310,8 @@ contract MIPS {
function proofOffset(uint8 proofIndex) internal pure returns (uint256 offset) {
function proofOffset(uint8 proofIndex) internal pure returns (uint256 offset) {
// A proof of 32 bit memory, with 32-byte leaf values, is (32-5)=27 bytes32 entries.
// A proof of 32 bit memory, with 32-byte leaf values, is (32-5)=27 bytes32 entries.
// And the leaf value itself needs to be encoded as well. And proof.offset == 3
90
// And the leaf value itself needs to be encoded as well. And proof.offset == 3
58
offset = 3
90
+ (uint256(proofIndex) * (28*32));
offset = 3
58
+ (uint256(proofIndex) * (28*32));
uint256 s = 0;
uint256 s = 0;
assembly { s := calldatasize() }
assembly { s := calldatasize() }
require(s >= (offset + 28*32), "check that there is enough calldata");
require(s >= (offset + 28*32), "check that there is enough calldata");
...
@@ -379,7 +379,7 @@ contract MIPS {
...
@@ -379,7 +379,7 @@ contract MIPS {
}
}
// will revert if any required input state is missing
// will revert if any required input state is missing
function Step(bytes
32 stateHash, bytes
calldata stateData, bytes calldata proof) public returns (bytes32) {
function Step(bytes calldata stateData, bytes calldata proof) public returns (bytes32) {
State memory state;
State memory state;
// packed data is ~6 times smaller
// packed data is ~6 times smaller
assembly {
assembly {
...
@@ -389,10 +389,10 @@ contract MIPS {
...
@@ -389,10 +389,10 @@ contract MIPS {
if iszero(eq(mload(0x40), mul(32, 48))) { // expected memory check
if iszero(eq(mload(0x40), mul(32, 48))) { // expected memory check
revert(0,0)
revert(0,0)
}
}
if iszero(eq(stateData.offset, 1
32)) { // 32*4+4=132
expected state data offset
if iszero(eq(stateData.offset, 1
00)) { // 32*3+4=100
expected state data offset
revert(0,0)
revert(0,0)
}
}
if iszero(eq(proof.offset, 3
90)) { // 132+32+226=390
expected proof offset
if iszero(eq(proof.offset, 3
58)) { // 100+32+226=358
expected proof offset
revert(0,0)
revert(0,0)
}
}
function putField(callOffset, memOffset, size) -> callOffsetOut, memOffsetOut {
function putField(callOffset, memOffset, size) -> callOffsetOut, memOffsetOut {
...
@@ -420,7 +420,7 @@ contract MIPS {
...
@@ -420,7 +420,7 @@ contract MIPS {
for { let i := 0 } lt(i, 32) { i := add(i, 1) } { c, m := putField(c, m, 4) } // registers
for { let i := 0 } lt(i, 32) { i := add(i, 1) } { c, m := putField(c, m, 4) } // registers
}
}
if(state.exited) { // don't change state once exited
if(state.exited) { // don't change state once exited
return
stateHash
;
return
outputState()
;
}
}
state.step += 1;
state.step += 1;
...
...
mipsevm/evm.go
View file @
d34f78a0
...
@@ -21,7 +21,7 @@ import (
...
@@ -21,7 +21,7 @@ import (
)
)
var
(
var
(
StepBytes4
=
crypto
.
Keccak256
([]
byte
(
"Step(bytes
32,bytes
,bytes)"
))[
:
4
]
StepBytes4
=
crypto
.
Keccak256
([]
byte
(
"Step(bytes,bytes)"
))[
:
4
]
CheatBytes4
=
crypto
.
Keccak256
([]
byte
(
"cheat(uint256,bytes32,bytes32,uint256)"
))[
:
4
]
CheatBytes4
=
crypto
.
Keccak256
([]
byte
(
"cheat(uint256,bytes32,bytes32,uint256)"
))[
:
4
]
LoadKeccak256PreimagePartBytes4
=
crypto
.
Keccak256
([]
byte
(
"loadKeccak256PreimagePart(uint256,bytes)"
))[
:
4
]
LoadKeccak256PreimagePartBytes4
=
crypto
.
Keccak256
([]
byte
(
"loadKeccak256PreimagePart(uint256,bytes)"
))[
:
4
]
)
)
...
...
mipsevm/witness.go
View file @
d34f78a0
...
@@ -5,8 +5,6 @@ import (
...
@@ -5,8 +5,6 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum-optimism/cannon/preimage"
"github.com/ethereum-optimism/cannon/preimage"
)
)
...
@@ -28,12 +26,10 @@ func uint32ToBytes32(v uint32) []byte {
...
@@ -28,12 +26,10 @@ func uint32ToBytes32(v uint32) []byte {
}
}
func
(
wit
*
StepWitness
)
EncodeStepInput
()
[]
byte
{
func
(
wit
*
StepWitness
)
EncodeStepInput
()
[]
byte
{
stateHash
:=
crypto
.
Keccak256Hash
(
wit
.
State
)
var
input
[]
byte
var
input
[]
byte
input
=
append
(
input
,
StepBytes4
...
)
input
=
append
(
input
,
StepBytes4
...
)
input
=
append
(
input
,
stateHash
[
:
]
...
)
input
=
append
(
input
,
uint32ToBytes32
(
32
*
2
)
...
)
// state data offset in bytes
input
=
append
(
input
,
uint32ToBytes32
(
32
*
3
)
...
)
// state data offset in bytes
input
=
append
(
input
,
uint32ToBytes32
(
32
*
2
+
32
+
uint32
(
len
(
wit
.
State
)))
...
)
// proof data offset in bytes
input
=
append
(
input
,
uint32ToBytes32
(
32
*
3
+
32
+
uint32
(
len
(
wit
.
State
)))
...
)
// proof data offset in bytes
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
len
(
wit
.
State
)))
...
)
// state data length in bytes
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
len
(
wit
.
State
)))
...
)
// state data length in bytes
input
=
append
(
input
,
wit
.
State
[
:
]
...
)
input
=
append
(
input
,
wit
.
State
[
:
]
...
)
...
...
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