瀏覽代碼

Do not return arguments of revert (#1427)

Signed-off-by: Lucas Steuernagel <lucas.tnagel@gmail.com>
Lucas Steuernagel 2 年之前
父節點
當前提交
9a53ecbb32

+ 2 - 1
src/codegen/expression.rs

@@ -3612,7 +3612,8 @@ pub(super) fn assert_failure(
     cfg: &mut ControlFlowGraph,
     vartab: &mut Vartable,
 ) {
-    if arg.is_none() {
+    // On Solana, returning the encoded arguments has no effect
+    if arg.is_none() || ns.target == Target::Solana {
         cfg.add(vartab, Instr::AssertFailure { encoded_args: None });
         return;
     }

+ 18 - 0
tests/codegen_testcases/solidity/revert_require_solana.sol

@@ -0,0 +1,18 @@
+// RUN: --target solana --emit cfg
+
+contract Foo {
+    // BEGIN-CHECK: Foo::Foo::function::test__uint32
+    function test(uint32 c) public pure  {
+        if (c == 6) {
+            // CHECK: print
+            // NOT-CHECK: writebuffer
+            // CHECK: assert-failure
+            revert("Hello");
+        } else if (c == 9) {
+            // CHECK: print
+            // NOT-CHECK: writebuffer
+            // CHECK: assert-failure
+            require(c == 7, "failed");
+        }
+    }
+}

+ 11 - 0
tests/solana_tests/runtime_errors.rs

@@ -107,6 +107,10 @@ contract RuntimeErrors {
         return b32;
     }
 
+    function revert_with_message() public pure {
+        revert("I reverted!");
+    }
+
 }
 
 @program_id("Crea1hXZv5Snuvs38GW2SJ1vJQ2Z5uBavUnwPwpiaDiQ")
@@ -306,4 +310,11 @@ contract calle_contract {
     );
 
     vm.logs.clear();
+
+    _res = vm.function_must_fail("revert_with_message", &[]);
+    assert_eq!(
+        vm.logs,
+        "runtime_error: I reverted! revert encountered in test.sol:103:9-30,\n"
+    );
+    assert!(vm.return_data.is_none());
 }