From 0e7f612eb03bc03743b2e175eaadc8eea1678357 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Thu, 5 Sep 2024 03:04:02 -0400 Subject: [PATCH 001/131] chore: Fix typos in validator/server_jit/spawner.go --- validator/server_jit/spawner.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validator/server_jit/spawner.go b/validator/server_jit/spawner.go index d77317d218..0e16978fc0 100644 --- a/validator/server_jit/spawner.go +++ b/validator/server_jit/spawner.go @@ -30,7 +30,7 @@ type JitSpawnerConfigFecher func() *JitSpawnerConfig var DefaultJitSpawnerConfig = JitSpawnerConfig{ Workers: 0, Cranelift: true, - WasmMemoryUsageLimit: 4294967296, // 2^32 WASM memeory limit + WasmMemoryUsageLimit: 4294967296, // 2^32 WASM memory limit } func JitSpawnerConfigAddOptions(prefix string, f *flag.FlagSet) { @@ -82,7 +82,7 @@ func (v *JitSpawner) execute( ) (validator.GoGlobalState, error) { machine, err := v.machineLoader.GetMachine(ctx, moduleRoot) if err != nil { - return validator.GoGlobalState{}, fmt.Errorf("unabled to get WASM machine: %w", err) + return validator.GoGlobalState{}, fmt.Errorf("unable to get WASM machine: %w", err) } state, err := machine.prove(ctx, entry) From 1bb666593d668fd93f38ffa39f71712be06d36b6 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Tue, 15 Oct 2024 22:19:57 +0200 Subject: [PATCH 002/131] compile module only when activating or in targets list --- arbos/programs/native.go | 165 +++++++++++++++++++++--------- arbos/programs/programs.go | 4 +- arbos/programs/wasmstorehelper.go | 3 +- execution/gethexec/node.go | 3 - 4 files changed, 123 insertions(+), 52 deletions(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 725b302ac0..7fc3500e2e 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -70,7 +70,9 @@ func activateProgram( debug bool, burner burn.Burner, ) (*activationInfo, error) { - info, asmMap, err := activateProgramInternal(db, program, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, burner.GasLeft()) + targets := db.Database().WasmTargets() + moduleActivationMandatory := true + info, asmMap, err := activateProgramInternal(program, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, burner.GasLeft(), targets, moduleActivationMandatory) if err != nil { return nil, err } @@ -78,8 +80,7 @@ func activateProgram( return info, nil } -func activateProgramInternal( - db vm.StateDB, +func activateModule( addressForLogging common.Address, codehash common.Hash, wasm []byte, @@ -88,7 +89,7 @@ func activateProgramInternal( arbosVersionForGas uint64, debug bool, gasLeft *uint64, -) (*activationInfo, map[ethdb.WasmTarget][]byte, error) { +) (*activationInfo, []byte, error) { output := &rustBytes{} moduleHash := &bytes32{} stylusData := &C.StylusData{} @@ -106,7 +107,6 @@ func activateProgramInternal( stylusData, (*u64)(gasLeft), )) - module, msg, err := status_mod.toResult(output.intoBytes(), debug) if err != nil { if debug { @@ -114,72 +114,143 @@ func activateProgramInternal( } if errors.Is(err, vm.ErrExecutionReverted) { return nil, nil, fmt.Errorf("%w: %s", ErrProgramActivation, msg) + } else { + return nil, nil, err + } + } + info := &activationInfo{ + moduleHash: moduleHash.toHash(), + initGas: uint16(stylusData.init_cost), + cachedInitGas: uint16(stylusData.cached_init_cost), + asmEstimate: uint32(stylusData.asm_estimate), + footprint: uint16(stylusData.footprint), + } + return info, module, nil +} + +func compileNative( + wasm []byte, + stylusVersion uint16, + debug bool, + target ethdb.WasmTarget, +) ([]byte, error) { + output := &rustBytes{} + status_asm := C.stylus_compile( + goSlice(wasm), + u16(stylusVersion), + cbool(debug), + goSlice([]byte(target)), + output, + ) + asm := output.intoBytes() + if status_asm != 0 { + return nil, fmt.Errorf("%w: %s", ErrProgramActivation, string(asm)) + } + return asm, nil +} + +func activateProgramInternal( + addressForLogging common.Address, + codehash common.Hash, + wasm []byte, + page_limit uint16, + stylusVersion uint16, + arbosVersionForGas uint64, + debug bool, + gasLeft *uint64, + targets []ethdb.WasmTarget, + moduleActivationMandatory bool, +) (*activationInfo, map[ethdb.WasmTarget][]byte, error) { + var wavmFound bool + for _, target := range targets { + if target == rawdb.TargetWavm { + wavmFound = true + break } - return nil, nil, err } - hash := moduleHash.toHash() - targets := db.Database().WasmTargets() type result struct { target ethdb.WasmTarget asm []byte err error } + asmMap := make(map[ethdb.WasmTarget][]byte, len(targets)) + + // info can be set in separate thread, make sure to wait before reading + var info *activationInfo + var moduleActivationStarted bool + if moduleActivationMandatory { + moduleActivationStarted = true + var err error + var module []byte + info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) + if err != nil { + return nil, nil, err + } + if wavmFound { + asmMap[rawdb.TargetWavm] = module + } + } + results := make(chan result, len(targets)) for _, target := range targets { target := target if target == rawdb.TargetWavm { - results <- result{target, module, nil} + if moduleActivationStarted { + // skip if already started or activated because of moduleActivationMandatory + results <- result{target, nil, nil} + continue + } + go func() { + var err error + var module []byte + info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) + results <- result{target, module, err} + }() + moduleActivationStarted = true } else { go func() { - output := &rustBytes{} - status_asm := C.stylus_compile( - goSlice(wasm), - u16(stylusVersion), - cbool(debug), - goSlice([]byte(target)), - output, - ) - asm := output.intoBytes() - if status_asm != 0 { - results <- result{target, nil, fmt.Errorf("%w: %s", ErrProgramActivation, string(asm))} - return - } - results <- result{target, asm, nil} + asm, err := compileNative(wasm, stylusVersion, debug, target) + results <- result{target, asm, err} }() } } - asmMap := make(map[ethdb.WasmTarget][]byte, len(targets)) + var err error for range targets { res := <-results - if res.err != nil { - err = errors.Join(res.err, err) + if res.asm == nil { + continue + } else if res.err != nil { + err = errors.Join(res.err, fmt.Errorf("%s:%w", res.target, err)) } else { asmMap[res.target] = res.asm } } - if err != nil { - log.Error( - "Compilation failed for one or more targets despite activation succeeding", - "address", addressForLogging, - "codeHash", codeHash, - "moduleHash", hash, - "targets", targets, - "err", err, - ) + if err != nil && moduleActivationMandatory { + if info != nil { + log.Error( + "Compilation failed for one or more targets despite activation succeeding", + "address", addressForLogging, + "codehash", codehash, + "moduleHash", info.moduleHash, + "targets", targets, + "err", err, + ) + } else { + log.Error( + "Compilation failed for one or more targets despite activation succeeding", + "address", addressForLogging, + "codehash", codehash, + "targets", targets, + "err", err, + ) + } panic(fmt.Sprintf("Compilation of %v failed for one or more targets despite activation succeeding: %v", addressForLogging, err)) } - info := &activationInfo{ - moduleHash: hash, - initGas: uint16(stylusData.init_cost), - cachedInitGas: uint16(stylusData.cached_init_cost), - asmEstimate: uint32(stylusData.asm_estimate), - footprint: uint16(stylusData.footprint), - } return info, asmMap, err } -func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging common.Address, code []byte, codeHash common.Hash, pagelimit uint16, time uint64, debugMode bool, program Program) ([]byte, error) { +func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging common.Address, code []byte, codehash common.Hash, pagelimit uint16, time uint64, debugMode bool, program Program) ([]byte, error) { localTarget := rawdb.LocalTarget() localAsm, err := statedb.TryGetActivatedAsm(localTarget, moduleHash) if err == nil && len(localAsm) > 0 { @@ -197,8 +268,10 @@ func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging c zeroArbosVersion := uint64(0) zeroGas := uint64(0) + targets := statedb.Database().WasmTargets() // we know program is activated, so it must be in correct version and not use too much memory - info, asmMap, err := activateProgramInternal(statedb, addressForLogging, codeHash, wasm, pagelimit, program.version, zeroArbosVersion, debugMode, &zeroGas) + moduleActivationMandatory := false + info, asmMap, err := activateProgramInternal(addressForLogging, codehash, wasm, pagelimit, program.version, zeroArbosVersion, debugMode, &zeroGas, targets, moduleActivationMandatory) if err != nil { log.Error("failed to reactivate program", "address", addressForLogging, "expected moduleHash", moduleHash, "err", err) return nil, fmt.Errorf("failed to reactivate program address: %v err: %w", addressForLogging, err) @@ -300,10 +373,10 @@ func handleReqImpl(apiId usize, req_type u32, data *rustSlice, costPtr *u64, out // Caches a program in Rust. We write a record so that we can undo on revert. // For gas estimation and eth_call, we ignore permanent updates and rely on Rust's LRU. -func cacheProgram(db vm.StateDB, module common.Hash, program Program, addressForLogging common.Address, code []byte, codeHash common.Hash, params *StylusParams, debug bool, time uint64, runMode core.MessageRunMode) { +func cacheProgram(db vm.StateDB, module common.Hash, program Program, addressForLogging common.Address, code []byte, codehash common.Hash, params *StylusParams, debug bool, time uint64, runMode core.MessageRunMode) { if runMode == core.MessageCommitMode { // address is only used for logging - asm, err := getLocalAsm(db, module, addressForLogging, code, codeHash, params.PageLimit, time, debug, program) + asm, err := getLocalAsm(db, module, addressForLogging, code, codehash, params.PageLimit, time, debug, program) if err != nil { panic("unable to recreate wasm") } diff --git a/arbos/programs/programs.go b/arbos/programs/programs.go index 06ff4137da..5861181bff 100644 --- a/arbos/programs/programs.go +++ b/arbos/programs/programs.go @@ -170,7 +170,7 @@ func (p Programs) CallProgram( tracingInfo *util.TracingInfo, calldata []byte, reentrant bool, - runmode core.MessageRunMode, + runMode core.MessageRunMode, ) ([]byte, error) { evm := interpreter.Evm() contract := scope.Contract @@ -246,7 +246,7 @@ func (p Programs) CallProgram( address = *contract.CodeAddr } var arbos_tag uint32 - if runmode == core.MessageCommitMode { + if runMode == core.MessageCommitMode { arbos_tag = statedb.Database().WasmCacheTag() } ret, err := callProgram(address, moduleHash, localAsm, scope, interpreter, tracingInfo, calldata, evmData, goParams, model, arbos_tag) diff --git a/arbos/programs/wasmstorehelper.go b/arbos/programs/wasmstorehelper.go index c2d1aa65b0..1393752b72 100644 --- a/arbos/programs/wasmstorehelper.go +++ b/arbos/programs/wasmstorehelper.go @@ -62,7 +62,8 @@ func (p Programs) SaveActiveProgramToWasmStore(statedb *state.StateDB, codeHash // We know program is activated, so it must be in correct version and not use too much memory // Empty program address is supplied because we dont have access to this during rebuilding of wasm store - info, asmMap, err := activateProgramInternal(statedb, common.Address{}, codeHash, wasm, progParams.PageLimit, program.version, zeroArbosVersion, debugMode, &zeroGas) + moduleActivationMandatory := false + info, asmMap, err := activateProgramInternal(common.Address{}, codeHash, wasm, progParams.PageLimit, program.version, zeroArbosVersion, debugMode, &zeroGas, targets, moduleActivationMandatory) if err != nil { log.Error("failed to reactivate program while rebuilding wasm store", "expected moduleHash", moduleHash, "err", err) return fmt.Errorf("failed to reactivate program while rebuilding wasm store: %w", err) diff --git a/execution/gethexec/node.go b/execution/gethexec/node.go index 499a13164e..79c5c8896e 100644 --- a/execution/gethexec/node.go +++ b/execution/gethexec/node.go @@ -53,9 +53,6 @@ func (c *StylusTargetConfig) Validate() error { } targetsSet[target] = true } - if !targetsSet[rawdb.TargetWavm] { - return fmt.Errorf("%s target not found in archs list, archs: %v", rawdb.TargetWavm, c.ExtraArchs) - } targetsSet[rawdb.LocalTarget()] = true targets := make([]ethdb.WasmTarget, 0, len(c.ExtraArchs)+1) for target := range targetsSet { From 17bdb495fb1f2b068b61cc3ccb27105834379edc Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Wed, 16 Oct 2024 17:41:09 -0600 Subject: [PATCH 003/131] update wasmer pin tp merge 4.3.7 --- arbitrator/tools/wasmer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/tools/wasmer b/arbitrator/tools/wasmer index 6b15433d83..84aec79c13 160000 --- a/arbitrator/tools/wasmer +++ b/arbitrator/tools/wasmer @@ -1 +1 @@ -Subproject commit 6b15433d83f951555c24f0c56dc05e4751b0cc76 +Subproject commit 84aec79c13888bf3fb324ddbd69b3fecc22d4a8c From 0dca996a58e829253817c4284330d2708c3cec19 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Wed, 16 Oct 2024 17:42:25 -0600 Subject: [PATCH 004/131] update cargo.lock for new wasmer --- arbitrator/Cargo.lock | 61 +++++++++++++++++----------- arbitrator/wasm-libraries/Cargo.lock | 14 ++++++- 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/arbitrator/Cargo.lock b/arbitrator/Cargo.lock index 2b437968fa..9688d07229 100644 --- a/arbitrator/Cargo.lock +++ b/arbitrator/Cargo.lock @@ -747,11 +747,12 @@ dependencies = [ [[package]] name = "dashmap" -version = "5.5.3" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" dependencies = [ "cfg-if 1.0.0", + "crossbeam-utils", "hashbrown 0.14.5", "lock_api", "once_cell", @@ -974,8 +975,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -1312,15 +1315,6 @@ dependencies = [ "hashbrown 0.14.5", ] -[[package]] -name = "mach" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" -dependencies = [ - "libc", -] - [[package]] name = "mach2" version = "0.4.2" @@ -2558,7 +2552,7 @@ dependencies = [ [[package]] name = "wasmer" -version = "4.2.8" +version = "4.3.7" dependencies = [ "bytes", "cfg-if 1.0.0", @@ -2580,12 +2574,12 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wat", - "winapi", + "windows-sys 0.59.0", ] [[package]] name = "wasmer-compiler" -version = "4.2.8" +version = "4.3.7" dependencies = [ "backtrace", "bytes", @@ -2594,6 +2588,7 @@ dependencies = [ "enumset", "lazy_static", "leb128", + "libc", "memmap2 0.5.10", "more-asserts", "region", @@ -2605,12 +2600,13 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wasmparser", - "winapi", + "windows-sys 0.59.0", + "xxhash-rust", ] [[package]] name = "wasmer-compiler-cranelift" -version = "4.2.8" +version = "4.3.7" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -2627,7 +2623,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-llvm" -version = "4.2.8" +version = "4.3.7" dependencies = [ "byteorder", "cc", @@ -2649,7 +2645,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "4.2.8" +version = "4.3.7" dependencies = [ "byteorder", "dynasm", @@ -2666,7 +2662,7 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "4.2.8" +version = "4.3.7" dependencies = [ "proc-macro-error", "proc-macro2", @@ -2676,21 +2672,25 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.2.8" +version = "4.3.7" dependencies = [ "bytecheck", "enum-iterator 0.7.0", "enumset", + "getrandom", + "hex", "indexmap 1.9.3", "more-asserts", "rkyv", + "sha2 0.10.8", "target-lexicon", "thiserror", + "xxhash-rust", ] [[package]] name = "wasmer-vm" -version = "4.2.8" +version = "4.3.7" dependencies = [ "backtrace", "cc", @@ -2704,14 +2704,14 @@ dependencies = [ "indexmap 1.9.3", "lazy_static", "libc", - "mach", + "mach2", "memoffset", "more-asserts", "region", "scopeguard", "thiserror", "wasmer-types", - "winapi", + "windows-sys 0.59.0", ] [[package]] @@ -2830,6 +2830,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -2942,6 +2951,12 @@ dependencies = [ "tap", ] +[[package]] +name = "xxhash-rust" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" + [[package]] name = "zerocopy" version = "0.6.6" diff --git a/arbitrator/wasm-libraries/Cargo.lock b/arbitrator/wasm-libraries/Cargo.lock index a5a066e5c9..e62acf43a6 100644 --- a/arbitrator/wasm-libraries/Cargo.lock +++ b/arbitrator/wasm-libraries/Cargo.lock @@ -518,8 +518,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -1633,16 +1635,20 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.2.8" +version = "4.3.7" dependencies = [ "bytecheck", "enum-iterator 0.7.0", "enumset", + "getrandom", + "hex", "indexmap 1.9.3", "more-asserts", "rkyv", + "sha2 0.10.8", "target-lexicon", "thiserror", + "xxhash-rust", ] [[package]] @@ -1803,6 +1809,12 @@ dependencies = [ "tap", ] +[[package]] +name = "xxhash-rust" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" + [[package]] name = "zerocopy" version = "0.7.35" From 81155d85bee23c6a0783a7f24bff5bbca67c058a Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 23 Oct 2024 16:44:58 +0200 Subject: [PATCH 005/131] system_tests: fix checkWasmStoreContent helper --- system_tests/common_test.go | 4 +++- system_tests/program_test.go | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/system_tests/common_test.go b/system_tests/common_test.go index 027a41d875..21eaf89cd7 100644 --- a/system_tests/common_test.go +++ b/system_tests/common_test.go @@ -1322,6 +1322,7 @@ func createNonL1BlockChainWithStackConfig( if execConfig == nil { execConfig = ExecConfigDefaultTest(t) } + Require(t, execConfig.Validate()) stack, err := node.New(stackConfig) Require(t, err) @@ -1409,6 +1410,8 @@ func Create2ndNodeWithConfig( if execConfig == nil { execConfig = ExecConfigDefaultNonSequencerTest(t) } + Require(t, execConfig.Validate()) + feedErrChan := make(chan error, 10) parentChainRpcClient := parentChainStack.Attach() parentChainClient := ethclient.NewClient(parentChainRpcClient) @@ -1442,7 +1445,6 @@ func Create2ndNodeWithConfig( AddValNodeIfNeeded(t, ctx, nodeConfig, true, "", valnodeConfig.Wasm.RootPath) - Require(t, execConfig.Validate()) Require(t, nodeConfig.Validate()) configFetcher := func() *gethexec.Config { return execConfig } currentExec, err := gethexec.CreateExecutionNode(ctx, chainStack, chainDb, blockchain, parentChainClient, configFetcher) diff --git a/system_tests/program_test.go b/system_tests/program_test.go index 4c896d1791..156d9d3638 100644 --- a/system_tests/program_test.go +++ b/system_tests/program_test.go @@ -1991,6 +1991,7 @@ func readModuleHashes(t *testing.T, wasmDb ethdb.KeyValueStore) []common.Hash { } func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, targets []string, numModules int) { + t.Helper() modules := readModuleHashes(t, wasmDb) if len(modules) != numModules { t.Fatalf("Unexpected number of module hashes found in wasm store, want: %d, have: %d", numModules, len(modules)) @@ -2002,12 +2003,16 @@ func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, targets []s t.Fatalf("internal test error - unsupported target passed to checkWasmStoreContent: %v", target) } func() { + t.Helper() defer func() { if r := recover(); r != nil { t.Fatalf("Failed to read activated asm for target: %v, module: %v", target, module) } }() - _ = rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module) + asm := rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module) + if len(asm) == 0 { + t.Fatalf("Missing activated asm for target: %v, module: %v", target, module) + } }() } } From 8914c571031897357d203632cab0b0f558b65901 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 23 Oct 2024 19:32:40 +0200 Subject: [PATCH 006/131] run some tests with single wasm target --- system_tests/program_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/system_tests/program_test.go b/system_tests/program_test.go index 156d9d3638..342807cbe2 100644 --- a/system_tests/program_test.go +++ b/system_tests/program_test.go @@ -58,6 +58,12 @@ func TestProgramKeccak(t *testing.T) { builder.WithExtraArchs(allWasmTargets) }) }) + + t.Run("WithOnlyLocalTarget", func(t *testing.T) { + keccakTest(t, true, func(builder *NodeBuilder) { + builder.WithExtraArchs([]string{string(rawdb.LocalTarget())}) + }) + }) } func keccakTest(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) { @@ -163,6 +169,11 @@ func TestProgramActivateTwice(t *testing.T) { builder.WithExtraArchs(allWasmTargets) }) }) + t.Run("WithOnlyLocalTarget", func(t *testing.T) { + testActivateTwice(t, true, func(builder *NodeBuilder) { + builder.WithExtraArchs([]string{string(rawdb.LocalTarget())}) + }) + }) } func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) { From 1abc820181760f4b0ceddc4b16deaf27d6744756 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 23 Oct 2024 21:54:35 +0200 Subject: [PATCH 007/131] system_tests: check for unexpected extra asm in checkWasmStoreContent --- system_tests/program_test.go | 63 ++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/system_tests/program_test.go b/system_tests/program_test.go index 342807cbe2..65710a86a8 100644 --- a/system_tests/program_test.go +++ b/system_tests/program_test.go @@ -74,7 +74,7 @@ func keccakTest(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) { programAddress := deployWasm(t, ctx, auth, l2client, rustFile("keccak")) wasmDb := builder.L2.ExecNode.Backend.ArbInterface().BlockChain().StateCache().WasmStore() - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) wasm, _ := readWasmFile(t, rustFile("keccak")) otherAddressSameCode := deployContract(t, ctx, auth, l2client, wasm) @@ -87,7 +87,7 @@ func keccakTest(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) { Fatal(t, "activate should have failed with ProgramUpToDate", err) } }) - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) if programAddress == otherAddressSameCode { Fatal(t, "expected to deploy at two separate program addresses") @@ -205,7 +205,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder) multiAddr := deployWasm(t, ctx, auth, l2client, rustFile("multicall")) wasmDb := builder.L2.ExecNode.Backend.ArbInterface().BlockChain().StateCache().WasmStore() - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) preimage := []byte("it's time to du-du-du-du d-d-d-d-d-d-d de-duplicate") @@ -230,7 +230,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder) // Calling the contract pre-activation should fail. checkReverts() - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) // mechanisms for creating calldata activateProgram, _ := util.NewCallParser(pgen.ArbWasmABI, "activateProgram") @@ -253,7 +253,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder) // Ensure the revert also reverted keccak's activation checkReverts() - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) // Activate keccak program A, then call into B, which should succeed due to being the same codehash args = argsForMulticall(vm.CALL, types.ArbWasmAddress, oneEth, pack(activateProgram(keccakA))) @@ -261,7 +261,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder) tx = l2info.PrepareTxTo("Owner", &multiAddr, 1e9, oneEth, args) ensure(tx, l2client.SendTransaction(ctx, tx)) - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 2) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 2) validateBlocks(t, 7, jit, builder) } @@ -1917,7 +1917,7 @@ func TestWasmStoreRebuilding(t *testing.T) { storeMap, err := createMapFromDb(wasmDb) Require(t, err) - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) // close nodeB cleanupB() @@ -1974,7 +1974,7 @@ func TestWasmStoreRebuilding(t *testing.T) { } } - checkWasmStoreContent(t, wasmDbAfterRebuild, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDbAfterRebuild, builder.execConfig.StylusTarget.WasmTargets(), 1) cleanupB() } @@ -2001,30 +2001,43 @@ func readModuleHashes(t *testing.T, wasmDb ethdb.KeyValueStore) []common.Hash { return modules } -func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, targets []string, numModules int) { +func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, expectedTargets []ethdb.WasmTarget, numModules int) { t.Helper() modules := readModuleHashes(t, wasmDb) if len(modules) != numModules { t.Fatalf("Unexpected number of module hashes found in wasm store, want: %d, have: %d", numModules, len(modules)) } - for _, module := range modules { - for _, target := range targets { - wasmTarget := ethdb.WasmTarget(target) - if !rawdb.IsSupportedWasmTarget(wasmTarget) { - t.Fatalf("internal test error - unsupported target passed to checkWasmStoreContent: %v", target) - } - func() { - t.Helper() - defer func() { - if r := recover(); r != nil { - t.Fatalf("Failed to read activated asm for target: %v, module: %v", target, module) - } - }() - asm := rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module) - if len(asm) == 0 { - t.Fatalf("Missing activated asm for target: %v, module: %v", target, module) + readAsm := func(module common.Hash, target string) []byte { + wasmTarget := ethdb.WasmTarget(target) + if !rawdb.IsSupportedWasmTarget(wasmTarget) { + t.Fatalf("internal test error - unsupported target passed to checkWasmStoreContent: %v", target) + } + return func() []byte { + t.Helper() + defer func() { + if r := recover(); r != nil { + t.Fatalf("Failed to read activated asm for target: %v, module: %v", target, module) } }() + return rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module) + }() + } + for _, module := range modules { + for _, target := range allWasmTargets { + var expected bool + for _, expectedTarget := range expectedTargets { + if ethdb.WasmTarget(target) == expectedTarget { + expected = true + break + } + } + asm := readAsm(module, target) + if expected && len(asm) == 0 { + t.Fatalf("Missing asm for target: %v, module: %v", target, module) + } + if !expected && len(asm) > 0 { + t.Fatalf("Found asm for target: %v, module: %v, expected targets: %v", target, module, expectedTargets) + } } } } From 233c3248c94d6cc2707a021c8068a8267f13d594 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 13 Nov 2024 18:09:58 +0100 Subject: [PATCH 008/131] always recompile module when recompiling native targets to validate module hash --- arbos/programs/native.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 7fc3500e2e..8144cafb75 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -270,7 +270,7 @@ func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging c targets := statedb.Database().WasmTargets() // we know program is activated, so it must be in correct version and not use too much memory - moduleActivationMandatory := false + moduleActivationMandatory := true // TODO: refactor the parameter, always set to true info, asmMap, err := activateProgramInternal(addressForLogging, codehash, wasm, pagelimit, program.version, zeroArbosVersion, debugMode, &zeroGas, targets, moduleActivationMandatory) if err != nil { log.Error("failed to reactivate program", "address", addressForLogging, "expected moduleHash", moduleHash, "err", err) From 06c9affc5e53896b7ab1a7b77bc5cf47f490f1a6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 11:32:39 +0000 Subject: [PATCH 009/131] Bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1 Bumps [github.com/golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt) from 4.5.0 to 4.5.1. - [Release notes](https://github.com/golang-jwt/jwt/releases) - [Changelog](https://github.com/golang-jwt/jwt/blob/main/VERSION_HISTORY.md) - [Commits](https://github.com/golang-jwt/jwt/compare/v4.5.0...v4.5.1) --- updated-dependencies: - dependency-name: github.com/golang-jwt/jwt/v4 dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 34b04121f0..dc66862333 100644 --- a/go.mod +++ b/go.mod @@ -129,7 +129,7 @@ require ( github.com/gobwas/pool v0.2.1 // indirect github.com/gofrs/flock v0.8.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/golang-jwt/jwt/v4 v4.5.1 // indirect github.com/golang/glog v1.2.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect diff --git a/go.sum b/go.sum index bbb38af6ac..fe0cef8edb 100644 --- a/go.sum +++ b/go.sum @@ -277,8 +277,8 @@ github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14j github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= +github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= From e6571ca397c43642dda0dc6da31140c16a3a5013 Mon Sep 17 00:00:00 2001 From: Antonio Nunez Date: Fri, 15 Nov 2024 17:55:28 +0800 Subject: [PATCH 010/131] feat: update google-cloud-storage parameters and object retention setting --- das/google_cloud_storage_service.go | 173 +++++++++------------------- 1 file changed, 57 insertions(+), 116 deletions(-) diff --git a/das/google_cloud_storage_service.go b/das/google_cloud_storage_service.go index 829f4b5265..adf039347c 100644 --- a/das/google_cloud_storage_service.go +++ b/das/google_cloud_storage_service.go @@ -21,151 +21,88 @@ import ( "github.com/offchainlabs/nitro/util/pretty" ) -type GoogleCloudStorageOperator interface { - Bucket(name string) *googlestorage.BucketHandle - Upload(ctx context.Context, bucket, objectPrefix string, value []byte) error - Download(ctx context.Context, bucket, objectPrefix string, key common.Hash) ([]byte, error) - Close(ctx context.Context) error -} - -type GoogleCloudStorageClient struct { - client *googlestorage.Client -} - -func (g *GoogleCloudStorageClient) Bucket(name string) *googlestorage.BucketHandle { - return g.client.Bucket(name) -} - -func (g *GoogleCloudStorageClient) Upload(ctx context.Context, bucket, objectPrefix string, value []byte) error { - obj := g.client.Bucket(bucket).Object(objectPrefix + EncodeStorageServiceKey(dastree.Hash(value))) - w := obj.NewWriter(ctx) - - if _, err := fmt.Fprintln(w, value); err != nil { - return err - } - return w.Close() - -} - -func (g *GoogleCloudStorageClient) Download(ctx context.Context, bucket, objectPrefix string, key common.Hash) ([]byte, error) { - obj := g.client.Bucket(bucket).Object(objectPrefix + EncodeStorageServiceKey(key)) - reader, err := obj.NewReader(ctx) - if err != nil { - return nil, err - } - return io.ReadAll(reader) -} - -func (g *GoogleCloudStorageClient) Close(ctx context.Context) error { - return g.client.Close() -} - type GoogleCloudStorageServiceConfig struct { - Enable bool `koanf:"enable"` - AccessToken string `koanf:"access-token"` - Bucket string `koanf:"bucket"` - ObjectPrefix string `koanf:"object-prefix"` - EnableExpiry bool `koanf:"enable-expiry"` - MaxRetention time.Duration `koanf:"max-retention"` + Enable bool `koanf:"enable"` + AccessTokenFile string `koanf:"access-token-file"` + Bucket string `koanf:"bucket"` + ObjectPrefix string `koanf:"object-prefix"` + DiscardAfterTimeout bool `koanf:"discard-after-timeout"` } var DefaultGoogleCloudStorageServiceConfig = GoogleCloudStorageServiceConfig{} func GoogleCloudConfigAddOptions(prefix string, f *flag.FlagSet) { f.Bool(prefix+".enable", DefaultGoogleCloudStorageServiceConfig.Enable, "EXPERIMENTAL/unsupported - enable storage/retrieval of sequencer batch data from an Google Cloud Storage bucket") - f.String(prefix+".access-token", DefaultGoogleCloudStorageServiceConfig.AccessToken, "Google Cloud Storage access token") + f.String(prefix+".access-token-file", DefaultGoogleCloudStorageServiceConfig.AccessTokenFile, "Google Cloud Storage access token") f.String(prefix+".bucket", DefaultGoogleCloudStorageServiceConfig.Bucket, "Google Cloud Storage bucket") f.String(prefix+".object-prefix", DefaultGoogleCloudStorageServiceConfig.ObjectPrefix, "prefix to add to Google Cloud Storage objects") - f.Bool(prefix+".enable-expiry", DefaultLocalFileStorageConfig.EnableExpiry, "enable expiry of batches") - f.Duration(prefix+".max-retention", DefaultLocalFileStorageConfig.MaxRetention, "store requests with expiry times farther in the future than max-retention will be rejected") + f.Bool(prefix+".discard-after-timeout", DefaultGoogleCloudStorageServiceConfig.DiscardAfterTimeout, "discard data after its expiry timeout") } type GoogleCloudStorageService struct { - operator GoogleCloudStorageOperator - bucket string - objectPrefix string - enableExpiry bool - maxRetention time.Duration + client *googlestorage.Client + bucket string + objectPrefix string + discardAfterTimeout bool } func NewGoogleCloudStorageService(config GoogleCloudStorageServiceConfig) (StorageService, error) { - var client *googlestorage.Client - var err error - // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) - // https://cloud.google.com/docs/authentication/provide-credentials-adc. - if config.AccessToken == "" { - client, err = googlestorage.NewClient(context.Background()) - } else { - client, err = googlestorage.NewClient(context.Background(), option.WithCredentialsJSON([]byte(config.AccessToken))) - } + client, err := buildGoogleCloudStorageClient(config.AccessTokenFile) if err != nil { return nil, fmt.Errorf("error creating Google Cloud Storage client: %w", err) } - service := &GoogleCloudStorageService{ - operator: &GoogleCloudStorageClient{client: client}, - bucket: config.Bucket, - objectPrefix: config.ObjectPrefix, - enableExpiry: config.EnableExpiry, - maxRetention: config.MaxRetention, - } - if config.EnableExpiry { - lifecycleRule := googlestorage.LifecycleRule{ - Action: googlestorage.LifecycleAction{Type: "Delete"}, - Condition: googlestorage.LifecycleCondition{AgeInDays: int64(config.MaxRetention.Hours() / 24)}, // Objects older than 30 days - } - ctx := context.Background() - bucket := service.operator.Bucket(service.bucket) - // check if bucket exists (and others), and update expiration policy if enabled - attrs, err := bucket.Attrs(ctx) - if err != nil { - return nil, fmt.Errorf("error getting bucket attributes: %w", err) - } - attrs.Lifecycle.Rules = append(attrs.Lifecycle.Rules, lifecycleRule) - - bucketAttrsToUpdate := googlestorage.BucketAttrsToUpdate{ - Lifecycle: &attrs.Lifecycle, - } - if _, err := bucket.Update(ctx, bucketAttrsToUpdate); err != nil { - return nil, fmt.Errorf("failed to update bucket lifecycle: %w", err) - } - } - return service, nil + return &GoogleCloudStorageService{ + client: client, + bucket: config.Bucket, + objectPrefix: config.ObjectPrefix, + discardAfterTimeout: config.DiscardAfterTimeout, + }, nil } -func (gcs *GoogleCloudStorageService) Put(ctx context.Context, data []byte, expiry uint64) error { - logPut("das.GoogleCloudStorageService.Store", data, expiry, gcs) - if expiry > math.MaxInt64 { - return fmt.Errorf("request expiry time (%v) exceeds max int64", expiry) - } - // #nosec G115 - expiryTime := time.Unix(int64(expiry), 0) - currentTimePlusRetention := time.Now().Add(gcs.maxRetention) - if expiryTime.After(currentTimePlusRetention) { - return fmt.Errorf("requested expiry time (%v) exceeds current time plus maximum allowed retention period(%v)", expiryTime, currentTimePlusRetention) - } - if err := gcs.operator.Upload(ctx, gcs.bucket, gcs.objectPrefix, data); err != nil { - log.Error("das.GoogleCloudStorageService.Store", "err", err) - return err +func buildGoogleCloudStorageClient(accessTokenFile string) (*googlestorage.Client, error) { + // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) + // https://cloud.google.com/docs/authentication/provide-credentials-adc. + if accessTokenFile == "" { + return googlestorage.NewClient(context.Background()) } - return nil + return googlestorage.NewClient(context.Background(), option.WithCredentialsFile(accessTokenFile)) } func (gcs *GoogleCloudStorageService) GetByHash(ctx context.Context, key common.Hash) ([]byte, error) { log.Trace("das.GoogleCloudStorageService.GetByHash", "key", pretty.PrettyHash(key), "this", gcs) - buf, err := gcs.operator.Download(ctx, gcs.bucket, gcs.objectPrefix, key) + obj := gcs.client.Bucket(gcs.bucket).Object(gcs.objectPrefix + EncodeStorageServiceKey(key)) + reader, err := obj.NewReader(ctx) if err != nil { log.Error("das.GoogleCloudStorageService.GetByHash", "err", err) return nil, err } + buf, err := io.ReadAll(reader) + if err != nil { + log.Error("das.GoogleCloudStorageService.GetByHash", "err", err) + } return buf, nil } -func (gcs *GoogleCloudStorageService) ExpirationPolicy(ctx context.Context) (daprovider.ExpirationPolicy, error) { - if gcs.enableExpiry { - return daprovider.KeepForever, nil +func (gcs *GoogleCloudStorageService) Put(ctx context.Context, value []byte, timeout uint64) error { + logPut("das.GoogleCloudStorageService.Store", value, timeout, gcs) + obj := gcs.client.Bucket(gcs.bucket).Object(gcs.objectPrefix + EncodeStorageServiceKey(dastree.Hash(value))) + w := obj.NewWriter(ctx) + if gcs.discardAfterTimeout && timeout <= math.MaxInt64 { + w.Retention = &googlestorage.ObjectRetention{ + Mode: "Unlocked", + RetainUntil: time.Unix(int64(timeout), 0), + } + } + if _, err := fmt.Fprintln(w, value); err != nil { + log.Error("das.GoogleCloudStorageService.Store", "err", err) + return err + } + err := w.Close() + if err != nil { + log.Error("das.GoogleCloudStorageService.Store", "err", err) } - return daprovider.DiscardAfterDataTimeout, nil + return err } func (gcs *GoogleCloudStorageService) Sync(ctx context.Context) error { @@ -173,7 +110,14 @@ func (gcs *GoogleCloudStorageService) Sync(ctx context.Context) error { } func (gcs *GoogleCloudStorageService) Close(ctx context.Context) error { - return gcs.operator.Close(ctx) + return gcs.client.Close() +} + +func (gcs *GoogleCloudStorageService) ExpirationPolicy(ctx context.Context) (daprovider.ExpirationPolicy, error) { + if gcs.discardAfterTimeout { + return daprovider.DiscardAfterDataTimeout, nil + } + return daprovider.KeepForever, nil } func (gcs *GoogleCloudStorageService) String() string { @@ -181,11 +125,9 @@ func (gcs *GoogleCloudStorageService) String() string { } func (gcs *GoogleCloudStorageService) HealthCheck(ctx context.Context) error { - bucket := gcs.operator.Bucket(gcs.bucket) + bucket := gcs.client.Bucket(gcs.bucket) // check if we have bucket permissions permissions := []string{ - "storage.buckets.get", - "storage.buckets.list", "storage.objects.create", "storage.objects.delete", "storage.objects.list", @@ -200,6 +142,5 @@ func (gcs *GoogleCloudStorageService) HealthCheck(ctx context.Context) error { if !cmp.Equal(perms, permissions) { return fmt.Errorf("permissions mismatch (-want +got):\n%s", cmp.Diff(permissions, perms)) } - return nil } From 12a4a053e2bf135872a29e173645b33ec2874874 Mon Sep 17 00:00:00 2001 From: Antonio Nunez Date: Tue, 19 Nov 2024 22:19:00 +0800 Subject: [PATCH 011/131] updated --- das/google_cloud_storage_service.go | 119 ++++++++++++++--------- das/google_cloud_storage_service_test.go | 5 +- 2 files changed, 76 insertions(+), 48 deletions(-) diff --git a/das/google_cloud_storage_service.go b/das/google_cloud_storage_service.go index adf039347c..85fa796420 100644 --- a/das/google_cloud_storage_service.go +++ b/das/google_cloud_storage_service.go @@ -21,6 +21,51 @@ import ( "github.com/offchainlabs/nitro/util/pretty" ) +type GoogleCloudStorageOperator interface { + Bucket(name string) *googlestorage.BucketHandle + Upload(ctx context.Context, bucket, objectPrefix string, value []byte, discardAfterTimeout bool, timeout uint64) error + Download(ctx context.Context, bucket, objectPrefix string, key common.Hash) ([]byte, error) + Close(ctx context.Context) error +} + +type GoogleCloudStorageClient struct { + client *googlestorage.Client +} + +func (g *GoogleCloudStorageClient) Bucket(name string) *googlestorage.BucketHandle { + return g.client.Bucket(name) +} + +func (g *GoogleCloudStorageClient) Upload(ctx context.Context, bucket, objectPrefix string, value []byte, discardAfterTimeout bool, timeout uint64) error { + obj := g.client.Bucket(bucket).Object(objectPrefix + EncodeStorageServiceKey(dastree.Hash(value))) + w := obj.NewWriter(ctx) + + if discardAfterTimeout && timeout <= math.MaxInt64 { + w.Retention = &googlestorage.ObjectRetention{ + Mode: "Unlocked", + RetainUntil: time.Unix(int64(timeout), 0), + } + } + + if _, err := fmt.Fprintln(w, value); err != nil { + return err + } + return w.Close() +} + +func (g *GoogleCloudStorageClient) Download(ctx context.Context, bucket, objectPrefix string, key common.Hash) ([]byte, error) { + obj := g.client.Bucket(bucket).Object(objectPrefix + EncodeStorageServiceKey(key)) + reader, err := obj.NewReader(ctx) + if err != nil { + return nil, err + } + return io.ReadAll(reader) +} + +func (g *GoogleCloudStorageClient) Close(ctx context.Context) error { + return g.client.Close() +} + type GoogleCloudStorageServiceConfig struct { Enable bool `koanf:"enable"` AccessTokenFile string `koanf:"access-token-file"` @@ -37,72 +82,62 @@ func GoogleCloudConfigAddOptions(prefix string, f *flag.FlagSet) { f.String(prefix+".bucket", DefaultGoogleCloudStorageServiceConfig.Bucket, "Google Cloud Storage bucket") f.String(prefix+".object-prefix", DefaultGoogleCloudStorageServiceConfig.ObjectPrefix, "prefix to add to Google Cloud Storage objects") f.Bool(prefix+".discard-after-timeout", DefaultGoogleCloudStorageServiceConfig.DiscardAfterTimeout, "discard data after its expiry timeout") - } type GoogleCloudStorageService struct { - client *googlestorage.Client + operator GoogleCloudStorageOperator bucket string objectPrefix string discardAfterTimeout bool } func NewGoogleCloudStorageService(config GoogleCloudStorageServiceConfig) (StorageService, error) { - client, err := buildGoogleCloudStorageClient(config.AccessTokenFile) + var client *googlestorage.Client + var err error + // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) + // https://cloud.google.com/docs/authentication/provide-credentials-adc. + if config.AccessTokenFile == "" { + client, err = googlestorage.NewClient(context.Background()) + } else { + client, err = googlestorage.NewClient(context.Background(), option.WithCredentialsFile(config.AccessTokenFile)) + } if err != nil { return nil, fmt.Errorf("error creating Google Cloud Storage client: %w", err) } - return &GoogleCloudStorageService{ - client: client, + service := &GoogleCloudStorageService{ + operator: &GoogleCloudStorageClient{client: client}, bucket: config.Bucket, objectPrefix: config.ObjectPrefix, discardAfterTimeout: config.DiscardAfterTimeout, - }, nil + } + return service, nil } -func buildGoogleCloudStorageClient(accessTokenFile string) (*googlestorage.Client, error) { - // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) - // https://cloud.google.com/docs/authentication/provide-credentials-adc. - if accessTokenFile == "" { - return googlestorage.NewClient(context.Background()) +func (gcs *GoogleCloudStorageService) Put(ctx context.Context, value []byte, timeout uint64) error { + logPut("das.GoogleCloudStorageService.Store", value, timeout, gcs) + + if err := gcs.operator.Upload(ctx, gcs.bucket, gcs.objectPrefix, value, gcs.discardAfterTimeout, timeout); err != nil { + log.Error("das.GoogleCloudStorageService.Store", "err", err) + return err } - return googlestorage.NewClient(context.Background(), option.WithCredentialsFile(accessTokenFile)) + return nil } func (gcs *GoogleCloudStorageService) GetByHash(ctx context.Context, key common.Hash) ([]byte, error) { log.Trace("das.GoogleCloudStorageService.GetByHash", "key", pretty.PrettyHash(key), "this", gcs) - obj := gcs.client.Bucket(gcs.bucket).Object(gcs.objectPrefix + EncodeStorageServiceKey(key)) - reader, err := obj.NewReader(ctx) + buf, err := gcs.operator.Download(ctx, gcs.bucket, gcs.objectPrefix, key) if err != nil { log.Error("das.GoogleCloudStorageService.GetByHash", "err", err) return nil, err } - buf, err := io.ReadAll(reader) - if err != nil { - log.Error("das.GoogleCloudStorageService.GetByHash", "err", err) - } return buf, nil } -func (gcs *GoogleCloudStorageService) Put(ctx context.Context, value []byte, timeout uint64) error { - logPut("das.GoogleCloudStorageService.Store", value, timeout, gcs) - obj := gcs.client.Bucket(gcs.bucket).Object(gcs.objectPrefix + EncodeStorageServiceKey(dastree.Hash(value))) - w := obj.NewWriter(ctx) - if gcs.discardAfterTimeout && timeout <= math.MaxInt64 { - w.Retention = &googlestorage.ObjectRetention{ - Mode: "Unlocked", - RetainUntil: time.Unix(int64(timeout), 0), - } - } - if _, err := fmt.Fprintln(w, value); err != nil { - log.Error("das.GoogleCloudStorageService.Store", "err", err) - return err - } - err := w.Close() - if err != nil { - log.Error("das.GoogleCloudStorageService.Store", "err", err) +func (gcs *GoogleCloudStorageService) ExpirationPolicy(ctx context.Context) (daprovider.ExpirationPolicy, error) { + if gcs.discardAfterTimeout { + return daprovider.DiscardAfterDataTimeout, nil } - return err + return daprovider.KeepForever, nil } func (gcs *GoogleCloudStorageService) Sync(ctx context.Context) error { @@ -110,14 +145,7 @@ func (gcs *GoogleCloudStorageService) Sync(ctx context.Context) error { } func (gcs *GoogleCloudStorageService) Close(ctx context.Context) error { - return gcs.client.Close() -} - -func (gcs *GoogleCloudStorageService) ExpirationPolicy(ctx context.Context) (daprovider.ExpirationPolicy, error) { - if gcs.discardAfterTimeout { - return daprovider.DiscardAfterDataTimeout, nil - } - return daprovider.KeepForever, nil + return gcs.operator.Close(ctx) } func (gcs *GoogleCloudStorageService) String() string { @@ -125,7 +153,7 @@ func (gcs *GoogleCloudStorageService) String() string { } func (gcs *GoogleCloudStorageService) HealthCheck(ctx context.Context) error { - bucket := gcs.client.Bucket(gcs.bucket) + bucket := gcs.operator.Bucket(gcs.bucket) // check if we have bucket permissions permissions := []string{ "storage.objects.create", @@ -142,5 +170,6 @@ func (gcs *GoogleCloudStorageService) HealthCheck(ctx context.Context) error { if !cmp.Equal(perms, permissions) { return fmt.Errorf("permissions mismatch (-want +got):\n%s", cmp.Diff(permissions, perms)) } + return nil } diff --git a/das/google_cloud_storage_service_test.go b/das/google_cloud_storage_service_test.go index 94d6f3ee44..545437708b 100644 --- a/das/google_cloud_storage_service_test.go +++ b/das/google_cloud_storage_service_test.go @@ -34,7 +34,7 @@ func (c *mockGCSClient) Close(ctx context.Context) error { return nil } -func (c *mockGCSClient) Upload(ctx context.Context, bucket, objectPrefix string, value []byte) error { +func (c *mockGCSClient) Upload(ctx context.Context, bucket, objectPrefix string, value []byte, discardAfterTimeout bool, timeout uint64) error { key := objectPrefix + EncodeStorageServiceKey(dastree.Hash(value)) c.storage[key] = value return nil @@ -47,7 +47,7 @@ func NewTestGoogleCloudStorageService(ctx context.Context, googleCloudStorageCon operator: &mockGCSClient{ storage: make(map[string][]byte), }, - maxRetention: googleCloudStorageConfig.MaxRetention, + discardAfterTimeout: true, }, nil } @@ -57,7 +57,6 @@ func TestNewGoogleCloudStorageService(t *testing.T) { expiry := uint64(time.Now().Add(time.Hour).Unix()) googleCloudStorageServiceConfig := DefaultGoogleCloudStorageServiceConfig googleCloudStorageServiceConfig.Enable = true - googleCloudStorageServiceConfig.MaxRetention = time.Hour * 24 googleCloudService, err := NewTestGoogleCloudStorageService(ctx, googleCloudStorageServiceConfig) Require(t, err) From 32b398105c9b200790ed3a06bcf9cdff7035455d Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Tue, 19 Nov 2024 17:10:40 +0100 Subject: [PATCH 012/131] add retryable expiry system tests --- system_tests/retryable_test.go | 185 ++++++++++++++++++++++++++++++++- 1 file changed, 183 insertions(+), 2 deletions(-) diff --git a/system_tests/retryable_test.go b/system_tests/retryable_test.go index af5f8bf57c..bf47b9a643 100644 --- a/system_tests/retryable_test.go +++ b/system_tests/retryable_test.go @@ -16,10 +16,12 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/gasestimator" "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/rpc" "github.com/offchainlabs/nitro/arbnode" "github.com/offchainlabs/nitro/arbos" "github.com/offchainlabs/nitro/arbos/arbostypes" + "github.com/offchainlabs/nitro/arbos/l1pricing" "github.com/offchainlabs/nitro/arbos/l2pricing" "github.com/offchainlabs/nitro/arbos/retryables" "github.com/offchainlabs/nitro/arbos/util" @@ -445,6 +447,186 @@ func TestGetLifetime(t *testing.T) { } } +func warpL1Time(t *testing.T, builder *NodeBuilder, ctx context.Context, currentL1time, advanceTime uint64) uint64 { + t.Log("Warping L1 time...") + l1LatestHeader, err := builder.L1.Client.HeaderByNumber(ctx, big.NewInt(int64(rpc.LatestBlockNumber))) + Require(t, err) + if currentL1time == 0 { + currentL1time = l1LatestHeader.Time + } + newL1Timestamp := currentL1time + advanceTime + timeWarpHeader := &arbostypes.L1IncomingMessageHeader{ + Kind: arbostypes.L1MessageType_L2Message, + Poster: l1pricing.BatchPosterAddress, + BlockNumber: l1LatestHeader.Number.Uint64(), + Timestamp: newL1Timestamp, + RequestId: nil, + L1BaseFee: nil, + } + hooks := arbos.NoopSequencingHooks() + tx := builder.L2Info.PrepareTx("Faucet", "User2", 300000, big.NewInt(1), nil) + _, err = builder.L2.ExecNode.ExecEngine.SequenceTransactions(timeWarpHeader, types.Transactions{tx}, hooks) + Require(t, err) + return newL1Timestamp +} + +func TestRetryableExpiry(t *testing.T) { + t.Parallel() + builder, delayedInbox, lookupL2Tx, ctx, teardown := retryableSetup(t) + defer teardown() + + ownerTxOpts := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + usertxopts := builder.L1Info.GetDefaultTransactOpts("Faucet", ctx) + usertxopts.Value = arbmath.BigMul(big.NewInt(1e12), big.NewInt(1e12)) + + simpleAddr, _ := builder.L2.DeploySimple(t, ownerTxOpts) + simpleABI, err := mocksgen.SimpleMetaData.GetAbi() + Require(t, err) + + beneficiaryAddress := builder.L2Info.GetAddress("Beneficiary") + l1tx, err := delayedInbox.CreateRetryableTicket( + &usertxopts, + simpleAddr, + common.Big0, + big.NewInt(1e16), + beneficiaryAddress, + beneficiaryAddress, + // send enough L2 gas for intrinsic but not compute + big.NewInt(int64(params.TxGas+params.TxDataNonZeroGasEIP2028*4)), + big.NewInt(l2pricing.InitialBaseFeeWei*2), + simpleABI.Methods["incrementRedeem"].ID, + ) + Require(t, err) + + l1Receipt, err := builder.L1.EnsureTxSucceeded(l1tx) + Require(t, err) + if l1Receipt.Status != types.ReceiptStatusSuccessful { + Fatal(t, "l1Receipt indicated failure") + } + + waitForL1DelayBlocks(t, builder) + + receipt, err := builder.L2.EnsureTxSucceeded(lookupL2Tx(l1Receipt)) + Require(t, err) + if len(receipt.Logs) != 2 { + Fatal(t, len(receipt.Logs)) + } + ticketId := receipt.Logs[0].Topics[1] + firstRetryTxId := receipt.Logs[1].Topics[2] + + // make sure it failed + receipt, err = WaitForTx(ctx, builder.L2.Client, firstRetryTxId, time.Second*5) + Require(t, err) + if receipt.Status != types.ReceiptStatusFailed { + Fatal(t, receipt.GasUsed) + } + + arbRetryableTx, err := precompilesgen.NewArbRetryableTx(common.HexToAddress("6e"), builder.L2.Client) + Require(t, err) + + // check that the ticket exists + _, err = arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) + Require(t, err) + + _ = warpL1Time(t, builder, ctx, 0, retryables.RetryableLifetimeSeconds) + + // check that the ticket no longer exists + _, err = arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) + if (err == nil) || (err.Error() != "execution reverted: error NoTicketWithID(): NoTicketWithID()") { + Fatal(t, "didn't get expected NoTicketWithID error") + } +} + +func TestKeepaliveAndRetryableExpiry(t *testing.T) { + t.Parallel() + builder, delayedInbox, lookupL2Tx, ctx, teardown := retryableSetup(t) + defer teardown() + + ownerTxOpts := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + usertxopts := builder.L1Info.GetDefaultTransactOpts("Faucet", ctx) + usertxopts.Value = arbmath.BigMul(big.NewInt(1e12), big.NewInt(1e12)) + + simpleAddr, _ := builder.L2.DeploySimple(t, ownerTxOpts) + simpleABI, err := mocksgen.SimpleMetaData.GetAbi() + Require(t, err) + + beneficiaryAddress := builder.L2Info.GetAddress("Beneficiary") + l1tx, err := delayedInbox.CreateRetryableTicket( + &usertxopts, + simpleAddr, + common.Big0, + big.NewInt(1e16), + beneficiaryAddress, + beneficiaryAddress, + // send enough L2 gas for intrinsic but not compute + big.NewInt(int64(params.TxGas+params.TxDataNonZeroGasEIP2028*4)), + big.NewInt(l2pricing.InitialBaseFeeWei*2), + simpleABI.Methods["incrementRedeem"].ID, + ) + Require(t, err) + + l1Receipt, err := builder.L1.EnsureTxSucceeded(l1tx) + Require(t, err) + if l1Receipt.Status != types.ReceiptStatusSuccessful { + Fatal(t, "l1Receipt indicated failure") + } + + waitForL1DelayBlocks(t, builder) + + receipt, err := builder.L2.EnsureTxSucceeded(lookupL2Tx(l1Receipt)) + Require(t, err) + if len(receipt.Logs) != 2 { + Fatal(t, len(receipt.Logs)) + } + ticketId := receipt.Logs[0].Topics[1] + firstRetryTxId := receipt.Logs[1].Topics[2] + + // make sure it failed + receipt, err = WaitForTx(ctx, builder.L2.Client, firstRetryTxId, time.Second*5) + Require(t, err) + if receipt.Status != types.ReceiptStatusFailed { + Fatal(t, receipt.GasUsed) + } + + arbRetryableTx, err := precompilesgen.NewArbRetryableTx(common.HexToAddress("6e"), builder.L2.Client) + Require(t, err) + + // checks that the ticket exists and gets current timeout + timeoutBeforeKeepalive, err := arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) + Require(t, err) + + // checks beneficiary + retrievedBeneficiaryAddress, err := arbRetryableTx.GetBeneficiary(&bind.CallOpts{}, ticketId) + Require(t, err) + if retrievedBeneficiaryAddress != beneficiaryAddress { + Fatal(t, "expected beneficiary to be", beneficiaryAddress, "but got", retrievedBeneficiaryAddress) + } + + // checks that keepalive increases the timeout as expected + _, err = arbRetryableTx.Keepalive(&ownerTxOpts, ticketId) + Require(t, err) + timeoutAfterKeepalive, err := arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) + Require(t, err) + expectedTimeoutAfterKeepAlive := arbmath.BigAdd(timeoutBeforeKeepalive, big.NewInt(retryables.RetryableLifetimeSeconds)) + if timeoutAfterKeepalive.Cmp(expectedTimeoutAfterKeepAlive) != 0 { + Fatal(t, "expected timeout after keepalive to be", expectedTimeoutAfterKeepAlive, "but got", timeoutAfterKeepalive) + } + + currentL1time := warpL1Time(t, builder, ctx, 0, retryables.RetryableLifetimeSeconds) + + // check that the ticket still exists + _, err = arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) + Require(t, err) + + _ = warpL1Time(t, builder, ctx, currentL1time, retryables.RetryableLifetimeSeconds) + + // check that the ticket no longer exists + _, err = arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) + if (err == nil) || (err.Error() != "execution reverted: error NoTicketWithID(): NoTicketWithID()") { + Fatal(t, "didn't get expected NoTicketWithID error") + } +} + func TestKeepaliveAndCancelRetryable(t *testing.T) { t.Parallel() builder, delayedInbox, lookupL2Tx, ctx, teardown := retryableSetup(t) @@ -515,8 +697,7 @@ func TestKeepaliveAndCancelRetryable(t *testing.T) { Require(t, err) timeoutAfterKeepalive, err := arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) Require(t, err) - expectedTimeoutAfterKeepAlive := timeoutBeforeKeepalive - expectedTimeoutAfterKeepAlive.Add(expectedTimeoutAfterKeepAlive, big.NewInt(retryables.RetryableLifetimeSeconds)) + expectedTimeoutAfterKeepAlive := arbmath.BigAdd(timeoutBeforeKeepalive, big.NewInt(retryables.RetryableLifetimeSeconds)) if timeoutAfterKeepalive.Cmp(expectedTimeoutAfterKeepAlive) != 0 { Fatal(t, "expected timeout after keepalive to be", expectedTimeoutAfterKeepAlive, "but got", timeoutAfterKeepalive) } From 26cfce8ff986633bd8ebd5394d7a3f789ca85472 Mon Sep 17 00:00:00 2001 From: Antonio Nunez Date: Wed, 20 Nov 2024 13:58:41 +0800 Subject: [PATCH 013/131] support both access-token and access-token-file parameters --- das/google_cloud_storage_service.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/das/google_cloud_storage_service.go b/das/google_cloud_storage_service.go index 85fa796420..71924a690c 100644 --- a/das/google_cloud_storage_service.go +++ b/das/google_cloud_storage_service.go @@ -68,6 +68,7 @@ func (g *GoogleCloudStorageClient) Close(ctx context.Context) error { type GoogleCloudStorageServiceConfig struct { Enable bool `koanf:"enable"` + AccessToken string `koanf:"access-token"` AccessTokenFile string `koanf:"access-token-file"` Bucket string `koanf:"bucket"` ObjectPrefix string `koanf:"object-prefix"` @@ -78,7 +79,8 @@ var DefaultGoogleCloudStorageServiceConfig = GoogleCloudStorageServiceConfig{} func GoogleCloudConfigAddOptions(prefix string, f *flag.FlagSet) { f.Bool(prefix+".enable", DefaultGoogleCloudStorageServiceConfig.Enable, "EXPERIMENTAL/unsupported - enable storage/retrieval of sequencer batch data from an Google Cloud Storage bucket") - f.String(prefix+".access-token-file", DefaultGoogleCloudStorageServiceConfig.AccessTokenFile, "Google Cloud Storage access token") + f.String(prefix+".access-token", DefaultGoogleCloudStorageServiceConfig.AccessToken, "Google Cloud Storage access token (JSON string)") + f.String(prefix+".access-token-file", DefaultGoogleCloudStorageServiceConfig.AccessTokenFile, "Google Cloud Storage access token (JSON file path)") f.String(prefix+".bucket", DefaultGoogleCloudStorageServiceConfig.Bucket, "Google Cloud Storage bucket") f.String(prefix+".object-prefix", DefaultGoogleCloudStorageServiceConfig.ObjectPrefix, "prefix to add to Google Cloud Storage objects") f.Bool(prefix+".discard-after-timeout", DefaultGoogleCloudStorageServiceConfig.DiscardAfterTimeout, "discard data after its expiry timeout") @@ -96,10 +98,12 @@ func NewGoogleCloudStorageService(config GoogleCloudStorageServiceConfig) (Stora var err error // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) // https://cloud.google.com/docs/authentication/provide-credentials-adc. - if config.AccessTokenFile == "" { - client, err = googlestorage.NewClient(context.Background()) - } else { + if config.AccessToken != "" { + client, err = googlestorage.NewClient(context.Background(), option.WithCredentialsJSON([]byte(config.AccessToken))) + } else if config.AccessTokenFile != "" { client, err = googlestorage.NewClient(context.Background(), option.WithCredentialsFile(config.AccessTokenFile)) + } else { + client, err = googlestorage.NewClient(context.Background()) } if err != nil { return nil, fmt.Errorf("error creating Google Cloud Storage client: %w", err) From a471aab128545224dfcad0431cf10614335f193c Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Fri, 29 Nov 2024 14:27:03 +0100 Subject: [PATCH 014/131] Create ADR-0001 Avoid primative constraint types This PR creates the ADR (Architectural Decision Record) structure in the docs in our repository and adds the first two ADRs. The first is sort of a meta-ADR in that it just captures our decision to actually use ADRs to record our architecturally-significant decisions for posterity and which format to use. --- ...markdown-architectural-decision-records.md | 29 ++++++ .../0001-avoid-primative-constraint-types.md | 96 +++++++++++++++++++ docs/decisions/README.md | 10 ++ docs/decisions/adr-template-bare-minimal.md | 16 ++++ docs/decisions/adr-template-bare.md | 44 +++++++++ docs/decisions/adr-template-minimal.md | 23 +++++ docs/decisions/adr-template.md | 74 ++++++++++++++ 7 files changed, 292 insertions(+) create mode 100644 docs/decisions/0000-use-markdown-architectural-decision-records.md create mode 100644 docs/decisions/0001-avoid-primative-constraint-types.md create mode 100644 docs/decisions/README.md create mode 100644 docs/decisions/adr-template-bare-minimal.md create mode 100644 docs/decisions/adr-template-bare.md create mode 100644 docs/decisions/adr-template-minimal.md create mode 100644 docs/decisions/adr-template.md diff --git a/docs/decisions/0000-use-markdown-architectural-decision-records.md b/docs/decisions/0000-use-markdown-architectural-decision-records.md new file mode 100644 index 0000000000..506f5fa28b --- /dev/null +++ b/docs/decisions/0000-use-markdown-architectural-decision-records.md @@ -0,0 +1,29 @@ +# Use Markdown Architectural Decision Records + +## Context and Problem Statement + +We want to record architectural decisions made in this project independent +whether decisions concern the architecture ("architectural decision record"), +the code, or other fields. + +Which format and structure should these records follow? + +## Considered Options + +* [MADR](https://adr.github.io/madr/) 4.0.0 – The Markdown Architectural Decision Records +* [Michael Nygard's template](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions) – The first incarnation of the term "ADR" +* [Sustainable Architectural Decisions](https://www.infoq.com/articles/sustainable-architectural-design-decisions) – The Y-Statements +* Other templates listed at +* Formless – No conventions for file format and structure + +## Decision Outcome + +Chosen option: "MADR 4.0.0", because + +* Implicit assumptions should be made explicit. + Design documentation is important to enable people understanding the decisions later on. + See also ["A rational design process: How and why to fake it"](https://doi.org/10.1109/TSE.1986.6312940). +* MADR allows for structured capturing of any decision. +* The MADR format is lean and fits our development style. +* The MADR structure is comprehensible and facilitates usage & maintenance. +* The MADR project is vivid. diff --git a/docs/decisions/0001-avoid-primative-constraint-types.md b/docs/decisions/0001-avoid-primative-constraint-types.md new file mode 100644 index 0000000000..b52cea8bdd --- /dev/null +++ b/docs/decisions/0001-avoid-primative-constraint-types.md @@ -0,0 +1,96 @@ +--- +status: accepted +date: 2024-11-29 +decision-makers: eljobe@ plasmapower@ +--- + +# Avoid primative constraint types + +## Context and Problem Statement + +When working on the go code for BoLD, we became slightly annoyed that several +places in the history package were checking the constraint that the `virtual` +argumet to a function was positive. One possible workaround would have been +to create a constrained wrapper type around `uint64` which would only allow +positive values. For example: + +```go +// Pos64 is a type which represents a positive uint64. +// +// The "zero" value of Pos64 is 1. +type Pos64 struct { + uint64 +} + +// NewPos64 returns a new Pos64 with the given value. +// +// errors if v is 0. +func NewPos64(v uint64) (Pos64, error) { + if v == 0 { + return Pos64{}, errors.New("v must be positive. got: 0") + } + return Pos64{v}, nil +} + +// MustPos64 returns a new Pos64 with the given value. +// +// panics if v is 0. +func MustPos64(v uint64) Pos64 { + if v == 0 { + panic("v must be positive. got: 0") + } + return Pos64{v} +} + +// Val returns the value of the Pos64. +func (p Pos64) Val() uint64 { + // The zero value of Pos64 is 1. + if p.uint64 == 0 { + return 1 + } + return p.uint64 +} +``` + +The idea being that within a package, all of the functions which needed to deal +with a `virtual` argument, could take in a `Pos64` instead of a `uint64` and it +would be up to clients of the package to ensure that they only passed in +positive values. + +## Considered Options + +* New Package: `util/chk` for checking type constraint +* Status Quo: check the constraint in multiple places +* Minimize Checks: no check in package private functions + +## Decision Outcome + +Chosen option: "Status Quo", because the "New Package" option introduces a +regression in being able to use type type with operators, and "Minimize Checks" +is too prone to bugs introduced by refactoring. + + +## Pros and Cons of the Options + +### New Pacakge: `util/chk` for checking type constraint + +* Good, because it is expressive +* Good, because the constraint only needs to be checked during construction +* Bad, because `Pos64` doesn't compile with operators like `+ * - /` + +### Status Quo: check the constraint in multiple places + +* Good, because it is what the code is already doing +* Good, because when a funciton becomes public, the constraint holds +* Good, because when a function moves to another file or package, the constraint holds +* Bad, because it means the check may need to be repeated. DRY + +### Minimize Checks: no check in package private functions + +* Good, because it reduces the amount of times a constraint is checked +* Bad, because the assumption might be violated if a private function becomes + public, or gains an additional caller. + +## More Information + +See the discussion on now-closed #2743 diff --git a/docs/decisions/README.md b/docs/decisions/README.md new file mode 100644 index 0000000000..63b1a18cd2 --- /dev/null +++ b/docs/decisions/README.md @@ -0,0 +1,10 @@ +# Decisions + +For new Architectural Decision Records (ADRs), please use one of the following templates as a starting point: + +* [adr-template.md](adr-template.md) has all sections, with explanations about them. +* [adr-template-minmal.md](adr-template-minimal.md) only contains mandatory sections, with explanations about them. +* [adr-template-bare.md](adr-template-bare.md) has all sections, wich are empty (no explanations). +* [adr-template-bare-minimal.md](adr-template-bare-minimal.md) has the mandatory sections, without explanations. + +The MADR documentation is available at while general information about ADRs is available at . diff --git a/docs/decisions/adr-template-bare-minimal.md b/docs/decisions/adr-template-bare-minimal.md new file mode 100644 index 0000000000..bd16d0ea21 --- /dev/null +++ b/docs/decisions/adr-template-bare-minimal.md @@ -0,0 +1,16 @@ +# + +## Context and Problem Statement + + + +## Considered Options + + + +## Decision Outcome + + + +### Consequences + diff --git a/docs/decisions/adr-template-bare.md b/docs/decisions/adr-template-bare.md new file mode 100644 index 0000000000..26f6598f70 --- /dev/null +++ b/docs/decisions/adr-template-bare.md @@ -0,0 +1,44 @@ +--- +status: +date: +decision-makers: +consulted: +informed: +--- + +# + +## Context and Problem Statement + + + +## Decision Drivers + +* + +## Considered Options + +* + +## Decision Outcome + +Chosen option: "", because + +### Consequences + +* Good, because +* Bad, because + +### Confirmation + + + +## Pros and Cons of the Options + +### + +* Good, because +* Neutral, because +* Bad, because + +## More Information diff --git a/docs/decisions/adr-template-minimal.md b/docs/decisions/adr-template-minimal.md new file mode 100644 index 0000000000..267640bfbc --- /dev/null +++ b/docs/decisions/adr-template-minimal.md @@ -0,0 +1,23 @@ +# {short title, representative of solved problem and found solution} + +## Context and Problem Statement + +{Describe the context and problem statement, e.g., in free form using two to three sentences or in the form of an illustrative story. You may want to articulate the problem in form of a question and add links to collaboration boards or issue management systems.} + +## Considered Options + +* {title of option 1} +* {title of option 2} +* {title of option 3} +* â€Ļ + +## Decision Outcome + +Chosen option: "{title of option 1}", because {justification. e.g., only option, which meets k.o. criterion decision driver | which resolves force {force} | â€Ļ | comes out best (see below)}. + + +### Consequences + +* Good, because {positive consequence, e.g., improvement of one or more desired qualities, â€Ļ} +* Bad, because {negative consequence, e.g., compromising one or more desired qualities, â€Ļ} +* â€Ļ diff --git a/docs/decisions/adr-template.md b/docs/decisions/adr-template.md new file mode 100644 index 0000000000..08dac30ed8 --- /dev/null +++ b/docs/decisions/adr-template.md @@ -0,0 +1,74 @@ +--- +# These are optional metadata elements. Feel free to remove any of them. +status: "{proposed | rejected | accepted | deprecated | â€Ļ | superseded by ADR-0123" +date: {YYYY-MM-DD when the decision was last updated} +decision-makers: {list everyone involved in the decision} +consulted: {list everyone whose opinions are sought (typically subject-matter experts); and with whom there is a two-way communication} +informed: {list everyone who is kept up-to-date on progress; and with whom there is a one-way communication} +--- + +# {short title, representative of solved problem and found solution} + +## Context and Problem Statement + +{Describe the context and problem statement, e.g., in free form using two to three sentences or in the form of an illustrative story. You may want to articulate the problem in form of a question and add links to collaboration boards or issue management systems.} + + +## Decision Drivers + +* {decision driver 1, e.g., a force, facing concern, â€Ļ} +* {decision driver 2, e.g., a force, facing concern, â€Ļ} +* â€Ļ + +## Considered Options + +* {title of option 1} +* {title of option 2} +* {title of option 3} +* â€Ļ + +## Decision Outcome + +Chosen option: "{title of option 1}", because {justification. e.g., only option, which meets k.o. criterion decision driver | which resolves force {force} | â€Ļ | comes out best (see below)}. + + +### Consequences + +* Good, because {positive consequence, e.g., improvement of one or more desired qualities, â€Ļ} +* Bad, because {negative consequence, e.g., compromising one or more desired qualities, â€Ļ} +* â€Ļ + + +### Confirmation + +{Describe how the implementation of/compliance with the ADR can/will be confirmed. Are the design that was decided for and its implementation in line with the decision made? E.g., a design/code review or a test with a library such as ArchUnit can help validate this. Not that although we classify this element as optional, it is included in many ADRs.} + + +## Pros and Cons of the Options + +### {title of option 1} + + +{example | description | pointer to more information | â€Ļ} + +* Good, because {argument a} +* Good, because {argument b} + +* Neutral, because {argument c} +* Bad, because {argument d} +* â€Ļ + +### {title of other option} + +{example | description | pointer to more information | â€Ļ} + +* Good, because {argument a} +* Good, because {argument b} +* Neutral, because {argument c} +* Bad, because {argument d} +* â€Ļ + + +## More Information + +{You might want to provide additional evidence/confidence for the decision outcome here and/or document the team agreement on the decision and/or define when/how this decision the decision should be realized and if/when it should be re-visited. Links to other decisions and resources might appear here as well.} From 3e59f8fb3a6576c84d2387574dd4907d1f60bd62 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 16 Dec 2024 08:31:57 -0600 Subject: [PATCH 015/131] update bold submodule --- bold | 2 +- nitro-testnode | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bold b/bold index d0a87de774..d3f4d600ab 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit d0a87de774aecfa97161efd1b0a924d4d5fbcf74 +Subproject commit d3f4d600abdacec800e9e27a429a730639233073 diff --git a/nitro-testnode b/nitro-testnode index c177f28234..fa19e22104 160000 --- a/nitro-testnode +++ b/nitro-testnode @@ -1 +1 @@ -Subproject commit c177f282340285bcdae2d6a784547e2bb8b97498 +Subproject commit fa19e2210403ad24519ea46c2d337f54a9f47593 From da609b6c5bedb1999362ffaa28257f0fa7291d97 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 16 Dec 2024 08:50:05 -0600 Subject: [PATCH 016/131] include all the new config opts --- staker/bold/bold_staker.go | 88 +++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/staker/bold/bold_staker.go b/staker/bold/bold_staker.go index 1a8eed80fa..2a6c32f5a9 100644 --- a/staker/bold/bold_staker.go +++ b/staker/bold/bold_staker.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "math/big" + "strings" "time" flag "github.com/spf13/pflag" @@ -57,16 +58,21 @@ type BoldConfig struct { // How often to scan for newly created assertions onchain. AssertionScanningInterval time.Duration `koanf:"assertion-scanning-interval"` // How often to confirm assertions onchain. - AssertionConfirmingInterval time.Duration `koanf:"assertion-confirming-interval"` - API bool `koanf:"api"` - APIHost string `koanf:"api-host"` - APIPort uint16 `koanf:"api-port"` - APIDBPath string `koanf:"api-db-path"` - TrackChallengeParentAssertionHashes []string `koanf:"track-challenge-parent-assertion-hashes"` - CheckStakerSwitchInterval time.Duration `koanf:"check-staker-switch-interval"` - StateProviderConfig StateProviderConfig `koanf:"state-provider-config"` - StartValidationFromStaked bool `koanf:"start-validation-from-staked"` + AssertionConfirmingInterval time.Duration `koanf:"assertion-confirming-interval"` + API bool `koanf:"api"` + APIHost string `koanf:"api-host"` + APIPort uint16 `koanf:"api-port"` + APIDBPath string `koanf:"api-db-path"` + TrackChallengeParentAssertionHashes []string `koanf:"track-challenge-parent-assertion-hashes"` + CheckStakerSwitchInterval time.Duration `koanf:"check-staker-switch-interval"` + StateProviderConfig StateProviderConfig `koanf:"state-provider-config"` + StartValidationFromStaked bool `koanf:"start-validation-from-staked"` + AutoDeposit bool `koanf:"auto-deposit"` + AutoIncreaseAllowance bool `koanf:"auto-increase-allowance"` + DelegatedStaking DelegatedStakingConfig `koanf:"delegated-staking"` + RPCBlockNumber string `koanf:"rpc-block-number"` strategy legacystaker.StakerStrategy + blockNum rpc.BlockNumber } func (c *BoldConfig) Validate() error { @@ -75,9 +81,31 @@ func (c *BoldConfig) Validate() error { return err } c.strategy = strategy + var blockNum rpc.BlockNumber + switch strings.ToLower(c.RPCBlockNumber) { + case "safe": + blockNum = rpc.SafeBlockNumber + case "finalized": + blockNum = rpc.FinalizedBlockNumber + case "latest": + blockNum = rpc.LatestBlockNumber + default: + return fmt.Errorf("unknown rpc block number \"%v\", expected either latest, safe, or finalized", c.RPCBlockNumber) + } + c.blockNum = blockNum return nil } +type DelegatedStakingConfig struct { + Enable bool `koanf:"enable"` + CustomWithdrawalAddress string `koanf:"custom-withdrawal-address"` +} + +var DefaultDelegatedStakingConfig = DelegatedStakingConfig{ + Enable: false, + CustomWithdrawalAddress: "", +} + type StateProviderConfig struct { // A name identifier for the validator for cosmetic purposes. ValidatorName string `koanf:"validator-name"` @@ -106,6 +134,10 @@ var DefaultBoldConfig = BoldConfig{ CheckStakerSwitchInterval: time.Minute, // Every minute, check if the Nitro node staker should switch to using BOLD. StateProviderConfig: DefaultStateProviderConfig, StartValidationFromStaked: true, + AutoDeposit: true, + AutoIncreaseAllowance: true, + DelegatedStaking: DefaultDelegatedStakingConfig, + RPCBlockNumber: "finalized", } var BoldModes = map[legacystaker.StakerStrategy]boldtypes.Mode{ @@ -118,6 +150,7 @@ var BoldModes = map[legacystaker.StakerStrategy]boldtypes.Mode{ func BoldConfigAddOptions(prefix string, f *flag.FlagSet) { f.Bool(prefix+".enable", DefaultBoldConfig.Enable, "enable bold challenge protocol") f.String(prefix+".strategy", DefaultBoldConfig.Strategy, "define the bold validator staker strategy, either watchtower, defensive, stakeLatest, or makeNodes") + f.String(prefix+".rpc-block-number", DefaultBoldConfig.RPCBlockNumber, "define the block number to use for reading data onchain, either latest, safe, or finalized") f.Duration(prefix+".assertion-posting-interval", DefaultBoldConfig.AssertionPostingInterval, "assertion posting interval") f.Duration(prefix+".assertion-scanning-interval", DefaultBoldConfig.AssertionScanningInterval, "scan assertion interval") f.Duration(prefix+".assertion-confirming-interval", DefaultBoldConfig.AssertionConfirmingInterval, "confirm assertion interval") @@ -129,6 +162,9 @@ func BoldConfigAddOptions(prefix string, f *flag.FlagSet) { f.StringSlice(prefix+".track-challenge-parent-assertion-hashes", DefaultBoldConfig.TrackChallengeParentAssertionHashes, "only track challenges/edges with these parent assertion hashes") StateProviderConfigAddOptions(prefix+".state-provider-config", f) f.Bool(prefix+".start-validation-from-staked", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") + f.Bool(prefix+".auto-deposit", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") + f.Bool(prefix+".auto-increase-allowance", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") + DelegatedStakingConfigAddOptions(prefix+".delegated-staking", f) } func StateProviderConfigAddOptions(prefix string, f *flag.FlagSet) { @@ -137,6 +173,11 @@ func StateProviderConfigAddOptions(prefix string, f *flag.FlagSet) { f.String(prefix+".machine-leaves-cache-path", DefaultStateProviderConfig.MachineLeavesCachePath, "path to machine cache") } +func DelegatedStakingConfigAddOptions(prefix string, f *flag.FlagSet) { + f.Bool(prefix+".enable", DefaultDelegatedStakingConfig.Enable, "check batch finality") + f.String(prefix+".custom-withdrawal-address", DefaultDelegatedStakingConfig.CustomWithdrawalAddress, "path to machine cache") +} + type BOLDStaker struct { stopwaiter.StopWaiter config *BoldConfig @@ -365,7 +406,25 @@ func newBOLDChallengeManager( if err != nil { return nil, fmt.Errorf("could not create challenge manager bindings: %w", err) } - assertionChain, err := solimpl.NewAssertionChain(ctx, rollupAddress, chalManager, txOpts, client, NewDataPosterTransactor(dataPoster)) + assertionChainOpts := []solimpl.Opt{ + solimpl.WithRpcHeadBlockNumber(config.blockNum), + } + if config.DelegatedStaking.Enable && config.DelegatedStaking.CustomWithdrawalAddress != "" { + withdrawalAddr := common.HexToAddress(config.DelegatedStaking.CustomWithdrawalAddress) + assertionChainOpts = append(assertionChainOpts, solimpl.WithCustomWithdrawalAddress(withdrawalAddr)) + } + if !config.AutoDeposit { + assertionChainOpts = append(assertionChainOpts, solimpl.WithoutAutoDeposit()) + } + assertionChain, err := solimpl.NewAssertionChain( + ctx, + rollupAddress, + chalManager, + txOpts, + client, + NewDataPosterTransactor(dataPoster), + assertionChainOpts..., + ) if err != nil { return nil, fmt.Errorf("could not create assertion chain: %w", err) } @@ -455,6 +514,15 @@ func newBOLDChallengeManager( apiAddr := fmt.Sprintf("%s:%d", config.APIHost, config.APIPort) stackOpts = append(stackOpts, challengemanager.StackWithAPIEnabled(apiAddr, apiDBPath)) } + if !config.AutoDeposit { + stackOpts = append(stackOpts, challengemanager.StackWithoutAutoDeposit()) + } + if !config.AutoIncreaseAllowance { + stackOpts = append(stackOpts, challengemanager.StackWithoutAutoAllowanceApproval()) + } + if config.DelegatedStaking.Enable { + stackOpts = append(stackOpts, challengemanager.StackWithDelegatedStaking()) + } manager, err := challengemanager.NewChallengeStack( assertionChain, From 177b7a887821aceb838254acd7c040485ba8d999 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 16 Dec 2024 09:09:41 -0600 Subject: [PATCH 017/131] comment --- staker/bold/bold_staker.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/staker/bold/bold_staker.go b/staker/bold/bold_staker.go index 2a6c32f5a9..b08b2ec18b 100644 --- a/staker/bold/bold_staker.go +++ b/staker/bold/bold_staker.go @@ -162,8 +162,8 @@ func BoldConfigAddOptions(prefix string, f *flag.FlagSet) { f.StringSlice(prefix+".track-challenge-parent-assertion-hashes", DefaultBoldConfig.TrackChallengeParentAssertionHashes, "only track challenges/edges with these parent assertion hashes") StateProviderConfigAddOptions(prefix+".state-provider-config", f) f.Bool(prefix+".start-validation-from-staked", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") - f.Bool(prefix+".auto-deposit", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") - f.Bool(prefix+".auto-increase-allowance", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") + f.Bool(prefix+".auto-deposit", DefaultBoldConfig.AutoDeposit, "auto-deposit stake token whenever making a move in BoLD that does not have enough stake token balance") + f.Bool(prefix+".auto-increase-allowance", DefaultBoldConfig.AutoIncreaseAllowance, "auto-increase spending allowance of the stake token by the rollup and challenge manager contracts") DelegatedStakingConfigAddOptions(prefix+".delegated-staking", f) } @@ -174,8 +174,8 @@ func StateProviderConfigAddOptions(prefix string, f *flag.FlagSet) { } func DelegatedStakingConfigAddOptions(prefix string, f *flag.FlagSet) { - f.Bool(prefix+".enable", DefaultDelegatedStakingConfig.Enable, "check batch finality") - f.String(prefix+".custom-withdrawal-address", DefaultDelegatedStakingConfig.CustomWithdrawalAddress, "path to machine cache") + f.Bool(prefix+".enable", DefaultDelegatedStakingConfig.Enable, "enable delegated staking by having the validator call newStake on startup") + f.String(prefix+".custom-withdrawal-address", DefaultDelegatedStakingConfig.CustomWithdrawalAddress, "enable a custom withdrawal address for staking on the rollup contract, useful for delegated stakers") } type BOLDStaker struct { From ffdce5c13833c00b0a8f58463b95209e66cdc0aa Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 17 Dec 2024 14:01:58 -0600 Subject: [PATCH 018/131] edits --- nitro-testnode | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nitro-testnode b/nitro-testnode index fa19e22104..c177f28234 160000 --- a/nitro-testnode +++ b/nitro-testnode @@ -1 +1 @@ -Subproject commit fa19e2210403ad24519ea46c2d337f54a9f47593 +Subproject commit c177f282340285bcdae2d6a784547e2bb8b97498 From f7bacf667afd7b6fcb40516a2378e424c177b9f1 Mon Sep 17 00:00:00 2001 From: thirdkeyword Date: Thu, 19 Dec 2024 14:15:19 +0800 Subject: [PATCH 019/131] chore: fix some problematic method name and typos in comment Signed-off-by: thirdkeyword --- cmd/datool/datool.go | 2 +- execution/nodeInterface/NodeInterface.go | 2 +- relay/relay_stress_test.go | 2 +- system_tests/outbox_test.go | 2 +- system_tests/seqinbox_test.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/datool/datool.go b/cmd/datool/datool.go index 06f94dc952..2eb1e95660 100644 --- a/cmd/datool/datool.go +++ b/cmd/datool/datool.go @@ -99,7 +99,7 @@ func parseClientStoreConfig(args []string) (*ClientStoreConfig, error) { f.String("url", "", "URL of DAS server to connect to") f.String("message", "", "message to send") f.Int("random-message-size", 0, "send a message of a specified number of random bytes") - f.String("signing-key", "", "ecdsa private key to sign the message with, treated as a hex string if prefixed with 0x otherise treated as a file; if not specified the message is not signed") + f.String("signing-key", "", "ecdsa private key to sign the message with, treated as a hex string if prefixed with 0x otherwise treated as a file; if not specified the message is not signed") f.String("signing-wallet", "", "wallet containing ecdsa key to sign the message with") f.String("signing-wallet-password", genericconf.PASSWORD_NOT_SET, "password to unlock the wallet, if not specified the user is prompted for the password") f.Duration("das-retention-period", 24*time.Hour, "The period which DASes are requested to retain the stored batches.") diff --git a/execution/nodeInterface/NodeInterface.go b/execution/nodeInterface/NodeInterface.go index 20282f8231..189640d5d1 100644 --- a/execution/nodeInterface/NodeInterface.go +++ b/execution/nodeInterface/NodeInterface.go @@ -405,7 +405,7 @@ func (n NodeInterface) ConstructOutboxProof(c ctx, evm mech, size, leaf uint64) if !balanced { // This tree isn't balanced, so we'll need to use the partials to recover the missing info. - // To do this, we'll walk the boundry of what's known, computing hashes along the way + // To do this, we'll walk the boundary of what's known, computing hashes along the way step := *minPartialPlace step.Leaf += 1 << step.Level // we start on the min partial's zero-hash sibling diff --git a/relay/relay_stress_test.go b/relay/relay_stress_test.go index 93ba510193..e2cff07341 100644 --- a/relay/relay_stress_test.go +++ b/relay/relay_stress_test.go @@ -93,7 +93,7 @@ func (ts *dummyTxStreamer) AddBroadcastMessages(feedMessages []*message.Broadcas time.Sleep(50 * time.Millisecond) if !ts.logConnection { ts.logConnection = true - log.Info("test client is succesfully receiving messages", "client_Id", ts.id, "msg_size", feedMessages[0].Size()) + log.Info("test client is successfully receiving messages", "client_Id", ts.id, "msg_size", feedMessages[0].Size()) } return nil } diff --git a/system_tests/outbox_test.go b/system_tests/outbox_test.go index 10d1ebec42..2b3ff38da1 100644 --- a/system_tests/outbox_test.go +++ b/system_tests/outbox_test.go @@ -283,7 +283,7 @@ func TestOutboxProofs(t *testing.T) { if !balanced { // This tree isn't balanced, so we'll need to use the partials to recover the missing info. - // To do this, we'll walk the boundry of what's known, computing hashes along the way + // To do this, we'll walk the boundary of what's known, computing hashes along the way zero := common.Hash{} diff --git a/system_tests/seqinbox_test.go b/system_tests/seqinbox_test.go index a9f66b0e2f..44d96f39e7 100644 --- a/system_tests/seqinbox_test.go +++ b/system_tests/seqinbox_test.go @@ -353,7 +353,7 @@ func testSequencerInboxReaderImpl(t *testing.T, validator bool) { AfterDelayedMessagesRead: 1, }) if diff := diffAccessList(accessed, *wantAL); diff != "" { - t.Errorf("Access list mistmatch:\n%s\n", diff) + t.Errorf("Access list mismatch:\n%s\n", diff) } if i%5 == 0 { tx, err = seqInbox.AddSequencerL2Batch(&seqOpts, big.NewInt(int64(len(blockStates))), batchData, big.NewInt(1), gasRefunderAddr, big.NewInt(0), big.NewInt(0)) From 5fb7c01631eac527b698570a8e9448212bc32b98 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Thu, 19 Dec 2024 19:21:55 +0530 Subject: [PATCH 020/131] Add mock external signer binary --- Dockerfile | 1 + Makefile | 5 +- arbnode/dataposter/data_poster.go | 16 +++ arbnode/dataposter/dataposter_test.go | 18 +--- .../externalsignertest/externalsignertest.go | 4 +- cmd/mockexternalsigner/mockexternalsigner.go | 97 +++++++++++++++++++ system_tests/batch_poster_test.go | 17 +--- system_tests/fast_confirm_test.go | 5 +- system_tests/staker_test.go | 3 +- 9 files changed, 127 insertions(+), 39 deletions(-) create mode 100644 cmd/mockexternalsigner/mockexternalsigner.go diff --git a/Dockerfile b/Dockerfile index ba1f2feb3e..17372f2d08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -333,6 +333,7 @@ RUN rm -f /home/user/target/machines/latest COPY --from=prover-export /bin/jit /usr/local/bin/ COPY --from=node-builder /workspace/target/bin/deploy /usr/local/bin/ COPY --from=node-builder /workspace/target/bin/seq-coordinator-invalidate /usr/local/bin/ +COPY --from=node-builder /workspace/target/bin/mockexternalsigner /usr/local/bin/ COPY --from=module-root-calc /workspace/target/machines/latest/machine.wavm.br /home/user/target/machines/latest/ COPY --from=module-root-calc /workspace/target/machines/latest/until-host-io-state.bin /home/user/target/machines/latest/ COPY --from=module-root-calc /workspace/target/machines/latest/module-root.txt /home/user/target/machines/latest/ diff --git a/Makefile b/Makefile index 12dfb07cf8..1a618df9f7 100644 --- a/Makefile +++ b/Makefile @@ -169,7 +169,7 @@ all: build build-replay-env test-gen-proofs @touch .make/all .PHONY: build -build: $(patsubst %,$(output_root)/bin/%, nitro deploy relay daserver datool seq-coordinator-invalidate nitro-val seq-coordinator-manager dbconv) +build: $(patsubst %,$(output_root)/bin/%, nitro deploy relay daserver datool mockexternalsigner seq-coordinator-invalidate nitro-val seq-coordinator-manager dbconv) @printf $(done) .PHONY: build-node-deps @@ -314,6 +314,9 @@ $(output_root)/bin/daserver: $(DEP_PREDICATE) build-node-deps $(output_root)/bin/datool: $(DEP_PREDICATE) build-node-deps go build $(GOLANG_PARAMS) -o $@ "$(CURDIR)/cmd/datool" +$(output_root)/bin/mockexternalsigner: $(DEP_PREDICATE) build-node-deps + go build $(GOLANG_PARAMS) -o $@ "$(CURDIR)/cmd/mockexternalsigner" + $(output_root)/bin/seq-coordinator-invalidate: $(DEP_PREDICATE) build-node-deps go build $(GOLANG_PARAMS) -o $@ "$(CURDIR)/cmd/seq-coordinator-invalidate" diff --git a/arbnode/dataposter/data_poster.go b/arbnode/dataposter/data_poster.go index a977b9fc08..5accd6312d 100644 --- a/arbnode/dataposter/data_poster.go +++ b/arbnode/dataposter/data_poster.go @@ -41,6 +41,7 @@ import ( "github.com/ethereum/go-ethereum/signer/core/apitypes" "github.com/offchainlabs/nitro/arbnode/dataposter/dbstorage" + "github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest" "github.com/offchainlabs/nitro/arbnode/dataposter/noop" redisstorage "github.com/offchainlabs/nitro/arbnode/dataposter/redis" "github.com/offchainlabs/nitro/arbnode/dataposter/slice" @@ -1297,6 +1298,21 @@ type ExternalSignerCfg struct { InsecureSkipVerify bool `koanf:"insecure-skip-verify"` } +func ExternalSignerTestCfg(addr common.Address, url string) (*ExternalSignerCfg, error) { + cp, err := externalsignertest.CertPaths() + if err != nil { + return nil, fmt.Errorf("getting certificates path: %w", err) + } + return &ExternalSignerCfg{ + Address: common.Bytes2Hex(addr.Bytes()), + URL: url, + Method: externalsignertest.SignerMethod, + RootCA: cp.ServerCert, + ClientCert: cp.ClientCert, + ClientPrivateKey: cp.ClientKey, + }, nil +} + type DangerousConfig struct { // This should be used with caution, only when dataposter somehow gets in a // bad state and we require clearing it. diff --git a/arbnode/dataposter/dataposter_test.go b/arbnode/dataposter/dataposter_test.go index dc5df1a6c4..83401b2484 100644 --- a/arbnode/dataposter/dataposter_test.go +++ b/arbnode/dataposter/dataposter_test.go @@ -3,7 +3,6 @@ package dataposter import ( "context" "errors" - "fmt" "math/big" "testing" "time" @@ -25,21 +24,6 @@ import ( "github.com/offchainlabs/nitro/util/arbmath" ) -func signerTestCfg(addr common.Address, url string) (*ExternalSignerCfg, error) { - cp, err := externalsignertest.CertPaths() - if err != nil { - return nil, fmt.Errorf("getting certificates path: %w", err) - } - return &ExternalSignerCfg{ - Address: common.Bytes2Hex(addr.Bytes()), - URL: url, - Method: externalsignertest.SignerMethod, - RootCA: cp.ServerCert, - ClientCert: cp.ClientCert, - ClientPrivateKey: cp.ClientKey, - }, nil -} - var ( blobTx = types.NewTx( &types.BlobTx{ @@ -80,7 +64,7 @@ func TestExternalSigner(t *testing.T) { return } }() - signerCfg, err := signerTestCfg(srv.Address, srv.URL()) + signerCfg, err := ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting signer test config: %v", err) } diff --git a/arbnode/dataposter/externalsignertest/externalsignertest.go b/arbnode/dataposter/externalsignertest/externalsignertest.go index 51ccec1903..c71a36fc91 100644 --- a/arbnode/dataposter/externalsignertest/externalsignertest.go +++ b/arbnode/dataposter/externalsignertest/externalsignertest.go @@ -42,7 +42,7 @@ type CertAbsPaths struct { type SignerServer struct { *http.Server *SignerAPI - listener net.Listener + Listener net.Listener } func basePath() (string, error) { @@ -147,7 +147,7 @@ func (s *SignerServer) Start() error { if err != nil { return err } - if err := s.ServeTLS(s.listener, cp.ServerCert, cp.ServerKey); err != nil && !errors.Is(err, http.ErrServerClosed) { + if err := s.ServeTLS(s.Listener, cp.ServerCert, cp.ServerKey); err != nil && !errors.Is(err, http.ErrServerClosed) { return err } return nil diff --git a/cmd/mockexternalsigner/mockexternalsigner.go b/cmd/mockexternalsigner/mockexternalsigner.go new file mode 100644 index 0000000000..185923bcc8 --- /dev/null +++ b/cmd/mockexternalsigner/mockexternalsigner.go @@ -0,0 +1,97 @@ +package main + +import ( + "crypto/tls" + "crypto/x509" + "encoding/json" + "fmt" + "math/big" + "net/http" + "os" + "time" + + "github.com/ethereum/go-ethereum/rpc" + + "github.com/offchainlabs/nitro/arbnode/dataposter" + "github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest" + "github.com/offchainlabs/nitro/cmd/genericconf" + "github.com/offchainlabs/nitro/cmd/util" + "github.com/offchainlabs/nitro/util/testhelpers" +) + +func main() { + args := os.Args + if len(args) != 2 { + panic("Usage: mockexternalsigner [private_key]") + } + srv, err := NewServer(args[1]) + if err != nil { + panic(err) + } + go func() { + if err := srv.Start(); err != nil { + panic(err) + } + }() + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) + if err != nil { + panic(err) + } + signerCfgBytes, err := json.Marshal(signerCfg) + if err != nil { + panic(err) + } + fmt.Println(string(signerCfgBytes)) + +} + +func NewServer(privateKey string) (*externalsignertest.SignerServer, error) { + rpcServer := rpc.NewServer() + txOpts, _, err := util.OpenWallet( + "mockexternalsigner", + &genericconf.WalletConfig{PrivateKey: privateKey}, + big.NewInt(1337), + ) + if err != nil { + return nil, err + } + s := &externalsignertest.SignerAPI{SignerFn: txOpts.Signer, Address: txOpts.From} + if err := rpcServer.RegisterName("test", s); err != nil { + return nil, err + } + cp, err := externalsignertest.CertPaths() + if err != nil { + return nil, err + } + clientCert, err := os.ReadFile(cp.ClientCert) + if err != nil { + return nil, err + } + pool := x509.NewCertPool() + pool.AppendCertsFromPEM(clientCert) + + ln, err := testhelpers.FreeTCPPortListener() + if err != nil { + return nil, err + } + + httpServer := &http.Server{ + Addr: ln.Addr().String(), + Handler: rpcServer, + ReadTimeout: 30 * time.Second, + ReadHeaderTimeout: 30 * time.Second, + WriteTimeout: 30 * time.Second, + IdleTimeout: 120 * time.Second, + TLSConfig: &tls.Config{ + MinVersion: tls.VersionTLS12, + ClientAuth: tls.RequireAndVerifyClientCert, + ClientCAs: pool, + }, + } + + return &externalsignertest.SignerServer{ + Server: httpServer, + SignerAPI: s, + Listener: ln, + }, nil +} diff --git a/system_tests/batch_poster_test.go b/system_tests/batch_poster_test.go index ee0c3b4a3a..fe2fa2df1d 100644 --- a/system_tests/batch_poster_test.go +++ b/system_tests/batch_poster_test.go @@ -64,21 +64,6 @@ func addNewBatchPoster(ctx context.Context, t *testing.T, builder *NodeBuilder, } } -func externalSignerTestCfg(addr common.Address, url string) (*dataposter.ExternalSignerCfg, error) { - cp, err := externalsignertest.CertPaths() - if err != nil { - return nil, fmt.Errorf("getting certificates path: %w", err) - } - return &dataposter.ExternalSignerCfg{ - Address: common.Bytes2Hex(addr.Bytes()), - URL: url, - Method: externalsignertest.SignerMethod, - RootCA: cp.ServerCert, - ClientCert: cp.ClientCert, - ClientPrivateKey: cp.ClientKey, - }, nil -} - func testBatchPosterParallel(t *testing.T, useRedis bool) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -105,7 +90,7 @@ func testBatchPosterParallel(t *testing.T, useRedis bool) { builder := NewNodeBuilder(ctx).DefaultConfig(t, true) builder.nodeConfig.BatchPoster.Enable = false builder.nodeConfig.BatchPoster.RedisUrl = redisUrl - signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL()) + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting external signer config: %v", err) } diff --git a/system_tests/fast_confirm_test.go b/system_tests/fast_confirm_test.go index 8eb71bffd4..384e9649c6 100644 --- a/system_tests/fast_confirm_test.go +++ b/system_tests/fast_confirm_test.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbnode" + "github.com/offchainlabs/nitro/arbnode/dataposter" "github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest" "github.com/offchainlabs/nitro/arbnode/dataposter/storage" "github.com/offchainlabs/nitro/arbos/l2pricing" @@ -174,7 +175,7 @@ func TestFastConfirmation(t *testing.T) { err = stakerA.Initialize(ctx) Require(t, err) cfg := arbnode.ConfigDefaultL1NonSequencerTest() - signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL()) + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting external signer config: %v", err) } @@ -375,7 +376,7 @@ func TestFastConfirmationWithSafe(t *testing.T) { err = stakerA.Initialize(ctx) Require(t, err) cfg := arbnode.ConfigDefaultL1NonSequencerTest() - signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL()) + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting external signer config: %v", err) } diff --git a/system_tests/staker_test.go b/system_tests/staker_test.go index 69645d8878..b223e79a8c 100644 --- a/system_tests/staker_test.go +++ b/system_tests/staker_test.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbnode" + "github.com/offchainlabs/nitro/arbnode/dataposter" "github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest" "github.com/offchainlabs/nitro/arbnode/dataposter/storage" "github.com/offchainlabs/nitro/arbos/l2pricing" @@ -229,7 +230,7 @@ func stakerTestImpl(t *testing.T, faultyStaker bool, honestStakerInactive bool) } Require(t, err) cfg := arbnode.ConfigDefaultL1NonSequencerTest() - signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL()) + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting external signer config: %v", err) } From c5285afa712b3cb972f1ffbee5b04fdec1cb3e5c Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Thu, 19 Dec 2024 21:25:28 +0530 Subject: [PATCH 021/131] minor fix --- cmd/mockexternalsigner/mockexternalsigner.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/mockexternalsigner/mockexternalsigner.go b/cmd/mockexternalsigner/mockexternalsigner.go index 185923bcc8..4678d586ef 100644 --- a/cmd/mockexternalsigner/mockexternalsigner.go +++ b/cmd/mockexternalsigner/mockexternalsigner.go @@ -3,8 +3,6 @@ package main import ( "crypto/tls" "crypto/x509" - "encoding/json" - "fmt" "math/big" "net/http" "os" @@ -37,12 +35,15 @@ func main() { if err != nil { panic(err) } - signerCfgBytes, err := json.Marshal(signerCfg) - if err != nil { - panic(err) + print(" --externalSignerUrl " + signerCfg.URL) + print(" --externalSignerAddress " + signerCfg.Address) + print(" --externalSignerMethod " + signerCfg.Method) + print(" --externalSignerRootCA " + signerCfg.RootCA) + print(" --externalSignerClientCert " + signerCfg.ClientCert) + print(" --externalSignerClientPrivateKey " + signerCfg.ClientPrivateKey) + if signerCfg.InsecureSkipVerify { + print(" --externalSignerInsecureSkipVerify ") } - fmt.Println(string(signerCfgBytes)) - } func NewServer(privateKey string) (*externalsignertest.SignerServer, error) { From 784fa4662f2415d9b1f461d87a4e56ca03790282 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:10:00 +0000 Subject: [PATCH 022/131] Bump golang.org/x/crypto from 0.24.0 to 0.31.0 Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.24.0 to 0.31.0. - [Commits](https://github.com/golang/crypto/compare/v0.24.0...v0.31.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- go.mod | 12 ++++++------ go.sum | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 7a48b0520d..cfcca3628b 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.27 github.com/aws/aws-sdk-go-v2/service/s3 v1.64.1 github.com/cavaliergopher/grab/v3 v3.0.1 + github.com/ccoveille/go-safecast v1.1.0 github.com/cockroachdb/pebble v1.1.0 github.com/codeclysm/extract/v3 v3.0.2 github.com/dgraph-io/badger/v4 v4.2.0 @@ -46,9 +47,9 @@ require ( github.com/spf13/pflag v1.0.5 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/wealdtech/go-merkletree v1.0.0 - golang.org/x/crypto v0.24.0 - golang.org/x/sys v0.21.0 - golang.org/x/term v0.21.0 + golang.org/x/crypto v0.31.0 + golang.org/x/sys v0.28.0 + golang.org/x/term v0.27.0 golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d google.golang.org/api v0.187.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0 @@ -60,7 +61,6 @@ require ( cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect cloud.google.com/go/compute/metadata v0.3.0 // indirect cloud.google.com/go/iam v1.1.8 // indirect - github.com/ccoveille/go-safecast v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -195,8 +195,8 @@ require ( golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.22.0 - golang.org/x/sync v0.8.0 - golang.org/x/text v0.16.0 // indirect + golang.org/x/sync v0.10.0 + golang.org/x/text v0.21.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/protobuf v1.34.2 // indirect rsc.io/tmplfunc v0.0.3 // indirect diff --git a/go.sum b/go.sum index 55ad86267a..01b58980dd 100644 --- a/go.sum +++ b/go.sum @@ -535,8 +535,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= @@ -580,8 +580,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -614,14 +614,14 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -631,8 +631,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= From e3aaf054df3bb7bfb8d2cfb4f4267bde6849a2f2 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 23 Dec 2024 13:07:27 -0600 Subject: [PATCH 023/131] update submod --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index d3f4d600ab..53a6195bd7 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit d3f4d600abdacec800e9e27a429a730639233073 +Subproject commit 53a6195bd7bbd749a81319920429a98b0b9213d4 From f2bfd88fc2508e7dddda97f3f23e57eee9c30906 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 30 Dec 2024 20:37:51 -0600 Subject: [PATCH 024/131] edit bold submod --- bold | 2 +- go-ethereum | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bold b/bold index 53a6195bd7..3df1191028 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit 53a6195bd7bbd749a81319920429a98b0b9213d4 +Subproject commit 3df119102815a7c17b87251e18df6e09f6e58128 diff --git a/go-ethereum b/go-ethereum index 26b4dff616..0d33cae0dd 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 26b4dff6165650b6963fb1b6f88958c29c059214 +Subproject commit 0d33cae0dd24ce387c589532e9557911780b389c From 7fd9dba8e7cb3b9540065057c88eb51ac3f58e2f Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 30 Dec 2024 21:38:07 -0600 Subject: [PATCH 025/131] build --- arbos/util/transfer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbos/util/transfer.go b/arbos/util/transfer.go index 0b61868abe..55281fa284 100644 --- a/arbos/util/transfer.go +++ b/arbos/util/transfer.go @@ -67,7 +67,7 @@ func TransferBalance( if arbmath.BigLessThan(balance.ToBig(), amount) { return fmt.Errorf("%w: addr %v have %v want %v", vm.ErrInsufficientBalance, *from, balance, amount) } - if evm.Context.ArbOSVersion < params.ArbosVersion_30 && amount.Sign() == 0 { + if evm.Context.ArbOSVersion < params.ArbosVersion_Stylus && amount.Sign() == 0 { evm.StateDB.CreateZombieIfDeleted(*from) } evm.StateDB.SubBalance(*from, uint256.MustFromBig(amount), tracing.BalanceChangeTransfer) From a46dc68c366a76290e7f480f2d18e3c214577414 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 31 Dec 2024 10:31:30 -0600 Subject: [PATCH 026/131] geth --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index 0d33cae0dd..26b4dff616 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 0d33cae0dd24ce387c589532e9557911780b389c +Subproject commit 26b4dff6165650b6963fb1b6f88958c29c059214 From 89cf1f87db443ccea57d9b5fbd32f7207d363750 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 2 Jan 2025 14:11:21 -0600 Subject: [PATCH 027/131] use proper bold commit --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index 3df1191028..eae8d51fcf 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit 3df119102815a7c17b87251e18df6e09f6e58128 +Subproject commit eae8d51fcf02002d3216a0b15f23b66f819f792d From ad0160d8aacdbd8feffd3d781e94705c213c078d Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 27 Dec 2024 16:19:03 -0300 Subject: [PATCH 028/131] Adds CI step to check if stylus_benchmark can be built --- .github/workflows/arbitrator-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index dd58a30571..f53312731a 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -165,6 +165,9 @@ jobs: - name: Run rust tests run: cargo test -p arbutil -p prover -p jit -p stylus --release --manifest-path arbitrator/prover/Cargo.toml + - name: Check stylus_bechmark + run: cargo check --manifest-path arbitrator/tools/stylus_benchmark/Cargo.toml + - name: Rustfmt run: cargo fmt -p arbutil -p prover -p jit -p stylus --manifest-path arbitrator/Cargo.toml -- --check From 962d0b651ef74ea215e85287a2d5e004558e7d77 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 27 Dec 2024 16:23:19 -0300 Subject: [PATCH 029/131] Renames exec_program to launch_program_thread --- arbitrator/jit/src/program.rs | 4 ++-- arbitrator/tools/stylus_benchmark/src/benchmark.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arbitrator/jit/src/program.rs b/arbitrator/jit/src/program.rs index d80b3771c6..abb498cf55 100644 --- a/arbitrator/jit/src/program.rs +++ b/arbitrator/jit/src/program.rs @@ -139,10 +139,10 @@ pub fn new_program( ))); }; - exec_program(exec, module, calldata, config, evm_data, gas) + launch_program_thread(exec, module, calldata, config, evm_data, gas) } -pub fn exec_program( +pub fn launch_program_thread( exec: &mut WasmEnv, module: Arc<[u8]>, calldata: Vec, diff --git a/arbitrator/tools/stylus_benchmark/src/benchmark.rs b/arbitrator/tools/stylus_benchmark/src/benchmark.rs index 43f7b7553a..3cc2aabb7d 100644 --- a/arbitrator/tools/stylus_benchmark/src/benchmark.rs +++ b/arbitrator/tools/stylus_benchmark/src/benchmark.rs @@ -45,7 +45,7 @@ fn run(compiled_module: Vec) -> (Duration, Ink) { let exec = &mut WasmEnv::default(); - let module = jit::program::exec_program( + let module = jit::program::launch_program_thread( exec, compiled_module.into(), calldata, From f9fa7827f2e8683f6aa43f93d63a96dc3b1f10fc Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 3 Jan 2025 20:22:58 -0600 Subject: [PATCH 030/131] update bold pin --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index eae8d51fcf..70c9755ae1 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit eae8d51fcf02002d3216a0b15f23b66f819f792d +Subproject commit 70c9755ae1b731f1b2fdedb986461754e4da2e8f From 8d0c6cbf169244322119493e2b417a8ecb660e38 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Mon, 6 Jan 2025 11:01:37 -0300 Subject: [PATCH 031/131] stylus_benchmark: Prints available scenarios in help --- arbitrator/tools/stylus_benchmark/Cargo.lock | 35 +++---------------- arbitrator/tools/stylus_benchmark/Cargo.toml | 2 -- arbitrator/tools/stylus_benchmark/src/main.rs | 9 +++-- .../tools/stylus_benchmark/src/scenario.rs | 10 +++--- 4 files changed, 13 insertions(+), 43 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/Cargo.lock b/arbitrator/tools/stylus_benchmark/Cargo.lock index fe3ff5e908..f1b9fb4996 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.lock +++ b/arbitrator/tools/stylus_benchmark/Cargo.lock @@ -1663,12 +1663,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rustversion" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" - [[package]] name = "ryu" version = "1.0.18" @@ -1701,9 +1695,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] @@ -1721,9 +1715,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", @@ -1909,25 +1903,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "strum" -version = "0.26.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" - -[[package]] -name = "strum_macros" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" -dependencies = [ - "heck 0.5.0", - "proc-macro2", - "quote", - "rustversion", - "syn 2.0.87", -] - [[package]] name = "stylus" version = "0.1.0" @@ -1964,8 +1939,6 @@ dependencies = [ "eyre", "jit", "prover", - "strum", - "strum_macros", "stylus", "wasmer", "wasmer-compiler-cranelift", diff --git a/arbitrator/tools/stylus_benchmark/Cargo.toml b/arbitrator/tools/stylus_benchmark/Cargo.toml index e193fc0ca8..4f9ed74d46 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.toml +++ b/arbitrator/tools/stylus_benchmark/Cargo.toml @@ -12,5 +12,3 @@ arbutil = { path = "../../arbutil/" } prover = { path = "../../prover/", default-features = false, features = ["native"] } stylus = { path = "../../stylus/", default-features = false } clap = { version = "4.4.8", features = ["derive"] } -strum = "0.26" -strum_macros = "0.26" diff --git a/arbitrator/tools/stylus_benchmark/src/main.rs b/arbitrator/tools/stylus_benchmark/src/main.rs index 4b8971ecab..c2d55ef06c 100644 --- a/arbitrator/tools/stylus_benchmark/src/main.rs +++ b/arbitrator/tools/stylus_benchmark/src/main.rs @@ -4,10 +4,9 @@ mod benchmark; mod scenario; -use clap::Parser; +use clap::{Parser, ValueEnum}; use scenario::Scenario; use std::path::PathBuf; -use strum::IntoEnumIterator; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] @@ -20,7 +19,7 @@ struct Args { } fn handle_scenario(scenario: Scenario, output_wat_dir_path: Option) -> eyre::Result<()> { - println!("Benchmarking {}", scenario); + println!("Benchmarking {:?}", scenario); let wat = scenario::generate_wat(scenario, output_wat_dir_path); benchmark::benchmark(wat) } @@ -32,8 +31,8 @@ fn main() -> eyre::Result<()> { Some(scenario) => handle_scenario(scenario, args.output_wat_dir_path), None => { println!("No scenario specified, benchmarking all scenarios\n"); - for scenario in Scenario::iter() { - let benchmark_result = handle_scenario(scenario, args.output_wat_dir_path.clone()); + for scenario in Scenario::value_variants() { + let benchmark_result = handle_scenario(*scenario, args.output_wat_dir_path.clone()); if let Err(err) = benchmark_result { return Err(err); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 348678ed69..cfd2d59aa4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,13 +4,13 @@ use std::fs::File; use std::io::Write; use std::path::PathBuf; -use strum_macros::{Display, EnumIter, EnumString}; +use clap::ValueEnum; +use std::fmt; -#[derive(Copy, Clone, PartialEq, Eq, Debug, EnumString, Display, EnumIter)] +#[derive(ValueEnum, Copy, Clone, PartialEq, Eq, Debug)] +#[clap(rename_all = "PascalCase")] pub enum Scenario { - #[strum(serialize = "add_i32")] AddI32, - #[strum(serialize = "xor_i32")] XorI32, } @@ -119,7 +119,7 @@ pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> // print wat to file if needed if let Some(output_wat_dir_path) = output_wat_dir_path { let mut output_wat_path = output_wat_dir_path; - output_wat_path.push(format!("{}.wat", scenario)); + output_wat_path.push(format!("{:?}.wat", scenario)); let mut file = File::create(output_wat_path).unwrap(); file.write_all(&wat).unwrap(); } From ed480a006c1926d6cdc44d9273fb13a79134c57e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Mon, 6 Jan 2025 16:34:54 -0300 Subject: [PATCH 032/131] Prints ink per nano second instead of micro second --- arbitrator/tools/stylus_benchmark/src/benchmark.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/benchmark.rs b/arbitrator/tools/stylus_benchmark/src/benchmark.rs index 3cc2aabb7d..84a9b40af8 100644 --- a/arbitrator/tools/stylus_benchmark/src/benchmark.rs +++ b/arbitrator/tools/stylus_benchmark/src/benchmark.rs @@ -94,11 +94,11 @@ pub fn benchmark(wat: Vec) -> eyre::Result<()> { durations = durations[l..r].to_vec(); let avg_duration = durations.iter().sum::() / (r - l) as u32; - let avg_ink_spent_per_micro_second = ink_spent.0 / avg_duration.as_micros() as u64; + let avg_ink_spent_per_nano_second = ink_spent.0 / avg_duration.as_nanos() as u64; println!("After discarding top and bottom runs: "); println!( - "avg_duration: {:?}, avg_ink_spent_per_micro_second: {:?}", - avg_duration, avg_ink_spent_per_micro_second + "avg_duration: {:?}, avg_ink_spent_per_nano_second: {:?}", + avg_duration, avg_ink_spent_per_nano_second ); Ok(()) From c6f0ec841c24a6e2a5bd4f1bc9998b2103573c0d Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Mon, 6 Jan 2025 16:53:45 -0300 Subject: [PATCH 033/131] CallIndirect benchmark --- .../tools/stylus_benchmark/src/scenario.rs | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index cfd2d59aa4..4b63494191 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,17 +1,17 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use clap::ValueEnum; use std::fs::File; use std::io::Write; use std::path::PathBuf; -use clap::ValueEnum; -use std::fmt; #[derive(ValueEnum, Copy, Clone, PartialEq, Eq, Debug)] #[clap(rename_all = "PascalCase")] pub enum Scenario { AddI32, XorI32, + CallIndirect, } // Programs to be benchmarked have a loop in which several similar operations are executed. @@ -19,7 +19,7 @@ pub enum Scenario { // but not too large to avoid a big program size. // Keeping a small program size is important to better use CPU cache, trying to keep the code in the cache. -fn write_wat_beginning(wat: &mut Vec) { +fn write_common_wat_beginning(wat: &mut Vec) { wat.write_all(b"(module\n").unwrap(); wat.write_all(b" (import \"debug\" \"start_benchmark\" (func $start_benchmark))\n") .unwrap(); @@ -29,12 +29,17 @@ fn write_wat_beginning(wat: &mut Vec) { .unwrap(); wat.write_all(b" (global $ops_counter (mut i32) (i32.const 0))\n") .unwrap(); +} + +fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" (func (export \"user_entrypoint\") (param i32) (result i32)\n") .unwrap(); wat.write_all(b" call $start_benchmark\n").unwrap(); wat.write_all(b" (loop $loop\n").unwrap(); + wat.write_all(b" call $start_benchmark\n") + .unwrap(); } fn write_wat_end( @@ -73,13 +78,19 @@ fn write_wat_end( wat.write_all(b")").unwrap(); } -fn wat(write_wat_ops: fn(&mut Vec, usize)) -> Vec { +fn wat( + write_specific_wat_beginning: fn(&mut Vec), + write_wat_ops: fn(&mut Vec, usize), +) -> Vec { let number_of_loop_iterations = 200_000; let number_of_ops_per_loop_iteration = 2000; let mut wat = Vec::new(); - write_wat_beginning(&mut wat); + write_common_wat_beginning(&mut wat); + write_specific_wat_beginning(&mut wat); + + write_exported_func_beginning(&mut wat); write_wat_ops(&mut wat, number_of_ops_per_loop_iteration); @@ -110,10 +121,33 @@ fn write_xor_i32_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: us wat.write_all(b" drop\n").unwrap(); } +fn write_call_indirect_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (type $nop_func_type (func))\n") + .unwrap(); + wat.write_all(b" (func $nop nop)\n").unwrap(); + wat.write_all(b" (table 1 funcref)\n").unwrap(); + wat.write_all(b" (elem (i32.const 0) $nop)\n") + .unwrap(); +} + +fn write_call_indirect_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" i32.const 0\n").unwrap(); + wat.write_all(b" call_indirect (type $nop_func_type)\n") + .unwrap(); + } +} + +fn noop_write_specific_wat_beginning(_: &mut Vec) {} + pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> Vec { let wat = match scenario { - Scenario::AddI32 => wat(write_add_i32_wat_ops), - Scenario::XorI32 => wat(write_xor_i32_wat_ops), + Scenario::AddI32 => wat(noop_write_specific_wat_beginning, write_add_i32_wat_ops), + Scenario::XorI32 => wat(noop_write_specific_wat_beginning, write_xor_i32_wat_ops), + Scenario::CallIndirect => wat( + write_call_indirect_wat_beginning, + write_call_indirect_wat_ops, + ), }; // print wat to file if needed From 6f71e92865bb239f3e3c2a09fc9362bdc96ea128 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 09:41:23 -0300 Subject: [PATCH 034/131] ScenarioWatGenerator trait --- arbitrator/tools/stylus_benchmark/src/main.rs | 1 + .../tools/stylus_benchmark/src/scenario.rs | 89 +++++++------------ .../stylus_benchmark/src/scenarios/add_i32.rs | 15 ++++ .../src/scenarios/call_indirect.rs | 21 +++++ .../stylus_benchmark/src/scenarios/mod.rs | 6 ++ .../stylus_benchmark/src/scenarios/xor_i32.rs | 15 ++++ 6 files changed, 91 insertions(+), 56 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs diff --git a/arbitrator/tools/stylus_benchmark/src/main.rs b/arbitrator/tools/stylus_benchmark/src/main.rs index c2d55ef06c..297acc1867 100644 --- a/arbitrator/tools/stylus_benchmark/src/main.rs +++ b/arbitrator/tools/stylus_benchmark/src/main.rs @@ -3,6 +3,7 @@ mod benchmark; mod scenario; +mod scenarios; use clap::{Parser, ValueEnum}; use scenario::Scenario; diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 4b63494191..a06d380784 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,6 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use crate::scenarios::{add_i32, call_indirect, xor_i32}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -14,6 +15,35 @@ pub enum Scenario { CallIndirect, } +trait ScenarioWatGenerator { + fn write_specific_wat_beginning(&self, wat: &mut Vec); + fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize); +} + +impl ScenarioWatGenerator for Scenario { + fn write_specific_wat_beginning(&self, wat: &mut Vec) { + match self { + Scenario::AddI32 => add_i32::write_specific_wat_beginning(wat), + Scenario::XorI32 => xor_i32::write_specific_wat_beginning(wat), + Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), + } + } + + fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + match self { + Scenario::AddI32 => { + add_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration); + } + Scenario::XorI32 => { + xor_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration); + } + Scenario::CallIndirect => { + call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration); + } + } + } +} + // Programs to be benchmarked have a loop in which several similar operations are executed. // The number of operations per loop is chosen to be large enough so the overhead related to the loop is negligible, // but not too large to avoid a big program size. @@ -78,21 +108,18 @@ fn write_wat_end( wat.write_all(b")").unwrap(); } -fn wat( - write_specific_wat_beginning: fn(&mut Vec), - write_wat_ops: fn(&mut Vec, usize), -) -> Vec { +pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> Vec { let number_of_loop_iterations = 200_000; let number_of_ops_per_loop_iteration = 2000; let mut wat = Vec::new(); write_common_wat_beginning(&mut wat); - write_specific_wat_beginning(&mut wat); + scenario.write_specific_wat_beginning(&mut wat); write_exported_func_beginning(&mut wat); - write_wat_ops(&mut wat, number_of_ops_per_loop_iteration); + scenario.write_wat_ops(&mut wat, number_of_ops_per_loop_iteration); write_wat_end( &mut wat, @@ -100,56 +127,6 @@ fn wat( number_of_ops_per_loop_iteration, ); - wat.to_vec() -} - -fn write_add_i32_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.add\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} - -fn write_xor_i32_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 12312313\n").unwrap(); - wat.write_all(b" i32.xor\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} - -fn write_call_indirect_wat_beginning(wat: &mut Vec) { - wat.write_all(b" (type $nop_func_type (func))\n") - .unwrap(); - wat.write_all(b" (func $nop nop)\n").unwrap(); - wat.write_all(b" (table 1 funcref)\n").unwrap(); - wat.write_all(b" (elem (i32.const 0) $nop)\n") - .unwrap(); -} - -fn write_call_indirect_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { - for _ in 0..number_of_loop_iterations { - wat.write_all(b" i32.const 0\n").unwrap(); - wat.write_all(b" call_indirect (type $nop_func_type)\n") - .unwrap(); - } -} - -fn noop_write_specific_wat_beginning(_: &mut Vec) {} - -pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> Vec { - let wat = match scenario { - Scenario::AddI32 => wat(noop_write_specific_wat_beginning, write_add_i32_wat_ops), - Scenario::XorI32 => wat(noop_write_specific_wat_beginning, write_xor_i32_wat_ops), - Scenario::CallIndirect => wat( - write_call_indirect_wat_beginning, - write_call_indirect_wat_ops, - ), - }; - // print wat to file if needed if let Some(output_wat_dir_path) = output_wat_dir_path { let mut output_wat_path = output_wat_dir_path; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs new file mode 100644 index 0000000000..dc259357aa --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.add\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs new file mode 100644 index 0000000000..b104720c44 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs @@ -0,0 +1,21 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (type $nop_func_type (func))\n") + .unwrap(); + wat.write_all(b" (func $nop nop)\n").unwrap(); + wat.write_all(b" (table 1 funcref)\n").unwrap(); + wat.write_all(b" (elem (i32.const 0) $nop)\n") + .unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" i32.const 0\n").unwrap(); + wat.write_all(b" call_indirect (type $nop_func_type)\n") + .unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs new file mode 100644 index 0000000000..05cffcd8a3 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -0,0 +1,6 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +pub mod add_i32; +pub mod xor_i32; +pub mod call_indirect; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs new file mode 100644 index 0000000000..bd38fa8b34 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1231\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 12312313\n").unwrap(); + wat.write_all(b" i32.xor\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} From d6a92ad8d3a86c7ab7b418a3716120870f77b76e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 09:50:37 -0300 Subject: [PATCH 035/131] If scenario --- .../tools/stylus_benchmark/src/scenario.rs | 15 +++++++-------- .../stylus_benchmark/src/scenarios/if_op.rs | 17 +++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index a06d380784..24e6dfb7f7 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{add_i32, call_indirect, xor_i32}; +use crate::scenarios::{add_i32, call_indirect, if_op, xor_i32}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -13,6 +13,7 @@ pub enum Scenario { AddI32, XorI32, CallIndirect, + If, } trait ScenarioWatGenerator { @@ -26,20 +27,18 @@ impl ScenarioWatGenerator for Scenario { Scenario::AddI32 => add_i32::write_specific_wat_beginning(wat), Scenario::XorI32 => xor_i32::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), + Scenario::If => if_op::write_specific_wat_beginning(wat), } } fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { - Scenario::AddI32 => { - add_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration); - } - Scenario::XorI32 => { - xor_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration); - } + Scenario::AddI32 => add_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::XorI32 => xor_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { - call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration); + call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } + Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs new file mode 100644 index 0000000000..71559f78ea --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs @@ -0,0 +1,17 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 0\n").unwrap(); + wat.write_all(b" (if\n").unwrap(); + wat.write_all(b" (then\n").unwrap(); + wat.write_all(b" nop\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 05cffcd8a3..e4db532417 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,3 +4,4 @@ pub mod add_i32; pub mod xor_i32; pub mod call_indirect; +pub mod if_op; From 84839efdc480bc4dd2c03711d0da61b56ba9e190 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 09:57:57 -0300 Subject: [PATCH 036/131] Fix: removes start_benchmark inside loop --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 24e6dfb7f7..e32a222d64 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -67,8 +67,6 @@ fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" call $start_benchmark\n").unwrap(); wat.write_all(b" (loop $loop\n").unwrap(); - wat.write_all(b" call $start_benchmark\n") - .unwrap(); } fn write_wat_end( From 5ea72c06903582048cebf057bde43b6d5dcdd8ce Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:07:51 -0300 Subject: [PATCH 037/131] GlobalGet --- .../tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/global_get.rs | 16 ++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index e32a222d64..537f14b2ef 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{add_i32, call_indirect, if_op, xor_i32}; +use crate::scenarios::{add_i32, call_indirect, global_get, if_op, xor_i32}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -13,6 +13,7 @@ pub enum Scenario { AddI32, XorI32, CallIndirect, + GlobalGet, If, } @@ -27,6 +28,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::AddI32 => add_i32::write_specific_wat_beginning(wat), Scenario::XorI32 => xor_i32::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), + Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), } } @@ -38,6 +40,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } + Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs new file mode 100644 index 0000000000..f053ad8782 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (global $var i32 (i32.const 10))\n") + .unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" global.get $var\n").unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index e4db532417..c2ad9b7937 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,4 +4,5 @@ pub mod add_i32; pub mod xor_i32; pub mod call_indirect; +pub mod global_get; pub mod if_op; From 8c10174f1fc10d29b2ce7cff0c7549b87f7c6b46 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:11:04 -0300 Subject: [PATCH 038/131] add_i32 -> i32_add, xor_i32 -> i32_xor --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 14 +++++++------- .../src/scenarios/{add_i32.rs => i32_add.rs} | 0 .../src/scenarios/{xor_i32.rs => i32_xor.rs} | 0 .../tools/stylus_benchmark/src/scenarios/mod.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) rename arbitrator/tools/stylus_benchmark/src/scenarios/{add_i32.rs => i32_add.rs} (100%) rename arbitrator/tools/stylus_benchmark/src/scenarios/{xor_i32.rs => i32_xor.rs} (100%) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 537f14b2ef..9fa15b4199 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{add_i32, call_indirect, global_get, if_op, xor_i32}; +use crate::scenarios::{call_indirect, global_get, i32_add, i32_xor, if_op}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -10,8 +10,8 @@ use std::path::PathBuf; #[derive(ValueEnum, Copy, Clone, PartialEq, Eq, Debug)] #[clap(rename_all = "PascalCase")] pub enum Scenario { - AddI32, - XorI32, + I32Add, + I32Xor, CallIndirect, GlobalGet, If, @@ -25,8 +25,8 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { - Scenario::AddI32 => add_i32::write_specific_wat_beginning(wat), - Scenario::XorI32 => xor_i32::write_specific_wat_beginning(wat), + Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -35,8 +35,8 @@ impl ScenarioWatGenerator for Scenario { fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { - Scenario::AddI32 => add_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::XorI32 => xor_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs similarity index 100% rename from arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs rename to arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs similarity index 100% rename from arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs rename to arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index c2ad9b7937..dd0fe57b04 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -1,8 +1,8 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -pub mod add_i32; -pub mod xor_i32; +pub mod i32_add; +pub mod i32_xor; pub mod call_indirect; pub mod global_get; pub mod if_op; From b47fc570165ff1cbfd077add2d015f538f243caf Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:18:15 -0300 Subject: [PATCH 039/131] GlobalSet --- .../tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/global_set.rs | 16 ++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 9fa15b4199..db91f5cb17 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call_indirect, global_get, i32_add, i32_xor, if_op}; +use crate::scenarios::{call_indirect, global_get, global_set, i32_add, i32_xor, if_op}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -14,6 +14,7 @@ pub enum Scenario { I32Xor, CallIndirect, GlobalGet, + GlobalSet, If, } @@ -29,6 +30,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), + Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), } } @@ -41,6 +43,7 @@ impl ScenarioWatGenerator for Scenario { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs new file mode 100644 index 0000000000..1e648d7a85 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (global $var (mut i32) (i32.const 0))\n") + .unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" i32.const 10\n").unwrap(); + wat.write_all(b" global.set $var\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index dd0fe57b04..60a6368214 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -5,4 +5,5 @@ pub mod i32_add; pub mod i32_xor; pub mod call_indirect; pub mod global_get; +pub mod global_set; pub mod if_op; From 78efd18b687ca278d159914e2adb3bc3f6f5444a Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:44:18 -0300 Subject: [PATCH 040/131] Call --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 13 ++++++++----- .../tools/stylus_benchmark/src/scenarios/call.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/call.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index db91f5cb17..58f549bf7b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call_indirect, global_get, global_set, i32_add, i32_xor, if_op}; +use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_xor, if_op}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -12,6 +12,7 @@ use std::path::PathBuf; pub enum Scenario { I32Add, I32Xor, + Call, CallIndirect, GlobalGet, GlobalSet, @@ -26,24 +27,26 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { - Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), - Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), + Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), + Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), } } fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { - Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs new file mode 100644 index 0000000000..6160001510 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (func $nop nop)\n").unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" call $nop\n") + .unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 60a6368214..8ac1dc6444 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,6 +3,7 @@ pub mod i32_add; pub mod i32_xor; +pub mod call; pub mod call_indirect; pub mod global_get; pub mod global_set; From 7f2456245ce1cace901734560d2b22dc15717f1d Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:53:40 -0300 Subject: [PATCH 041/131] Select --- .../tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + .../stylus_benchmark/src/scenarios/select.rs | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/select.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 58f549bf7b..f8e6dd5857 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_xor, if_op}; +use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_xor, if_op, select}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -17,6 +17,7 @@ pub enum Scenario { GlobalGet, GlobalSet, If, + Select, } trait ScenarioWatGenerator { @@ -34,6 +35,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), + Scenario::Select => select::write_specific_wat_beginning(wat), } } @@ -48,6 +50,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8ac1dc6444..3f556a6072 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -8,3 +8,4 @@ pub mod call_indirect; pub mod global_get; pub mod global_set; pub mod if_op; +pub mod select; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs new file mode 100644 index 0000000000..a1487e47d0 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 10\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 20\n").unwrap(); + wat.write_all(b" i32.const 0\n").unwrap(); + wat.write_all(b" select\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} From 4f797c124dca8f673a388dd007f35f5aac9b8ed9 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 11:03:43 -0300 Subject: [PATCH 042/131] I32Eqz --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_eqz.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index f8e6dd5857..9cff07bbcc 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_xor, if_op, select}; +use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_eqz, i32_xor, if_op, select}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -11,6 +11,7 @@ use std::path::PathBuf; #[clap(rename_all = "PascalCase")] pub enum Scenario { I32Add, + I32Eqz, I32Xor, Call, CallIndirect, @@ -33,6 +34,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -48,6 +50,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs new file mode 100644 index 0000000000..15752cc800 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.eqz\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 3f556a6072..e2f41c4264 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod i32_add; +pub mod i32_eqz; pub mod i32_xor; pub mod call; pub mod call_indirect; From fb4fcf0fabaebb004923ac6c081390251051d558 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 11:05:23 -0300 Subject: [PATCH 043/131] I32Eq --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 ++++++- .../stylus_benchmark/src/scenarios/i32_eq.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 9cff07bbcc..3100f6fb1b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,9 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_eqz, i32_xor, if_op, select}; +use crate::scenarios::{ + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_xor, if_op, select, +}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -11,6 +13,7 @@ use std::path::PathBuf; #[clap(rename_all = "PascalCase")] pub enum Scenario { I32Add, + I32Eq, I32Eqz, I32Xor, Call, @@ -34,6 +37,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -50,6 +54,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs new file mode 100644 index 0000000000..8918f1b2e8 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.eq\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index e2f41c4264..decf8aba3a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod i32_add; +pub mod i32_eq; pub mod i32_eqz; pub mod i32_xor; pub mod call; From 7bc887bdb05b8471710f00b5e29a4c4c79a49de4 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 11:08:00 -0300 Subject: [PATCH 044/131] I32Ne --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 6 +++++- .../stylus_benchmark/src/scenarios/i32_ne.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 3100f6fb1b..996899c566 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ne, i32_xor, if_op, + select, }; use clap::ValueEnum; use std::fs::File; @@ -15,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32Ne, I32Xor, Call, CallIndirect, @@ -39,6 +41,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -56,6 +59,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs new file mode 100644 index 0000000000..139743938c --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.ne\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index decf8aba3a..6bc6f1f19b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_ne; pub mod i32_xor; pub mod call; pub mod call_indirect; From 1fb803dafe79e59be09e31f75371c2041cc80411 Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Tue, 7 Jan 2025 09:36:34 -0700 Subject: [PATCH 045/131] Update geth in for flatcalltracer fix Pulls in the following go-ethereum PRs https://github.com/OffchainLabs/go-ethereum/pull/372 https://github.com/OffchainLabs/go-ethereum/pull/385 https://github.com/OffchainLabs/go-ethereum/pull/393 --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index 26b4dff616..dd32b782ed 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 26b4dff6165650b6963fb1b6f88958c29c059214 +Subproject commit dd32b782ed255c1ac20ed5beee11dd6a821f9be2 From 6e0758e0fe3425b54d3c1d44e33b0896454d8b70 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:10:48 -0300 Subject: [PATCH 046/131] i32_lt_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_lt_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 996899c566..31b700bc03 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ne, i32_xor, if_op, - select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_lt_s, i32_ne, + i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32LtS, I32Ne, I32Xor, Call, @@ -41,6 +42,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -59,6 +61,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs new file mode 100644 index 0000000000..2adcbcfc4a --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.lt_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 6bc6f1f19b..6d49ab92c0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_lt_s; pub mod i32_ne; pub mod i32_xor; pub mod call; From c6e2b0f31192579ad4d514ef2bff15cae64d143c Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:12:58 -0300 Subject: [PATCH 047/131] i32_lt_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_lt_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 31b700bc03..ce04db71e1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_lt_s, i32_ne, - i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_lt_s, i32_lt_u, + i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32LtU, I32LtS, I32Ne, I32Xor, @@ -42,6 +43,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), @@ -61,6 +63,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs new file mode 100644 index 0000000000..59ba86f600 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.lt_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 6d49ab92c0..5c6586d944 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; pub mod i32_xor; From 5f2b8c8dc511efdd44160220ee0ee5b9b9e752ab Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:16:42 -0300 Subject: [PATCH 048/131] stylus_benchmark: i32_gt_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_gt_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index ce04db71e1..edad346def 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_lt_s, i32_lt_u, - i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_lt_s, + i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32GtS, I32LtU, I32LtS, I32Ne, @@ -43,6 +44,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), @@ -63,6 +65,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs new file mode 100644 index 0000000000..59a5c59afc --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.gt_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 5c6586d944..d0b532be4a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_gt_s; pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; From 45468070a6d723ed7b92abf87951a9a24fac8c57 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:19:46 -0300 Subject: [PATCH 049/131] stylus_benchmark: i32_gt_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_gt_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index edad346def..03650d2e7b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_lt_s, - i32_lt_u, i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_gt_u, + i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32GtU, I32GtS, I32LtU, I32LtS, @@ -44,6 +45,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), @@ -65,6 +67,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs new file mode 100644 index 0000000000..ae057bc1e6 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.gt_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index d0b532be4a..d21321cfe5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_gt_u; pub mod i32_gt_s; pub mod i32_lt_u; pub mod i32_lt_s; From f802dbe3185da08992768d7374d67a1a6dade079 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:28:26 -0300 Subject: [PATCH 050/131] stylus_benchmark: i32_le_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_le_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 03650d2e7b..958d91a855 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_gt_u, - i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + i32_le_s, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -18,6 +18,7 @@ pub enum Scenario { I32Eqz, I32GtU, I32GtS, + I32LeS, I32LtU, I32LtS, I32Ne, @@ -47,6 +48,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), + Scenario::I32LeS => i32_le_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), @@ -69,6 +71,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32LeS => i32_le_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs new file mode 100644 index 0000000000..8e8621a18c --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.le_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index d21321cfe5..303bc81c46 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -6,6 +6,7 @@ pub mod i32_eq; pub mod i32_eqz; pub mod i32_gt_u; pub mod i32_gt_s; +pub mod i32_le_s; pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; From b7448068e7ac6b36a252989c71009e2347211dab Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:29:55 -0300 Subject: [PATCH 051/131] stylus_benchmark: i32_le_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_le_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 958d91a855..055ca639cb 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_gt_u, - i32_le_s, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + i32_le_u, i32_le_s, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -18,6 +18,7 @@ pub enum Scenario { I32Eqz, I32GtU, I32GtS, + I32LeU, I32LeS, I32LtU, I32LtS, @@ -48,6 +49,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), + Scenario::I32LeU => i32_le_u::write_specific_wat_beginning(wat), Scenario::I32LeS => i32_le_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), @@ -71,6 +73,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32LeU => i32_le_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LeS => i32_le_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs new file mode 100644 index 0000000000..abf69ca27d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.le_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 303bc81c46..b730155eb0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -6,6 +6,7 @@ pub mod i32_eq; pub mod i32_eqz; pub mod i32_gt_u; pub mod i32_gt_s; +pub mod i32_le_u; pub mod i32_le_s; pub mod i32_lt_u; pub mod i32_lt_s; From ec72c2a862d7ba63b814c4cf824b8e4a57a37caa Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:31:46 -0300 Subject: [PATCH 052/131] stylus_benchmark: i32.ge_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_ge_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 055ca639cb..e569b11995 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_gt_u, - i32_le_u, i32_le_s, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ge_s, i32_gt_s, + i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32GeS, I32GtU, I32GtS, I32LeU, @@ -47,6 +48,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), Scenario::I32LeU => i32_le_u::write_specific_wat_beginning(wat), @@ -71,6 +73,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LeU => i32_le_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs new file mode 100644 index 0000000000..f2b4cd1b5d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.ge_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index b730155eb0..5591d6535c 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_ge_s; pub mod i32_gt_u; pub mod i32_gt_s; pub mod i32_le_u; From 6c0ed575f6e12c0f6ab0b5b6957c619de653d57e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:34:25 -0300 Subject: [PATCH 053/131] stylus_benchmark: i32.ge_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_ge_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index e569b11995..ce094ce295 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ge_s, i32_gt_s, - i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, + i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -17,6 +17,7 @@ pub enum Scenario { I32Eq, I32Eqz, I32GeS, + I32GeU, I32GtU, I32GtS, I32LeU, @@ -49,6 +50,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), + Scenario::I32GeU => i32_ge_u::write_specific_wat_beginning(wat), Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), Scenario::I32LeU => i32_le_u::write_specific_wat_beginning(wat), @@ -74,6 +76,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GeU => i32_ge_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LeU => i32_le_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs new file mode 100644 index 0000000000..524fc106d0 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.ge_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 5591d6535c..a5d813a2bf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_ge_u; pub mod i32_ge_s; pub mod i32_gt_u; pub mod i32_gt_s; From 0e440c5da9971baf84399ed4f2bb1e23c91bdd34 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 16:12:02 -0300 Subject: [PATCH 054/131] stylus_benchmark: i32.clz --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 8 ++++++-- .../stylus_benchmark/src/scenarios/i32_clz.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index ce094ce295..5cce4f6961 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, - i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_eq, i32_eqz, i32_ge_s, + i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, + select, }; use clap::ValueEnum; use std::fs::File; @@ -14,6 +15,7 @@ use std::path::PathBuf; #[clap(rename_all = "PascalCase")] pub enum Scenario { I32Add, + I32Clz, I32Eq, I32Eqz, I32GeS, @@ -47,6 +49,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), @@ -73,6 +76,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs new file mode 100644 index 0000000000..398908e09d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1231\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.clz\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index a5d813a2bf..c193ef4bb6 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod i32_add; +pub mod i32_clz; pub mod i32_eq; pub mod i32_eqz; pub mod i32_ge_u; From 4ab50eb7153779920144657bc64809c4fb0d578e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 16:15:25 -0300 Subject: [PATCH 055/131] stylus_benchmark: i32.ctz --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 9 ++++++--- .../stylus_benchmark/src/scenarios/i32_ctz.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 5cce4f6961..feaf4663b3 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_eq, i32_eqz, i32_ge_s, - i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, - select, + call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, + i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, + i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ use std::path::PathBuf; pub enum Scenario { I32Add, I32Clz, + I32Ctz, I32Eq, I32Eqz, I32GeS, @@ -50,6 +51,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), + Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), @@ -77,6 +79,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs new file mode 100644 index 0000000000..822b5a899d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1231\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.ctz\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index c193ef4bb6..94ac00ead6 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,6 +3,7 @@ pub mod i32_add; pub mod i32_clz; +pub mod i32_ctz; pub mod i32_eq; pub mod i32_eqz; pub mod i32_ge_u; From 55c41f58fab13878c75f3a1ffad8245926360305 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 7 Jan 2025 14:09:57 -0600 Subject: [PATCH 056/131] bold submod to main --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index 70c9755ae1..a537dac0c5 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit 70c9755ae1b731f1b2fdedb986461754e4da2e8f +Subproject commit a537dac0c5fc95a07afe54dad4d7691121a4f484 From 7acdd8fa8dcb11d54b63746416ab5c0e1dce6d8c Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 18:07:44 -0700 Subject: [PATCH 057/131] update nightly version and fix wasm --- .github/workflows/arbitrator-ci.yml | 2 +- .github/workflows/ci.yml | 2 +- Makefile | 26 ++++++++++++++++++++++ arbitrator/stylus/tests/.cargo/config.toml | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index dd58a30571..d9c4618e8b 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -76,7 +76,7 @@ jobs: uses: dtolnay/rust-toolchain@nightly id: install-rust-nightly with: - toolchain: 'nightly-2024-08-06' + toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'rust-src, rustfmt, clippy' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1eda1d9b7e..e9e184f786 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: uses: dtolnay/rust-toolchain@nightly id: install-rust-nightly with: - toolchain: 'nightly-2024-08-06' + toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'rust-src, rustfmt, clippy' diff --git a/Makefile b/Makefile index 12dfb07cf8..39b221dcee 100644 --- a/Makefile +++ b/Makefile @@ -440,54 +440,80 @@ $(stylus_test_dir)/%.wasm: $(stylus_test_dir)/%.b $(stylus_lang_bf) $(stylus_test_keccak_wasm): $(stylus_test_keccak_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_keccak-100_wasm): $(stylus_test_keccak-100_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_fallible_wasm): $(stylus_test_fallible_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_storage_wasm): $(stylus_test_storage_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_multicall_wasm): $(stylus_test_multicall_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_log_wasm): $(stylus_test_log_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_create_wasm): $(stylus_test_create_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_math_wasm): $(stylus_test_math_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_evm-data_wasm): $(stylus_test_evm-data_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_read-return-data_wasm): $(stylus_test_read-return-data_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_sdk-storage_wasm): $(stylus_test_sdk-storage_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_erc20_wasm): $(stylus_test_erc20_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary $(stylus_test_hostio-test_wasm): $(stylus_test_hostio-test_src) $(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo) + wasm2wat $@ > $@.wat #removing reference types + wat2wasm $@.wat -o $@ @touch -c $@ # cargo might decide to not rebuild the binary contracts/test/prover/proofs/float%.json: $(arbitrator_cases)/float%.wasm $(prover_bin) $(output_latest)/soft-float.wasm diff --git a/arbitrator/stylus/tests/.cargo/config.toml b/arbitrator/stylus/tests/.cargo/config.toml index 702a5c04b3..6ca5e18651 100644 --- a/arbitrator/stylus/tests/.cargo/config.toml +++ b/arbitrator/stylus/tests/.cargo/config.toml @@ -5,6 +5,7 @@ target = "wasm32-unknown-unknown" rustflags = [ "-C", "target-cpu=mvp", "-C", "link-arg=-zstack-size=8192", + "-C", "target-feature=-reference-types", # "-C", "link-arg=--export=__heap_base", # "-C", "link-arg=--export=__data_end", ] From 25ea73540716bf602e90bdb0587f35162dcf2531 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 18:35:22 -0700 Subject: [PATCH 058/131] fix rust stable to 1.80.1 --- .github/workflows/arbitrator-ci.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index d9c4618e8b..b765acee99 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -69,7 +69,7 @@ jobs: - name: Install rust stable uses: dtolnay/rust-toolchain@stable with: - toolchain: 'stable' + toolchain: '1.80.1' components: 'llvm-tools-preview, rustfmt, clippy' - name: Install rust nightly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9e184f786..b943b34686 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,7 @@ jobs: - name: Install rust stable uses: dtolnay/rust-toolchain@stable with: - toolchain: 'stable' + toolchain: '1.80.1' targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'llvm-tools-preview, rustfmt, clippy' From 6a66ea4db34886e13f1a317b97737b70f3bf3908 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 19:44:52 -0700 Subject: [PATCH 059/131] ci: only use stable clippy --- .github/workflows/arbitrator-ci.yml | 3 ++- .github/workflows/ci.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index b765acee99..3ef8d336ff 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -67,6 +67,7 @@ jobs: cache-dependency-path: '**/yarn.lock' - name: Install rust stable + id: install-rust uses: dtolnay/rust-toolchain@stable with: toolchain: '1.80.1' @@ -78,7 +79,7 @@ jobs: with: toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' - components: 'rust-src, rustfmt, clippy' + components: 'rust-src, rustfmt' - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b943b34686..006c01a378 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,7 @@ jobs: - name: Install rust stable uses: dtolnay/rust-toolchain@stable + id: install-rust with: toolchain: '1.80.1' targets: 'wasm32-wasi, wasm32-unknown-unknown' @@ -66,7 +67,7 @@ jobs: with: toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' - components: 'rust-src, rustfmt, clippy' + components: 'rust-src, rustfmt' - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" From fb03fe67e1bec2fe9959915448e484add6d8d61f Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 19:31:06 -0700 Subject: [PATCH 060/131] clippy fixes: initial --- arbitrator/arbutil/src/operator.rs | 4 ++-- arbitrator/jit/src/caller_env.rs | 2 +- arbitrator/prover/src/binary.rs | 2 +- arbitrator/prover/src/programs/counter.rs | 2 +- arbitrator/prover/src/programs/depth.rs | 4 ++-- arbitrator/prover/src/programs/meter.rs | 2 +- arbitrator/prover/src/programs/mod.rs | 6 +++--- arbitrator/stylus/src/env.rs | 10 +++++----- arbitrator/stylus/src/host.rs | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/arbitrator/arbutil/src/operator.rs b/arbitrator/arbutil/src/operator.rs index cc1f684366..9abf237a66 100644 --- a/arbitrator/arbutil/src/operator.rs +++ b/arbitrator/arbutil/src/operator.rs @@ -595,13 +595,13 @@ impl Display for OperatorCode { } } -impl<'a> From> for OperatorCode { +impl From> for OperatorCode { fn from(op: Operator) -> Self { OperatorCode::from(&op) } } -impl<'a> From<&Operator<'a>> for OperatorCode { +impl From<&Operator<'_>> for OperatorCode { fn from(op: &Operator) -> Self { use Operator as O; diff --git a/arbitrator/jit/src/caller_env.rs b/arbitrator/jit/src/caller_env.rs index 41240d3d98..9fe4288d21 100644 --- a/arbitrator/jit/src/caller_env.rs +++ b/arbitrator/jit/src/caller_env.rs @@ -34,7 +34,7 @@ impl<'a> JitEnv<'a> for WasmEnvMut<'a> { } } -impl<'s> JitMemAccess<'s> { +impl JitMemAccess<'_> { fn view(&self) -> MemoryView { self.memory.view(&self.store) } diff --git a/arbitrator/prover/src/binary.rs b/arbitrator/prover/src/binary.rs index 2260f6bf48..77bc44ec4c 100644 --- a/arbitrator/prover/src/binary.rs +++ b/arbitrator/prover/src/binary.rs @@ -499,7 +499,7 @@ pub fn parse<'a>(input: &'a [u8], path: &'_ Path) -> Result> { Ok(binary) } -impl<'a> Debug for WasmBinary<'a> { +impl Debug for WasmBinary<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("WasmBinary") .field("types", &self.types) diff --git a/arbitrator/prover/src/programs/counter.rs b/arbitrator/prover/src/programs/counter.rs index cd54178cf8..4006e70ee6 100644 --- a/arbitrator/prover/src/programs/counter.rs +++ b/arbitrator/prover/src/programs/counter.rs @@ -75,7 +75,7 @@ pub struct FuncCounter<'a> { block: Vec>, } -impl<'a> FuncCounter<'a> { +impl FuncCounter<'_> { fn new(counters: Arc>>) -> Self { let block = vec![]; Self { counters, block } diff --git a/arbitrator/prover/src/programs/depth.rs b/arbitrator/prover/src/programs/depth.rs index 2000190917..fb0e0cb6d2 100644 --- a/arbitrator/prover/src/programs/depth.rs +++ b/arbitrator/prover/src/programs/depth.rs @@ -107,7 +107,7 @@ pub struct FuncDepthChecker<'a> { done: bool, } -impl<'a> FuncDepthChecker<'a> { +impl FuncDepthChecker<'_> { fn new( global: GlobalIndex, funcs: Arc>, @@ -227,7 +227,7 @@ impl<'a> FuncMiddleware<'a> for FuncDepthChecker<'a> { } } -impl<'a> FuncDepthChecker<'a> { +impl FuncDepthChecker<'_> { fn worst_case_depth(&self) -> Result { use Operator::*; diff --git a/arbitrator/prover/src/programs/meter.rs b/arbitrator/prover/src/programs/meter.rs index 0d7b3151d7..258c932944 100644 --- a/arbitrator/prover/src/programs/meter.rs +++ b/arbitrator/prover/src/programs/meter.rs @@ -122,7 +122,7 @@ pub struct FuncMeter<'a, F: OpcodePricer> { sigs: Arc, } -impl<'a, F: OpcodePricer> FuncMeter<'a, F> { +impl FuncMeter<'_, F> { fn new( ink_global: GlobalIndex, status_global: GlobalIndex, diff --git a/arbitrator/prover/src/programs/mod.rs b/arbitrator/prover/src/programs/mod.rs index a35308e7ff..517ccc1971 100644 --- a/arbitrator/prover/src/programs/mod.rs +++ b/arbitrator/prover/src/programs/mod.rs @@ -244,7 +244,7 @@ impl ModuleMod for ModuleInfo { fn drop_exports_and_names(&mut self, keep: &HashMap<&str, ExportKind>) { self.exports.retain(|name, export| { keep.get(name.as_str()) - .map_or(false, |x| *x == (*export).into()) + .is_some_and(|x| *x == (*export).into()) }); self.function_names.clear(); } @@ -263,7 +263,7 @@ impl ModuleMod for ModuleInfo { } } -impl<'a> ModuleMod for WasmBinary<'a> { +impl ModuleMod for WasmBinary<'_> { fn add_global(&mut self, name: &str, _ty: Type, init: GlobalInit) -> Result { let global = match init { GlobalInit::I32Const(x) => Value::I32(x as u32), @@ -364,7 +364,7 @@ impl<'a> ModuleMod for WasmBinary<'a> { fn drop_exports_and_names(&mut self, keep: &HashMap<&str, ExportKind>) { self.exports - .retain(|name, ty| keep.get(name.as_str()).map_or(false, |x| *x == ty.1)); + .retain(|name, ty| keep.get(name.as_str()).is_some_and(|x| *x == ty.1)); self.names.functions.clear(); } diff --git a/arbitrator/stylus/src/env.rs b/arbitrator/stylus/src/env.rs index a2c8189029..ef12d2480a 100644 --- a/arbitrator/stylus/src/env.rs +++ b/arbitrator/stylus/src/env.rs @@ -147,7 +147,7 @@ pub struct HostioInfo<'a, D: DataReader, E: EvmApi> { pub start_ink: Ink, } -impl<'a, D: DataReader, E: EvmApi> HostioInfo<'a, D, E> { +impl> HostioInfo<'_, D, E> { pub fn config(&self) -> StylusConfig { self.config.expect("no config") } @@ -172,7 +172,7 @@ impl<'a, D: DataReader, E: EvmApi> HostioInfo<'a, D, E> { } } -impl<'a, D: DataReader, E: EvmApi> MeteredMachine for HostioInfo<'a, D, E> { +impl> MeteredMachine for HostioInfo<'_, D, E> { fn ink_left(&self) -> MachineMeter { let vm = self.env.meter(); match vm.status() { @@ -188,13 +188,13 @@ impl<'a, D: DataReader, E: EvmApi> MeteredMachine for HostioInfo<'a, D, E> { } } -impl<'a, D: DataReader, E: EvmApi> GasMeteredMachine for HostioInfo<'a, D, E> { +impl> GasMeteredMachine for HostioInfo<'_, D, E> { fn pricing(&self) -> PricingParams { self.config().pricing } } -impl<'a, D: DataReader, E: EvmApi> Deref for HostioInfo<'a, D, E> { +impl> Deref for HostioInfo<'_, D, E> { type Target = WasmEnv; fn deref(&self) -> &Self::Target { @@ -202,7 +202,7 @@ impl<'a, D: DataReader, E: EvmApi> Deref for HostioInfo<'a, D, E> { } } -impl<'a, D: DataReader, E: EvmApi> DerefMut for HostioInfo<'a, D, E> { +impl> DerefMut for HostioInfo<'_, D, E> { fn deref_mut(&mut self) -> &mut Self::Target { self.env } diff --git a/arbitrator/stylus/src/host.rs b/arbitrator/stylus/src/host.rs index 67497302a1..c4fc7cea1e 100644 --- a/arbitrator/stylus/src/host.rs +++ b/arbitrator/stylus/src/host.rs @@ -22,7 +22,7 @@ use std::{ use user_host_trait::UserHost; use wasmer::{MemoryAccessError, WasmPtr}; -impl<'a, DR, A> UserHost for HostioInfo<'a, DR, A> +impl UserHost for HostioInfo<'_, DR, A> where DR: DataReader, A: EvmApi, From 00cb2f9b5ab025e13dd156c6cda346149aa10985 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 20:30:29 -0700 Subject: [PATCH 061/131] circumvent lifetime errors from clippy --- arbitrator/prover/src/programs/meter.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/arbitrator/prover/src/programs/meter.rs b/arbitrator/prover/src/programs/meter.rs index 258c932944..cfb91e647d 100644 --- a/arbitrator/prover/src/programs/meter.rs +++ b/arbitrator/prover/src/programs/meter.rs @@ -1,5 +1,6 @@ // Copyright 2022-2023, Offchain Labs, Inc. // For license information, see https://github.com/nitro/blob/master/LICENSE +#![allow(clippy::needless_lifetimes)] use crate::{ programs::{ From 82274225c91ce0a294485cac8c5472dc468768f1 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 20:54:53 -0700 Subject: [PATCH 062/131] ci: add nightly clippy back --- .github/workflows/arbitrator-ci.yml | 16 ++++++++-------- .github/workflows/ci.yml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 3ef8d336ff..45cf3c1a3d 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -66,20 +66,20 @@ jobs: cache: 'yarn' cache-dependency-path: '**/yarn.lock' - - name: Install rust stable - id: install-rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: '1.80.1' - components: 'llvm-tools-preview, rustfmt, clippy' - - name: Install rust nightly uses: dtolnay/rust-toolchain@nightly id: install-rust-nightly with: toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' - components: 'rust-src, rustfmt' + components: 'rust-src, rustfmt, clippy' + + - name: Install rust stable + id: install-rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: '1.80.1' + components: 'llvm-tools-preview, rustfmt, clippy' - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 006c01a378..b4ce5bf27f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: with: toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' - components: 'rust-src, rustfmt' + components: 'rust-src, rustfmt, clippy' - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" From 12c76eac50b8b30d90874452f449128a91897067 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 21:10:09 -0700 Subject: [PATCH 063/131] arbitrator ci: stable after nightly --- .github/workflows/arbitrator-ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 3ef8d336ff..0552fc4a3a 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -66,13 +66,6 @@ jobs: cache: 'yarn' cache-dependency-path: '**/yarn.lock' - - name: Install rust stable - id: install-rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: '1.80.1' - components: 'llvm-tools-preview, rustfmt, clippy' - - name: Install rust nightly uses: dtolnay/rust-toolchain@nightly id: install-rust-nightly @@ -81,6 +74,13 @@ jobs: targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'rust-src, rustfmt' + - name: Install rust stable + id: install-rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: '1.80.1' + components: 'llvm-tools-preview, rustfmt, clippy' + - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" From ffa2f67140f44223eab539524d9019983ed32c07 Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Wed, 8 Jan 2025 13:38:54 +0100 Subject: [PATCH 064/131] Add the wasm targets to the stable rust installation Without these targets the build was complaining about the missing `core` crate and suggested installing them. --- .github/workflows/arbitrator-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 45cf3c1a3d..51c0617f3e 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -79,6 +79,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: '1.80.1' + targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'llvm-tools-preview, rustfmt, clippy' - name: Set STYLUS_NIGHTLY_VER environment variable From 2f95a47fbae4d4b82f017cb4afa587b64d9c9b2f Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:04:25 -0300 Subject: [PATCH 065/131] stylus_benchmark: i32.popcnt --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_popcnt.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index feaf4663b3..449ccb869f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, - i32_xor, if_op, select, + i32_popcnt, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -28,6 +28,7 @@ pub enum Scenario { I32LtU, I32LtS, I32Ne, + I32Popcnt, I32Xor, Call, CallIndirect, @@ -63,6 +64,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), + Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -91,6 +93,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs new file mode 100644 index 0000000000..294a3a7b93 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1231\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.popcnt\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 94ac00ead6..aece3c7233 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -15,6 +15,7 @@ pub mod i32_le_s; pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; +pub mod i32_popcnt; pub mod i32_xor; pub mod call; pub mod call_indirect; From badbb5b7193934505914ba1ca92e1b59ea9d86bb Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:07:01 -0300 Subject: [PATCH 066/131] stylus_benchmark: i32.sub --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_sub.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 449ccb869f..9faaff4568 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, - i32_popcnt, i32_xor, if_op, select, + i32_popcnt, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -29,6 +29,7 @@ pub enum Scenario { I32LtS, I32Ne, I32Popcnt, + I32Sub, I32Xor, Call, CallIndirect, @@ -65,6 +66,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), + Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -94,6 +96,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs new file mode 100644 index 0000000000..54c0e1f0e5 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 10000000\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.sub\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index aece3c7233..562950a14e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -16,6 +16,7 @@ pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; pub mod i32_popcnt; +pub mod i32_sub; pub mod i32_xor; pub mod call; pub mod call_indirect; From 92f8756b85adf898ca1adb28165bd3a5427f25f0 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:09:18 -0300 Subject: [PATCH 067/131] stylus_benchmark: i32.mul --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_mul.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 9faaff4568..8ef1745215 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,8 +3,8 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, - i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, - i32_popcnt, i32_sub, i32_xor, if_op, select, + i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, + i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -27,6 +27,7 @@ pub enum Scenario { I32LeS, I32LtU, I32LtS, + I32Mul, I32Ne, I32Popcnt, I32Sub, @@ -64,6 +65,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LeS => i32_le_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), + Scenario::I32Mul => i32_mul::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), @@ -94,6 +96,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LeS => i32_le_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Mul => i32_mul::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs new file mode 100644 index 0000000000..0e156920a2 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.mul\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 562950a14e..e5542be2e4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -14,6 +14,7 @@ pub mod i32_le_u; pub mod i32_le_s; pub mod i32_lt_u; pub mod i32_lt_s; +pub mod i32_mul; pub mod i32_ne; pub mod i32_popcnt; pub mod i32_sub; From 535a2f544547201d213c200c19d28278aacffda0 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:15:28 -0300 Subject: [PATCH 068/131] stylus_benchmark: i32.div_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 9 ++++++--- .../stylus_benchmark/src/scenarios/i32_div_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 8ef1745215..017579f9b1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, - i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, - i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_eq, + i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, + i32_mul, i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -17,6 +17,7 @@ pub enum Scenario { I32Add, I32Clz, I32Ctz, + I32DivS, I32Eq, I32Eqz, I32GeS, @@ -55,6 +56,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), + Scenario::I32DivS => i32_div_s::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), @@ -86,6 +88,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32DivS => i32_div_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs new file mode 100644 index 0000000000..b9404408f1 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.div_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index e5542be2e4..85273d0e31 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_clz; pub mod i32_ctz; +pub mod i32_div_s; pub mod i32_eq; pub mod i32_eqz; pub mod i32_ge_u; From c602d733b3b6278fea22ac18d2d2a347311c787a Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:17:16 -0300 Subject: [PATCH 069/131] stylus_benchmark: i32.div_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 9 ++++++--- .../stylus_benchmark/src/scenarios/i32_div_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 017579f9b1..cf055339d2 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_eq, - i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, - i32_mul, i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_div_u, + i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, + i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -18,6 +18,7 @@ pub enum Scenario { I32Clz, I32Ctz, I32DivS, + I32DivU, I32Eq, I32Eqz, I32GeS, @@ -57,6 +58,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), Scenario::I32DivS => i32_div_s::write_specific_wat_beginning(wat), + Scenario::I32DivU => i32_div_u::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), @@ -89,6 +91,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32DivS => i32_div_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32DivU => i32_div_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs new file mode 100644 index 0000000000..4183dcd82f --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.div_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 85273d0e31..891c7e3e45 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_clz; pub mod i32_ctz; +pub mod i32_div_u; pub mod i32_div_s; pub mod i32_eq; pub mod i32_eqz; From 5088d6ed2139a5f24776a7ea28358f832b72c195 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:19:26 -0300 Subject: [PATCH 070/131] stylus_benchmark: i32.rem_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_rem_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index cf055339d2..caf284a63a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, - i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, + i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -32,6 +32,7 @@ pub enum Scenario { I32Mul, I32Ne, I32Popcnt, + I32RemS, I32Sub, I32Xor, Call, @@ -72,6 +73,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Mul => i32_mul::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), + Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -105,6 +107,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Mul => i32_mul::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs new file mode 100644 index 0000000000..f9cd4f5fda --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.rem_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 891c7e3e45..0e49692bc2 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,8 +4,8 @@ pub mod i32_add; pub mod i32_clz; pub mod i32_ctz; -pub mod i32_div_u; pub mod i32_div_s; +pub mod i32_div_u; pub mod i32_eq; pub mod i32_eqz; pub mod i32_ge_u; @@ -19,6 +19,7 @@ pub mod i32_lt_s; pub mod i32_mul; pub mod i32_ne; pub mod i32_popcnt; +pub mod i32_rem_s; pub mod i32_sub; pub mod i32_xor; pub mod call; From a06b8543516865a3aa3edd90efced7653df1f17e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:22:14 -0300 Subject: [PATCH 071/131] stylus_benchmark: i32.rem_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_rem_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index caf284a63a..4fc93ee01b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, - i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_sub, i32_xor, if_op, select, + i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -33,6 +33,7 @@ pub enum Scenario { I32Ne, I32Popcnt, I32RemS, + I32RemU, I32Sub, I32Xor, Call, @@ -74,6 +75,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), + Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -108,6 +110,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs new file mode 100644 index 0000000000..1fc645ae94 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.rem_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 0e49692bc2..b79e9ac771 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -20,6 +20,7 @@ pub mod i32_mul; pub mod i32_ne; pub mod i32_popcnt; pub mod i32_rem_s; +pub mod i32_rem_u; pub mod i32_sub; pub mod i32_xor; pub mod call; From 926482319b9efd2aebefff8982ede7a795c570a1 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:23:53 -0300 Subject: [PATCH 072/131] stylus_benchmark: i32.and --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 10 +++++++--- .../stylus_benchmark/src/scenarios/i32_and.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 4fc93ee01b..be632f047e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,10 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_div_u, - i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, - i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, + i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, + i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, i32_xor, if_op, + select, }; use clap::ValueEnum; use std::fs::File; @@ -15,6 +16,7 @@ use std::path::PathBuf; #[clap(rename_all = "PascalCase")] pub enum Scenario { I32Add, + I32And, I32Clz, I32Ctz, I32DivS, @@ -57,6 +59,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32And => i32_and::write_specific_wat_beginning(wat), Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), Scenario::I32DivS => i32_div_s::write_specific_wat_beginning(wat), @@ -92,6 +95,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32And => i32_and::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32DivS => i32_div_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs new file mode 100644 index 0000000000..1ffc094058 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 11111\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1111111\n").unwrap(); + wat.write_all(b" i32.and\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index b79e9ac771..c4ceeabf06 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod i32_add; +pub mod i32_and; pub mod i32_clz; pub mod i32_ctz; pub mod i32_div_s; From eeb1aafa7cf549ebcdb60eb847865f40bc1ae4f9 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:25:44 -0300 Subject: [PATCH 073/131] stylus_benchmark: i32.or --- .../tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_or.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 17 +++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index be632f047e..902a67bf0e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,8 +4,8 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, - i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, i32_xor, if_op, - select, + i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, + i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -33,6 +33,7 @@ pub enum Scenario { I32LtS, I32Mul, I32Ne, + I32Or, I32Popcnt, I32RemS, I32RemU, @@ -76,6 +77,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Mul => i32_mul::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), + Scenario::I32Or => i32_or::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), @@ -112,6 +114,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Mul => i32_mul::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Or => i32_or::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs new file mode 100644 index 0000000000..7bf3343e56 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 23132213\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 12344\n").unwrap(); + wat.write_all(b" i32.or\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index c4ceeabf06..a28a8a9e77 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -1,6 +1,10 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +pub mod call; +pub mod call_indirect; +pub mod global_get; +pub mod global_set; pub mod i32_add; pub mod i32_and; pub mod i32_clz; @@ -9,24 +13,21 @@ pub mod i32_div_s; pub mod i32_div_u; pub mod i32_eq; pub mod i32_eqz; -pub mod i32_ge_u; pub mod i32_ge_s; -pub mod i32_gt_u; +pub mod i32_ge_u; pub mod i32_gt_s; -pub mod i32_le_u; +pub mod i32_gt_u; pub mod i32_le_s; -pub mod i32_lt_u; +pub mod i32_le_u; pub mod i32_lt_s; +pub mod i32_lt_u; pub mod i32_mul; pub mod i32_ne; +pub mod i32_or; pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; pub mod i32_sub; pub mod i32_xor; -pub mod call; -pub mod call_indirect; -pub mod global_get; -pub mod global_set; pub mod if_op; pub mod select; From 929ad0710e1f489c1848ef2af0994111bbb6032b Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:30:40 -0300 Subject: [PATCH 074/131] stylus_benchmark: i32.shl --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_shl.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 902a67bf0e..d85442beda 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,8 +4,8 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, - i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, - i32_xor, if_op, select, + i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_shl, + i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -37,6 +37,7 @@ pub enum Scenario { I32Popcnt, I32RemS, I32RemU, + I32Shl, I32Sub, I32Xor, Call, @@ -81,6 +82,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), + Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -118,6 +120,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs new file mode 100644 index 0000000000..b15f446e99 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1212323\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.shl\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index a28a8a9e77..8395286699 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -27,6 +27,7 @@ pub mod i32_or; pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; +pub mod i32_shl; pub mod i32_sub; pub mod i32_xor; pub mod if_op; From 559f08312980517620bc8ab591c2421b02f3c618 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:43:33 -0300 Subject: [PATCH 075/131] stylus_benchmark: i32.shr_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_shr_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index d85442beda..76aa40d4d8 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -5,7 +5,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_shl, - i32_sub, i32_xor, if_op, select, + i32_shr_s, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -38,6 +38,7 @@ pub enum Scenario { I32RemS, I32RemU, I32Shl, + I32ShrS, I32Sub, I32Xor, Call, @@ -83,6 +84,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), + Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -121,6 +123,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs new file mode 100644 index 0000000000..1ac8afa24d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 123123\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.shr_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8395286699..168d70870b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -28,6 +28,7 @@ pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; pub mod i32_shl; +pub mod i32_shr_s; pub mod i32_sub; pub mod i32_xor; pub mod if_op; From f43c579899e19afd3228c158a4d4f41b496b095b Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:44:53 -0300 Subject: [PATCH 076/131] stylus_benchmark: i32.shr_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_shr_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 76aa40d4d8..f1db0efe4f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -5,7 +5,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_shl, - i32_shr_s, i32_sub, i32_xor, if_op, select, + i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -39,6 +39,7 @@ pub enum Scenario { I32RemU, I32Shl, I32ShrS, + I32ShrU, I32Sub, I32Xor, Call, @@ -85,6 +86,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), + Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -124,6 +126,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs new file mode 100644 index 0000000000..5539710521 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 123123\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.shr_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 168d70870b..8d3f402a11 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -29,6 +29,7 @@ pub mod i32_rem_s; pub mod i32_rem_u; pub mod i32_shl; pub mod i32_shr_s; +pub mod i32_shr_u; pub mod i32_sub; pub mod i32_xor; pub mod if_op; From 6f9a9f3d978cb1050dcc0e69581ad7a4daab1535 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:46:29 -0300 Subject: [PATCH 077/131] stylus_benchmark: i32.rotl --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_rotl.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index f1db0efe4f..126d10c099 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,8 +4,8 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, - i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_shl, - i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, + i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_rotl, + i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -37,6 +37,7 @@ pub enum Scenario { I32Popcnt, I32RemS, I32RemU, + I32Rotl, I32Shl, I32ShrS, I32ShrU, @@ -84,6 +85,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), + Scenario::I32Rotl => i32_rotl::write_specific_wat_beginning(wat), Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), @@ -124,6 +126,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Rotl => i32_rotl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs new file mode 100644 index 0000000000..de2edc73f1 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 123123\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.rotl\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8d3f402a11..8ffb9ca0cf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -27,6 +27,7 @@ pub mod i32_or; pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; +pub mod i32_rotl; pub mod i32_shl; pub mod i32_shr_s; pub mod i32_shr_u; From 05c4288ac38d36edd58148acad5abacd5f62b80a Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:49:13 -0300 Subject: [PATCH 078/131] stylus_benchmark: i32.rotr --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_rotr.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 126d10c099..3083a181a8 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -5,7 +5,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_rotl, - i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, + i32_rotr, i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -38,6 +38,7 @@ pub enum Scenario { I32RemS, I32RemU, I32Rotl, + I32Rotr, I32Shl, I32ShrS, I32ShrU, @@ -86,6 +87,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), Scenario::I32Rotl => i32_rotl::write_specific_wat_beginning(wat), + Scenario::I32Rotr => i32_rotr::write_specific_wat_beginning(wat), Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), @@ -127,6 +129,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Rotl => i32_rotl::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Rotr => i32_rotr::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs new file mode 100644 index 0000000000..c2ab4e666e --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 123123\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.rotr\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8ffb9ca0cf..4ab9d7175f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -28,6 +28,7 @@ pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; pub mod i32_rotl; +pub mod i32_rotr; pub mod i32_shl; pub mod i32_shr_s; pub mod i32_shr_u; From 7bfc31ae709b1c19ca35a764353fdc740d87d962 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:56:00 -0300 Subject: [PATCH 079/131] stylus_benchmark: i32.wrap_i64 --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_wrap_i64.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 3083a181a8..9d8061faa4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -5,7 +5,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_rotl, - i32_rotr, i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, + i32_rotr, i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_wrap_i64, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -43,6 +43,7 @@ pub enum Scenario { I32ShrS, I32ShrU, I32Sub, + I32WrapI64, I32Xor, Call, CallIndirect, @@ -92,6 +93,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), + Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -134,6 +136,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32WrapI64 => i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs new file mode 100644 index 0000000000..2634615447 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i64.const 123123\n").unwrap(); + wat.write_all(b" i32.wrap_i64\n").unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 4ab9d7175f..7088335107 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -33,6 +33,7 @@ pub mod i32_shl; pub mod i32_shr_s; pub mod i32_shr_u; pub mod i32_sub; +pub mod i32_wrap_i64; pub mod i32_xor; pub mod if_op; pub mod select; From 79b3af04cbe77ea8f071658968e04278c9757d93 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Wed, 8 Jan 2025 10:07:23 -0600 Subject: [PATCH 080/131] update main --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index a537dac0c5..290743f517 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit a537dac0c5fc95a07afe54dad4d7691121a4f484 +Subproject commit 290743f517f7a94d62460231399fb095cb18c3a4 From b0a8e387ca50cb7618de505fde751148914bb5d0 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 15:45:21 -0300 Subject: [PATCH 081/131] instruction_with_2_args_1_return --- .../tools/stylus_benchmark/src/scenario.rs | 260 ++++++++++++++---- .../stylus_benchmark/src/scenarios/i32_add.rs | 15 - .../stylus_benchmark/src/scenarios/i32_and.rs | 15 - .../src/scenarios/i32_div_s.rs | 15 - .../src/scenarios/i32_div_u.rs | 15 - .../stylus_benchmark/src/scenarios/i32_eq.rs | 15 - .../src/scenarios/i32_ge_s.rs | 15 - .../src/scenarios/i32_ge_u.rs | 15 - .../src/scenarios/i32_gt_s.rs | 15 - .../src/scenarios/i32_gt_u.rs | 15 - .../src/scenarios/i32_le_s.rs | 15 - .../src/scenarios/i32_le_u.rs | 15 - .../src/scenarios/i32_lt_s.rs | 15 - .../src/scenarios/i32_lt_u.rs | 15 - .../stylus_benchmark/src/scenarios/i32_mul.rs | 15 - .../stylus_benchmark/src/scenarios/i32_ne.rs | 15 - .../stylus_benchmark/src/scenarios/i32_or.rs | 15 - .../src/scenarios/i32_rem_s.rs | 15 - .../src/scenarios/i32_rem_u.rs | 15 - .../src/scenarios/i32_rotl.rs | 15 - .../src/scenarios/i32_rotr.rs | 15 - .../stylus_benchmark/src/scenarios/i32_shl.rs | 15 - .../src/scenarios/i32_shr_s.rs | 15 - .../src/scenarios/i32_shr_u.rs | 15 - .../stylus_benchmark/src/scenarios/i32_sub.rs | 15 - .../stylus_benchmark/src/scenarios/i32_xor.rs | 15 - .../instruction_with_2_args_1_return.rs | 13 + .../stylus_benchmark/src/scenarios/mod.rs | 26 +- 28 files changed, 219 insertions(+), 455 deletions(-) delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 9d8061faa4..c70a5ba9e4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,10 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, - i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, - i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_rotl, - i32_rotr, i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_wrap_i64, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_eqz, i32_popcnt, i32_wrap_i64, if_op, i32_ctz, i32_clz, + instruction_with_2_args_1_return, select, }; use clap::ValueEnum; use std::fs::File; @@ -65,36 +63,36 @@ impl ScenarioWatGenerator for Scenario { Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), - Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), - Scenario::I32And => i32_and::write_specific_wat_beginning(wat), + Scenario::I32Add => {} + Scenario::I32And => {} Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), - Scenario::I32DivS => i32_div_s::write_specific_wat_beginning(wat), - Scenario::I32DivU => i32_div_u::write_specific_wat_beginning(wat), - Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), + Scenario::I32DivS => {} + Scenario::I32DivU => {} + Scenario::I32Eq => {} Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), - Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), - Scenario::I32GeU => i32_ge_u::write_specific_wat_beginning(wat), - Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), - Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), - Scenario::I32LeU => i32_le_u::write_specific_wat_beginning(wat), - Scenario::I32LeS => i32_le_s::write_specific_wat_beginning(wat), - Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), - Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), - Scenario::I32Mul => i32_mul::write_specific_wat_beginning(wat), - Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), - Scenario::I32Or => i32_or::write_specific_wat_beginning(wat), + Scenario::I32GeS => {} + Scenario::I32GeU => {} + Scenario::I32GtU => {} + Scenario::I32GtS => {} + Scenario::I32LeU => {} + Scenario::I32LeS => {} + Scenario::I32LtU => {} + Scenario::I32LtS => {} + Scenario::I32Mul => {} + Scenario::I32Ne => {} + Scenario::I32Or => {} Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), - Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), - Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), - Scenario::I32Rotl => i32_rotl::write_specific_wat_beginning(wat), - Scenario::I32Rotr => i32_rotr::write_specific_wat_beginning(wat), - Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), - Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), - Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), - Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), + Scenario::I32RemS => {} + Scenario::I32RemU => {} + Scenario::I32Rotl => {} + Scenario::I32Rotr => {} + Scenario::I32Shl => {} + Scenario::I32ShrS => {} + Scenario::I32ShrU => {} + Scenario::I32Sub => {} Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), - Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), + Scenario::I32Xor => {} Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), } @@ -108,36 +106,188 @@ impl ScenarioWatGenerator for Scenario { } Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32And => i32_and::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Add => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.add", + 0, + 1, + ), + Scenario::I32And => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.and", + 0, + 1, + ), Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32DivS => i32_div_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32DivU => i32_div_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.div_s", + 1, + 1, + ), + Scenario::I32DivU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.div_u", + 1, + 1, + ), + Scenario::I32Eq => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.eq", + 0, + 1, + ), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32GeU => i32_ge_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32LeU => i32_le_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32LeS => i32_le_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Mul => i32_mul::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Or => i32_or::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.ge_s", + 0, + 1, + ), + Scenario::I32GeU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.ge_u", + 0, + 1, + ), + Scenario::I32GtU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.gt_u", + 0, + 1, + ), + Scenario::I32GtS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.gt_s", + 0, + 1, + ), + Scenario::I32LeU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.le_u", + 0, + 1, + ), + Scenario::I32LeS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.le_s", + 0, + 1, + ), + Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.lt_u", + 0, + 1, + ), + Scenario::I32LtS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.lt_s", + 0, + 1, + ), + Scenario::I32Mul => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.mul", + 0, + 1, + ), + Scenario::I32Ne => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.ne", + 0, + 1, + ), + Scenario::I32Or => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.or", + 0, + 1, + ), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Rotl => i32_rotl::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Rotr => i32_rotr::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32WrapI64 => i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.rem_s", + 1, + 1, + ), + Scenario::I32RemU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.rem_u", + 1, + 1, + ), + Scenario::I32Rotl => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.rotl", + 11231, + 1, + ), + Scenario::I32Rotr => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.rotr", + 11231, + 1, + ), + Scenario::I32Shl => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.shl", + 11231, + 1, + ), + Scenario::I32ShrS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.shr_s", + 11231, + 1, + ), + Scenario::I32ShrU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.shr_u", + 11231, + 1, + ), + Scenario::I32Sub => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.sub", + 11231, + 1, + ), + Scenario::I32WrapI64 => { + i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration) + } + Scenario::I32Xor => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.xor", + 11231, + 13242, + ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs deleted file mode 100644 index dc259357aa..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.add\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs deleted file mode 100644 index 1ffc094058..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 11111\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1111111\n").unwrap(); - wat.write_all(b" i32.and\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs deleted file mode 100644 index b9404408f1..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.div_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs deleted file mode 100644 index 4183dcd82f..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.div_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs deleted file mode 100644 index 8918f1b2e8..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.eq\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs deleted file mode 100644 index f2b4cd1b5d..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.ge_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs deleted file mode 100644 index 524fc106d0..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.ge_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs deleted file mode 100644 index 59a5c59afc..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.gt_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs deleted file mode 100644 index ae057bc1e6..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.gt_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs deleted file mode 100644 index 8e8621a18c..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.le_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs deleted file mode 100644 index abf69ca27d..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.le_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs deleted file mode 100644 index 2adcbcfc4a..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.lt_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs deleted file mode 100644 index 59ba86f600..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.lt_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs deleted file mode 100644 index 0e156920a2..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.mul\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs deleted file mode 100644 index 139743938c..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.ne\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs deleted file mode 100644 index 7bf3343e56..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 23132213\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 12344\n").unwrap(); - wat.write_all(b" i32.or\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs deleted file mode 100644 index f9cd4f5fda..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.rem_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs deleted file mode 100644 index 1fc645ae94..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.rem_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs deleted file mode 100644 index de2edc73f1..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 123123\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.rotl\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs deleted file mode 100644 index c2ab4e666e..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 123123\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.rotr\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs deleted file mode 100644 index b15f446e99..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1212323\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.shl\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs deleted file mode 100644 index 1ac8afa24d..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 123123\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.shr_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs deleted file mode 100644 index 5539710521..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 123123\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.shr_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs deleted file mode 100644 index 54c0e1f0e5..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 10000000\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.sub\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs deleted file mode 100644 index bd38fa8b34..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 12312313\n").unwrap(); - wat.write_all(b" i32.xor\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs new file mode 100644 index 0000000000..610bf33c8a --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -0,0 +1,13 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, instruction: &str, first_arg: usize, second_arg: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(format!(" i32.const {}\n", first_arg).as_bytes()).unwrap(); + wat.write_all(format!(" i32.const {}\n", second_arg).as_bytes()).unwrap(); + wat.write_all(format!(" {}\n", instruction).as_bytes()).unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 7088335107..f217ca80ea 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -5,35 +5,11 @@ pub mod call; pub mod call_indirect; pub mod global_get; pub mod global_set; -pub mod i32_add; -pub mod i32_and; pub mod i32_clz; pub mod i32_ctz; -pub mod i32_div_s; -pub mod i32_div_u; -pub mod i32_eq; pub mod i32_eqz; -pub mod i32_ge_s; -pub mod i32_ge_u; -pub mod i32_gt_s; -pub mod i32_gt_u; -pub mod i32_le_s; -pub mod i32_le_u; -pub mod i32_lt_s; -pub mod i32_lt_u; -pub mod i32_mul; -pub mod i32_ne; -pub mod i32_or; pub mod i32_popcnt; -pub mod i32_rem_s; -pub mod i32_rem_u; -pub mod i32_rotl; -pub mod i32_rotr; -pub mod i32_shl; -pub mod i32_shr_s; -pub mod i32_shr_u; -pub mod i32_sub; pub mod i32_wrap_i64; -pub mod i32_xor; pub mod if_op; +pub mod instruction_with_2_args_1_return; pub mod select; From b122e7088539c97a92322c9ab5b8c73813e68e11 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 16:46:50 -0300 Subject: [PATCH 082/131] instruction_with_1_arg_1_return --- .../tools/stylus_benchmark/src/scenario.rs | 40 ++++++++++++++----- .../stylus_benchmark/src/scenarios/i32_ctz.rs | 14 ------- .../stylus_benchmark/src/scenarios/i32_eqz.rs | 14 ------- .../src/scenarios/i32_popcnt.rs | 14 ------- ....rs => instruction_with_1_arg_1_return.rs} | 10 ++--- .../stylus_benchmark/src/scenarios/mod.rs | 5 +-- 6 files changed, 35 insertions(+), 62 deletions(-) delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs rename arbitrator/tools/stylus_benchmark/src/scenarios/{i32_clz.rs => instruction_with_1_arg_1_return.rs} (50%) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index c70a5ba9e4..20db7496fe 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_eqz, i32_popcnt, i32_wrap_i64, if_op, i32_ctz, i32_clz, - instruction_with_2_args_1_return, select, + call, call_indirect, global_get, global_set, i32_wrap_i64, if_op, + instruction_with_1_arg_1_return, instruction_with_2_args_1_return, select, }; use clap::ValueEnum; use std::fs::File; @@ -65,12 +65,12 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => {} Scenario::I32And => {} - Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), - Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), + Scenario::I32Clz => {} + Scenario::I32Ctz => {} Scenario::I32DivS => {} Scenario::I32DivU => {} Scenario::I32Eq => {} - Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32Eqz => {} Scenario::I32GeS => {} Scenario::I32GeU => {} Scenario::I32GtU => {} @@ -82,7 +82,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Mul => {} Scenario::I32Ne => {} Scenario::I32Or => {} - Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), + Scenario::I32Popcnt => {} Scenario::I32RemS => {} Scenario::I32RemU => {} Scenario::I32Rotl => {} @@ -120,8 +120,18 @@ impl ScenarioWatGenerator for Scenario { 0, 1, ), - Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Clz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.clz", + 1231, + ), + Scenario::I32Ctz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.ctz", + 1231, + ), Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, @@ -143,7 +153,12 @@ impl ScenarioWatGenerator for Scenario { 0, 1, ), - Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Eqz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.eqz", + 1231, + ), Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, @@ -221,7 +236,12 @@ impl ScenarioWatGenerator for Scenario { 0, 1, ), - Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Popcnt => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.popcnt", + 1231, + ), Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs deleted file mode 100644 index 822b5a899d..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.ctz\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs deleted file mode 100644 index 15752cc800..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.eqz\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs deleted file mode 100644 index 294a3a7b93..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.popcnt\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs similarity index 50% rename from arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs rename to arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index 398908e09d..fd2d749a39 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -3,12 +3,10 @@ use std::io::Write; -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, instruction: &str, arg: usize) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.clz\n").unwrap(); + wat.write_all(format!(" i32.const {}\n", arg).as_bytes()).unwrap(); + wat.write_all(format!(" {}\n", instruction).as_bytes()).unwrap(); + wat.write_all(b" drop\n").unwrap(); } - wat.write_all(b" drop\n").unwrap(); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index f217ca80ea..29a2953018 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -5,11 +5,8 @@ pub mod call; pub mod call_indirect; pub mod global_get; pub mod global_set; -pub mod i32_clz; -pub mod i32_ctz; -pub mod i32_eqz; -pub mod i32_popcnt; pub mod i32_wrap_i64; pub mod if_op; pub mod instruction_with_2_args_1_return; +pub mod instruction_with_1_arg_1_return; pub mod select; From fbecd0fac8edcb49cdb719b7eb72c3b6adf68f9e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 17:09:19 -0300 Subject: [PATCH 083/131] Adds DataType to intruction_with_1_arg_1_return --- arbitrator/tools/stylus_benchmark/Cargo.lock | 27 +++++++++++++++++++ arbitrator/tools/stylus_benchmark/Cargo.toml | 2 ++ .../tools/stylus_benchmark/src/scenario.rs | 14 ++++++---- .../src/scenarios/data_type.rs | 12 +++++++++ .../instruction_with_1_arg_1_return.rs | 7 ++--- .../stylus_benchmark/src/scenarios/mod.rs | 3 ++- 6 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs diff --git a/arbitrator/tools/stylus_benchmark/Cargo.lock b/arbitrator/tools/stylus_benchmark/Cargo.lock index f1b9fb4996..1168b45a2a 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.lock +++ b/arbitrator/tools/stylus_benchmark/Cargo.lock @@ -1663,6 +1663,12 @@ dependencies = [ "semver", ] +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + [[package]] name = "ryu" version = "1.0.18" @@ -1903,6 +1909,25 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.87", +] + [[package]] name = "stylus" version = "0.1.0" @@ -1939,6 +1964,8 @@ dependencies = [ "eyre", "jit", "prover", + "strum", + "strum_macros", "stylus", "wasmer", "wasmer-compiler-cranelift", diff --git a/arbitrator/tools/stylus_benchmark/Cargo.toml b/arbitrator/tools/stylus_benchmark/Cargo.toml index 4f9ed74d46..e193fc0ca8 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.toml +++ b/arbitrator/tools/stylus_benchmark/Cargo.toml @@ -12,3 +12,5 @@ arbutil = { path = "../../arbutil/" } prover = { path = "../../prover/", default-features = false, features = ["native"] } stylus = { path = "../../stylus/", default-features = false } clap = { version = "4.4.8", features = ["derive"] } +strum = "0.26" +strum_macros = "0.26" diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 20db7496fe..a6ed2ff05f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_wrap_i64, if_op, + call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, select, }; use clap::ValueEnum; @@ -123,13 +123,15 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Clz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.clz", + DataType::I32, + "clz", 1231, ), Scenario::I32Ctz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.ctz", + DataType::I32, + "ctz", 1231, ), Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( @@ -156,7 +158,8 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.eqz", + DataType::I32, + "eqz", 1231, ), Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( @@ -239,7 +242,8 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.popcnt", + DataType::I32, + "popcnt", 1231, ), Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs new file mode 100644 index 0000000000..a3bd2228c7 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -0,0 +1,12 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use strum_macros::{Display, EnumString}; +use strum; + +#[derive(Debug, Display, EnumString)] +#[strum(serialize_all = "lowercase")] +pub enum DataType { + I32, + I64 +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index fd2d749a39..9e59adf41a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -2,11 +2,12 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; +use crate::scenarios::data_type::DataType; -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, instruction: &str, arg: usize) { +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str, arg: usize) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" i32.const {}\n", arg).as_bytes()).unwrap(); - wat.write_all(format!(" {}\n", instruction).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, arg).as_bytes()).unwrap(); + wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()).unwrap(); wat.write_all(b" drop\n").unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 29a2953018..7dd8bf31cf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,10 +3,11 @@ pub mod call; pub mod call_indirect; +pub mod data_type; pub mod global_get; pub mod global_set; pub mod i32_wrap_i64; pub mod if_op; -pub mod instruction_with_2_args_1_return; pub mod instruction_with_1_arg_1_return; +pub mod instruction_with_2_args_1_return; pub mod select; From 134c64acec261b22912c19d0ffd842a9ec5efb3a Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 17:19:35 -0300 Subject: [PATCH 084/131] Adds DataType to intruction_with_2_args_1_return --- .../tools/stylus_benchmark/src/scenario.rs | 75 ++++++++++++------- .../instruction_with_2_args_1_return.rs | 19 ++++- 2 files changed, 65 insertions(+), 29 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index a6ed2ff05f..c7b7bb953d 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -109,14 +109,16 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.add", + DataType::I32, + "add", 0, 1, ), Scenario::I32And => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.and", + DataType::I32, + "and", 0, 1, ), @@ -137,21 +139,24 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.div_s", + DataType::I32, + "div_s", 1, 1, ), Scenario::I32DivU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.div_u", + DataType::I32, + "div_u", 1, 1, ), Scenario::I32Eq => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.eq", + DataType::I32, + "eq", 0, 1, ), @@ -165,77 +170,88 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.ge_s", + DataType::I32, + "ge_s", 0, 1, ), Scenario::I32GeU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.ge_u", + DataType::I32, + "ge_u", 0, 1, ), Scenario::I32GtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.gt_u", + DataType::I32, + "gt_u", 0, 1, ), Scenario::I32GtS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.gt_s", + DataType::I32, + "gt_s", 0, 1, ), Scenario::I32LeU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.le_u", + DataType::I32, + "le_u", 0, 1, ), Scenario::I32LeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.le_s", + DataType::I32, + "le_s", 0, 1, ), Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.lt_u", + DataType::I32, + "lt_u", 0, 1, ), Scenario::I32LtS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.lt_s", + DataType::I32, + "lt_s", 0, 1, ), Scenario::I32Mul => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.mul", + DataType::I32, + "mul", 0, 1, ), Scenario::I32Ne => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.ne", + DataType::I32, + "ne", 0, 1, ), Scenario::I32Or => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.or", + DataType::I32, + "or", 0, 1, ), @@ -249,56 +265,64 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.rem_s", + DataType::I32, + "rem_s", 1, 1, ), Scenario::I32RemU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.rem_u", + DataType::I32, + "rem_u", 1, 1, ), Scenario::I32Rotl => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.rotl", + DataType::I32, + "rotl", 11231, 1, ), Scenario::I32Rotr => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.rotr", + DataType::I32, + "rotr", 11231, 1, ), Scenario::I32Shl => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.shl", + DataType::I32, + "shl", 11231, 1, ), Scenario::I32ShrS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.shr_s", + DataType::I32, + "shr_s", 11231, 1, ), Scenario::I32ShrU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.shr_u", + DataType::I32, + "shr_u", 11231, 1, ), Scenario::I32Sub => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.sub", + DataType::I32, + "sub", 11231, 1, ), @@ -308,7 +332,8 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Xor => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.xor", + DataType::I32, + "xor", 11231, 13242, ), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs index 610bf33c8a..7e8b893a5c 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -2,12 +2,23 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; +use crate::scenarios::data_type::DataType; -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, instruction: &str, first_arg: usize, second_arg: usize) { +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + data_type: DataType, + instruction: &str, + first_arg: usize, + second_arg: usize, +) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" i32.const {}\n", first_arg).as_bytes()).unwrap(); - wat.write_all(format!(" i32.const {}\n", second_arg).as_bytes()).unwrap(); - wat.write_all(format!(" {}\n", instruction).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, first_arg).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, second_arg).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) + .unwrap(); wat.write_all(b" drop\n").unwrap(); } } From f19ddc5da3cc8efac83d4484a1605f87b16eff4e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 10:31:33 -0300 Subject: [PATCH 085/131] stylus_benchmark: generate random values --- arbitrator/tools/stylus_benchmark/Cargo.lock | 1 + arbitrator/tools/stylus_benchmark/Cargo.toml | 1 + .../tools/stylus_benchmark/src/scenario.rs | 54 ------------------- .../src/scenarios/data_type.rs | 16 +++++- .../instruction_with_1_arg_1_return.rs | 6 +-- .../instruction_with_2_args_1_return.rs | 8 ++- 6 files changed, 23 insertions(+), 63 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/Cargo.lock b/arbitrator/tools/stylus_benchmark/Cargo.lock index 1168b45a2a..44a838fd15 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.lock +++ b/arbitrator/tools/stylus_benchmark/Cargo.lock @@ -1964,6 +1964,7 @@ dependencies = [ "eyre", "jit", "prover", + "rand", "strum", "strum_macros", "stylus", diff --git a/arbitrator/tools/stylus_benchmark/Cargo.toml b/arbitrator/tools/stylus_benchmark/Cargo.toml index e193fc0ca8..20d169e3e5 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.toml +++ b/arbitrator/tools/stylus_benchmark/Cargo.toml @@ -14,3 +14,4 @@ stylus = { path = "../../stylus/", default-features = false } clap = { version = "4.4.8", features = ["derive"] } strum = "0.26" strum_macros = "0.26" +rand = "0.8.5" diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index c7b7bb953d..3f7837a1cf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -111,220 +111,168 @@ impl ScenarioWatGenerator for Scenario { number_of_ops_per_loop_iteration, DataType::I32, "add", - 0, - 1, ), Scenario::I32And => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "and", - 0, - 1, ), Scenario::I32Clz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "clz", - 1231, ), Scenario::I32Ctz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "ctz", - 1231, ), Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "div_s", - 1, - 1, ), Scenario::I32DivU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "div_u", - 1, - 1, ), Scenario::I32Eq => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "eq", - 0, - 1, ), Scenario::I32Eqz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "eqz", - 1231, ), Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "ge_s", - 0, - 1, ), Scenario::I32GeU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "ge_u", - 0, - 1, ), Scenario::I32GtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "gt_u", - 0, - 1, ), Scenario::I32GtS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "gt_s", - 0, - 1, ), Scenario::I32LeU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "le_u", - 0, - 1, ), Scenario::I32LeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "le_s", - 0, - 1, ), Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "lt_u", - 0, - 1, ), Scenario::I32LtS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "lt_s", - 0, - 1, ), Scenario::I32Mul => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "mul", - 0, - 1, ), Scenario::I32Ne => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "ne", - 0, - 1, ), Scenario::I32Or => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "or", - 0, - 1, ), Scenario::I32Popcnt => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "popcnt", - 1231, ), Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "rem_s", - 1, - 1, ), Scenario::I32RemU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "rem_u", - 1, - 1, ), Scenario::I32Rotl => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "rotl", - 11231, - 1, ), Scenario::I32Rotr => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "rotr", - 11231, - 1, ), Scenario::I32Shl => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "shl", - 11231, - 1, ), Scenario::I32ShrS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "shr_s", - 11231, - 1, ), Scenario::I32ShrU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "shr_u", - 11231, - 1, ), Scenario::I32Sub => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "sub", - 11231, - 1, ), Scenario::I32WrapI64 => { i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration) @@ -334,8 +282,6 @@ impl ScenarioWatGenerator for Scenario { number_of_ops_per_loop_iteration, DataType::I32, "xor", - 11231, - 13242, ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index a3bd2228c7..dda7ad80b7 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -1,8 +1,8 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use rand::Rng; use strum_macros::{Display, EnumString}; -use strum; #[derive(Debug, Display, EnumString)] #[strum(serialize_all = "lowercase")] @@ -10,3 +10,17 @@ pub enum DataType { I32, I64 } + +pub trait Rand { + fn gen(&self) -> usize; +} + +impl Rand for DataType { + fn gen(&self) -> usize { + let mut rng = rand::thread_rng(); + match self { + DataType::I32 => rng.gen::().try_into().unwrap(), + DataType::I64 => rng.gen::().try_into().unwrap(), + } + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index 9e59adf41a..44421bb756 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -2,11 +2,11 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; -use crate::scenarios::data_type::DataType; +use crate::scenarios::data_type::{DataType, Rand}; -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str, arg: usize) { +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", data_type, arg).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()).unwrap(); wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()).unwrap(); wat.write_all(b" drop\n").unwrap(); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs index 7e8b893a5c..470b994caa 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -2,20 +2,18 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; -use crate::scenarios::data_type::DataType; +use crate::scenarios::data_type::{DataType, Rand}; pub fn write_wat_ops( wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str, - first_arg: usize, - second_arg: usize, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", data_type, first_arg).as_bytes()) + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) .unwrap(); - wat.write_all(format!(" {}.const {}\n", data_type, second_arg).as_bytes()) + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) .unwrap(); wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) .unwrap(); From 9413683b1fff455ac50181015a70f2d0b2013db3 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 10:45:03 -0300 Subject: [PATCH 086/131] stylus_benchmark: local.get --- .../tools/stylus_benchmark/src/scenario.rs | 53 ++++++++++++++++++- .../src/scenarios/local_get.rs | 17 ++++++ .../stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 3f7837a1cf..3723e4ae17 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,7 @@ use crate::scenarios::{ call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, - instruction_with_1_arg_1_return, instruction_with_2_args_1_return, select, + instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, select, }; use clap::ValueEnum; use std::fs::File; @@ -48,11 +48,13 @@ pub enum Scenario { GlobalGet, GlobalSet, If, + LocalGet, Select, } trait ScenarioWatGenerator { fn write_specific_wat_beginning(&self, wat: &mut Vec); + fn write_specific_exported_func_beginning(&self, wat: &mut Vec); fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize); } @@ -94,10 +96,53 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), Scenario::I32Xor => {} Scenario::If => if_op::write_specific_wat_beginning(wat), + Scenario::LocalGet => {}, Scenario::Select => select::write_specific_wat_beginning(wat), } } + fn write_specific_exported_func_beginning(&self, wat: &mut Vec) { + match self { + Scenario::Call => {} + Scenario::CallIndirect => {} + Scenario::GlobalGet => {} + Scenario::GlobalSet => {} + Scenario::I32Add => {} + Scenario::I32And => {} + Scenario::I32Clz => {} + Scenario::I32Ctz => {} + Scenario::I32DivS => {} + Scenario::I32DivU => {} + Scenario::I32Eq => {} + Scenario::I32Eqz => {} + Scenario::I32GeS => {} + Scenario::I32GeU => {} + Scenario::I32GtU => {} + Scenario::I32GtS => {} + Scenario::I32LeU => {} + Scenario::I32LeS => {} + Scenario::I32LtU => {} + Scenario::I32LtS => {} + Scenario::I32Mul => {} + Scenario::I32Ne => {} + Scenario::I32Or => {} + Scenario::I32Popcnt => {} + Scenario::I32RemS => {} + Scenario::I32RemU => {} + Scenario::I32Rotl => {} + Scenario::I32Rotr => {} + Scenario::I32Shl => {} + Scenario::I32ShrS => {} + Scenario::I32ShrU => {} + Scenario::I32Sub => {} + Scenario::I32WrapI64 => {} + Scenario::I32Xor => {} + Scenario::If => {} + Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), + Scenario::Select => {} + } + } + fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), @@ -284,6 +329,7 @@ impl ScenarioWatGenerator for Scenario { "xor", ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::LocalGet => local_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } @@ -309,9 +355,10 @@ fn write_common_wat_beginning(wat: &mut Vec) { fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" (func (export \"user_entrypoint\") (param i32) (result i32)\n") .unwrap(); +} +fn write_loop_beginning(wat: &mut Vec) { wat.write_all(b" call $start_benchmark\n").unwrap(); - wat.write_all(b" (loop $loop\n").unwrap(); } @@ -361,6 +408,8 @@ pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> scenario.write_specific_wat_beginning(&mut wat); write_exported_func_beginning(&mut wat); + scenario.write_specific_exported_func_beginning(&mut wat); + write_loop_beginning(&mut wat); scenario.write_wat_ops(&mut wat, number_of_ops_per_loop_iteration); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs new file mode 100644 index 0000000000..edd304c007 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs @@ -0,0 +1,17 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_exported_func_beginning(wat: &mut Vec) { + wat.write_all(b" (local $var i32)\n").unwrap(); + wat.write_all(b" (local.set $var (i32.const 10))\n") + .unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" local.get $var\n").unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 7dd8bf31cf..335de00ed6 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -10,4 +10,5 @@ pub mod i32_wrap_i64; pub mod if_op; pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; +pub mod local_get; pub mod select; From a0aeffe1963c57049c3058dd2c5065a52b75e99b Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 10:48:52 -0300 Subject: [PATCH 087/131] stylus_benchmark: local.set --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 9 +++++++-- .../stylus_benchmark/src/scenarios/local_set.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 3723e4ae17..e6a6212d0f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,8 @@ use crate::scenarios::{ call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, - instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, select, + instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, local_set, + select, }; use clap::ValueEnum; use std::fs::File; @@ -49,6 +50,7 @@ pub enum Scenario { GlobalSet, If, LocalGet, + LocalSet, Select, } @@ -96,7 +98,8 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), Scenario::I32Xor => {} Scenario::If => if_op::write_specific_wat_beginning(wat), - Scenario::LocalGet => {}, + Scenario::LocalGet => {} + Scenario::LocalSet => {} Scenario::Select => select::write_specific_wat_beginning(wat), } } @@ -139,6 +142,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Xor => {} Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), + Scenario::LocalSet => local_set::write_specific_exported_func_beginning(wat), Scenario::Select => {} } } @@ -330,6 +334,7 @@ impl ScenarioWatGenerator for Scenario { ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalGet => local_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::LocalSet => local_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs new file mode 100644 index 0000000000..6b0261a819 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_exported_func_beginning(wat: &mut Vec) { + wat.write_all(b" (local $var i32)\n").unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" (local.set $var (i32.const 1073741823))\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 335de00ed6..4564799eb1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -11,4 +11,5 @@ pub mod if_op; pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; pub mod local_get; +pub mod local_set; pub mod select; From bedf6d8e5e1d80a89a0b616691d985a787f3809c Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 10:59:52 -0300 Subject: [PATCH 088/131] stylus_benchmark: local.tee --- .../tools/stylus_benchmark/src/scenario.rs | 6 +++++- .../stylus_benchmark/src/scenarios/local_tee.rs | 16 ++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index e6a6212d0f..bf8d5d875e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, local_set, - select, + local_tee, select, }; use clap::ValueEnum; use std::fs::File; @@ -51,6 +51,7 @@ pub enum Scenario { If, LocalGet, LocalSet, + LocalTee, Select, } @@ -100,6 +101,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::LocalGet => {} Scenario::LocalSet => {} + Scenario::LocalTee => {} Scenario::Select => select::write_specific_wat_beginning(wat), } } @@ -143,6 +145,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), Scenario::LocalSet => local_set::write_specific_exported_func_beginning(wat), + Scenario::LocalTee => local_tee::write_specific_exported_func_beginning(wat), Scenario::Select => {} } } @@ -335,6 +338,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalGet => local_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalSet => local_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::LocalTee => local_tee::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs new file mode 100644 index 0000000000..6369a1331f --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_exported_func_beginning(wat: &mut Vec) { + wat.write_all(b" (local $var i32)\n").unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + wat.write_all(b" (i32.const 1073741823)\n").unwrap(); + for _ in 0..number_of_loop_iterations { + wat.write_all(b" local.tee $var\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 4564799eb1..dbdf9d0257 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -12,4 +12,5 @@ pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; pub mod local_get; pub mod local_set; +pub mod local_tee; pub mod select; From 6102825e2aeb59769e496587f2dac5c6c2d35048 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 9 Jan 2025 15:10:46 +0100 Subject: [PATCH 089/131] don't required waxm module recompilation when getting local asm --- arbos/programs/native.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 8eb2aacda1..3ca3003175 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -272,14 +272,14 @@ func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging c targets := statedb.Database().WasmTargets() // we know program is activated, so it must be in correct version and not use too much memory - moduleActivationMandatory := true // TODO: refactor the parameter, always set to true + moduleActivationMandatory := false info, asmMap, err := activateProgramInternal(addressForLogging, codehash, wasm, pagelimit, program.version, zeroArbosVersion, debugMode, &zeroGas, targets, moduleActivationMandatory) if err != nil { log.Error("failed to reactivate program", "address", addressForLogging, "expected moduleHash", moduleHash, "err", err) return nil, fmt.Errorf("failed to reactivate program address: %v err: %w", addressForLogging, err) } - if info.moduleHash != moduleHash { + if info != nil && info.moduleHash != moduleHash { log.Error("failed to reactivate program", "address", addressForLogging, "expected moduleHash", moduleHash, "got", info.moduleHash) return nil, fmt.Errorf("failed to reactivate program. address: %v, expected ModuleHash: %v", addressForLogging, moduleHash) } @@ -296,7 +296,7 @@ func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging c } else { // program activated recently, possibly in this eth_call // store it to statedb. It will be stored to database if statedb is commited - statedb.ActivateWasm(info.moduleHash, asmMap) + statedb.ActivateWasm(moduleHash, asmMap) } asm, exists := asmMap[localTarget] if !exists { From 2275b42ff710e94d0150aef71dc19553a5c84b1b Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 9 Jan 2025 16:23:17 +0100 Subject: [PATCH 090/131] refactor activateProgramInternal --- arbos/programs/native.go | 76 +++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 3ca3003175..9d34504888 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -164,10 +164,12 @@ func activateProgramInternal( moduleActivationMandatory bool, ) (*activationInfo, map[ethdb.WasmTarget][]byte, error) { var wavmFound bool + var nativeTargets []ethdb.WasmTarget for _, target := range targets { if target == rawdb.TargetWavm { wavmFound = true - break + } else { + nativeTargets = append(nativeTargets, target) } } type result struct { @@ -175,59 +177,53 @@ func activateProgramInternal( asm []byte err error } - asmMap := make(map[ethdb.WasmTarget][]byte, len(targets)) - - // info can be set in separate thread, make sure to wait before reading + results := make(chan result) + // info will be set in separate thread, make sure to wait before reading var info *activationInfo - var moduleActivationStarted bool + asmMap := make(map[ethdb.WasmTarget][]byte, len(nativeTargets)+1) + if moduleActivationMandatory || wavmFound { + go func() { + var err error + var module []byte + info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) + results <- result{rawdb.TargetWavm, module, err} + }() + } if moduleActivationMandatory { - moduleActivationStarted = true - var err error - var module []byte - info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) - if err != nil { - return nil, nil, err - } - if wavmFound { - asmMap[rawdb.TargetWavm] = module + // wait for the module activation before starting compilation for other targets + res := <-results + if res.err != nil { + return info, nil, res.err + } else if wavmFound { + asmMap[res.target] = res.asm } } - results := make(chan result, len(targets)) - for _, target := range targets { + for _, target := range nativeTargets { target := target - if target == rawdb.TargetWavm { - if moduleActivationStarted { - // skip if already started or activated because of moduleActivationMandatory - results <- result{target, nil, nil} - continue - } - go func() { - var err error - var module []byte - info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) - results <- result{target, module, err} - }() - moduleActivationStarted = true - } else { - go func() { - asm, err := compileNative(wasm, stylusVersion, debug, target) - results <- result{target, asm, err} - }() - } + go func() { + asm, err := compileNative(wasm, stylusVersion, debug, target) + results <- result{target, asm, err} + }() } + + expectedResults := len(nativeTargets) + if !moduleActivationMandatory && wavmFound { + // we didn't wait for module activation result, so wait for it too + expectedResults++ + } + var err error - for range targets { + for i := 0; i < expectedResults; i++ { res := <-results - if res.asm == nil { - continue - } else if res.err != nil { + if res.err != nil { err = errors.Join(res.err, fmt.Errorf("%s:%w", res.target, err)) } else { asmMap[res.target] = res.asm } } - if err != nil && moduleActivationMandatory { + + if err != nil && (moduleActivationMandatory || len(asmMap[rawdb.TargetWavm]) > 0) { if info != nil { log.Error( "Compilation failed for one or more targets despite activation succeeding", From 83f572e632cc732419311d9fe512887291f43c12 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 9 Jan 2025 16:37:48 +0100 Subject: [PATCH 091/131] simplify panic condition when moduleActivationMandatory and some native compilation fails --- arbos/programs/native.go | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 9d34504888..1abbd91158 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -198,7 +198,6 @@ func activateProgramInternal( asmMap[res.target] = res.asm } } - for _, target := range nativeTargets { target := target go func() { @@ -206,13 +205,11 @@ func activateProgramInternal( results <- result{target, asm, err} }() } - expectedResults := len(nativeTargets) if !moduleActivationMandatory && wavmFound { // we didn't wait for module activation result, so wait for it too expectedResults++ } - var err error for i := 0; i < expectedResults; i++ { res := <-results @@ -222,29 +219,17 @@ func activateProgramInternal( asmMap[res.target] = res.asm } } - - if err != nil && (moduleActivationMandatory || len(asmMap[rawdb.TargetWavm]) > 0) { - if info != nil { - log.Error( - "Compilation failed for one or more targets despite activation succeeding", - "address", addressForLogging, - "codehash", codehash, - "moduleHash", info.moduleHash, - "targets", targets, - "err", err, - ) - } else { - log.Error( - "Compilation failed for one or more targets despite activation succeeding", - "address", addressForLogging, - "codehash", codehash, - "targets", targets, - "err", err, - ) - } + if err != nil && moduleActivationMandatory { + log.Error( + "Compilation failed for one or more targets despite activation succeeding", + "address", addressForLogging, + "codehash", codehash, + "moduleHash", info.moduleHash, + "targets", targets, + "err", err, + ) panic(fmt.Sprintf("Compilation of %v failed for one or more targets despite activation succeeding: %v", addressForLogging, err)) } - return info, asmMap, err } From 6be86bf4eb1ae4a0a391104daf4274877d93441e Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 9 Jan 2025 16:54:10 +0100 Subject: [PATCH 092/131] return nil activationInfo in case of error --- arbos/programs/native.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 1abbd91158..5995d9dafe 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -193,7 +193,7 @@ func activateProgramInternal( // wait for the module activation before starting compilation for other targets res := <-results if res.err != nil { - return info, nil, res.err + return nil, nil, res.err } else if wavmFound { asmMap[res.target] = res.asm } From 86a6b25fe7c34f8189d45bcf93430ce214c02247 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 14:24:04 -0300 Subject: [PATCH 093/131] Removes unused fn --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 6 +++--- .../tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs | 2 -- arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs | 2 -- arbitrator/tools/stylus_benchmark/src/scenarios/select.rs | 2 -- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index bf8d5d875e..427f8a8604 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -96,13 +96,13 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32ShrS => {} Scenario::I32ShrU => {} Scenario::I32Sub => {} - Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), + Scenario::I32WrapI64 => {}, Scenario::I32Xor => {} - Scenario::If => if_op::write_specific_wat_beginning(wat), + Scenario::If => {}, Scenario::LocalGet => {} Scenario::LocalSet => {} Scenario::LocalTee => {} - Scenario::Select => select::write_specific_wat_beginning(wat), + Scenario::Select => {}, } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs index 2634615447..59352016aa 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs @@ -3,8 +3,6 @@ use std::io::Write; -pub fn write_specific_wat_beginning(_: &mut Vec) {} - pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { for _ in 0..number_of_ops_per_loop_iteration { wat.write_all(b" i64.const 123123\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs index 71559f78ea..59199d6cde 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs @@ -3,8 +3,6 @@ use std::io::Write; -pub fn write_specific_wat_beginning(_: &mut Vec) {} - pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { for _ in 0..number_of_ops_per_loop_iteration { wat.write_all(b" i32.const 0\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs index a1487e47d0..f35e3420d6 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs @@ -3,8 +3,6 @@ use std::io::Write; -pub fn write_specific_wat_beginning(_: &mut Vec) {} - pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { wat.write_all(b" i32.const 10\n").unwrap(); for _ in 0..number_of_ops_per_loop_iteration { From d4189586de75f3a981fe9c7a20424dfad0a0fd88 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 15:41:11 -0300 Subject: [PATCH 094/131] convert mod instead of i32_wrap_i64 mod --- .../tools/stylus_benchmark/src/scenario.rs | 18 +++++++++++------- .../stylus_benchmark/src/scenarios/convert.rs | 19 +++++++++++++++++++ .../src/scenarios/i32_wrap_i64.rs | 12 ------------ .../stylus_benchmark/src/scenarios/mod.rs | 2 +- 4 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 427f8a8604..6b1919385a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, + call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, local_set, local_tee, select, }; @@ -96,13 +96,13 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32ShrS => {} Scenario::I32ShrU => {} Scenario::I32Sub => {} - Scenario::I32WrapI64 => {}, + Scenario::I32WrapI64 => {} Scenario::I32Xor => {} - Scenario::If => {}, + Scenario::If => {} Scenario::LocalGet => {} Scenario::LocalSet => {} Scenario::LocalTee => {} - Scenario::Select => {}, + Scenario::Select => {} } } @@ -326,9 +326,13 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "sub", ), - Scenario::I32WrapI64 => { - i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration) - } + Scenario::I32WrapI64 => convert::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + DataType::I32, + "wrap_i64", + ), Scenario::I32Xor => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs new file mode 100644 index 0000000000..07ccf43aee --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs @@ -0,0 +1,19 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use crate::scenarios::data_type::{DataType, Rand}; +use std::io::Write; + +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + source_data_type: DataType, + dest_data_type: DataType, + instruction: &str, +) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(format!(" {}.const {}\n", source_data_type, dest_data_type.gen()).as_bytes()).unwrap(); + wat.write_all(format!(" {}.{}\n", dest_data_type, instruction).as_bytes()).unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs deleted file mode 100644 index 59352016aa..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i64.const 123123\n").unwrap(); - wat.write_all(b" i32.wrap_i64\n").unwrap(); - wat.write_all(b" drop\n").unwrap(); - } -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index dbdf9d0257..8998f991f7 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,10 +3,10 @@ pub mod call; pub mod call_indirect; +pub mod convert; pub mod data_type; pub mod global_get; pub mod global_set; -pub mod i32_wrap_i64; pub mod if_op; pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; From 71c2ec865a037f32fcda235aa9e88da604cf3b68 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 16:28:21 -0300 Subject: [PATCH 095/131] stylus_benchmark: i64.extend_i32_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 10 ++++++++++ .../tools/stylus_benchmark/src/scenarios/convert.rs | 2 +- .../tools/stylus_benchmark/src/scenarios/data_type.rs | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 6b1919385a..bd5c72d5c4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -44,6 +44,7 @@ pub enum Scenario { I32Sub, I32WrapI64, I32Xor, + I64ExtendI32S, Call, CallIndirect, GlobalGet, @@ -98,6 +99,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64ExtendI32S => {} Scenario::If => {} Scenario::LocalGet => {} Scenario::LocalSet => {} @@ -142,6 +144,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64ExtendI32S => {} Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), Scenario::LocalSet => local_set::write_specific_exported_func_beginning(wat), @@ -339,6 +342,13 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "xor", ), + Scenario::I64ExtendI32S => convert::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I32, + DataType::I64, + "extend_i32_s", + ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalGet => local_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalSet => local_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs index 07ccf43aee..573bdd3858 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs @@ -12,7 +12,7 @@ pub fn write_wat_ops( instruction: &str, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", source_data_type, dest_data_type.gen()).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", source_data_type, DataType::I32.gen()).as_bytes()).unwrap(); wat.write_all(format!(" {}.{}\n", dest_data_type, instruction).as_bytes()).unwrap(); wat.write_all(b" drop\n").unwrap(); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index dda7ad80b7..6425dd852c 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -19,8 +19,8 @@ impl Rand for DataType { fn gen(&self) -> usize { let mut rng = rand::thread_rng(); match self { - DataType::I32 => rng.gen::().try_into().unwrap(), - DataType::I64 => rng.gen::().try_into().unwrap(), + DataType::I32 => (rng.gen::() >> 1).try_into().unwrap(), + DataType::I64 => (rng.gen::() >> 1).try_into().unwrap(), } } } From 67ff06307a044abe478c8e843785f076ffe16c53 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 16:29:25 -0300 Subject: [PATCH 096/131] stylus_benchmark: i64.extend_i32_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index bd5c72d5c4..c8d06faa43 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -44,6 +44,7 @@ pub enum Scenario { I32Sub, I32WrapI64, I32Xor, + I64ExtendI32U, I64ExtendI32S, Call, CallIndirect, @@ -99,6 +100,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64ExtendI32U => {} Scenario::I64ExtendI32S => {} Scenario::If => {} Scenario::LocalGet => {} @@ -144,6 +146,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64ExtendI32U => {} Scenario::I64ExtendI32S => {} Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), @@ -342,6 +345,13 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "xor", ), + Scenario::I64ExtendI32U => convert::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I32, + DataType::I64, + "extend_i32_u", + ), Scenario::I64ExtendI32S => convert::write_wat_ops( wat, number_of_ops_per_loop_iteration, From bd5969283abe6984df02cdbb981ab9a75359dd2e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 18:55:58 -0300 Subject: [PATCH 097/131] stylus_benchmark: i32.load --- .../tools/stylus_benchmark/src/scenario.rs | 16 +++++++++++++-- .../stylus_benchmark/src/scenarios/load.rs | 20 +++++++++++++++++++ .../stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/load.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index c8d06faa43..08da65a4c9 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,7 @@ use crate::scenarios::{ call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, - instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, local_set, + instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, local_tee, select, }; use clap::ValueEnum; @@ -28,6 +28,7 @@ pub enum Scenario { I32GtS, I32LeU, I32LeS, + I32Load, I32LtU, I32LtS, I32Mul, @@ -84,6 +85,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32GtS => {} Scenario::I32LeU => {} Scenario::I32LeS => {} + Scenario::I32Load => {} Scenario::I32LtU => {} Scenario::I32LtS => {} Scenario::I32Mul => {} @@ -130,6 +132,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32GtS => {} Scenario::I32LeU => {} Scenario::I32LeS => {} + Scenario::I32Load => {} Scenario::I32LtU => {} Scenario::I32LtS => {} Scenario::I32Mul => {} @@ -248,6 +251,12 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "le_s", ), + Scenario::I32Load => load::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I32, + "load", + ), Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, @@ -379,7 +388,10 @@ fn write_common_wat_beginning(wat: &mut Vec) { .unwrap(); wat.write_all(b" (import \"debug\" \"end_benchmark\" (func $end_benchmark))\n") .unwrap(); - wat.write_all(b" (memory (export \"memory\") 0 0)\n") + wat.write_all(b" (import \"vm_hooks\" \"pay_for_memory_grow\" (func (param i32)))\n") + .unwrap(); + wat.write_all(b" (memory $memory 1)\n").unwrap(); + wat.write_all(b" (export \"memory\" (memory $memory))\n") .unwrap(); wat.write_all(b" (global $ops_counter (mut i32) (i32.const 0))\n") .unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs new file mode 100644 index 0000000000..3de0211ce3 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs @@ -0,0 +1,20 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use crate::scenarios::data_type::DataType; +use std::io::Write; + +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + data_type: DataType, + instruction: &str, +) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) + .unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8998f991f7..be9cc3d228 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -14,3 +14,4 @@ pub mod local_get; pub mod local_set; pub mod local_tee; pub mod select; +pub mod load; From 43ab5321d56cdbaaf7654d96e055c6cc55b144b7 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 19:01:38 -0300 Subject: [PATCH 098/131] stylus_benchmark: i32.store --- .../tools/stylus_benchmark/src/scenario.rs | 17 +++++++++------- .../stylus_benchmark/src/scenarios/load.rs | 3 +-- .../stylus_benchmark/src/scenarios/mod.rs | 3 ++- .../stylus_benchmark/src/scenarios/store.rs | 20 +++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/store.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 08da65a4c9..75b3432ef0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, - local_tee, select, + local_tee, select, store, }; use clap::ValueEnum; use std::fs::File; @@ -42,6 +42,7 @@ pub enum Scenario { I32Shl, I32ShrS, I32ShrU, + I32Store, I32Sub, I32WrapI64, I32Xor, @@ -99,6 +100,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Shl => {} Scenario::I32ShrS => {} Scenario::I32ShrU => {} + Scenario::I32Store => {} Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} @@ -146,6 +148,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Shl => {} Scenario::I32ShrS => {} Scenario::I32ShrU => {} + Scenario::I32Store => {} Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} @@ -251,12 +254,9 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "le_s", ), - Scenario::I32Load => load::write_wat_ops( - wat, - number_of_ops_per_loop_iteration, - DataType::I32, - "load", - ), + Scenario::I32Load => { + load::write_wat_ops(wat, number_of_ops_per_loop_iteration, DataType::I32) + } Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, @@ -335,6 +335,9 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "shr_u", ), + Scenario::I32Store => { + store::write_wat_ops(wat, number_of_ops_per_loop_iteration, DataType::I32) + } Scenario::I32Sub => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs index 3de0211ce3..90ec890719 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs @@ -8,12 +8,11 @@ pub fn write_wat_ops( wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, - instruction: &str, ) { for _ in 0..number_of_ops_per_loop_iteration { wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) .unwrap(); - wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) + wat.write_all(format!(" {}.load\n", data_type).as_bytes()) .unwrap(); wat.write_all(b" drop\n").unwrap(); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index be9cc3d228..70ddbf40ad 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -10,8 +10,9 @@ pub mod global_set; pub mod if_op; pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; +pub mod load; pub mod local_get; pub mod local_set; pub mod local_tee; pub mod select; -pub mod load; +pub mod store; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs new file mode 100644 index 0000000000..89f6a59157 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs @@ -0,0 +1,20 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use crate::scenarios::data_type::{DataType, Rand}; +use std::io::Write; + +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + data_type: DataType, +) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.store\n", data_type).as_bytes()) + .unwrap(); + } +} From 309e79c3375b719d193f8e38df3c0464a5864492 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 19:17:13 -0300 Subject: [PATCH 099/131] stylus_benchmark: I64 ops --- .../tools/stylus_benchmark/src/scenario.rs | 273 ++++++++++++++++++ 1 file changed, 273 insertions(+) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 75b3432ef0..39588d75db 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -46,6 +46,37 @@ pub enum Scenario { I32Sub, I32WrapI64, I32Xor, + I64Add, + I64And, + I64Clz, + I64Ctz, + I64DivS, + I64DivU, + I64Eq, + I64Eqz, + I64GeS, + I64GeU, + I64GtU, + I64GtS, + I64LeU, + I64LeS, + I64Load, + I64LtU, + I64LtS, + I64Mul, + I64Ne, + I64Or, + I64Popcnt, + I64RemS, + I64RemU, + I64Rotl, + I64Rotr, + I64Shl, + I64ShrS, + I64ShrU, + I64Store, + I64Sub, + I64Xor, I64ExtendI32U, I64ExtendI32S, Call, @@ -104,6 +135,37 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64Add => {} + Scenario::I64And => {} + Scenario::I64Clz => {} + Scenario::I64Ctz => {} + Scenario::I64DivS => {} + Scenario::I64DivU => {} + Scenario::I64Eq => {} + Scenario::I64Eqz => {} + Scenario::I64GeS => {} + Scenario::I64GeU => {} + Scenario::I64GtU => {} + Scenario::I64GtS => {} + Scenario::I64LeU => {} + Scenario::I64LeS => {} + Scenario::I64Load => {} + Scenario::I64LtU => {} + Scenario::I64LtS => {} + Scenario::I64Mul => {} + Scenario::I64Ne => {} + Scenario::I64Or => {} + Scenario::I64Popcnt => {} + Scenario::I64RemS => {} + Scenario::I64RemU => {} + Scenario::I64Rotl => {} + Scenario::I64Rotr => {} + Scenario::I64Shl => {} + Scenario::I64ShrS => {} + Scenario::I64ShrU => {} + Scenario::I64Store => {} + Scenario::I64Sub => {} + Scenario::I64Xor => {} Scenario::I64ExtendI32U => {} Scenario::I64ExtendI32S => {} Scenario::If => {} @@ -152,6 +214,37 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64Add => {} + Scenario::I64And => {} + Scenario::I64Clz => {} + Scenario::I64Ctz => {} + Scenario::I64DivS => {} + Scenario::I64DivU => {} + Scenario::I64Eq => {} + Scenario::I64Eqz => {} + Scenario::I64GeS => {} + Scenario::I64GeU => {} + Scenario::I64GtU => {} + Scenario::I64GtS => {} + Scenario::I64LeU => {} + Scenario::I64LeS => {} + Scenario::I64Load => {} + Scenario::I64LtU => {} + Scenario::I64LtS => {} + Scenario::I64Mul => {} + Scenario::I64Ne => {} + Scenario::I64Or => {} + Scenario::I64Popcnt => {} + Scenario::I64RemS => {} + Scenario::I64RemU => {} + Scenario::I64Rotl => {} + Scenario::I64Rotr => {} + Scenario::I64Shl => {} + Scenario::I64ShrS => {} + Scenario::I64ShrU => {} + Scenario::I64Store => {} + Scenario::I64Sub => {} + Scenario::I64Xor => {} Scenario::I64ExtendI32U => {} Scenario::I64ExtendI32S => {} Scenario::If => {} @@ -357,6 +450,186 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "xor", ), + Scenario::I64Add => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "add", + ), + Scenario::I64And => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "and", + ), + Scenario::I64Clz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "clz", + ), + Scenario::I64Ctz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "ctz", + ), + Scenario::I64DivS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "div_s", + ), + Scenario::I64DivU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "div_u", + ), + Scenario::I64Eq => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "eq", + ), + Scenario::I64Eqz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "eqz", + ), + Scenario::I64GeS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "ge_s", + ), + Scenario::I64GeU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "ge_u", + ), + Scenario::I64GtU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "gt_u", + ), + Scenario::I64GtS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "gt_s", + ), + Scenario::I64LeU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "le_u", + ), + Scenario::I64LeS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "le_s", + ), + Scenario::I64Load => { + load::write_wat_ops(wat, number_of_ops_per_loop_iteration, DataType::I64) + } + Scenario::I64LtU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "lt_u", + ), + Scenario::I64LtS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "lt_s", + ), + Scenario::I64Mul => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "mul", + ), + Scenario::I64Ne => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "ne", + ), + Scenario::I64Or => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "or", + ), + Scenario::I64Popcnt => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "popcnt", + ), + Scenario::I64RemS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "rem_s", + ), + Scenario::I64RemU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "rem_u", + ), + Scenario::I64Rotl => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "rotl", + ), + Scenario::I64Rotr => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "rotr", + ), + Scenario::I64Shl => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "shl", + ), + Scenario::I64ShrS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "shr_s", + ), + Scenario::I64ShrU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "shr_u", + ), + Scenario::I64Store => { + store::write_wat_ops(wat, number_of_ops_per_loop_iteration, DataType::I64) + } + Scenario::I64Sub => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "sub", + ), + Scenario::I64Xor => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "xor", + ), Scenario::I64ExtendI32U => convert::write_wat_ops( wat, number_of_ops_per_loop_iteration, From 20c7d4a2840f728f87abe1cba537254719e0c627 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 19:21:17 -0300 Subject: [PATCH 100/131] Uses local instead of global for ops_counter --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 39588d75db..e10e500ec0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -669,13 +669,14 @@ fn write_common_wat_beginning(wat: &mut Vec) { wat.write_all(b" (memory $memory 1)\n").unwrap(); wat.write_all(b" (export \"memory\" (memory $memory))\n") .unwrap(); - wat.write_all(b" (global $ops_counter (mut i32) (i32.const 0))\n") - .unwrap(); } fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" (func (export \"user_entrypoint\") (param i32) (result i32)\n") .unwrap(); + wat.write_all(b" (local $ops_counter i32)\n") + .unwrap(); + wat.write_all(b" (local.set $ops_counter (i32.const 0))\n").unwrap(); } fn write_loop_beginning(wat: &mut Vec) { @@ -691,7 +692,7 @@ fn write_wat_end( let number_of_ops = number_of_loop_iterations * number_of_ops_per_loop_iteration; // update ops_counter - wat.write_all(b" global.get $ops_counter\n") + wat.write_all(b" local.get $ops_counter\n") .unwrap(); wat.write_all( format!( @@ -702,12 +703,10 @@ fn write_wat_end( ) .unwrap(); wat.write_all(b" i32.add\n").unwrap(); - wat.write_all(b" global.set $ops_counter\n") + wat.write_all(b" local.tee $ops_counter\n") .unwrap(); // check if we need to continue looping - wat.write_all(b" global.get $ops_counter\n") - .unwrap(); wat.write_all(format!(" i32.const {}\n", number_of_ops).as_bytes()) .unwrap(); wat.write_all(b" i32.lt_s\n").unwrap(); From 02f9249d17130857c3d018ce9ef78ca6f3ce3468 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 09:29:12 -0300 Subject: [PATCH 101/131] stylus_benchmark: br --- .../tools/stylus_benchmark/src/scenario.rs | 9 +++++++-- .../tools/stylus_benchmark/src/scenarios/br.rs | 16 ++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/br.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index e10e500ec0..b695a33635 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, + br, call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, local_tee, select, store, }; @@ -79,6 +79,7 @@ pub enum Scenario { I64Xor, I64ExtendI32U, I64ExtendI32S, + Br, Call, CallIndirect, GlobalGet, @@ -99,6 +100,7 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { + Scenario::Br => {}, Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), @@ -178,6 +180,7 @@ impl ScenarioWatGenerator for Scenario { fn write_specific_exported_func_beginning(&self, wat: &mut Vec) { match self { + Scenario::Br => {}, Scenario::Call => {} Scenario::CallIndirect => {} Scenario::GlobalGet => {} @@ -257,6 +260,7 @@ impl ScenarioWatGenerator for Scenario { fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { + Scenario::Br => br::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) @@ -676,7 +680,8 @@ fn write_exported_func_beginning(wat: &mut Vec) { .unwrap(); wat.write_all(b" (local $ops_counter i32)\n") .unwrap(); - wat.write_all(b" (local.set $ops_counter (i32.const 0))\n").unwrap(); + wat.write_all(b" (local.set $ops_counter (i32.const 0))\n") + .unwrap(); } fn write_loop_beginning(wat: &mut Vec) { diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs new file mode 100644 index 0000000000..1356c048ea --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" (block\n").unwrap(); + wat.write_all(b" (block \n").unwrap(); + wat.write_all(b" (block \n").unwrap(); + wat.write_all(b" br 2\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 70ddbf40ad..8f2146bec7 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -1,6 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +pub mod br; pub mod call; pub mod call_indirect; pub mod convert; From 7298af4c8795a558f6ea349a0e2610a7bdf932a9 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 09:34:17 -0300 Subject: [PATCH 102/131] stylus_benchmark: br_if --- .../tools/stylus_benchmark/src/scenario.rs | 10 +++++++--- .../tools/stylus_benchmark/src/scenarios/br.rs | 2 +- .../stylus_benchmark/src/scenarios/br_if.rs | 17 +++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index b695a33635..790cd65396 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - br, call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, + br, br_if, call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, local_tee, select, store, }; @@ -80,6 +80,7 @@ pub enum Scenario { I64ExtendI32U, I64ExtendI32S, Br, + BrIf, Call, CallIndirect, GlobalGet, @@ -100,7 +101,8 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { - Scenario::Br => {}, + Scenario::Br => {} + Scenario::BrIf => {} Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), @@ -180,7 +182,8 @@ impl ScenarioWatGenerator for Scenario { fn write_specific_exported_func_beginning(&self, wat: &mut Vec) { match self { - Scenario::Br => {}, + Scenario::Br => {} + Scenario::BrIf => {} Scenario::Call => {} Scenario::CallIndirect => {} Scenario::GlobalGet => {} @@ -261,6 +264,7 @@ impl ScenarioWatGenerator for Scenario { fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { Scenario::Br => br::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::BrIf => br_if::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs index 1356c048ea..a79b5173ce 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs @@ -8,7 +8,7 @@ pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) wat.write_all(b" (block\n").unwrap(); wat.write_all(b" (block \n").unwrap(); wat.write_all(b" (block \n").unwrap(); - wat.write_all(b" br 2\n").unwrap(); + wat.write_all(b" br 2\n").unwrap(); // it will jump to the end of the last block wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs new file mode 100644 index 0000000000..01f7620afe --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs @@ -0,0 +1,17 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" (block\n").unwrap(); + wat.write_all(b" (block \n").unwrap(); + wat.write_all(b" (block \n").unwrap(); + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" br_if 2\n").unwrap(); // it will jump to the end of the last block + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8f2146bec7..e1452151e5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod br; +pub mod br_if; pub mod call; pub mod call_indirect; pub mod convert; From 8ec1f561b26829072b55be1194ed46fb4de15c7e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 09:58:58 -0300 Subject: [PATCH 103/131] stylus_benchmark: br_table --- .../tools/stylus_benchmark/src/scenario.rs | 10 ++++-- .../src/scenarios/br_table.rs | 32 +++++++++++++++++++ .../stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 790cd65396..159581441d 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - br, br_if, call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, - instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, - local_tee, select, store, + br, br_if, br_table, call, call_indirect, convert, data_type::DataType, global_get, global_set, + if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, + local_set, local_tee, select, store, }; use clap::ValueEnum; use std::fs::File; @@ -81,6 +81,7 @@ pub enum Scenario { I64ExtendI32S, Br, BrIf, + BrTable, Call, CallIndirect, GlobalGet, @@ -103,6 +104,7 @@ impl ScenarioWatGenerator for Scenario { match self { Scenario::Br => {} Scenario::BrIf => {} + Scenario::BrTable => {} Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), @@ -184,6 +186,7 @@ impl ScenarioWatGenerator for Scenario { match self { Scenario::Br => {} Scenario::BrIf => {} + Scenario::BrTable => {} Scenario::Call => {} Scenario::CallIndirect => {} Scenario::GlobalGet => {} @@ -265,6 +268,7 @@ impl ScenarioWatGenerator for Scenario { match self { Scenario::Br => br::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::BrIf => br_if::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::BrTable => br_table::write_wat_ops(wat, number_of_ops_per_loop_iteration, 5), Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs new file mode 100644 index 0000000000..b4b0db8e4b --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -0,0 +1,32 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +fn rm_identation(s: &mut String) { + for _ in 0..4 { + s.pop(); + } +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, table_size: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + let mut identation = String::from(" "); + for _ in 0..table_size { + wat.write_all(format!("{}(block\n", identation).as_bytes()).unwrap(); + identation.push_str(" "); + } + wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()).unwrap(); // it will jump to the end of the last block + + let mut br_table = String::from("br_table"); + for i in 0..table_size { + br_table.push_str(&format!(" {}", i)); + } + wat.write_all(format!("{}{}\n", identation, br_table).as_bytes()).unwrap(); + + for _ in 0..table_size { + rm_identation(&mut identation); + wat.write_all(format!("{})\n", identation).as_bytes()).unwrap(); + } + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index e1452151e5..1f02b63aaf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,6 +3,7 @@ pub mod br; pub mod br_if; +pub mod br_table; pub mod call; pub mod call_indirect; pub mod convert; From 751d62316a0fe09ff15cc0150b13c16ce94c51fd Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 10:02:05 -0300 Subject: [PATCH 104/131] Updates date in copyright --- arbitrator/tools/stylus_benchmark/src/benchmark.rs | 2 +- arbitrator/tools/stylus_benchmark/src/main.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenario.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/call.rs | 2 +- .../tools/stylus_benchmark/src/scenarios/call_indirect.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs | 2 +- .../src/scenarios/instruction_with_1_arg_1_return.rs | 2 +- .../src/scenarios/instruction_with_2_args_1_return.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/load.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/select.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/store.rs | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/benchmark.rs b/arbitrator/tools/stylus_benchmark/src/benchmark.rs index 84a9b40af8..40ea15ad0b 100644 --- a/arbitrator/tools/stylus_benchmark/src/benchmark.rs +++ b/arbitrator/tools/stylus_benchmark/src/benchmark.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use arbutil::evm::{api::Ink, EvmData}; diff --git a/arbitrator/tools/stylus_benchmark/src/main.rs b/arbitrator/tools/stylus_benchmark/src/main.rs index 297acc1867..db5ff2e5c1 100644 --- a/arbitrator/tools/stylus_benchmark/src/main.rs +++ b/arbitrator/tools/stylus_benchmark/src/main.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE mod benchmark; diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 159581441d..1bccb170f3 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs index a79b5173ce..a9ddd1f109 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs index 01f7620afe..485baef01e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs index b4b0db8e4b..f257772a19 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs index 6160001510..acb66fb391 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs index b104720c44..6dbe6cbe6f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs index 573bdd3858..ddcd24eaff 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::data_type::{DataType, Rand}; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index 6425dd852c..10895be62c 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use rand::Rng; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs index f053ad8782..f2fa065bc5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs index 1e648d7a85..4781a9b276 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs index 59199d6cde..1c076a6700 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index 44421bb756..5545bd9cac 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs index 470b994caa..a6c2275ed1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs index 90ec890719..5abc52a1ce 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::data_type::DataType; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs index edd304c007..bd89fe6925 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs index 6b0261a819..7697e8d16d 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs index 6369a1331f..c442433bcf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 1f02b63aaf..6cf7d499ce 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod br; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs index f35e3420d6..5ad3a996ee 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs index 89f6a59157..0157235e5b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::data_type::{DataType, Rand}; From 4fe605be63c3a0e22ea55d7de80ee571ca0de72c Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 10:23:28 -0300 Subject: [PATCH 105/131] Fix load --- arbitrator/tools/stylus_benchmark/src/scenarios/load.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs index 5abc52a1ce..50094bf19d 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs @@ -10,7 +10,7 @@ pub fn write_wat_ops( data_type: DataType, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) + wat.write_all(format!(" i32.const 0\n").as_bytes()) .unwrap(); wat.write_all(format!(" {}.load\n", data_type).as_bytes()) .unwrap(); From 2cae13b028bdc9d7af5db8ae3ce9d078a8b6dd7f Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 10:26:40 -0300 Subject: [PATCH 106/131] Fix store --- arbitrator/tools/stylus_benchmark/src/scenarios/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs index 0157235e5b..78b3067870 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs @@ -10,7 +10,7 @@ pub fn write_wat_ops( data_type: DataType, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) + wat.write_all(format!(" i32.const 0\n").as_bytes()) .unwrap(); wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) .unwrap(); From d6f01fffd5810173efe48cafa49651c9002f18ef Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 10:33:03 -0300 Subject: [PATCH 107/131] Fix fmt --- .../stylus_benchmark/src/scenarios/br_if.rs | 3 ++- .../stylus_benchmark/src/scenarios/br_table.rs | 18 +++++++++++++----- .../stylus_benchmark/src/scenarios/call.rs | 3 +-- .../stylus_benchmark/src/scenarios/convert.rs | 13 +++++++++++-- .../src/scenarios/data_type.rs | 2 +- .../instruction_with_1_arg_1_return.rs | 15 +++++++++++---- .../instruction_with_2_args_1_return.rs | 2 +- .../src/scenarios/local_set.rs | 3 ++- .../src/scenarios/local_tee.rs | 3 ++- 9 files changed, 44 insertions(+), 18 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs index 485baef01e..be178a57be 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs @@ -8,7 +8,8 @@ pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) wat.write_all(b" (block\n").unwrap(); wat.write_all(b" (block \n").unwrap(); wat.write_all(b" (block \n").unwrap(); - wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.const 1\n") + .unwrap(); wat.write_all(b" br_if 2\n").unwrap(); // it will jump to the end of the last block wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs index f257772a19..02dee3501f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -9,24 +9,32 @@ fn rm_identation(s: &mut String) { } } -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, table_size: usize) { +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + table_size: usize, +) { for _ in 0..number_of_ops_per_loop_iteration { let mut identation = String::from(" "); for _ in 0..table_size { - wat.write_all(format!("{}(block\n", identation).as_bytes()).unwrap(); + wat.write_all(format!("{}(block\n", identation).as_bytes()) + .unwrap(); identation.push_str(" "); } - wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()).unwrap(); // it will jump to the end of the last block + wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()) + .unwrap(); // it will jump to the end of the last block let mut br_table = String::from("br_table"); for i in 0..table_size { br_table.push_str(&format!(" {}", i)); } - wat.write_all(format!("{}{}\n", identation, br_table).as_bytes()).unwrap(); + wat.write_all(format!("{}{}\n", identation, br_table).as_bytes()) + .unwrap(); for _ in 0..table_size { rm_identation(&mut identation); - wat.write_all(format!("{})\n", identation).as_bytes()).unwrap(); + wat.write_all(format!("{})\n", identation).as_bytes()) + .unwrap(); } } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs index acb66fb391..8a79ba79f0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs @@ -9,7 +9,6 @@ pub fn write_specific_wat_beginning(wat: &mut Vec) { pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { for _ in 0..number_of_loop_iterations { - wat.write_all(b" call $nop\n") - .unwrap(); + wat.write_all(b" call $nop\n").unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs index ddcd24eaff..63b8829c44 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs @@ -12,8 +12,17 @@ pub fn write_wat_ops( instruction: &str, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", source_data_type, DataType::I32.gen()).as_bytes()).unwrap(); - wat.write_all(format!(" {}.{}\n", dest_data_type, instruction).as_bytes()).unwrap(); + wat.write_all( + format!( + " {}.const {}\n", + source_data_type, + DataType::I32.gen() + ) + .as_bytes(), + ) + .unwrap(); + wat.write_all(format!(" {}.{}\n", dest_data_type, instruction).as_bytes()) + .unwrap(); wat.write_all(b" drop\n").unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index 10895be62c..94d52ee20f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -8,7 +8,7 @@ use strum_macros::{Display, EnumString}; #[strum(serialize_all = "lowercase")] pub enum DataType { I32, - I64 + I64, } pub trait Rand { diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index 5545bd9cac..06c13c541f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -1,13 +1,20 @@ // Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use std::io::Write; use crate::scenarios::data_type::{DataType, Rand}; +use std::io::Write; -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str) { +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + data_type: DataType, + instruction: &str, +) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()).unwrap(); - wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) + .unwrap(); wat.write_all(b" drop\n").unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs index a6c2275ed1..dd4f20c542 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -1,8 +1,8 @@ // Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use std::io::Write; use crate::scenarios::data_type::{DataType, Rand}; +use std::io::Write; pub fn write_wat_ops( wat: &mut Vec, diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs index 7697e8d16d..f686a6d598 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs @@ -9,6 +9,7 @@ pub fn write_specific_exported_func_beginning(wat: &mut Vec) { pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { for _ in 0..number_of_loop_iterations { - wat.write_all(b" (local.set $var (i32.const 1073741823))\n").unwrap(); + wat.write_all(b" (local.set $var (i32.const 1073741823))\n") + .unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs index c442433bcf..ed81647cd5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs @@ -8,7 +8,8 @@ pub fn write_specific_exported_func_beginning(wat: &mut Vec) { } pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { - wat.write_all(b" (i32.const 1073741823)\n").unwrap(); + wat.write_all(b" (i32.const 1073741823)\n") + .unwrap(); for _ in 0..number_of_loop_iterations { wat.write_all(b" local.tee $var\n").unwrap(); } From d328ed433560a2a4a490c9842c421dbefa1278ca Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 11:00:44 -0300 Subject: [PATCH 108/131] ops_counter as global again --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 1bccb170f3..b05190f288 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -681,15 +681,13 @@ fn write_common_wat_beginning(wat: &mut Vec) { wat.write_all(b" (memory $memory 1)\n").unwrap(); wat.write_all(b" (export \"memory\" (memory $memory))\n") .unwrap(); + wat.write_all(b" (global $ops_counter (mut i32) (i32.const 0))\n") + .unwrap(); } fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" (func (export \"user_entrypoint\") (param i32) (result i32)\n") .unwrap(); - wat.write_all(b" (local $ops_counter i32)\n") - .unwrap(); - wat.write_all(b" (local.set $ops_counter (i32.const 0))\n") - .unwrap(); } fn write_loop_beginning(wat: &mut Vec) { @@ -705,7 +703,7 @@ fn write_wat_end( let number_of_ops = number_of_loop_iterations * number_of_ops_per_loop_iteration; // update ops_counter - wat.write_all(b" local.get $ops_counter\n") + wat.write_all(b" global.get $ops_counter\n") .unwrap(); wat.write_all( format!( @@ -716,10 +714,12 @@ fn write_wat_end( ) .unwrap(); wat.write_all(b" i32.add\n").unwrap(); - wat.write_all(b" local.tee $ops_counter\n") + wat.write_all(b" global.set $ops_counter\n") .unwrap(); // check if we need to continue looping + wat.write_all(b" global.get $ops_counter\n") + .unwrap(); wat.write_all(format!(" i32.const {}\n", number_of_ops).as_bytes()) .unwrap(); wat.write_all(b" i32.lt_s\n").unwrap(); From 3cd6b0ac0b90b4110370cb7fc23f153329e79c22 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:07:52 -0300 Subject: [PATCH 109/131] Update comments related to branch instructions --- arbitrator/tools/stylus_benchmark/src/scenarios/br.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs index a9ddd1f109..84f3dfbac1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs @@ -8,7 +8,7 @@ pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) wat.write_all(b" (block\n").unwrap(); wat.write_all(b" (block \n").unwrap(); wat.write_all(b" (block \n").unwrap(); - wat.write_all(b" br 2\n").unwrap(); // it will jump to the end of the last block + wat.write_all(b" br 2\n").unwrap(); // it will jump to the end of the first block wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs index be178a57be..fe7509b646 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs @@ -10,7 +10,7 @@ pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) wat.write_all(b" (block \n").unwrap(); wat.write_all(b" i32.const 1\n") .unwrap(); - wat.write_all(b" br_if 2\n").unwrap(); // it will jump to the end of the last block + wat.write_all(b" br_if 2\n").unwrap(); // it will jump to the end of the first block wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs index 02dee3501f..3fc5503b08 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -21,8 +21,9 @@ pub fn write_wat_ops( .unwrap(); identation.push_str(" "); } + // it will jump to the end of the first block wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()) - .unwrap(); // it will jump to the end of the last block + .unwrap(); let mut br_table = String::from("br_table"); for i in 0..table_size { From 8d259101a4319883b57f2f240ff2b52845b56ec6 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:16:33 -0300 Subject: [PATCH 110/131] Fix br_table --- arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs index 3fc5503b08..e3a0e00815 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -22,7 +22,7 @@ pub fn write_wat_ops( identation.push_str(" "); } // it will jump to the end of the first block - wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()) + wat.write_all(format!("{}i32.const {}\n", identation, table_size - 1).as_bytes()) .unwrap(); let mut br_table = String::from("br_table"); From fe323f6a041ff38c5190936cdda9c7dcb9badf2d Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:20:08 -0300 Subject: [PATCH 111/131] Fixes data_type.gen --- arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index 94d52ee20f..262250cc17 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -19,8 +19,9 @@ impl Rand for DataType { fn gen(&self) -> usize { let mut rng = rand::thread_rng(); match self { - DataType::I32 => (rng.gen::() >> 1).try_into().unwrap(), - DataType::I64 => (rng.gen::() >> 1).try_into().unwrap(), + // makes sure that the generated number fits a signed integer + DataType::I32 => (rng.gen::() / 2 - 1).try_into().unwrap(), + DataType::I64 => (rng.gen::() / 2 - 1).try_into().unwrap(), } } } From aef94dcb59670ee6cafeea55de420aec455a1070 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:33:04 -0300 Subject: [PATCH 112/131] Generates number in local.set --- .../tools/stylus_benchmark/src/scenarios/local_set.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs index f686a6d598..6333a84c06 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs @@ -1,6 +1,7 @@ // Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use crate::scenarios::data_type::{DataType, Rand}; use std::io::Write; pub fn write_specific_exported_func_beginning(wat: &mut Vec) { @@ -9,7 +10,13 @@ pub fn write_specific_exported_func_beginning(wat: &mut Vec) { pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { for _ in 0..number_of_loop_iterations { - wat.write_all(b" (local.set $var (i32.const 1073741823))\n") - .unwrap(); + wat.write_all( + format!( + " (local.set $var (i32.const {}))\n", + DataType::I32.gen() + ) + .as_bytes(), + ) + .unwrap(); } } From fb1e838cea17b5426c37f21192755f34bdf6c975 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:37:23 -0300 Subject: [PATCH 113/131] Fixes select --- .../tools/stylus_benchmark/src/scenarios/select.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs index 5ad3a996ee..7b744625a1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs @@ -1,14 +1,17 @@ // Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use crate::scenarios::data_type::{DataType, Rand}; use std::io::Write; pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 10\n").unwrap(); for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 20\n").unwrap(); + wat.write_all(format!(" i32.const {}\n", DataType::I32.gen()).as_bytes()) + .unwrap(); + wat.write_all(format!(" i32.const {}\n", DataType::I32.gen()).as_bytes()) + .unwrap(); wat.write_all(b" i32.const 0\n").unwrap(); wat.write_all(b" select\n").unwrap(); + wat.write_all(b" drop\n").unwrap(); } - wat.write_all(b" drop\n").unwrap(); } From 79422c9640570cb3408b9ee1ba24577e3cb4e942 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 10 Jan 2025 11:23:56 -0600 Subject: [PATCH 114/131] Create a metric for local block execution time --- execution/gethexec/executionengine.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index ffc6ceee9f..b4f91a1605 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -56,6 +56,7 @@ var ( txCountHistogram = metrics.NewRegisteredHistogram("arb/block/transactions/count", nil, metrics.NewBoundedHistogramSample()) txGasUsedHistogram = metrics.NewRegisteredHistogram("arb/block/transactions/gasused", nil, metrics.NewBoundedHistogramSample()) gasUsedSinceStartupCounter = metrics.NewRegisteredCounter("arb/gas_used", nil) + blockExecutionTimer = metrics.NewRegisteredTimer("arb/block/execution", nil) ) type L1PriceDataOfMsg struct { @@ -522,10 +523,11 @@ func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes. false, core.MessageCommitMode, ) + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } - blockCalcTime := time.Since(startTime) if len(hooks.TxErrors) != len(txes) { return nil, fmt.Errorf("unexpected number of error results: %v vs number of txes %v", len(hooks.TxErrors), len(txes)) } @@ -611,10 +613,11 @@ func (s *ExecutionEngine) sequenceDelayedMessageWithBlockMutex(message *arbostyp startTime := time.Now() block, statedb, receipts, err := s.createBlockFromNextMessage(&messageWithMeta, false) + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } - blockCalcTime := time.Since(startTime) msgResult, err := s.resultFromHeader(block.Header()) if err != nil { @@ -875,11 +878,13 @@ func (s *ExecutionEngine) digestMessageWithBlockMutex(num arbutil.MessageIndex, } block, statedb, receipts, err := s.createBlockFromNextMessage(msg, false) + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } - err = s.appendBlock(block, statedb, receipts, time.Since(startTime)) + err = s.appendBlock(block, statedb, receipts, blockCalcTime) if err != nil { return nil, err } From e3385d0eaa5aa8883a1b55786ec898592e7f2db2 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 10 Jan 2025 14:49:03 -0600 Subject: [PATCH 115/131] address PR comments --- execution/gethexec/executionengine.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index b4f91a1605..2475c816d4 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -57,6 +57,7 @@ var ( txGasUsedHistogram = metrics.NewRegisteredHistogram("arb/block/transactions/gasused", nil, metrics.NewBoundedHistogramSample()) gasUsedSinceStartupCounter = metrics.NewRegisteredCounter("arb/gas_used", nil) blockExecutionTimer = metrics.NewRegisteredTimer("arb/block/execution", nil) + blockWriteToDbTimer = metrics.NewRegisteredTimer("arb/block/writetodb", nil) ) type L1PriceDataOfMsg struct { @@ -523,11 +524,11 @@ func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes. false, core.MessageCommitMode, ) - blockCalcTime := time.Since(startTime) - blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) if len(hooks.TxErrors) != len(txes) { return nil, fmt.Errorf("unexpected number of error results: %v vs number of txes %v", len(hooks.TxErrors), len(txes)) } @@ -613,11 +614,11 @@ func (s *ExecutionEngine) sequenceDelayedMessageWithBlockMutex(message *arbostyp startTime := time.Now() block, statedb, receipts, err := s.createBlockFromNextMessage(&messageWithMeta, false) - blockCalcTime := time.Since(startTime) - blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) msgResult, err := s.resultFromHeader(block.Header()) if err != nil { @@ -704,6 +705,7 @@ func (s *ExecutionEngine) appendBlock(block *types.Block, statedb *state.StateDB for _, receipt := range receipts { logs = append(logs, receipt.Logs...) } + startTime := time.Now() status, err := s.bc.WriteBlockAndSetHeadWithTime(block, receipts, logs, statedb, true, duration) if err != nil { return err @@ -711,6 +713,8 @@ func (s *ExecutionEngine) appendBlock(block *types.Block, statedb *state.StateDB if status == core.SideStatTy { return errors.New("geth rejected block as non-canonical") } + blockCalcTime := time.Since(startTime) + blockWriteToDbTimer.Update(blockCalcTime) baseFeeGauge.Update(block.BaseFee().Int64()) txCountHistogram.Update(int64(len(block.Transactions()) - 1)) var blockGasused uint64 @@ -878,11 +882,11 @@ func (s *ExecutionEngine) digestMessageWithBlockMutex(num arbutil.MessageIndex, } block, statedb, receipts, err := s.createBlockFromNextMessage(msg, false) - blockCalcTime := time.Since(startTime) - blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) err = s.appendBlock(block, statedb, receipts, blockCalcTime) if err != nil { From 7bab83a5af5b9e67b324580de287336addb7b7de Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Fri, 10 Jan 2025 15:51:22 -0700 Subject: [PATCH 116/131] fix arbitrator-ci --- .github/workflows/arbitrator-ci.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 0355ebb722..45cf3c1a3d 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -74,14 +74,6 @@ jobs: targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'rust-src, rustfmt, clippy' - - name: Install rust stable - id: install-rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: '1.80.1' - targets: 'wasm32-wasi, wasm32-unknown-unknown' - components: 'llvm-tools-preview, rustfmt, clippy' - - name: Install rust stable id: install-rust uses: dtolnay/rust-toolchain@stable From fe7ee6e9146054713b89ed5b4408cdc55478a5f6 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 10 Jan 2025 16:57:18 -0600 Subject: [PATCH 117/131] fix typo --- execution/gethexec/executionengine.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index 2475c816d4..7cf83c7183 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -713,8 +713,7 @@ func (s *ExecutionEngine) appendBlock(block *types.Block, statedb *state.StateDB if status == core.SideStatTy { return errors.New("geth rejected block as non-canonical") } - blockCalcTime := time.Since(startTime) - blockWriteToDbTimer.Update(blockCalcTime) + blockWriteToDbTimer.Update(time.Since(startTime)) baseFeeGauge.Update(block.BaseFee().Int64()) txCountHistogram.Update(int64(len(block.Transactions()) - 1)) var blockGasused uint64 From 34ef4c28bbe79207866a64c96ffe853a56016ffc Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 20:04:40 -0300 Subject: [PATCH 118/131] Uses catch all in match --- .../tools/stylus_benchmark/src/scenario.rs | 149 +----------------- 1 file changed, 2 insertions(+), 147 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index b05190f288..8856080d05 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -102,165 +102,20 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { - Scenario::Br => {} - Scenario::BrIf => {} - Scenario::BrTable => {} Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), - Scenario::I32Add => {} - Scenario::I32And => {} - Scenario::I32Clz => {} - Scenario::I32Ctz => {} - Scenario::I32DivS => {} - Scenario::I32DivU => {} - Scenario::I32Eq => {} - Scenario::I32Eqz => {} - Scenario::I32GeS => {} - Scenario::I32GeU => {} - Scenario::I32GtU => {} - Scenario::I32GtS => {} - Scenario::I32LeU => {} - Scenario::I32LeS => {} - Scenario::I32Load => {} - Scenario::I32LtU => {} - Scenario::I32LtS => {} - Scenario::I32Mul => {} - Scenario::I32Ne => {} - Scenario::I32Or => {} - Scenario::I32Popcnt => {} - Scenario::I32RemS => {} - Scenario::I32RemU => {} - Scenario::I32Rotl => {} - Scenario::I32Rotr => {} - Scenario::I32Shl => {} - Scenario::I32ShrS => {} - Scenario::I32ShrU => {} - Scenario::I32Store => {} - Scenario::I32Sub => {} - Scenario::I32WrapI64 => {} - Scenario::I32Xor => {} - Scenario::I64Add => {} - Scenario::I64And => {} - Scenario::I64Clz => {} - Scenario::I64Ctz => {} - Scenario::I64DivS => {} - Scenario::I64DivU => {} - Scenario::I64Eq => {} - Scenario::I64Eqz => {} - Scenario::I64GeS => {} - Scenario::I64GeU => {} - Scenario::I64GtU => {} - Scenario::I64GtS => {} - Scenario::I64LeU => {} - Scenario::I64LeS => {} - Scenario::I64Load => {} - Scenario::I64LtU => {} - Scenario::I64LtS => {} - Scenario::I64Mul => {} - Scenario::I64Ne => {} - Scenario::I64Or => {} - Scenario::I64Popcnt => {} - Scenario::I64RemS => {} - Scenario::I64RemU => {} - Scenario::I64Rotl => {} - Scenario::I64Rotr => {} - Scenario::I64Shl => {} - Scenario::I64ShrS => {} - Scenario::I64ShrU => {} - Scenario::I64Store => {} - Scenario::I64Sub => {} - Scenario::I64Xor => {} - Scenario::I64ExtendI32U => {} - Scenario::I64ExtendI32S => {} - Scenario::If => {} - Scenario::LocalGet => {} - Scenario::LocalSet => {} - Scenario::LocalTee => {} - Scenario::Select => {} + _ => {} } } fn write_specific_exported_func_beginning(&self, wat: &mut Vec) { match self { - Scenario::Br => {} - Scenario::BrIf => {} - Scenario::BrTable => {} - Scenario::Call => {} - Scenario::CallIndirect => {} - Scenario::GlobalGet => {} - Scenario::GlobalSet => {} - Scenario::I32Add => {} - Scenario::I32And => {} - Scenario::I32Clz => {} - Scenario::I32Ctz => {} - Scenario::I32DivS => {} - Scenario::I32DivU => {} - Scenario::I32Eq => {} - Scenario::I32Eqz => {} - Scenario::I32GeS => {} - Scenario::I32GeU => {} - Scenario::I32GtU => {} - Scenario::I32GtS => {} - Scenario::I32LeU => {} - Scenario::I32LeS => {} - Scenario::I32Load => {} - Scenario::I32LtU => {} - Scenario::I32LtS => {} - Scenario::I32Mul => {} - Scenario::I32Ne => {} - Scenario::I32Or => {} - Scenario::I32Popcnt => {} - Scenario::I32RemS => {} - Scenario::I32RemU => {} - Scenario::I32Rotl => {} - Scenario::I32Rotr => {} - Scenario::I32Shl => {} - Scenario::I32ShrS => {} - Scenario::I32ShrU => {} - Scenario::I32Store => {} - Scenario::I32Sub => {} - Scenario::I32WrapI64 => {} - Scenario::I32Xor => {} - Scenario::I64Add => {} - Scenario::I64And => {} - Scenario::I64Clz => {} - Scenario::I64Ctz => {} - Scenario::I64DivS => {} - Scenario::I64DivU => {} - Scenario::I64Eq => {} - Scenario::I64Eqz => {} - Scenario::I64GeS => {} - Scenario::I64GeU => {} - Scenario::I64GtU => {} - Scenario::I64GtS => {} - Scenario::I64LeU => {} - Scenario::I64LeS => {} - Scenario::I64Load => {} - Scenario::I64LtU => {} - Scenario::I64LtS => {} - Scenario::I64Mul => {} - Scenario::I64Ne => {} - Scenario::I64Or => {} - Scenario::I64Popcnt => {} - Scenario::I64RemS => {} - Scenario::I64RemU => {} - Scenario::I64Rotl => {} - Scenario::I64Rotr => {} - Scenario::I64Shl => {} - Scenario::I64ShrS => {} - Scenario::I64ShrU => {} - Scenario::I64Store => {} - Scenario::I64Sub => {} - Scenario::I64Xor => {} - Scenario::I64ExtendI32U => {} - Scenario::I64ExtendI32S => {} - Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), Scenario::LocalSet => local_set::write_specific_exported_func_beginning(wat), Scenario::LocalTee => local_tee::write_specific_exported_func_beginning(wat), - Scenario::Select => {} + _ => {} } } From 18478e0c43a15c582cc63249c10a384cab299937 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Fri, 10 Jan 2025 16:08:31 -0700 Subject: [PATCH 119/131] add targets to arbitrator --- .github/workflows/arbitrator-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 45cf3c1a3d..51c0617f3e 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -79,6 +79,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: '1.80.1' + targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'llvm-tools-preview, rustfmt, clippy' - name: Set STYLUS_NIGHTLY_VER environment variable From 35ae6f32bb1e55a65ad40983be61ca15898f5746 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 20:32:51 -0300 Subject: [PATCH 120/131] Fixes data_type.gen --- arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index 262250cc17..f7af36fdd5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -19,9 +19,8 @@ impl Rand for DataType { fn gen(&self) -> usize { let mut rng = rand::thread_rng(); match self { - // makes sure that the generated number fits a signed integer - DataType::I32 => (rng.gen::() / 2 - 1).try_into().unwrap(), - DataType::I64 => (rng.gen::() / 2 - 1).try_into().unwrap(), + DataType::I32 => rng.gen_range(0..i32::MAX).try_into().unwrap(), + DataType::I64 => rng.gen_range(0..i64::MAX).try_into().unwrap(), } } } From f3139eaa1ed6b605aea38a4aa844e38ddd8976ae Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Sat, 11 Jan 2025 20:37:16 -0700 Subject: [PATCH 121/131] Fix `--execution.rpc.gas-cap=0` to again mean infinite gas There was a regression introduced in v3.3.0 where specifying `--execution.rpc.gas-cap=0` would cause gas related errors. --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index dd32b782ed..aaded574dc 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit dd32b782ed255c1ac20ed5beee11dd6a821f9be2 +Subproject commit aaded574dcf7b2f6b5851ee858603cb61335217e From 26b4c1028fdc8475c349510dbe392d99e27dc082 Mon Sep 17 00:00:00 2001 From: dashangcun <907225865@qq.com> Date: Mon, 13 Jan 2025 17:42:03 +0800 Subject: [PATCH 122/131] refactor: using slices.Contains to simplify the code Signed-off-by: dashangcun <907225865@qq.com> --- cmd/conf/init.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/cmd/conf/init.go b/cmd/conf/init.go index 74bd89fd16..97b31958d5 100644 --- a/cmd/conf/init.go +++ b/cmd/conf/init.go @@ -3,6 +3,7 @@ package conf import ( "fmt" "runtime" + "slices" "strings" "time" @@ -106,7 +107,7 @@ func (c *InitConfig) Validate() error { if c.Force && c.RecreateMissingStateFrom > 0 { log.Warn("force init enabled, recreate-missing-state-from will have no effect") } - if c.Latest != "" && !isAcceptedSnapshotKind(c.Latest) { + if c.Latest != "" && !slices.Contains(acceptedSnapshotKinds, c.Latest) { return fmt.Errorf("invalid value for latest option: \"%s\" %s", c.Latest, acceptedSnapshotKindsStr) } if c.Prune != "" && c.PruneThreads <= 0 { @@ -139,12 +140,3 @@ var ( acceptedSnapshotKinds = []string{"archive", "pruned", "genesis"} acceptedSnapshotKindsStr = "(accepted values: \"" + strings.Join(acceptedSnapshotKinds, "\" | \"") + "\")" ) - -func isAcceptedSnapshotKind(kind string) bool { - for _, valid := range acceptedSnapshotKinds { - if kind == valid { - return true - } - } - return false -} From c721fdbf0f6e824b25f2c78875b079bb0d2aa5ed Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Mon, 13 Jan 2025 18:43:37 +0100 Subject: [PATCH 123/131] Fix typo pimative -> primitive --- ...traint-types.md => 0001-avoid-primitive-constraint-types.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename docs/decisions/{0001-avoid-primative-constraint-types.md => 0001-avoid-primitive-constraint-types.md} (98%) diff --git a/docs/decisions/0001-avoid-primative-constraint-types.md b/docs/decisions/0001-avoid-primitive-constraint-types.md similarity index 98% rename from docs/decisions/0001-avoid-primative-constraint-types.md rename to docs/decisions/0001-avoid-primitive-constraint-types.md index b52cea8bdd..8a3ecb0632 100644 --- a/docs/decisions/0001-avoid-primative-constraint-types.md +++ b/docs/decisions/0001-avoid-primitive-constraint-types.md @@ -4,7 +4,7 @@ date: 2024-11-29 decision-makers: eljobe@ plasmapower@ --- -# Avoid primative constraint types +# Avoid primitive constraint types ## Context and Problem Statement From b7e28f2f12c8b808ade3f0103d45d780cdb19c83 Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Mon, 13 Jan 2025 11:53:45 -0700 Subject: [PATCH 124/131] Update geth pin to pull in extra comment --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index aaded574dc..779b669ac0 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit aaded574dcf7b2f6b5851ee858603cb61335217e +Subproject commit 779b669ac0d0020099a67a1c39fbaf66b901c1a5 From 84bfafa45edf97a50828a0d57790cdaed3999b42 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Tue, 14 Jan 2025 10:25:11 -0700 Subject: [PATCH 125/131] Enable the geth trie prefetcher for the sequencer --- execution/gethexec/executionengine.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index 7cf83c7183..e606027419 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -508,6 +508,8 @@ func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes. if err != nil { return nil, err } + statedb.StartPrefetcher("Sequencer") + defer statedb.StopPrefetcher() delayedMessagesRead := lastBlockHeader.Nonce.Uint64() From b18e8f0d8d48093c7a2986404ae78870b76c888b Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Tue, 14 Jan 2025 14:39:00 -0700 Subject: [PATCH 126/131] Revert wasmer update New version of wasmer considers binaries created by current version of wasmer as incompatible. Will delay merging in new versions to reduce the number of times that stylus contracts will need to be recompiled. This reverts commit 93841cee1db6d2fc826c169992aa8bb73163703b, reversing changes made to 3ba8fc2dd39315e2d449f5f6666c23a472d11cf1. --- arbitrator/Cargo.lock | 61 +++++++++++----------------- arbitrator/tools/wasmer | 2 +- arbitrator/wasm-libraries/Cargo.lock | 14 +------ 3 files changed, 25 insertions(+), 52 deletions(-) diff --git a/arbitrator/Cargo.lock b/arbitrator/Cargo.lock index 9688d07229..2b437968fa 100644 --- a/arbitrator/Cargo.lock +++ b/arbitrator/Cargo.lock @@ -747,12 +747,11 @@ dependencies = [ [[package]] name = "dashmap" -version = "6.1.0" +version = "5.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils", "hashbrown 0.14.5", "lock_api", "once_cell", @@ -975,10 +974,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", - "js-sys", "libc", "wasi", - "wasm-bindgen", ] [[package]] @@ -1315,6 +1312,15 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + [[package]] name = "mach2" version = "0.4.2" @@ -2552,7 +2558,7 @@ dependencies = [ [[package]] name = "wasmer" -version = "4.3.7" +version = "4.2.8" dependencies = [ "bytes", "cfg-if 1.0.0", @@ -2574,12 +2580,12 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wat", - "windows-sys 0.59.0", + "winapi", ] [[package]] name = "wasmer-compiler" -version = "4.3.7" +version = "4.2.8" dependencies = [ "backtrace", "bytes", @@ -2588,7 +2594,6 @@ dependencies = [ "enumset", "lazy_static", "leb128", - "libc", "memmap2 0.5.10", "more-asserts", "region", @@ -2600,13 +2605,12 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wasmparser", - "windows-sys 0.59.0", - "xxhash-rust", + "winapi", ] [[package]] name = "wasmer-compiler-cranelift" -version = "4.3.7" +version = "4.2.8" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -2623,7 +2627,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-llvm" -version = "4.3.7" +version = "4.2.8" dependencies = [ "byteorder", "cc", @@ -2645,7 +2649,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "4.3.7" +version = "4.2.8" dependencies = [ "byteorder", "dynasm", @@ -2662,7 +2666,7 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "4.3.7" +version = "4.2.8" dependencies = [ "proc-macro-error", "proc-macro2", @@ -2672,25 +2676,21 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.3.7" +version = "4.2.8" dependencies = [ "bytecheck", "enum-iterator 0.7.0", "enumset", - "getrandom", - "hex", "indexmap 1.9.3", "more-asserts", "rkyv", - "sha2 0.10.8", "target-lexicon", "thiserror", - "xxhash-rust", ] [[package]] name = "wasmer-vm" -version = "4.3.7" +version = "4.2.8" dependencies = [ "backtrace", "cc", @@ -2704,14 +2704,14 @@ dependencies = [ "indexmap 1.9.3", "lazy_static", "libc", - "mach2", + "mach", "memoffset", "more-asserts", "region", "scopeguard", "thiserror", "wasmer-types", - "windows-sys 0.59.0", + "winapi", ] [[package]] @@ -2830,15 +2830,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" @@ -2951,12 +2942,6 @@ dependencies = [ "tap", ] -[[package]] -name = "xxhash-rust" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" - [[package]] name = "zerocopy" version = "0.6.6" diff --git a/arbitrator/tools/wasmer b/arbitrator/tools/wasmer index 84aec79c13..6b15433d83 160000 --- a/arbitrator/tools/wasmer +++ b/arbitrator/tools/wasmer @@ -1 +1 @@ -Subproject commit 84aec79c13888bf3fb324ddbd69b3fecc22d4a8c +Subproject commit 6b15433d83f951555c24f0c56dc05e4751b0cc76 diff --git a/arbitrator/wasm-libraries/Cargo.lock b/arbitrator/wasm-libraries/Cargo.lock index e62acf43a6..a5a066e5c9 100644 --- a/arbitrator/wasm-libraries/Cargo.lock +++ b/arbitrator/wasm-libraries/Cargo.lock @@ -518,10 +518,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", - "js-sys", "libc", "wasi", - "wasm-bindgen", ] [[package]] @@ -1635,20 +1633,16 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.3.7" +version = "4.2.8" dependencies = [ "bytecheck", "enum-iterator 0.7.0", "enumset", - "getrandom", - "hex", "indexmap 1.9.3", "more-asserts", "rkyv", - "sha2 0.10.8", "target-lexicon", "thiserror", - "xxhash-rust", ] [[package]] @@ -1809,12 +1803,6 @@ dependencies = [ "tap", ] -[[package]] -name = "xxhash-rust" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" - [[package]] name = "zerocopy" version = "0.7.35" From f272f84ae0043c8e8992811468583e9d9c8d149a Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Thu, 16 Jan 2025 10:07:37 -0600 Subject: [PATCH 127/131] Upgrade actions/upload-artifact in CI --- .github/workflows/ci.yml | 2 +- .github/workflows/docker.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4ce5bf27f..2e9c7e1bf4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -204,7 +204,7 @@ jobs: run: ${{ github.workspace }}/.github/workflows/gotestsum.sh --tags stylustest --run TestProgramLong --timeout 60m --cover - name: Archive detailed run log - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ matrix.test-mode }}-full.log path: full.log diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2aacf32f00..8526024fb3 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -81,7 +81,7 @@ jobs: echo -e "\x1b[1;34mWAVM module root:\x1b[0m $module_root" - name: Upload WAVM machine as artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: wavm-machine-${{ steps.module-root.outputs.module-root }} path: target/machines/latest/* From 1748e8bdca91627f68f4d20006f638097677a02f Mon Sep 17 00:00:00 2001 From: linchizhen Date: Fri, 17 Jan 2025 17:11:34 +0800 Subject: [PATCH 128/131] chore: fix some function names in comment Signed-off-by: linchizhen --- arbnode/batch_poster.go | 2 +- arbnode/delay_buffer.go | 2 +- cmd/genericconf/logging.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arbnode/batch_poster.go b/arbnode/batch_poster.go index 70c5952042..7e87d9a05e 100644 --- a/arbnode/batch_poster.go +++ b/arbnode/batch_poster.go @@ -539,7 +539,7 @@ func (b *BatchPoster) getTxsInfoByBlock(ctx context.Context, number int64) ([]tx return blk.Transactions, nil } -// checkRevert checks blocks with number in range [from, to] whether they +// checkReverts checks blocks with number in range [from, to] whether they // contain reverted batch_poster transaction. // It returns true if it finds batch posting needs to halt, which is true if a batch reverts // unless the data poster is configured with noop storage which can tolerate reverts. diff --git a/arbnode/delay_buffer.go b/arbnode/delay_buffer.go index 3f0514bbe2..f2d73076ef 100644 --- a/arbnode/delay_buffer.go +++ b/arbnode/delay_buffer.go @@ -26,7 +26,7 @@ type DelayBufferConfig struct { Threshold uint64 } -// GetBufferConfig gets the delay buffer config from the sequencer inbox contract. +// GetDelayBufferConfig gets the delay buffer config from the sequencer inbox contract. // If the contract doesn't support the delay buffer, it returns a config with Enabled set to false. func GetDelayBufferConfig(ctx context.Context, sequencerInbox *bridgegen.SequencerInbox) ( *DelayBufferConfig, error) { diff --git a/cmd/genericconf/logging.go b/cmd/genericconf/logging.go index 4cdaa5f3e8..a7a4fa88d5 100644 --- a/cmd/genericconf/logging.go +++ b/cmd/genericconf/logging.go @@ -89,7 +89,7 @@ func (l *fileLoggerFactory) close() error { return nil } -// initLog is not threadsafe +// InitLog is not threadsafe func InitLog(logType string, logLevel string, fileLoggingConfig *FileLoggingConfig, pathResolver func(string) string) error { var glogger *log.GlogHandler // always close previous instance of file logger From ab3c7f0a3deeb744397ee6503efff442684ea25e Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Fri, 17 Jan 2025 14:22:01 +0100 Subject: [PATCH 129/131] Add the installation of the cbindgen binary This binary is used in the make invocation, so it needs to be installed. --- .github/workflows/codeql-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 26447947d4..247f434ea0 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -128,7 +128,7 @@ jobs: restore-keys: ${{ runner.os }}-go- - name: Build all lint dependencies - run: make -j build-node-deps + run: cargo install --force cbindgen && make -j build-node-deps # ℹī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun From 7244e7a39304b17319a519a3dc73fb8a8b3ea251 Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Mon, 20 Jan 2025 09:47:52 +0100 Subject: [PATCH 130/131] Add cbindgen to both workflows It turns out that the ci.yml workflow was also failing because of the removal of cbindgen from the Ubuntu 24.04 image used by the GitHub action runners. This change also moves the installation of cbindgen earlier in the codequl-analysis.yml file and expands the scope of what is cached after a rust installation to include the cbindgen binary (which is installed in ~/.cargo/bin) --- .github/workflows/ci.yml | 3 +++ .github/workflows/codeql-analysis.yml | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e9c7e1bf4..32f50917d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,9 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 + + - name: Install cbindgen + run: cargo install --force cbindgen - name: Cache Build Products uses: actions/cache@v3 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 247f434ea0..f9a46a92c3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -81,12 +81,14 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 + - name: Install cbindgen + run: cargo install --force cbindgen + - name: Cache Rust Build Products uses: actions/cache@v3 with: path: | - ~/.cargo/registry/ - ~/.cargo/git/ + ~/.cargo/ arbitrator/target/ arbitrator/wasm-libraries/target/ arbitrator/wasm-libraries/soft-float/SoftFloat/build @@ -128,7 +130,7 @@ jobs: restore-keys: ${{ runner.os }}-go- - name: Build all lint dependencies - run: cargo install --force cbindgen && make -j build-node-deps + run: make -j build-node-deps # ℹī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun From 9d66ce67951313050f55c724a53f3f1ae8415c0d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 12:59:18 +0000 Subject: [PATCH 131/131] Bump golang.org/x/net from 0.26.0 to 0.33.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.26.0 to 0.33.0. - [Commits](https://github.com/golang/net/compare/v0.26.0...v0.33.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e85906b22f..562ab073d4 100644 --- a/go.mod +++ b/go.mod @@ -193,7 +193,7 @@ require ( github.com/yusufpapurcu/wmi v1.2.2 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/mod v0.17.0 // indirect - golang.org/x/net v0.26.0 // indirect + golang.org/x/net v0.33.0 // indirect golang.org/x/oauth2 v0.22.0 golang.org/x/sync v0.10.0 golang.org/x/text v0.21.0 // indirect diff --git a/go.sum b/go.sum index 27c408c723..285e4fb872 100644 --- a/go.sum +++ b/go.sum @@ -565,8 +565,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=