aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
5.98k stars 3.58k forks source link

[Bug] 2 mutable borrows in nested calls leads to `CALL_BORROWED_MUTABLE_REFERENCE_ERROR` on v2 only #13976

Open brmataptos opened 2 weeks ago

brmataptos commented 2 weeks ago

🐛 Bug

    fun lifted_lambda(ap: &mut u64, z: u64): u64 {
        *ap = *ap + 1;
        z * *ap
    }

    entry fun foo2(): u64 {
        let a = 2;
        let z = 3;
        lifted_lambda(&mut a,
            lifted_lambda(&mut a, z))
    }

leads to a VM problem only on V2, not V1.

brmataptos commented 2 weeks ago

See https://github.com/aptos-labs/aptos-core/compare/brm-test-lambda for some example inputs and test outputs. lambda_lifted2.move avoids the problem with a slight change to the code.