Skip to content

fix(brillig_vm): Remove slice padding for foreign call inputs#9321

Merged
aakoshh merged 35 commits intomasterfrom
mv/remove-padding-in-vm-rather-than-decode
Aug 11, 2025
Merged

fix(brillig_vm): Remove slice padding for foreign call inputs#9321
aakoshh merged 35 commits intomasterfrom
mv/remove-padding-in-vm-rather-than-decode

Conversation

@vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Jul 24, 2025

Description

Problem*

Alternative to #9288

Summary*

Changes brillig_vm::VM::get_memory_values to remove any extra items from HeapVectors that are beyond its length, as indicated by the preceding u32 field in the parent data structure or list of inputs. This is so that when we pass the data as a ForeignCallParameter, we don't have to deal with any padding while decoding the data.

Unlike #9288 this is a backwards compatible change.

Additional Context

Slice length and vector size can differ when we use IfElse to merge slices of different lengths. The array backing the slice is created so that it can fit both outcomes, and if we end up filling it with data from the shorter slice, the rest is padding. Arguably there is no reason for the client to receive those extra elements.

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.

@aakoshh
Copy link
Contributor

aakoshh commented Jul 24, 2025

I like this idea. I have a similar conundrum in #9320 where I can't think for a reason not to truncate the extra elements during slice operations.

@vezenovm
Copy link
Contributor Author

I like this idea. I have a similar conundrum in #9320 where I can't think for a reason not to truncate the extra elements during slice operations.

I'll be able to take a deeper look at #9320 tomorrow. For the interpreter I agree that we should be able to remove the padding as we have access to the actual dynamic length.

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: 78e0665 Previous: 1748cbe Ratio
test_report_zkpassport_noir-ecdsa_ 3 s 2 s 1.50

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

CC: @TomAFrench

@aakoshh
Copy link
Contributor

aakoshh commented Jul 24, 2025

I checked on the parent of this PR what ACIR passes to the oracle when the hybrid slice is being popped/pushed (appended to the PR description in the interpreter fix), and it's definitely not what the interpreter would pass, so these values should not be relied on by anybody. Removing would be the cleanest approach 👏

@aakoshh aakoshh changed the base branch from af/9271-fix-print-slice-alt to master July 25, 2025 10:05
@aakoshh aakoshh requested a review from a team July 25, 2025 10:36
@aakoshh aakoshh self-requested a review July 28, 2025 12:14
@TomAFrench
Copy link
Member

I imagine this could still be breaking if there's code in aztec-packages which is assuming that it needs to do this truncation itself.

@aakoshh
Copy link
Contributor

aakoshh commented Aug 4, 2025

I thought that wouldn’t be a problem, because if the slices are passed as a separate ForeignCallParam then they would just truncate something that is already shorter, which is a no-op.

If they instead dealt with flattened data, then they would have had to hardcode some value for the capacity on their side, since nothing indicates it in the data, which would be tight coupling to an implementation detail that I imagine wasn’t meant to be part of the interface, and would have been fragile anyway.

@aakoshh aakoshh requested a review from TomAFrench August 11, 2025 10:08
@aakoshh aakoshh force-pushed the mv/remove-padding-in-vm-rather-than-decode branch from c29790a to 78e0665 Compare August 11, 2025 10:19
Copy link
Member

@TomAFrench TomAFrench left a comment

Choose a reason for hiding this comment

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

LGTM

@aakoshh aakoshh enabled auto-merge August 11, 2025 12:52
@aakoshh aakoshh added this pull request to the merge queue Aug 11, 2025
Merged via the queue into master with commit 57778ea Aug 11, 2025
122 checks passed
@aakoshh aakoshh deleted the mv/remove-padding-in-vm-rather-than-decode branch August 11, 2025 14:12
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Aug 12, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(LSP): don't crash on broken function definition
(noir-lang/noir#9441)
feat(opt): Don't clone on array_len
(noir-lang/noir#9440)
feat(ssa_fuzzer): mode without instruction simplification + array
instructions mutations + limits fix
(noir-lang/noir#9438)
feat(fuzz): Push and pop for slices
(noir-lang/noir#9262)
fix(brillig_vm): Remove slice padding for foreign call inputs
(noir-lang/noir#9321)
fix: allow calling private impl method defined on another module from…
(noir-lang/noir#9449)
fix: guard `Eq` for `[T]` to avoid OOB on length mismatch
(noir-lang/noir#9453)
chore: bump external pinned commits
(noir-lang/noir#9454)
END_COMMIT_OVERRIDE

Co-authored-by: AztecBot <tech@aztecprotocol.com>
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