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 witgen for bus accumulators #1628

Merged
merged 3 commits into from
Aug 5, 2024
Merged

Fix witgen for bus accumulators #1628

merged 3 commits into from
Aug 5, 2024

Conversation

georgwiese
Copy link
Collaborator

@georgwiese georgwiese commented Jul 30, 2024

Fixes #1604

With this PR, we bypass machine detection during witness generation of stages > 0. See this comment for a motivation.

This currently needs to be tested manually, as follows:

$ RUST_LOG=trace cargo run pil test_data/asm/block_to_block_with_bus.asm -o output -f --field bn254 --prove-with halo2-mock
...
===== Summary for row 7:
    main.acc1 = 20713437912485111384541749944547180564950035591542371144095269313127123163196
    main.acc2 = 5162472027861336027760332823162682203738251621730423286600997430635718406729
    main.z = 3
    main.res = 9
    main_arith.acc1 = 1174804959354163837704655800710094523598328808873663199602934873448685332421
    main_arith.acc2 = 16725770843977939194486072922094592884810112778685611057097206755940090088888
    main_arith.acc1_next = 463668501342879563405020640323131794083013726819708055681247370540753473777
    main_arith.acc2_next = 20043340305711842349747334022818855888193664738087810292789887394167185113571
    main_arith.y = 1
    main_arith.z = 1
    main.dummy = 0
    main.acc1_next = 0
    main.acc2_next = 0
    main_arith.x = 0
    main_arith.sel[0] = 0
---------------------
...

Computing main.acc1 + main_arith.acc1 and main.acc2 + main_arith.acc2 both yields 21888242871839275222246405745257275088548364400416034343698204186575808495617, which is the BN254 scalar field prime! In other words, the partial accumulators sum to 0.

let alpha = from_base(challenge(0, 1));
let beta = from_base(challenge(0, 2));

let is_first: col = std::well_known::is_first;
col witness stage(1) acc;

bus_receive(is_first, ARITH_INTERACTION_ID, [0, x, y, z], latch, [acc], alpha, beta);
bus_send(is_first, ARITH_INTERACTION_ID, [0, x, y, z], instr_add, [acc], alpha, beta);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These (and the changes below) were bugs.

@georgwiese georgwiese changed the title [WIP] Fix witgen for bus accumulators Fix witgen for bus accumulators Jul 30, 2024
@georgwiese georgwiese marked this pull request as ready for review July 30, 2024 10:40
acc1' = acc1_next;
acc2' = acc2_next;

// TODO: Expose final value of acc as public.
Copy link
Member

Choose a reason for hiding this comment

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

open issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs to be done all over the place (we have the same TODO many times) and is tracked in #1499.

@leonardoalt leonardoalt added this pull request to the merge queue Aug 5, 2024
Merged via the queue into main with commit f77c0a7 Aug 5, 2024
14 checks passed
@leonardoalt leonardoalt deleted the second-phase-witgen branch August 5, 2024 12:39
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.

Witgen not working for bus in block machines
2 participants