From b00aa6ebe3286e5a6a7321cdc09f352867fe7389 Mon Sep 17 00:00:00 2001 From: Bolaji Ahmad <56865496+bolajahmad@users.noreply.github.com> Date: Mon, 22 Jul 2024 12:48:14 +0100 Subject: [PATCH 1/2] fix: add RVRT to unallowed opcodes for predicates --- sway-core/src/asm_generation/fuel/checks.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sway-core/src/asm_generation/fuel/checks.rs b/sway-core/src/asm_generation/fuel/checks.rs index 8e5a4bb9074..3260cfb9912 100644 --- a/sway-core/src/asm_generation/fuel/checks.rs +++ b/sway-core/src/asm_generation/fuel/checks.rs @@ -62,8 +62,9 @@ pub(crate) fn check_script_opcodes( /// Checks if an opcode is one that cannot be executed from within a predicate. /// If so, throw an error. /// -/// All contract opcodes are not allowed in predicates. Except for RVRT that can -/// be used to abort the predicate. One example of disallowed code is as follows: +/// All contract opcodes are not allowed in predicates, including RVRT that causes +/// a panic according to https://github.com/FuelLabs/fuel-vm/blob/master/fuel-asm/src/lib.rs#L984. +/// One example of disallowed code is as follows: /// ```ignore /// pub fn burn(sub_id: SubId, amount: u64) { /// asm(r1: amount) { @@ -120,6 +121,7 @@ pub(crate) fn check_predicate_opcodes( TIME(..) => invalid_opcode("TIME"), TR(..) => invalid_opcode("TR"), TRO(..) => invalid_opcode("TRO"), + RVRT(..) => invalid_opcode("RVRT"), _ => (), }; } From 691d1e076f6d01a3db6e7acab06cdd030b8c1e6d Mon Sep 17 00:00:00 2001 From: Bolaji Ahmad <56865496+bolajahmad@users.noreply.github.com> Date: Mon, 12 Aug 2024 11:37:09 +0100 Subject: [PATCH 2/2] updates predicate invalid opcodes test.toml to check for RVRT opcodes --- .../should_fail/predicate_invalid_opcodes/src/main.sw | 5 ++++- .../should_fail/predicate_invalid_opcodes/test.toml | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/src/main.sw index c4afb3c6574..cd3dce7232d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/src/main.sw @@ -73,7 +73,10 @@ fn main() -> bool { } // retd: There is no way of testing - // rvrt: It is allowed and used to abort predicates. + + asm(r1) { + rvrt r1; + } asm(r1: 0, r2: 0, r3: 0, r4: 0) { smo r1 r2 r3 r4; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/test.toml index b384ae9f5a9..8f167e84406 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/test.toml @@ -17,7 +17,7 @@ category = "fail" # check: cb r1; # nextln: $()The CB opcode cannot be used in a predicate. - + # check: ccp r1 r2 r3 r4; # nextln: $()The CCP opcode cannot be used in a predicate. @@ -56,4 +56,5 @@ category = "fail" # check: tr r1 r2 r3; # nextln: $()The TR opcode cannot be used in a predicate. - +# check: rvrt r1; +# nextln: $()The RVRT opcode cannot be used in a predicate.