Commit 0ca3c050 authored by protolambda's avatar protolambda

cannon: semgrep fixes

parent 090eb3bc
......@@ -46,8 +46,8 @@ go build -o cannon .
--input ./state.json
--
../optimism/op-program/bin/op-program
--l2 ws://127.0.0.1:8746
--l1 ws://127.0.0.1:8646
--l2 http://127.0.0.1:8745
--l1 http://127.0.0.1:8645
--l1.trustrpc
--l1.rpckind debug_geth
--log.format terminal
......
......@@ -124,7 +124,7 @@ func NewProcessPreimageOracle(name string, args []string) (*ProcessPreimageOracl
return nil, err
}
cmd := exec.Command(name, args...)
cmd := exec.Command(name, args...) // nosemgrep
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.ExtraFiles = []*os.File{
......@@ -317,10 +317,11 @@ func Run(ctx *cli.Context) error {
StepInput: witness.EncodeStepInput(),
}
if witness.HasPreimage() {
proof.OracleInput, err = witness.EncodePreimageOracleInput()
inp, err := witness.EncodePreimageOracleInput()
if err != nil {
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 {
return fmt.Errorf("failed to write proof data: %w", err)
......
......@@ -236,7 +236,7 @@ type pageEntry struct {
Data *Page `json:"data"`
}
func (m *Memory) MarshalJSON() ([]byte, error) {
func (m *Memory) MarshalJSON() ([]byte, error) { // nosemgrep
pages := make([]pageEntry, 0, len(m.pages))
for k, p := range m.pages {
pages = append(pages, pageEntry{
......
......@@ -392,7 +392,7 @@ func execute(insn uint32, rs uint32, rt uint32, mem uint32) uint32 {
if opcode < 0x20 {
// transform ArithLogI
// TODO: replace with table
// TODO(CLI-4136): replace with table
if opcode >= 8 && opcode < 0xF {
switch opcode {
case 8:
......
......@@ -61,7 +61,7 @@ func (wit *StepWitness) EncodePreimageOracleInput() ([]byte, error) {
copy(tmp[:], wit.PreimageValue[wit.PreimageOffset:])
input = append(input, tmp[:]...)
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
case preimage.Keccak256KeyType:
var input []byte
......@@ -70,7 +70,7 @@ func (wit *StepWitness) EncodePreimageOracleInput() ([]byte, error) {
input = append(input, uint32ToBytes32(32+32)...) // partOffset, calldata offset
input = append(input, uint32ToBytes32(uint32(len(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
default:
return nil, fmt.Errorf("unsupported pre-image type %d, cannot prepare preimage with key %x offset %d for oracle",
......
......@@ -431,7 +431,7 @@ contract MIPS {
// j-type j/jal
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))
return handleJump(opcode == 2 ? 0 : 31, SE(insn&0x03FFFFFF, 26) << 2);
}
......@@ -532,11 +532,11 @@ contract MIPS {
function execute(uint32 insn, uint32 rs, uint32 rt, uint32 mem) internal pure returns (uint32) {
uint32 opcode = insn >> 26; // 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) {
// transform ArithLogI
// TODO: replace with table
// TODO(CLI-4136): replace with table
if (opcode >= 8 && opcode < 0xF) {
if (opcode == 8) { func = 0x20; } // addi
else if (opcode == 9) { func = 0x21; } // addiu
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment