From 22d0291f774ed7ca3219675dec3dd034b9eaf622 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Fri, 21 Nov 2025 15:46:38 +0530 Subject: [PATCH 1/7] add infinite loop test --- src/test/app/Wasm_test.cpp | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index b7ad172f2f6..aa9ba688c03 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -715,6 +715,67 @@ struct Wasm_test : public beast::unit_test::suite } } + void + testInfiniteLoop() + { + testcase("infinite loop"); + + using namespace test::jtx; + Env env{*this}; + + /* + void + loop() + { + int volatile x = 0; + while (1) + x++; + } + */ + static std::string const infiniteWasmHex = + "0061736d01000000010401600000030302000005030100020638097f004180080b" + "7f004180" + "080b7f004180080b7f00418088040b7f004180080b7f00418088040b7f00418080" + "080b7f00" + "41000b7f0041010b07a8010c066d656d6f72790200115f5f7761736d5f63616c6c" + "5f63746f" + "72730000046c6f6f7000010c5f5f64736f5f68616e646c6503000a5f5f64617461" + "5f656e64" + "03010b5f5f737461636b5f6c6f7703020c5f5f737461636b5f6869676803030d5f" + "5f676c6f" + "62616c5f6261736503040b5f5f686561705f6261736503050a5f5f686561705f65" + "6e640306" + "0d5f5f6d656d6f72795f6261736503070c5f5f7461626c655f6261736503080a27" + "0202000b" + "220041fc87044100360200034041fc870441fc870428020041016a3602000c000b" + "000b007f" + "0970726f647563657273010c70726f6365737365642d62790105636c616e675f31" + "392e312e" + "352d776173692d73646b202868747470733a2f2f6769746875622e636f6d2f6c6c" + "766d2f6c" + "6c766d2d70726f6a65637420616234623561326462353832393538616631656533" + "30386137" + "3930636664623432626432343732302900490f7461726765745f66656174757265" + "73042b0f" + "6d757461626c652d676c6f62616c732b087369676e2d6578742b0f726566657265" + "6e63652d" + "74797065732b0a6d756c746976616c7565"; + auto const wasmStr = boost::algorithm::unhex(infiniteWasmHex); + Bytes wasm(wasmStr.begin(), wasmStr.end()); + std::string const funcName("infinite"); + TestHostFunctions hfs(env, 0); + + { + // f32 set constant, opcode disabled exception + auto const re = + runEscrowWasm(wasm, funcName, {}, &hfs, 1'000'000, env.journal); + if (BEAST_EXPECT(!re.has_value())) + { + BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); + } + } + } + void run() override { @@ -735,6 +796,7 @@ struct Wasm_test : public beast::unit_test::suite testCodecovWasm(); testDisabledFloat(); + testInfiniteLoop(); // perfTest(); } From ea4d66822356d620f1221e2ec867e2e5fde81e31 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Fri, 21 Nov 2025 16:12:59 +0530 Subject: [PATCH 2/7] improve test --- src/test/app/Wasm_test.cpp | 46 +++++++++++++++----------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index aa9ba688c03..2587f0ef675 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -724,42 +724,32 @@ struct Wasm_test : public beast::unit_test::suite Env env{*this}; /* - void + int loop() { int volatile x = 0; while (1) x++; + return x; } */ static std::string const infiniteWasmHex = - "0061736d01000000010401600000030302000005030100020638097f004180080b" - "7f004180" - "080b7f004180080b7f00418088040b7f004180080b7f00418088040b7f00418080" - "080b7f00" - "41000b7f0041010b07a8010c066d656d6f72790200115f5f7761736d5f63616c6c" - "5f63746f" - "72730000046c6f6f7000010c5f5f64736f5f68616e646c6503000a5f5f64617461" - "5f656e64" - "03010b5f5f737461636b5f6c6f7703020c5f5f737461636b5f6869676803030d5f" - "5f676c6f" - "62616c5f6261736503040b5f5f686561705f6261736503050a5f5f686561705f65" - "6e640306" - "0d5f5f6d656d6f72795f6261736503070c5f5f7461626c655f6261736503080a27" - "0202000b" - "220041fc87044100360200034041fc870441fc870428020041016a3602000c000b" - "000b007f" - "0970726f647563657273010c70726f6365737365642d62790105636c616e675f31" - "392e312e" - "352d776173692d73646b202868747470733a2f2f6769746875622e636f6d2f6c6c" - "766d2f6c" - "6c766d2d70726f6a65637420616234623561326462353832393538616631656533" - "30386137" - "3930636664623432626432343732302900490f7461726765745f66656174757265" - "73042b0f" - "6d757461626c652d676c6f62616c732b087369676e2d6578742b0f726566657265" - "6e63652d" - "74797065732b0a6d756c746976616c7565"; + "0061736d010000000108026000006000017f030302000105030100020638097f00" + "4180080b7f004180080b7f004180080b7f00418088040b7f004180080b7f004180" + "88040b7f00418080080b7f0041000b7f0041010b07a8010c066d656d6f72790200" + "115f5f7761736d5f63616c6c5f63746f72730000046c6f6f7000010c5f5f64736f" + "5f68616e646c6503000a5f5f646174615f656e6403010b5f5f737461636b5f6c6f" + "7703020c5f5f737461636b5f6869676803030d5f5f676c6f62616c5f6261736503" + "040b5f5f686561705f6261736503050a5f5f686561705f656e6403060d5f5f6d65" + "6d6f72795f6261736503070c5f5f7461626c655f6261736503080a270202000b22" + "0041fc87044100360200034041fc870441fc870428020041016a3602000c000b00" + "0b007f0970726f647563657273010c70726f6365737365642d62790105636c616e" + "675f31392e312e352d776173692d73646b202868747470733a2f2f676974687562" + "2e636f6d2f6c6c766d2f6c6c766d2d70726f6a6563742061623462356132646235" + "383239353861663165653330386137393063666462343262643234373230290049" + "0f7461726765745f6665617475726573042b0f6d757461626c652d676c6f62616c" + "732b087369676e2d6578742b0f7265666572656e63652d74797065732b0a6d756c" + "746976616c7565"; auto const wasmStr = boost::algorithm::unhex(infiniteWasmHex); Bytes wasm(wasmStr.begin(), wasmStr.end()); std::string const funcName("infinite"); From c038dabca7a2f1c07bd37b55d82a336bf45ce8b0 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 2 Dec 2025 13:01:00 -0500 Subject: [PATCH 3/7] fix rebase issue --- src/test/app/Wasm_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index 2587f0ef675..a979583f03f 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -757,8 +757,7 @@ struct Wasm_test : public beast::unit_test::suite { // f32 set constant, opcode disabled exception - auto const re = - runEscrowWasm(wasm, funcName, {}, &hfs, 1'000'000, env.journal); + auto const re = runEscrowWasm(wasm, hfs, funcName, {}, 1'000'000); if (BEAST_EXPECT(!re.has_value())) { BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); From dc5f0ecda1e8a6f782797f756053cf2867f8740d Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 2 Dec 2025 18:38:47 -0500 Subject: [PATCH 4/7] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/test/app/Wasm_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index a979583f03f..776226141f0 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -752,11 +752,11 @@ struct Wasm_test : public beast::unit_test::suite "746976616c7565"; auto const wasmStr = boost::algorithm::unhex(infiniteWasmHex); Bytes wasm(wasmStr.begin(), wasmStr.end()); - std::string const funcName("infinite"); + std::string const funcName("loop"); TestHostFunctions hfs(env, 0); { - // f32 set constant, opcode disabled exception + // infinite loop should be caught and fail auto const re = runEscrowWasm(wasm, hfs, funcName, {}, 1'000'000); if (BEAST_EXPECT(!re.has_value())) { From 7d60d2a619f783453814cd786ba13be45a3bf947 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 6 Jan 2026 15:56:37 -0500 Subject: [PATCH 5/7] use fixtures file --- src/test/app/Wasm_test.cpp | 29 +---------------------- src/test/app/wasm_fixtures/fixtures.cpp | 16 +++++++++++++ src/test/app/wasm_fixtures/fixtures.h | 2 ++ src/test/app/wasm_fixtures/infiniteLoop.c | 8 +++++++ 4 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 src/test/app/wasm_fixtures/infiniteLoop.c diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index e3c2ad6c36d..b6ddf7af025 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -740,34 +740,7 @@ struct Wasm_test : public beast::unit_test::suite using namespace test::jtx; Env env{*this}; - /* - int - loop() - { - int volatile x = 0; - while (1) - x++; - return x; - } - */ - static std::string const infiniteWasmHex = - "0061736d010000000108026000006000017f030302000105030100020638097f00" - "4180080b7f004180080b7f004180080b7f00418088040b7f004180080b7f004180" - "88040b7f00418080080b7f0041000b7f0041010b07a8010c066d656d6f72790200" - "115f5f7761736d5f63616c6c5f63746f72730000046c6f6f7000010c5f5f64736f" - "5f68616e646c6503000a5f5f646174615f656e6403010b5f5f737461636b5f6c6f" - "7703020c5f5f737461636b5f6869676803030d5f5f676c6f62616c5f6261736503" - "040b5f5f686561705f6261736503050a5f5f686561705f656e6403060d5f5f6d65" - "6d6f72795f6261736503070c5f5f7461626c655f6261736503080a270202000b22" - "0041fc87044100360200034041fc870441fc870428020041016a3602000c000b00" - "0b007f0970726f647563657273010c70726f6365737365642d62790105636c616e" - "675f31392e312e352d776173692d73646b202868747470733a2f2f676974687562" - "2e636f6d2f6c6c766d2f6c6c766d2d70726f6a6563742061623462356132646235" - "383239353861663165653330386137393063666462343262643234373230290049" - "0f7461726765745f6665617475726573042b0f6d757461626c652d676c6f62616c" - "732b087369676e2d6578742b0f7265666572656e63652d74797065732b0a6d756c" - "746976616c7565"; - auto const wasmStr = boost::algorithm::unhex(infiniteWasmHex); + auto const wasmStr = boost::algorithm::unhex(infiniteLoopWasmHex); Bytes wasm(wasmStr.begin(), wasmStr.end()); std::string const funcName("loop"); TestHostFunctions hfs(env, 0); diff --git a/src/test/app/wasm_fixtures/fixtures.cpp b/src/test/app/wasm_fixtures/fixtures.cpp index 6a6ae2e686e..20b98f8647e 100644 --- a/src/test/app/wasm_fixtures/fixtures.cpp +++ b/src/test/app/wasm_fixtures/fixtures.cpp @@ -1208,3 +1208,19 @@ extern std::string const wasiPrintHex = "656d6f727902000666696e69736800010a1d011b01017f4118210041014100410120001000" "45047f410105417f0b0b0b1e030041100b0648656c6c6f0a0041000b04100000000041040b" "0406000000"; + +extern std::string const infiniteLoopWasmHex = + "0061736d010000000108026000006000017f030302000105030100020638097f004180080b" + "7f004180080b7f004180080b7f00418088040b7f004180080b7f00418088040b7f00418080" + "080b7f0041000b7f0041010b07a8010c066d656d6f72790200115f5f7761736d5f63616c6c" + "5f63746f72730000046c6f6f7000010c5f5f64736f5f68616e646c6503000a5f5f64617461" + "5f656e6403010b5f5f737461636b5f6c6f7703020c5f5f737461636b5f6869676803030d5f" + "5f676c6f62616c5f6261736503040b5f5f686561705f6261736503050a5f5f686561705f65" + "6e6403060d5f5f6d656d6f72795f6261736503070c5f5f7461626c655f6261736503080a27" + "0202000b220041fc87044100360200034041fc870441fc870428020041016a3602000c000b" + "000b007f0970726f647563657273010c70726f6365737365642d62790105636c616e675f31" + "392e312e352d776173692d73646b202868747470733a2f2f6769746875622e636f6d2f6c6c" + "766d2f6c6c766d2d70726f6a65637420616234623561326462353832393538616631656533" + "303861373930636664623432626432343732302900490f7461726765745f66656174757265" + "73042b0f6d757461626c652d676c6f62616c732b087369676e2d6578742b0f726566657265" + "6e63652d74797065732b0a6d756c746976616c7565"; diff --git a/src/test/app/wasm_fixtures/fixtures.h b/src/test/app/wasm_fixtures/fixtures.h index cb4f6e69d65..431ee612e71 100644 --- a/src/test/app/wasm_fixtures/fixtures.h +++ b/src/test/app/wasm_fixtures/fixtures.h @@ -64,3 +64,5 @@ extern std::string const trapFuncSigMismatchHex; extern std::string const wasiGetTimeHex; extern std::string const wasiPrintHex; + +extern std::string const infiniteLoopWasmHex; diff --git a/src/test/app/wasm_fixtures/infiniteLoop.c b/src/test/app/wasm_fixtures/infiniteLoop.c new file mode 100644 index 00000000000..037a843cac3 --- /dev/null +++ b/src/test/app/wasm_fixtures/infiniteLoop.c @@ -0,0 +1,8 @@ +int +loop() +{ + int volatile x = 0; + while (1) + x++; + return x; +} From 2c89c2a68021ecf03bb0abe9e25797623c331d3c Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 6 Jan 2026 15:58:16 -0500 Subject: [PATCH 6/7] move next to recursion test --- src/test/app/Wasm_test.cpp | 42 ++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index b6ddf7af025..749cfd9f9c6 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -467,6 +467,24 @@ struct Wasm_test : public beast::unit_test::suite BEAST_EXPECT(countSubstr(s, "exception: failure") > 0); } + { + // infinite loop + auto const wasmStr = boost::algorithm::unhex(infiniteLoopWasmHex); + Bytes wasm(wasmStr.begin(), wasmStr.end()); + std::string const funcName("loop"); + TestHostFunctions hfs(env, 0); + + { + // infinite loop should be caught and fail + auto const re = + runEscrowWasm(wasm, hfs, funcName, {}, 1'000'000); + if (BEAST_EXPECT(!re.has_value())) + { + BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); + } + } + } + { // expected import not provided auto wasmStr = boost::algorithm::unhex(ledgerSqnWasmHex); @@ -732,29 +750,6 @@ struct Wasm_test : public beast::unit_test::suite } } - void - testInfiniteLoop() - { - testcase("infinite loop"); - - using namespace test::jtx; - Env env{*this}; - - auto const wasmStr = boost::algorithm::unhex(infiniteLoopWasmHex); - Bytes wasm(wasmStr.begin(), wasmStr.end()); - std::string const funcName("loop"); - TestHostFunctions hfs(env, 0); - - { - // infinite loop should be caught and fail - auto const re = runEscrowWasm(wasm, hfs, funcName, {}, 1'000'000); - if (BEAST_EXPECT(!re.has_value())) - { - BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); - } - } - } - void testWasmMemory() { @@ -857,7 +852,6 @@ struct Wasm_test : public beast::unit_test::suite testCodecovWasm(); testDisabledFloat(); - testInfiniteLoop(); testWasmMemory(); testWasmTable(); From 7933c33e23063ff04b517325caaa548248f86d28 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 6 Jan 2026 16:49:19 -0500 Subject: [PATCH 7/7] respond to copilot --- src/test/app/Wasm_test.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index 749cfd9f9c6..59961fded8b 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -467,21 +467,17 @@ struct Wasm_test : public beast::unit_test::suite BEAST_EXPECT(countSubstr(s, "exception: failure") > 0); } - { - // infinite loop + { // infinite loop auto const wasmStr = boost::algorithm::unhex(infiniteLoopWasmHex); Bytes wasm(wasmStr.begin(), wasmStr.end()); std::string const funcName("loop"); TestHostFunctions hfs(env, 0); + // infinite loop should be caught and fail + auto const re = runEscrowWasm(wasm, hfs, funcName, {}, 1'000'000); + if (BEAST_EXPECT(!re.has_value())) { - // infinite loop should be caught and fail - auto const re = - runEscrowWasm(wasm, hfs, funcName, {}, 1'000'000); - if (BEAST_EXPECT(!re.has_value())) - { - BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); - } + BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); } }