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][move-binary-format] failure serializing signature for a program with a lot of locals #12596

Closed
brmataptos opened this issue Mar 19, 2024 · 2 comments
Labels
bug Something isn't working compiler-v2 stale-exempt Prevents issues from being automatically marked and closed as stale

Comments

@brmataptos
Copy link
Contributor

🐛 Bug

When I try the following transactional test code, I see a failure writing the file format. What's odd is that it's not happening due to having too many local variables, but in serialize_signature_size() (298 cannot exceed 255). The bytecode printed shows 298 local variables, but only 255 are actually used. Why would the signature size vary? How is the signature generated?

Note that this failure is occurring with move-compiler (V1), but it may be useful for V2 to understand how this might happen.

//# publish --print-bytecode
module 0xcafe::vectors {
    use std::vector;

    fun make_big_vector(a: u64): vector<u64> {
        let x = vector[a,
            {a = a + 1; a},
            ... <297 more identical lines: 298 total>
            ];
        let y = x;
        y
    }

    fun sum(a: &vector<u64>): u64 {
        let sum = 0;
        vector::for_each_ref(a, |elt| { sum = sum + *elt});
        sum
    }

    public fun test_big_vector() {
        let v = make_big_vector(0);
        let len = vector::length(&v);
        let sum = sum(&v);
        assert!(len == 300, len);
        assert!(sum == (len * (len -1)) / 2, sum);
    }
}

A clear and concise description of what the bug is.
To report a security issue, please email security@aptoslabs.com.

To reproduce

Code snippet to reproduce

# Your code goes here
# Please make sure it does not require any external dependencies

Stack trace/error message

// Paste the output here

Expected Behavior

A clear and concise description of what you expected to happen.

System information

Please complete the following information:

  • Aptos Core Version
  • Rust Version
  • Computer OS

Additional context

Add any other context about the problem here.

@brmataptos brmataptos added the bug Something isn't working label Mar 19, 2024
@brmataptos
Copy link
Contributor Author

I did a little debugging, and it seems that signature_size is the length of the Signature, as defined in third_party/move/move-binary-format/src/file_format.rs, which is "the list of locals used by a function".

V2 has its own checks, so yields more useful error messages.

@sausagee sausagee added the stale-exempt Prevents issues from being automatically marked and closed as stale label Mar 25, 2024
@brmataptos
Copy link
Contributor Author

I think this is redundant with #12453, so I'm closing it.

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 stale-exempt Prevents issues from being automatically marked and closed as stale
Projects
Status: Done
Development

No branches or pull requests

2 participants