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

fix: shift right overflow in ACIR with unknown var now returns zero #7509

Merged
merged 5 commits into from
Feb 28, 2025

Conversation

asterite
Copy link
Collaborator

Description

Problem

Resolves #7412

Summary

The explanation of the bug is here: #7412 (comment)

This is one way to solve this. I wonder if there's a better one (less ops).

Additional Context

Documentation

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Execution Memory'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 31996c6 Previous: ef51d8a Ratio
rollup-base-private 582.03 MB 441.61 MB 1.32
rollup-block-root 3500 MB 1420 MB 2.46

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 31996c6 Previous: ef51d8a Ratio
AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob 61 s 50 s 1.22

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Copy link
Contributor

github-actions bot commented Feb 24, 2025

Changes to circuit sizes

Generated at commit: 9ffb0c8478b2b79e2e334748759ab7cbd99ea3b7, compared to commit: ebaff44cae9d9dc9d930fe2ccf4a1ce85bcd8d3c

🧾 Summary (10% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
bit_shifts_runtime +7 ❌ +2.46% +7 ❌ +0.18%
u128_type +3 ❌ +2.11% +3 ❌ +0.07%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
bit_shifts_runtime 291 (+7) +2.46% 3,952 (+7) +0.18%
u128_type 145 (+3) +2.11% 4,609 (+3) +0.07%

@asterite asterite requested a review from a team February 24, 2025 21:10
@jfecher
Copy link
Contributor

jfecher commented Feb 27, 2025

Looks like Rust panics when this happens. Are we sure we want to return 0 in acir then instead of changing brillig to also halt?

@asterite
Copy link
Collaborator Author

In a chat with @TomAFrench on Slack he said that ideally it's zero. But it's a good opportunity to revisit this as I also tend to prefer matching Rust's behavior.

@jfecher
Copy link
Contributor

jfecher commented Feb 27, 2025

@TomAFrench can you elaborate here (or on the linked issue) why zero is preferable to erroring?

@TomAFrench
Copy link
Member

I suggested this as currently the program

fn main(x: u8) -> pub u8 {
    x >> 9
}

returns 0 when given an input of 1 so we have precedent. (we should create an error for this case if we're wanting to reject larger shifts)

I was also thinking of these lines in the sha256 impl where when we're bitshifting by a value which is only known at runtime and need to add a guard to avoid this error case.

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

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

The regressions seem fairly small

@jfecher jfecher added this pull request to the merge queue Feb 28, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 28, 2025
@asterite asterite enabled auto-merge February 28, 2025 14:23
@asterite asterite added this pull request to the merge queue Feb 28, 2025
Merged via the queue into master with commit ca21820 Feb 28, 2025
101 of 102 checks passed
@asterite asterite deleted the ab/shift-discrepancy-acir-brillig branch February 28, 2025 14:46
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.

result of shr differs in acir and brillig
3 participants