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
0ca3c050
Unverified
Commit
0ca3c050
authored
Jun 19, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cannon: semgrep fixes
parent
090eb3bc
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
12 additions
and
11 deletions
+12
-11
README.md
cannon/README.md
+2
-2
run.go
cannon/cmd/run.go
+3
-2
memory.go
cannon/mipsevm/memory.go
+1
-1
mips.go
cannon/mipsevm/mips.go
+1
-1
witness.go
cannon/mipsevm/witness.go
+2
-2
MIPS.sol
packages/contracts-bedrock/contracts/cannon/MIPS.sol
+3
-3
No files found.
cannon/README.md
View file @
0ca3c050
...
@@ -46,8 +46,8 @@ go build -o cannon .
...
@@ -46,8 +46,8 @@ go build -o cannon .
--input
./state.json
--input
./state.json
--
--
../optimism/op-program/bin/op-program
../optimism/op-program/bin/op-program
--l2
ws://127.0.0.1:8746
--l2
http://127.0.0.1:8745
--l1
ws://127.0.0.1:8646
--l1
http://127.0.0.1:8645
--l1
.trustrpc
--l1
.trustrpc
--l1
.rpckind debug_geth
--l1
.rpckind debug_geth
--log
.format terminal
--log
.format terminal
...
...
cannon/cmd/run.go
View file @
0ca3c050
...
@@ -124,7 +124,7 @@ func NewProcessPreimageOracle(name string, args []string) (*ProcessPreimageOracl
...
@@ -124,7 +124,7 @@ func NewProcessPreimageOracle(name string, args []string) (*ProcessPreimageOracl
return
nil
,
err
return
nil
,
err
}
}
cmd
:=
exec
.
Command
(
name
,
args
...
)
cmd
:=
exec
.
Command
(
name
,
args
...
)
// nosemgrep
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
cmd
.
Stderr
=
os
.
Stderr
cmd
.
ExtraFiles
=
[]
*
os
.
File
{
cmd
.
ExtraFiles
=
[]
*
os
.
File
{
...
@@ -317,10 +317,11 @@ func Run(ctx *cli.Context) error {
...
@@ -317,10 +317,11 @@ func Run(ctx *cli.Context) error {
StepInput
:
witness
.
EncodeStepInput
(),
StepInput
:
witness
.
EncodeStepInput
(),
}
}
if
witness
.
HasPreimage
()
{
if
witness
.
HasPreimage
()
{
proof
.
OracleInput
,
err
=
witness
.
EncodePreimageOracleInput
()
inp
,
err
:
=
witness
.
EncodePreimageOracleInput
()
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to encode pre-image oracle input: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to encode pre-image oracle input: %w"
,
err
)
}
}
proof
.
OracleInput
=
inp
}
}
if
err
:=
writeJSON
[
*
Proof
](
fmt
.
Sprintf
(
proofFmt
,
step
),
proof
,
true
);
err
!=
nil
{
if
err
:=
writeJSON
[
*
Proof
](
fmt
.
Sprintf
(
proofFmt
,
step
),
proof
,
true
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to write proof data: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to write proof data: %w"
,
err
)
...
...
cannon/mipsevm/memory.go
View file @
0ca3c050
...
@@ -236,7 +236,7 @@ type pageEntry struct {
...
@@ -236,7 +236,7 @@ type pageEntry struct {
Data
*
Page
`json:"data"`
Data
*
Page
`json:"data"`
}
}
func
(
m
*
Memory
)
MarshalJSON
()
([]
byte
,
error
)
{
func
(
m
*
Memory
)
MarshalJSON
()
([]
byte
,
error
)
{
// nosemgrep
pages
:=
make
([]
pageEntry
,
0
,
len
(
m
.
pages
))
pages
:=
make
([]
pageEntry
,
0
,
len
(
m
.
pages
))
for
k
,
p
:=
range
m
.
pages
{
for
k
,
p
:=
range
m
.
pages
{
pages
=
append
(
pages
,
pageEntry
{
pages
=
append
(
pages
,
pageEntry
{
...
...
cannon/mipsevm/mips.go
View file @
0ca3c050
...
@@ -392,7 +392,7 @@ func execute(insn uint32, rs uint32, rt uint32, mem uint32) uint32 {
...
@@ -392,7 +392,7 @@ func execute(insn uint32, rs uint32, rt uint32, mem uint32) uint32 {
if
opcode
<
0x20
{
if
opcode
<
0x20
{
// transform ArithLogI
// transform ArithLogI
// TODO: replace with table
// TODO
(CLI-4136)
: replace with table
if
opcode
>=
8
&&
opcode
<
0xF
{
if
opcode
>=
8
&&
opcode
<
0xF
{
switch
opcode
{
switch
opcode
{
case
8
:
case
8
:
...
...
cannon/mipsevm/witness.go
View file @
0ca3c050
...
@@ -61,7 +61,7 @@ func (wit *StepWitness) EncodePreimageOracleInput() ([]byte, error) {
...
@@ -61,7 +61,7 @@ func (wit *StepWitness) EncodePreimageOracleInput() ([]byte, error) {
copy
(
tmp
[
:
],
wit
.
PreimageValue
[
wit
.
PreimageOffset
:
])
copy
(
tmp
[
:
],
wit
.
PreimageValue
[
wit
.
PreimageOffset
:
])
input
=
append
(
input
,
tmp
[
:
]
...
)
input
=
append
(
input
,
tmp
[
:
]
...
)
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
len
(
wit
.
PreimageValue
))
-
8
)
...
)
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
len
(
wit
.
PreimageValue
))
-
8
)
...
)
//
TODO: do we want to pad the end to a multiple of 32 bytes?
//
Note: we can pad calldata to 32 byte multiple, but don't strictly have to
return
input
,
nil
return
input
,
nil
case
preimage
.
Keccak256KeyType
:
case
preimage
.
Keccak256KeyType
:
var
input
[]
byte
var
input
[]
byte
...
@@ -70,7 +70,7 @@ func (wit *StepWitness) EncodePreimageOracleInput() ([]byte, error) {
...
@@ -70,7 +70,7 @@ func (wit *StepWitness) EncodePreimageOracleInput() ([]byte, error) {
input
=
append
(
input
,
uint32ToBytes32
(
32
+
32
)
...
)
// partOffset, calldata offset
input
=
append
(
input
,
uint32ToBytes32
(
32
+
32
)
...
)
// partOffset, calldata offset
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
len
(
wit
.
PreimageValue
))
-
8
)
...
)
input
=
append
(
input
,
uint32ToBytes32
(
uint32
(
len
(
wit
.
PreimageValue
))
-
8
)
...
)
input
=
append
(
input
,
wit
.
PreimageValue
[
8
:
]
...
)
input
=
append
(
input
,
wit
.
PreimageValue
[
8
:
]
...
)
//
TODO: do we want to pad the end to a multiple of 32 bytes?
//
Note: we can pad calldata to 32 byte multiple, but don't strictly have to
return
input
,
nil
return
input
,
nil
default
:
default
:
return
nil
,
fmt
.
Errorf
(
"unsupported pre-image type %d, cannot prepare preimage with key %x offset %d for oracle"
,
return
nil
,
fmt
.
Errorf
(
"unsupported pre-image type %d, cannot prepare preimage with key %x offset %d for oracle"
,
...
...
packages/contracts-bedrock/contracts/cannon/MIPS.sol
View file @
0ca3c050
...
@@ -431,7 +431,7 @@ contract MIPS {
...
@@ -431,7 +431,7 @@ contract MIPS {
// j-type j/jal
// j-type j/jal
if (opcode == 2 || opcode == 3) {
if (opcode == 2 || opcode == 3) {
// TODO likely bug in original code: MIPS spec says this should be in the "current" region;
// TODO
(CLI-4136):
likely bug in original code: MIPS spec says this should be in the "current" region;
// a 256 MB aligned region (i.e. use top 4 bits of branch delay slot (pc+4))
// a 256 MB aligned region (i.e. use top 4 bits of branch delay slot (pc+4))
return handleJump(opcode == 2 ? 0 : 31, SE(insn&0x03FFFFFF, 26) << 2);
return handleJump(opcode == 2 ? 0 : 31, SE(insn&0x03FFFFFF, 26) << 2);
}
}
...
@@ -532,11 +532,11 @@ contract MIPS {
...
@@ -532,11 +532,11 @@ contract MIPS {
function execute(uint32 insn, uint32 rs, uint32 rt, uint32 mem) internal pure returns (uint32) {
function execute(uint32 insn, uint32 rs, uint32 rt, uint32 mem) internal pure returns (uint32) {
uint32 opcode = insn >> 26; // 6-bits
uint32 opcode = insn >> 26; // 6-bits
uint32 func = insn & 0x3f; // 6-bits
uint32 func = insn & 0x3f; // 6-bits
// TODO: deref the immed into a register
// TODO
(CLI-4136)
: deref the immed into a register
if (opcode < 0x20) {
if (opcode < 0x20) {
// transform ArithLogI
// transform ArithLogI
// TODO: replace with table
// TODO
(CLI-4136)
: replace with table
if (opcode >= 8 && opcode < 0xF) {
if (opcode >= 8 && opcode < 0xF) {
if (opcode == 8) { func = 0x20; } // addi
if (opcode == 8) { func = 0x20; } // addi
else if (opcode == 9) { func = 0x21; } // addiu
else if (opcode == 9) { func = 0x21; } // addiu
...
...
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