Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

LT & GT opcode spec #53

Merged
merged 5 commits into from
Oct 29, 2021

Conversation

scroll-dev
Copy link
Contributor

@scroll-dev scroll-dev commented Oct 19, 2021

Add the python code and doc for LT and GT opcode. Also refactor the test code.

@scroll-dev
Copy link
Contributor Author

cc @ChihChengLiang @miha-stopar This PR is ready for review.

Copy link
Collaborator

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

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

LGTM. I added some feedbacks.
Great work on also fixing other parts of the spec/code.


The `LT` and `GT` opcode compares the top two values on the stack, and push the
result (0 or 1) back to the stack.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to see a short description on

  1. How do we use c8s === b8s - a8s to check b8s > a8s
  2. How do we use swap to reuse the same gadget for GT and LT.

So that the reviewer or the auditor can have a rough idea before diving into the Python code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the doc

swap: bool,
carry: bool,
):
assert not swap
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest renaming swap to something like is_gt so that it doesn't collide with the SWAPX opcode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Copy link
Contributor

@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.

LGTM! However, would it make sense to include the EQ opcode as well if privacy-scaling-explorations/zkevm-circuits#120 is merged?

"""
Check if c8s equals to b8s - a8s.
When result is 1, the last carry of the addition of a8s and c8s should be 0,
and c8s should not equal to 0.
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: "not be equal to 0."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thank you.

):
"""
Check if c8s equals to b8s - a8s.
When result is 1, the last carry of the addition of a8s and c8s should be 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this properly formulated? Don't we have only one carry?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update the doc to be more clear.

@scroll-dev
Copy link
Contributor Author

@ChihChengLiang I moved the test basic add and sub test from src/zkevm_specs/add_sub.py into the tests/test_add_sub.py. I also fixed a bug that passes the a8s, b8s, and sum8s in the wrong order for SUB opcode. Could you take a look?

Copy link
Collaborator

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

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

LGTM
Waiting for a final look from @miha-stopar before merging

@miha-stopar
Copy link
Contributor

It seems cool to me as it reflects the current implementation. However, the implementation is now being changed here. There are some differences in the concept of both implementations and there is also EQ added in the new one. Would it be OK to reflect the new implementation before merging it?

Copy link
Contributor

@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.

Talked with @ChihChengLiang - it makes sense to merge it now and then reflect the implementation changes in a separate PR. Thanks for good work!

@miha-stopar miha-stopar merged commit 6434b64 into privacy-scaling-explorations:master Oct 29, 2021
DreamWuGit referenced this pull request in scroll-tech/zkevm-specs Nov 9, 2021
* add lt & gt spec

Co-authored-by: gaswhat <hs@scroll.tech>
@icemelon icemelon deleted the lt-gt branch March 18, 2022 03:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new LT and GT comparator to reflect the new circuit implementation
3 participants