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

[Bug][Compiler-v2][Prover] CALL_BORROWED_MUTABLE_REFERENCE_ERROR is raised when there is an inline spec #14762

Closed
rahxephon89 opened this issue Sep 26, 2024 · 2 comments · Fixed by #14890
Assignees
Labels
bug Something isn't working compiler-v2 move-prover

Comments

@rahxephon89
Copy link
Contributor

rahxephon89 commented Sep 26, 2024

🐛 Bug

When adding to the following spec block after the while loop in the inline function vector::find

        spec {
           assert find ==> f(self[found_index]);
        };

compiler v2 will generate the following error when compiling the aptos-framework code:

bug: bytecode verification failed with unexpected status code CALL_BORROWED_MUTABLE_REFERENCE_ERROR. This is a compiler bug, consider reporting it.
┌─ /Users/tengzhang/aptos-core/aptos-move/framework/aptos-framework/sources/jwks.move:582:26

582 │ option::some(vector::remove(&mut jwks.entries, index))
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@rahxephon89 rahxephon89 added the bug Something isn't working label Sep 26, 2024
@rahxephon89 rahxephon89 changed the title [Bug][Compiler-v2] [Bug][Compiler-v2][Prover] CALL_BORROWED_MUTABLE_REFERENCE_ERROR in jwks.move when adding spec block to the inline function vector::find Sep 26, 2024
@rahxephon89 rahxephon89 self-assigned this Sep 26, 2024
@rahxephon89 rahxephon89 moved this from 🆕 New to Assigned in Move Language and Runtime Sep 27, 2024
@rahxephon89
Copy link
Contributor Author

rahxephon89 commented Oct 7, 2024

This is the minimal example and inline is actually not involved:

module 0xc0ffee::m {
    use std::vector;

    struct S has copy, drop, store {
        i: u8,
    }

    struct T has copy, drop, store {
        entries: vector<S>,
    }

    fun test(t: &mut T) {
        let set: &S = vector::borrow(&t.entries, 0);
        spec {
            assert set.i == 0;
        };
        vector::remove(&mut t.entries, 0);
    }
}

This is the file-format:

// Move bytecode v7
module c0ffee.m {
use 0000000000000000000000000000000000000000000000000000000000000001::vector;


struct T has copy, drop, store {
	entries: vector<S>
}
struct S has copy, drop, store {
	i: u8
}

test(Arg0: &mut T) /* def_idx: 0 */ {
L1:	loc0: &S
B0:
	0: CopyLoc[0](Arg0: &mut T)
	1: ImmBorrowField[0](T.entries: vector<S>)
	2: LdU64(0)
	3: VecImmBorrow(2)
	4: StLoc[1](loc0: &S)
	5: Nop
	6: MoveLoc[0](Arg0: &mut T)
	7: MutBorrowField[0](T.entries: vector<S>)
	8: LdU64(0)
	9: Call vector::remove<S>(&mut vector<S>, u64): S
	10: Pop
	11: Ret
}
}

Note that instead of using set, if we use the following spec, no error will be generated.

        spec {
            assert t.entries[0].i == 0;
        };

@rahxephon89 rahxephon89 changed the title [Bug][Compiler-v2][Prover] CALL_BORROWED_MUTABLE_REFERENCE_ERROR in jwks.move when adding spec block to the inline function vector::find [Bug][Compiler-v2][Prover] CALL_BORROWED_MUTABLE_REFERENCE_ERROR is raised when there is an inline spec Oct 7, 2024
@rahxephon89
Copy link
Contributor Author

rahxephon89 commented Oct 7, 2024

Another example with inline function used:

module 0xc0ffee::m {
    use std::vector;

    struct S has copy, drop, store {
        i: u8,
    }

    struct T has copy, drop, store {
        entries: vector<S>,
    }

    inline fun inline_test(t: &mut T) {
        spec {
            assert t.entries[0].i == 0;
        };
    }

    fun test(t: &mut T) {
        inline_test(t);
        vector::remove(&mut t.entries, 0);
    }
}

Unlike the previous example, there is no work around of writing this spec to avoid the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler-v2 move-prover
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant