anza-xyz / move

Move compiler targeting llvm supported backends
https://discord.gg/wFgfjG9J
Apache License 2.0
107 stars 32 forks source link

[Bug] Multiple issues with large vecs #399

Open brson opened 6 months ago

brson commented 6 months ago

The sui-move branch (cc https://github.com/solana-labs/move/issues/396) contains these two tests, both of which fail on rbpf:

    #[test]
    fun size_limit_ok() {
        let v = V::empty();
        let i = 0;
        // Limit is currently 1024 * 1024
        let max_len = 1024 * 1024;

        while (i < max_len) {
            V::push_back(&mut v, i);
            i = i + 1;
        };
    }

    #[test]
    #[expected_failure(vector_error, minor_status = 4, location = Self)]
    fun size_limit_fail() {
        let v = V::empty();
        let i = 0;
        // Limit is currently 1024 * 1024
        let max_len = 1024 * 1024 + 1;

        while (i < max_len) {
            V::push_back(&mut v, i);
            i = i + 1;
        };
    }

There are two issues here:

First, both tests appear to be recursing off the end of the stack:

$ MOVE_NATIVE=$(pwd)/language/move-native cargo run -p move-cli --features solana-backend -- test -p languag[240/1842]
lib/ --arch solana --solana size_limit
    Finished dev [unoptimized + debuginfo] target(s) in 0.50s
warning: the following packages contain code that will be rejected by a future version of Rust: nom v5.1.2
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatib
ilities --id 3`
     Running `target/debug/move test -p language/move-stdlib/ --arch solana --solana size_limit`
BUILDING MoveStdlib
Running Move unit tests
[ FAIL    ] 0x1::vector_tests::size_limit_fail
[ FAIL    ] 0x1::vector_tests::size_limit_ok

Test failures:

Failures in 0x1::vector_tests:

┌── size_limit_fail ──────
│ Failed to run a program on Solana VM.
│
│
│ Err(CallDepthExceeded(34965, 8192))
└──────────────────

┌── size_limit_ok ──────
│ Failed to run a program on Solana VM.
│
│
│ Err(CallDepthExceeded(34965, 8192))
└──────────────────

Test result: FAILED. Total tests: 2; passed: 0; failed: 2

I can't imagine offhand why this would be - I don't see anything here that should trigger recursion in the runtime.

Secondly, the second test enforces a size limit on vecs that move-native does not.