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
4fc794ca
Unverified
Commit
4fc794ca
authored
Jul 16, 2023
by
inphi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cannon: Invalid STF for branch/jump in delay slots
parent
94a01d5b
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
26 deletions
+54
-26
evm_test.go
cannon/mipsevm/evm_test.go
+35
-22
mips.go
cannon/mipsevm/mips.go
+7
-0
mips.go
op-bindings/bindings/mips.go
+1
-1
mips_more.go
op-bindings/bindings/mips_more.go
+2
-2
preimageoracle_more.go
op-bindings/bindings/preimageoracle_more.go
+1
-1
MIPS.sol
packages/contracts-bedrock/src/cannon/MIPS.sol
+8
-0
No files found.
cannon/mipsevm/evm_test.go
View file @
4fc794ca
...
...
@@ -174,17 +174,28 @@ func TestEVMFault(t *testing.T) {
env
,
evmState
:=
NewEVMEnv
(
contracts
,
addrs
)
env
.
Config
.
Tracer
=
tracer
programMem
:=
[]
byte
{
0xff
,
0xff
,
0xff
,
0xff
}
state
:=
&
State
{
PC
:
0
,
NextPC
:
4
,
Memory
:
NewMemory
()}
initialState
:=
&
State
{
PC
:
0
,
NextPC
:
4
,
Memory
:
state
.
Memory
}
err
:=
state
.
Memory
.
SetMemoryRange
(
0
,
bytes
.
NewReader
(
programMem
))
require
.
NoError
(
t
,
err
,
"load program into state"
)
type
testInput
struct
{
name
string
nextPC
uint32
insn
uint32
}
cases
:=
[]
testInput
{
{
"illegal instruction"
,
0
,
0xFF
_FF_FF_FF
},
{
"branch in delay-slot"
,
8
,
0x11
_02_00_03
},
{
"jump in delay-slot"
,
8
,
0x0c
_00_00_0c
},
}
for
_
,
tt
:=
range
cases
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
state
:=
&
State
{
PC
:
0
,
NextPC
:
tt
.
nextPC
,
Memory
:
NewMemory
()}
initialState
:=
&
State
{
PC
:
0
,
NextPC
:
tt
.
nextPC
,
Memory
:
state
.
Memory
}
state
.
Memory
.
SetMemory
(
0
,
tt
.
insn
)
// set the return address ($ra) to jump into when test completes
state
.
Registers
[
31
]
=
endAddr
goState
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
require
.
Panics
(
t
,
func
()
{
_
,
_
=
goState
.
Step
(
true
)
},
"must panic on illegal instruction"
)
us
:=
NewInstrumentedState
(
state
,
nil
,
os
.
Stdout
,
os
.
Stderr
)
require
.
Panics
(
t
,
func
()
{
_
,
_
=
us
.
Step
(
true
)
}
)
insnProof
:=
initialState
.
Memory
.
MerkleProof
(
0
)
stepWitness
:=
&
StepWitness
{
...
...
@@ -194,10 +205,12 @@ func TestEVMFault(t *testing.T) {
input
:=
stepWitness
.
EncodeStepInput
()
startingGas
:=
uint64
(
30
_000_000
)
_
,
_
,
err
=
env
.
Call
(
vm
.
AccountRef
(
sender
),
addrs
.
MIPS
,
input
,
startingGas
,
big
.
NewInt
(
0
))
_
,
_
,
err
:
=
env
.
Call
(
vm
.
AccountRef
(
sender
),
addrs
.
MIPS
,
input
,
startingGas
,
big
.
NewInt
(
0
))
require
.
EqualValues
(
t
,
err
,
vm
.
ErrExecutionReverted
)
logs
:=
evmState
.
Logs
()
require
.
Equal
(
t
,
0
,
len
(
logs
))
})
}
}
func
TestHelloEVM
(
t
*
testing
.
T
)
{
...
...
cannon/mipsevm/mips.go
View file @
4fc794ca
...
...
@@ -180,6 +180,10 @@ func (m *InstrumentedState) handleSyscall() error {
}
func
(
m
*
InstrumentedState
)
handleBranch
(
opcode
uint32
,
insn
uint32
,
rtReg
uint32
,
rs
uint32
)
error
{
if
m
.
state
.
NextPC
!=
m
.
state
.
PC
+
4
{
panic
(
"branch in delay slot"
)
}
shouldBranch
:=
false
if
opcode
==
4
||
opcode
==
5
{
// beq/bne
rt
:=
m
.
state
.
Registers
[
rtReg
]
...
...
@@ -246,6 +250,9 @@ func (m *InstrumentedState) handleHiLo(fun uint32, rs uint32, rt uint32, storeRe
}
func
(
m
*
InstrumentedState
)
handleJump
(
linkReg
uint32
,
dest
uint32
)
error
{
if
m
.
state
.
NextPC
!=
m
.
state
.
PC
+
4
{
panic
(
"jump in delay slot"
)
}
prevPC
:=
m
.
state
.
PC
m
.
state
.
PC
=
m
.
state
.
NextPC
m
.
state
.
NextPC
=
dest
...
...
op-bindings/bindings/mips.go
View file @
4fc794ca
This diff is collapsed.
Click to expand it.
op-bindings/bindings/mips_more.go
View file @
4fc794ca
This diff is collapsed.
Click to expand it.
op-bindings/bindings/preimageoracle_more.go
View file @
4fc794ca
This diff is collapsed.
Click to expand it.
packages/contracts-bedrock/src/cannon/MIPS.sol
View file @
4fc794ca
...
...
@@ -290,6 +290,10 @@ contract MIPS {
bool shouldBranch = false;
if (state.nextPC != state.pc+4) {
revert("branch in delay slot");
}
// beq/bne: Branch on equal / not equal
if (_opcode == 4 || _opcode == 5) {
uint32 rt = state.registers[_rtReg];
...
...
@@ -419,6 +423,10 @@ contract MIPS {
state := 0x80
}
if (state.nextPC != state.pc+4) {
revert("jump in delay slot");
}
// Update the next PC to the jump destination.
uint32 prevPC = state.pc;
state.pc = state.nextPC;
...
...
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