Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning a storage variable to memory causes an execution error. #1740

Open
Subway2023 opened this issue Feb 11, 2025 · 0 comments
Open

Assigning a storage variable to memory causes an execution error. #1740

Subway2023 opened this issue Feb 11, 2025 · 0 comments

Comments

@Subway2023
Copy link

Version: v0.3.3: Atlantis
Description: When assigning a storage variable to a memory variable, accessing the memory variable will cause an error. Specifically, return (m[0][0], m[0][3]); causes an execution error. However, if modified to return (a[0][0], a[0][3]) or return (a_[0][0], a_[0][3]), it does not cause an error. When running the program with solc and EVM, there are no errors.

contract C {
    uint72[5][] a;

    function f() public returns (uint72, uint72) {
        for (uint i = 0; i < 4; i++)
            a.push();
        a[0][0] = 1;
        a[0][3] = 2;
        uint72[5][] storage a_ = a;
        uint72[5][] memory m = a_;
        return (m[0][0], m[0][3]);
        // return (a[0][0], a[0][3]);
        // return (a_[0][0], a_[0][3]);

    }
}

Reproduction: I set up a Solang compilation and execution environment to test the program.

solang/target/debug/vmRunNoPara test.sol C f

The execution error is as follows:

Contract name: C
function new for 4gEZoZtF814TBjE7r5o4qMoDX7QZEJbGN1WMo1ZyzruT
input: 872ccdc6190148bc
running bpf with calldata:872ccdc6190148bc
program: 4gEZoZtF814TBjE7r5o4qMoDX7QZEJbGN1WMo1ZyzruT
static: length:8 0000000000000000
offset:28 prev:10 next:10 length:0 allocated:0 
function f for 4gEZoZtF814TBjE7r5o4qMoDX7QZEJbGN1WMo1ZyzruT
input: 352dd00eb9a6751b
running bpf with calldata:352dd00eb9a6751b
program: 4gEZoZtF814TBjE7r5o4qMoDX7QZEJbGN1WMo1ZyzruT
thread 'main' panicked at src/tests/solana.rs:639:13:
assertion `left == right` failed
  left: 12884902304
 right: 12884902144
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7608018cbdac9e55d0d13529cf43adc33d53efcf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/7608018cbdac9e55d0d13529cf43adc33d53efcf/library/core/src/panicking.rs:74:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
   4: solang::tests::solana::SyscallContext::heap_verify
             at ./compiler/solang/src/tests/solana.rs:639:13
   5: solang::tests::solana::sol_log
             at ./compiler/solang/src/tests/solana.rs:679:5
   6: solana_rbpf::interpreter::Interpreter<V,C>::step
             at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/solana_rbpf-0.6.1/src/interpreter.rs:453:25
   7: solana_rbpf::vm::EbpfVm<C>::execute_program
             at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/solana_rbpf-0.6.1/src/vm.rs:550:19
   8: solang::tests::solana::VirtualMachine::execute
             at ./compiler/solang/src/tests/solana.rs:1577:24
   9: solang::tests::solana::VmFunction::call_with_error_code
             at ./compiler/solang/src/tests/solana.rs:1847:19
  10: solang::tests::solana::VmFunction::call
             at ./compiler/solang/src/tests/solana.rs:1815:15
  11: vmRunNoPara::function_call_with_account
             at ./compiler/solang/src/bin/vmRunNoPara.rs:205:11
  12: vmRunNoPara::main
             at ./compiler/solang/src/bin/vmRunNoPara.rs:258:5
  13: core::ops::function::FnOnce::call_once
             at /root/.rustup/toolchains/nightly-2024-09-30-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant