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

Add SplitBN254 machine, use queries in SplitGL machine #716

Merged
merged 1 commit into from
Nov 1, 2023

Conversation

georgwiese
Copy link
Collaborator

@georgwiese georgwiese commented Oct 23, 2023

Includes the changes from #735.

This PR does two small changes to the existing SplitGL machine:

Then, it adds an analogous machine & test for BN254. I recommend reviewing the diff to the Goldilocks machine.

@georgwiese georgwiese force-pushed the block-machine-queries branch 5 times, most recently from f98e992 to 5345624 Compare October 26, 2023 16:55
Base automatically changed from block-machine-queries to main October 26, 2023 18:20
@georgwiese georgwiese force-pushed the split-machines-with-queries branch 3 times, most recently from fe0f2db to 4d6e811 Compare October 31, 2023 18:00
@georgwiese georgwiese force-pushed the split-machines-with-queries branch from 4d6e811 to ec0dd52 Compare October 31, 2023 18:11
@@ -40,7 +40,7 @@ fn gen_halo2_proof(file_name: &str, inputs: Vec<Bn254Field>) {
inputs,
&mktemp::Temp::new_dir().unwrap(),
true,
Some(backend::BackendType::Halo2),
Some(backend::BackendType::Halo2Mock),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Otherwise, the test takes very long and eventually gets cancelled.

I think it's completely fine to use the mock prover here, as it checks that all constraints are satisfied and that's all we want to test here.


// 1. Decompose the input into bytes

// The byte decomposition of the input, in little-endian order
// and shifted forward by one (to use the last row of the
// previous block)
col witness bytes;
// Puts the bytes together to form the input
col witness bytes(i) query ("hint", (in_acc' >> (((i + 1) % 8) * 8)) % 0xff);
Copy link
Member

Choose a reason for hiding this comment

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

wat

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Too confusing? 😄

  • ((i + 1) % 8) is the index in the current block, shifted by 1
  • (in_acc' >> (((i + 1) % 8) * 8)) is the input shifted by that many bytes
  • (in_acc' >> (((i + 1) % 8) * 8)) % 0xff) selects the least significant byte

So in the end, it does what the comment above says that it should, but let me know if you have an idea how to make it clearer :)

Copy link
Member

Choose a reason for hiding this comment

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

Yea it's fine. If the prover passes malicious values now, witgen won't fail, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd phrase it differently, if the constraints allow for more than one value, witgen won't fail anymore. For example, if we remove step 3 and fix #593. That's why I think it's always better to rely on automatic witgen, but in this case it's not possible.

@georgwiese georgwiese marked this pull request as ready for review October 31, 2023 18:22
std/split/split_gl.asm Outdated Show resolved Hide resolved
@georgwiese georgwiese force-pushed the split-machines-with-queries branch from ec0dd52 to f26a161 Compare October 31, 2023 18:27
@@ -135,7 +135,7 @@ where
}
} else {
Err(IncompleteCause::ExpressionEvaluationUnimplemented(
"Cannot evaluate arrays or next references.".to_string(),
"Cannot evaluate arrays.".to_string(),
Copy link
Member

Choose a reason for hiding this comment

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

Are these changes needed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, otherwise the machine doesn't work, but they are also in #735, so if we merge that first they'll go away.

reg A7;
reg A8;

degree 65536;
Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't have degree statements in std machines, because if a program with a longer ROM uses this, the compiler issues an error and the user needs to manually change it. Maybe we should have something like a "lower bound" thing, because this is what it is, right?

Copy link
Member

Choose a reason for hiding this comment

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

Ah wait, this is a test file so it's fine

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, but this is just the test!

assert_eq A5, 0;
assert_eq A6, 0;
assert_eq A7, 0;
assert_eq A8, 0;
Copy link
Member

Choose a reason for hiding this comment

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

Nice!!

@leonardoalt leonardoalt added this pull request to the merge queue Nov 1, 2023
Merged via the queue into main with commit 3159475 Nov 1, 2023
2 checks passed
@leonardoalt leonardoalt deleted the split-machines-with-queries branch November 1, 2023 11:18
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.

2 participants