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

added padding advice column in Exp Circuit #359

Closed

Conversation

rrzhang139
Copy link
Contributor

There is no column to indicate whether a row is padding or not.

specs/exp-proof.md Outdated Show resolved Hide resolved
@ed255
Copy link
Member

ed255 commented Jan 19, 2023

Hi @rrzhang139 , is this PR related to this one? privacy-scaling-explorations/zkevm-circuits#1062

@rrzhang139
Copy link
Contributor Author

@ed255 Yes, trying to push this PR before working on that one

@CPerezz
Copy link
Member

CPerezz commented Jan 19, 2023

@rrzhang139 thanks for working in this order. As @roynalnaruto suggested, we should use some mechanism similar to the one used in privacy-scaling-explorations/zkevm-circuits#1064 for the CopyCircuit padding.

I think the PR can serve you as inspiration on how to deal with this.

@rrzhang139
Copy link
Contributor Author

Thanks! @CPerezz. Will check it out.

@rrzhang139 rrzhang139 requested review from CPerezz and roynalnaruto and removed request for CPerezz January 20, 2023 02:00
Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

Can't we re-use is_step column and remove padding?
On this way, if is_step is false then we know it's padding.

Also see the comment for the final constraint.

specs/exp-proof.md Outdated Show resolved Hide resolved
@ed255
Copy link
Member

ed255 commented Jan 24, 2023

I would like to discuss the possibility of a different approach:

  • The exp circuit structure works following a repeated pattern of steps
  • If we could define a fixed number of steps no matter what the input is, we would have constant fixed columns
  • I see that an exponentiation like 2^1 takes 1 step
  • Why not define max_exp_steps and then assign all the meaningful steps and fill the rest (until max_exp_steps) is reached with the steps corresponding to 2^1 repeatedly? This way we don't need extra columns or constraints.

Edit: I originally meant to say 1^2 instead of 2^1 to be used for padding, which is a case that requires a single step (I think 2^1 requires no steps)

@roynalnaruto
Copy link
Collaborator

roynalnaruto commented Jan 24, 2023

@ed255 Great idea! This was also proposed by @z2trillion today and I was gonna post it here for comments. This is totally doable, removes the need for padding and simplifies constraints as all the "dummy" steps would be 2 ^ 1 == 2 (mod 2^256).

I was thinking about this today and I am completely supportive of this approach! @rrzhang139 would you be willing to drop the current padding approach and instead implement this? Please ask any questions if you are not completely sure how this would work.

@ed255 ed255 closed this Jan 24, 2023
@ed255 ed255 reopened this Jan 24, 2023
@ed255
Copy link
Member

ed255 commented Jan 24, 2023

Sorry, I pressed the button Close with comment unintentionally (when I just wanted to cancel writing a comment 😓 )

@CPerezz
Copy link
Member

CPerezz commented Jan 24, 2023

I would like to discuss the possibility of a different approach:

* The exp circuit structure works following a repeated pattern of steps

* If we could define a fixed number of steps no matter what the input is, we would have constant fixed columns

* I see that an exponentiation like `2^1` takes 1 step

* Why not define `max_exp_steps` and then assign all the meaningful steps and fill the rest (until `max_exp_steps`) is reached with the steps corresponding to `2^1` repeatedly?  This way we don't need extra columns or constraints.

Edit: I originally meant to say 1^2 instead of 2^1 to be used for padding, which is a case that requires a single step (I think 2^1 requires no steps)

Won't this require padding anyway?? Maybe I'm missing something but I don't see how padding is not needed here. As "filling-up" is the same as padding isn't it??

@rrzhang139
Copy link
Contributor Author

@CPerezz yes I think you are right. Padding is involved, just how do we implement it to show that it is padding? I think exp_circuit does a good job delineating what is padding by creating a separate function, but I am open to some other design ideas.

@z2trillion
Copy link
Collaborator

Won't this require padding anyway?? Maybe I'm missing something but I don't see how padding is not needed here. As "filling-up" is the same as padding isn't it??

"Padding" would still be needed in the sense that some rows in the exp circuit will not be used by anything in the EVM circuit. the benefit (imo) would be that we wouldn't need to add an additional is_padding advice column and the only constraint we would need to add would be one saying that q_usable is always 1.

@CPerezz
Copy link
Member

CPerezz commented Jan 25, 2023

@z2trillion sounds good! Let's go for this then!

Copy link
Collaborator

@roynalnaruto roynalnaruto left a comment

Choose a reason for hiding this comment

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

Good progress so far, I have a few suggestions :)

specs/exp-proof.md Outdated Show resolved Hide resolved
src/zkevm_specs/evm/typing.py Outdated Show resolved Hide resolved
src/zkevm_specs/evm/typing.py Outdated Show resolved Hide resolved
src/zkevm_specs/evm/typing.py Outdated Show resolved Hide resolved
@rrzhang139 rrzhang139 requested review from roynalnaruto and removed request for CPerezz February 2, 2023 03:42
@rrzhang139
Copy link
Contributor Author

rrzhang139 commented Feb 14, 2023

@ed255 @roynalnaruto @CPerezz can we merge this PR since its zkevm-circuits PR is already merged? It sufficiently reflects the padding behavior exhibited in the circuits. Because it oversimplifies the number of rows in a step (I think it only uses two rows per step), I don't think we need to include the specificities of inserting unusable rows like in the circuits.

A few more changes I made to the latest commit were converting the steps -> rows by multiplying with OFFSET_INCREMENT, and removing pad_rows since we don't really pad but fill in dummy events.

@aguzmant103 aguzmant103 requested review from ed255 and CPerezz and removed request for CPerezz February 23, 2023 12:30
Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

Leaving the review to @ed255 as he was involved in the merge of the PR that solved this in the circuits.

Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

LGTM! Sorry for the delay on reviewing this 😅

@ed255
Copy link
Member

ed255 commented Feb 27, 2023

There's currently a type error in src/zkevm_specs/evm/typing.py, I think changing the max_exp_steps type like this should fix it:

class ExpCircuit:
    # [...]

    def __init__(self, max_exp_steps: int = 100) -> None:
        #[...]

We can merge once all the tests pass.

Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

LGTM once @ed255 's comments are applied!

@CPerezz CPerezz self-requested a review February 27, 2023 16:27
@ed255
Copy link
Member

ed255 commented Mar 9, 2023

@rrzhang139 Could you take a look at this and fix the typing issue so that we can merge this? Thanks!

@rrzhang139
Copy link
Contributor Author

Sorry for the delay! Just pushed!

@ed255
Copy link
Member

ed255 commented Apr 13, 2023

@rrzhang139 sorry we've been away for some weeks, can you resolve the conflicts and we merge this?

@rrzhang139
Copy link
Contributor Author

This is weird. I'm not getting any merge conflicts on my side so I can't even push a new commit.

Copy link
Collaborator

@roynalnaruto roynalnaruto left a comment

Choose a reason for hiding this comment

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

Overall looks good, except the one addition which is not required for the specs. I'll go through it again once you update your PR

src/zkevm_specs/evm_circuit/typing.py Outdated Show resolved Hide resolved
@rrzhang139
Copy link
Contributor Author

@roynalnaruto I have resolved. But why is this conflict always appearing?

@lispc
Copy link
Collaborator

lispc commented Apr 14, 2023

i dont know, what about squashing commits into one and forcing push again?

@aguzmant103
Copy link
Member

@rrzhang139 just following up, did you figure out how to solve the conflicts to get this merged? Need any help from PSE?

@ed255
Copy link
Member

ed255 commented Apr 27, 2023

@rrzhang139 we can take this PR and replicate it with the conflicts solved and merge it (we can't do it on the current PR because it's on a scroll branch); let us know if you'd prefer to work on it yourself, otherwise we'll take it in a few days :)

Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

LGTM

@ed255
Copy link
Member

ed255 commented May 8, 2023

Superseded by #419

@ed255 ed255 closed this May 8, 2023
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.

None yet

7 participants