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

Bytecode unroller #170

Merged

Conversation

Brechtpd
Copy link
Collaborator

@Brechtpd Brechtpd commented Nov 14, 2021

Spec: privacy-scaling-explorations/zkevm-specs#74

Disabled the bytecode_invalid_index for now because with the halo update it now gives an internal error on a circuit that should fail: panicked at 'internal error: entered unreachable code', /home/brecht/.cargo/git/checkouts/halo2-b8251ca10f182e2b/b78c39c/src/dev/util.rs:48:42. With the previous halo this test worked fine so not sure what's going on yet.

The constraint builder could be modified a bit more to make the circuit writing for these standalone circuits even a bit nicer, but Han's PR already does a couple of good changes so will await that one instead before doing so.

@github-actions github-actions bot added T-opcode Type: opcode-related and focused PR/Issue crate-zkevm-circuits Issues related to the zkevm-circuits workspace member labels Nov 14, 2021
@icemelon
Copy link
Collaborator

I would suggest renaming the folder bytecode_unroller_circuit to bytecode_circuit.

@Brechtpd Brechtpd marked this pull request as ready for review December 4, 2021 22:54
@Brechtpd Brechtpd changed the title [WIP] Bytecode unroller Bytecode unroller Dec 5, 2021
Copy link
Collaborator

@miha-stopar miha-stopar left a comment

Choose a reason for hiding this comment

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

Nice!

Sorry for not reviewing this PR earlier! It looks really good to me and can be merged after rebase from my point of view. At first I thought padding could be set to 0 in is_final or before, but then I saw you have a constraint for padding to be 0 when is_final, so all good!

meta.query_selector(q_enable)
* not::expr(meta.query_fixed(q_first, Rotation::cur()))
},
|meta| meta.query_advice(push_rindex, Rotation::prev()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

one question: why not current rotation meta.query_advice(push_rindex, Rotation::cur()) when checking push_rindex?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Certainly possible to do it in different ways, but I think always necessary to check 2 rows for some column because inherently we do not have enough data on a single row (need some history to handle the PUSH data). With how it currently works, the push_rindex == 0 check is done against the previous row so that push_rindex of the current row can store the rindex for the byte in the current row (push_rindex := is_code ? byte_push_size : push_rindex_prev - 1). It's also possible I guess to check the value in the current row, and write the value in the next row, which is kind of the same thing but I think complicates things somewhat (because we then need special handling of the last byte which cannot use a value for the next row).

Copy link
Collaborator

Choose a reason for hiding this comment

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

sound good to me, thanks !

meta.query_advice(index, Rotation::cur()),
meta.query_advice(index, Rotation::prev()) + 1u64.expr(),
);
// `is_code := push_rindex_prev == 0`
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about is_code := push_rindex == 0 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same explanation as above I think.

@ChihChengLiang
Copy link
Collaborator

@Brechtpd Can we do a rebase for this?

Copy link
Collaborator

@DreamWuGit DreamWuGit left a comment

Choose a reason for hiding this comment

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

LGTM !

bytecodes.iter().map(|v| v.bytes.clone()).enumerate()
{
let hash: F = keccak(&bytecode[..], self.r);
let rlc: F = linear_combine(bytecode.clone(), self.r);
Copy link
Collaborator

Choose a reason for hiding this comment

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

one more: keccak table validity(hash correctness) will be checked elsewhere like RW_table, Tx_table, 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.

That's right, will be checked in the keccak circuit.

@Brechtpd
Copy link
Collaborator Author

@Brechtpd Can we do a rebase for this?

Done. The latest ConstraintBuilder contains things specifically for the opcode implementations, and I used the old ConstraintBuilder for just some basic constraint management. I think that still makes a lot of sense, but to do that I had to split up the ConstraintBuilder in a more general and basic reusable part for all circuits, and the more opcode specific part that also makes use of the basic part. I don't think it's very pretty but I haven't come up with something better yet.

@ChihChengLiang ChihChengLiang merged commit 3caf937 into privacy-scaling-explorations:main Feb 15, 2022
@ChihChengLiang
Copy link
Collaborator

@Brechtpd Merged, thank you for the epic work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate-zkevm-circuits Issues related to the zkevm-circuits workspace member T-opcode Type: opcode-related and focused PR/Issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants