Skip to content

Commit

Permalink
Merge branch 'master' into bold-review
Browse files Browse the repository at this point in the history
  • Loading branch information
amsanghi authored Sep 26, 2024
2 parents 7975a06 + 5cd7d69 commit 5334e63
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ clean:
rm -f arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/*.a
rm -f arbitrator/wasm-libraries/forward/*.wat
rm -rf arbitrator/stylus/tests/*/target/ arbitrator/stylus/tests/*/*.wasm
rm -rf brotli/buildfiles
@rm -rf contracts/build contracts/cache solgen/go/
@rm -f .make/*

Expand Down
7 changes: 4 additions & 3 deletions arbitrator/arbutil/src/evm/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,10 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApi<D> for EvmApiRequestor<D, H> {
let mut request = Vec::with_capacity(2 * 8 + 3 * 2 + name.len() + args.len() + outs.len());
request.extend(start_ink.to_be_bytes());
request.extend(end_ink.to_be_bytes());
request.extend((name.len() as u16).to_be_bytes());
request.extend((args.len() as u16).to_be_bytes());
request.extend((outs.len() as u16).to_be_bytes());
// u32 is enough to represent the slices lengths because the WASM environment runs in 32 bits.
request.extend((name.len() as u32).to_be_bytes());
request.extend((args.len() as u32).to_be_bytes());
request.extend((outs.len() as u32).to_be_bytes());
request.extend(name.as_bytes());
request.extend(args);
request.extend(outs);
Expand Down
24 changes: 24 additions & 0 deletions arbitrator/stylus/tests/write-result-len.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
;; Copyright 2024, Offchain Labs, Inc.
;; For license information, see https://github.com/nitro/blob/master/LICENSE

(module
(import "vm_hooks" "read_args" (func $read_args (param i32)))
(import "vm_hooks" "write_result" (func $write_result (param i32 i32)))
(memory (export "memory") 2 2)
(func $main (export "user_entrypoint") (param $args_len i32) (result i32)
(local $len i32)

;; write args to 0x0
(call $read_args (i32.const 0))

;; treat first 4 bytes as size to write
(i32.load (i32.const 0))
local.set $len

;; call write
(call $write_result (i32.const 0) (local.get $len))

;; return success
i32.const 0
)
)
6 changes: 3 additions & 3 deletions arbos/programs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ func newApiClosures(
}
startInk := takeU64()
endInk := takeU64()
nameLen := takeU16()
argsLen := takeU16()
outsLen := takeU16()
nameLen := takeU32()
argsLen := takeU32()
outsLen := takeU32()
name := string(takeFixed(int(nameLen)))
args := takeFixed(int(argsLen))
outs := takeFixed(int(outsLen))
Expand Down
9 changes: 5 additions & 4 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,14 +1010,15 @@ func initReorg(initConfig conf.InitConfig, chainConfig *params.ChainConfig, inbo
return nil
}
// Reorg out the batch containing the next message
var missing bool
var found bool
var err error
batchCount, missing, err = inboxTracker.FindInboxBatchContainingMessage(messageIndex + 1)
batchCount, found, err = inboxTracker.FindInboxBatchContainingMessage(messageIndex + 1)
if err != nil {
return err
}
if missing {
return fmt.Errorf("cannot reorg to unknown message index %v", messageIndex)
if !found {
log.Warn("init-reorg: no need to reorg, because message ahead of chain", "messageIndex", messageIndex)
return nil
}
}
return inboxTracker.ReorgBatchesTo(batchCount)
Expand Down
15 changes: 15 additions & 0 deletions system_tests/stylus_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package arbtest
import (
"bytes"
"encoding/binary"
"math"
"math/big"
"testing"

Expand Down Expand Up @@ -478,3 +479,17 @@ func TestStylusOpcodeTraceEquivalence(t *testing.T) {
checkOpcode(t, wasmResult, 12, vm.RETURN, offset, returnLen)
checkOpcode(t, evmResult, 5078, vm.RETURN, offset, returnLen)
}

func TestStylusHugeWriteResultTrace(t *testing.T) {
const jit = false
builder, auth, cleanup := setupProgramTest(t, jit)
ctx := builder.ctx
l2client := builder.L2.Client
defer cleanup()

program := deployWasm(t, ctx, auth, l2client, watFile("write-result-len"))
const returnLen = math.MaxUint16 + 1
args := binary.LittleEndian.AppendUint32(nil, returnLen)
result := sendAndTraceTransaction(t, builder, program, nil, args)
checkOpcode(t, result, 3, vm.RETURN, nil, intToBe32(returnLen))
}

0 comments on commit 5334e63

Please sign in to comment.