Skip to content

feat: rich external loop invariant error messages#342

Merged
andrii-a8c merged 4 commits intomainfrom
loop-inv-error-message
Nov 12, 2025
Merged

feat: rich external loop invariant error messages#342
andrii-a8c merged 4 commits intomainfrom
loop-inv-error-message

Conversation

@andrii-a8c
Copy link
Copy Markdown
Collaborator

No description provided.

@andrii-a8c andrii-a8c self-assigned this Nov 12, 2025
Copilot AI review requested due to automatic review settings November 12, 2025 16:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances error messages for external loop invariant validation by adding a list of available variables when a parameter mismatch is detected. This makes debugging easier by showing developers what variables they can actually use in their loop invariant functions.

Key Changes:

  • Added helper function to parse variable names by stripping internal compiler suffixes
  • Enhanced error message to include list of available variables when parameter not found
  • Updated test snapshot to reflect the improved error message format

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/move-stackless-bytecode/src/move_loop_invariants.rs Added parse_var_name helper function and enhanced error message to list available variables
crates/sui-prover/tests/snapshots/loop_invariant/external_invalid_arg_name.move.snap Updated test snapshot to reflect new error message format with available variables list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@andreistefanescu andreistefanescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@andrii-a8c andrii-a8c merged commit b1532df into main Nov 12, 2025
9 checks passed
@andrii-a8c andrii-a8c deleted the loop-inv-error-message branch November 12, 2025 18:06
let res = test_loop!(n);
ensures(res == (n as u128) * ((n as u128) + 1) / 2);
res
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add something like

fun map_test(v: &vector<u8>) {
  let u = v.map!(|x| 0);
  assert(u.length() == v.length());
}
#[spec_only(loop_inv(target=map_test))]
fun map_loop_inv(i: u64, stop: u64, v: vector<u8>) {
  i <= stop && v.length() == stop - i
}
#[spec(prove)]
fun map_test_spec(v: &vector<u8>) {
  map_test(v);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image it's interesting, loop invariant is not triggered in this case because this impl is not loop at all

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventually there should be a loop, maybe in v.length().do!

BigBadE pushed a commit that referenced this pull request Nov 19, 2025
* feat: rich error messages

* cleanup

* cleanup

* feat: added types and 1 more test
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

Successfully merging this pull request may close these issues.

4 participants