From ae87e88690d010030660f55ddf47b14ae5364983 Mon Sep 17 00:00:00 2001 From: Sergey Kuznetsov Date: Wed, 2 Sep 2026 11:41:36 +0100 Subject: [PATCH] refactor: Use temINVALID_BYTECODE istead of temBAD_WASM (#8156) --- crates/xrpl-wasm-vm-ffi/src/lib.rs | 2 +- include/xrpl/protocol/TER.h | 2 +- include/xrpl/tx/wasm/WasmVM.h | 2 +- src/libxrpl/protocol/TER.cpp | 2 +- src/libxrpl/tx/wasm/WasmVM.cpp | 2 +- src/tests/libxrpl/tx/wasm/Preflight.cpp | 26 ++++++++++++------------- src/tests/libxrpl/tx/wasm/WasmVM.cpp | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/crates/xrpl-wasm-vm-ffi/src/lib.rs b/crates/xrpl-wasm-vm-ffi/src/lib.rs index f0bfa8e833..4b26ae2f9a 100644 --- a/crates/xrpl-wasm-vm-ffi/src/lib.rs +++ b/crates/xrpl-wasm-vm-ffi/src/lib.rs @@ -1271,7 +1271,7 @@ mod tests { } /// A panic during a check is its own status rather than one more malformed - /// module: the far side answers a node-local failure, not `temBAD_WASM`. + /// module: the far side answers a node-local failure, not `temINVALID_BYTECODE`. #[test] fn a_panic_during_a_check_becomes_a_status_instead_of_an_unwind() { let crossed = guarded( diff --git a/include/xrpl/protocol/TER.h b/include/xrpl/protocol/TER.h index b2f45b3267..393ea91a78 100644 --- a/include/xrpl/protocol/TER.h +++ b/include/xrpl/protocol/TER.h @@ -132,7 +132,7 @@ enum TEMcodes : TERUnderlyingType { temBAD_MPT, temBAD_CIPHERTEXT, - temBAD_WASM, + temINVALID_BYTECODE, }; //------------------------------------------------------------------------------ diff --git a/include/xrpl/tx/wasm/WasmVM.h b/include/xrpl/tx/wasm/WasmVM.h index 99161b93af..51ea24dce1 100644 --- a/include/xrpl/tx/wasm/WasmVM.h +++ b/include/xrpl/tx/wasm/WasmVM.h @@ -37,7 +37,7 @@ runEscrowWasm( // That is what makes this callable from a transactor's `preflight`, which has no view // to build a host over. // -// `temBAD_WASM` for every fault in the module - the transaction carries something this +// `temINVALID_BYTECODE` for every fault in the module - the transaction carries something this // engine cannot run, so it is refused before it can reach the ledger. // `telFAILED_PROCESSING` if the engine itself failed: nothing was learned about the // module, and a defect here is not evidence that the transaction is malformed. diff --git a/src/libxrpl/protocol/TER.cpp b/src/libxrpl/protocol/TER.cpp index 345edc2ee4..b69ecd5612 100644 --- a/src/libxrpl/protocol/TER.cpp +++ b/src/libxrpl/protocol/TER.cpp @@ -205,7 +205,7 @@ transResults() MAKE_ERROR(temBAD_TRANSFER_FEE, "Malformed: Transfer fee is outside valid range."), MAKE_ERROR(temINVALID_INNER_BATCH, "Malformed: Invalid inner batch transaction."), MAKE_ERROR(temBAD_CIPHERTEXT, "Malformed: Invalid ciphertext."), - MAKE_ERROR(temBAD_WASM, "Malformed: Provided WASM code is invalid."), + MAKE_ERROR(temINVALID_BYTECODE, "Malformed: Provided byte code is invalid."), MAKE_ERROR(terRETRY, "Retry transaction."), MAKE_ERROR(terFUNDS_SPENT, "DEPRECATED."), diff --git a/src/libxrpl/tx/wasm/WasmVM.cpp b/src/libxrpl/tx/wasm/WasmVM.cpp index 7f05eea138..711a69e9f1 100644 --- a/src/libxrpl/tx/wasm/WasmVM.cpp +++ b/src/libxrpl/tx/wasm/WasmVM.cpp @@ -104,7 +104,7 @@ verdict(CheckStatus status) case CheckStatus::EntryPoint: case CheckStatus::Memory: case CheckStatus::Table: - return temBAD_WASM; + return temINVALID_BYTECODE; // The engine panicked: a defect in the engine, reported rather than fatal to // the node, and not the transaction's fault. diff --git a/src/tests/libxrpl/tx/wasm/Preflight.cpp b/src/tests/libxrpl/tx/wasm/Preflight.cpp index 24b358b269..2309fafd46 100644 --- a/src/tests/libxrpl/tx/wasm/Preflight.cpp +++ b/src/tests/libxrpl/tx/wasm/Preflight.cpp @@ -62,8 +62,8 @@ TEST_F(PreflightTest, RunnableContractPasses) TEST_F(PreflightTest, GarbageIsRefused) { - EXPECT_EQ(preflightBytes(Bytes{}), temBAD_WASM); - EXPECT_EQ(preflightBytes(Bytes{0x00, 0x61, 0x73, 0x6d}), temBAD_WASM); + EXPECT_EQ(preflightBytes(Bytes{}), temINVALID_BYTECODE); + EXPECT_EQ(preflightBytes(Bytes{0x00, 0x61, 0x73, 0x6d}), temINVALID_BYTECODE); } // The engine takes wasm binaries, and text is not one. The suite writes its modules as text @@ -73,7 +73,7 @@ TEST_F(PreflightTest, TextFormatModuleIsRefused) { Bytes const text{kRunnableWat.begin(), kRunnableWat.end()}; - EXPECT_EQ(preflightBytes(text), temBAD_WASM); + EXPECT_EQ(preflightBytes(text), temINVALID_BYTECODE); EXPECT_EQ(preflight(kRunnableWat), tesSUCCESS) << "the same module, assembled first"; } @@ -86,7 +86,7 @@ TEST_F(PreflightTest, ImportOfAnUnknownHostFunctionIsRefused) (func (export "escrow_finish") (result i32) (call $f (i32.const 0)))) )wat"; - EXPECT_EQ(preflight(wat), temBAD_WASM); + EXPECT_EQ(preflight(wat), temINVALID_BYTECODE); EXPECT_THAT(logged(), testing::HasSubstr("no host function 'no_such_function'")); } @@ -101,7 +101,7 @@ TEST_F(PreflightTest, ImportFromAnotherModuleIsRefused) (func (export "escrow_finish") (result i32) (i32.const 0))) )wat"; - EXPECT_EQ(preflight(wat), temBAD_WASM); + EXPECT_EQ(preflight(wat), temINVALID_BYTECODE); EXPECT_THAT(logged(), testing::HasSubstr("is not from 'host_lib'")); } @@ -115,7 +115,7 @@ TEST_F(PreflightTest, MemoryPastTheCapIsRefused) (func (export "escrow_finish") (result i32) (i32.const 0))) )wat"; - EXPECT_EQ(preflight(tooMuch), temBAD_WASM); + EXPECT_EQ(preflight(tooMuch), temINVALID_BYTECODE); EXPECT_THAT(logged(), testing::HasSubstr("memory: initial memory of 129 pages")); constexpr std::string_view atTheCap = R"wat( @@ -139,7 +139,7 @@ TEST_F(PreflightTest, TablePastTheCapIsRefused) (func (export "escrow_finish") (result i32) (i32.const 0))) )wat"; - EXPECT_EQ(preflight(tooMuch), temBAD_WASM); + EXPECT_EQ(preflight(tooMuch), temINVALID_BYTECODE); EXPECT_THAT(logged(), testing::HasSubstr("table: initial table of 1025 elements")); constexpr std::string_view atTheCap = R"wat( @@ -160,7 +160,7 @@ TEST_F(PreflightTest, MissingEntryPointIsRefused) (func (export "other") (result i32) (i32.const 0))) )wat"; - EXPECT_EQ(preflight(wat), temBAD_WASM); + EXPECT_EQ(preflight(wat), temINVALID_BYTECODE); EXPECT_THAT(logged(), testing::HasSubstr("no entry point 'escrow_finish'")); } @@ -172,7 +172,7 @@ TEST_F(PreflightTest, EntryPointOfTheWrongTypeIsRefused) (func (export "escrow_finish") (result i64) (i64.const 0))) )wat"; - EXPECT_EQ(preflight(wat), temBAD_WASM); + EXPECT_EQ(preflight(wat), temINVALID_BYTECODE); EXPECT_THAT(logged(), testing::HasSubstr("has the wrong signature")); } @@ -187,18 +187,18 @@ TEST_F(PreflightTest, EntryPointIsTheNameTheCallerGives) )wat"; EXPECT_EQ(preflight(wat, "other"), tesSUCCESS); - EXPECT_EQ(preflight(wat), temBAD_WASM); + EXPECT_EQ(preflight(wat), temINVALID_BYTECODE); } // Every refusal is logged with the engine's own description and the TER: without it a node -// operator has a `temBAD_WASM` and no way to tell a contract author which of the three +// operator has a `temINVALID_BYTECODE` and no way to tell a contract author which of the three // stages refused the module. TEST_F(PreflightTest, RefusalNamesTheReasonAndTheTer) { - EXPECT_EQ(preflightBytes(Bytes{0x00, 0x61, 0x73, 0x6d}), temBAD_WASM); + EXPECT_EQ(preflightBytes(Bytes{0x00, 0x61, 0x73, 0x6d}), temINVALID_BYTECODE); EXPECT_THAT(logged(), testing::HasSubstr("compile: ")); - EXPECT_THAT(logged(), testing::HasSubstr(transToken(temBAD_WASM))); + EXPECT_THAT(logged(), testing::HasSubstr(transToken(temINVALID_BYTECODE))); } // A module that passes screening still has to pass the run's own stages, and one that fails diff --git a/src/tests/libxrpl/tx/wasm/WasmVM.cpp b/src/tests/libxrpl/tx/wasm/WasmVM.cpp index 9b1f8fd291..f4c771872a 100644 --- a/src/tests/libxrpl/tx/wasm/WasmVM.cpp +++ b/src/tests/libxrpl/tx/wasm/WasmVM.cpp @@ -136,7 +136,7 @@ TEST_F(WasmVMTest, ModuleThatWillNotInstantiateIsChargedToTheContract) EXPECT_TRUE(outcome.error().cost.has_value()); } -// Preflight is meant to refuse these with `temBAD_WASM`; reaching apply means the screening +// Preflight is meant to refuse these with `temINVALID_BYTECODE`; reaching apply means the screening // did not happen, which is the node's fault and not the transaction's. TEST_F(WasmVMTest, UnrunnableModuleIsNodeSideFault) {