-
Notifications
You must be signed in to change notification settings - Fork 46
Feat/refacto block data module #2449
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
Open
amkCha
wants to merge
3
commits into
arith-dev
Choose a base branch
from
feat/refacto-block-data-module
base: arith-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
...ization/src/main/java/net/consensys/linea/zktracer/module/blockdata/BlockDataExoCall.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /* | ||
| * Copyright ConsenSys Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package net.consensys.linea.zktracer.module.blockdata; | ||
|
|
||
| import static net.consensys.linea.zktracer.Trace.*; | ||
| import static net.consensys.linea.zktracer.types.Conversions.ZERO; | ||
| import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.experimental.Accessors; | ||
| import net.consensys.linea.zktracer.module.euc.Euc; | ||
| import net.consensys.linea.zktracer.module.euc.EucOperation; | ||
| import net.consensys.linea.zktracer.module.wcp.Wcp; | ||
| import net.consensys.linea.zktracer.types.EWord; | ||
| import org.apache.tuweni.bytes.Bytes; | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @Accessors(fluent = true) | ||
| public class BlockDataExoCall { | ||
|
|
||
| @Builder.Default private final boolean wcpFlag = false; | ||
| @Builder.Default private final boolean eucFlag = false; | ||
| @Builder.Default private final int instruction = 0; | ||
| @Builder.Default private final Bytes arg1Hi = Bytes.EMPTY; | ||
| @Builder.Default private final Bytes arg1Lo = Bytes.EMPTY; | ||
| @Builder.Default private final Bytes arg2Hi = Bytes.EMPTY; | ||
| @Builder.Default private final Bytes arg2Lo = Bytes.EMPTY; | ||
| // Results for wcp computations | ||
| // Quotients for euc computations in trace | ||
| @Builder.Default private final Bytes res = ZERO; | ||
|
|
||
| public static BlockDataExoCall callToLT(final Wcp wcp, Bytes arg1, Bytes arg2) { | ||
|
|
||
| final EWord arg1B32 = EWord.of(arg1); | ||
| final EWord arg2B32 = EWord.of(arg2); | ||
|
|
||
| return BlockDataExoCall.builder() | ||
| .wcpFlag(true) | ||
| .instruction(EVM_INST_LT) | ||
| .arg1Hi(arg1B32.lo()) | ||
| .arg1Lo(arg1B32.hi()) | ||
| .arg2Hi(arg2B32.lo()) | ||
| .arg2Lo(arg2B32.hi()) | ||
| .res(booleanToBytes(wcp.callLT(arg1B32, arg2B32))) | ||
| .build(); | ||
| } | ||
|
|
||
| public static BlockDataExoCall callToGT(final Wcp wcp, Bytes arg1, Bytes arg2) { | ||
|
|
||
| final EWord arg1B32 = EWord.of(arg1); | ||
| final EWord arg2B32 = EWord.of(arg2); | ||
|
|
||
| return BlockDataExoCall.builder() | ||
| .wcpFlag(true) | ||
| .instruction(EVM_INST_GT) | ||
| .arg1Hi(arg1B32.lo()) | ||
| .arg1Lo(arg1B32.hi()) | ||
| .arg2Hi(arg2B32.lo()) | ||
| .arg2Lo(arg2B32.hi()) | ||
| .res(booleanToBytes(wcp.callLT(arg1B32, arg2B32))) | ||
| .build(); | ||
| } | ||
|
|
||
| public static BlockDataExoCall callToLEQ(final Wcp wcp, Bytes arg1, Bytes arg2) { | ||
|
|
||
| final EWord arg1B32 = EWord.of(arg1); | ||
| final EWord arg2B32 = EWord.of(arg2); | ||
|
|
||
| return BlockDataExoCall.builder() | ||
| .wcpFlag(true) | ||
| .instruction(WCP_INST_LEQ) | ||
| .arg1Hi(arg1B32.lo()) | ||
| .arg1Lo(arg1B32.hi()) | ||
| .arg2Hi(arg2B32.lo()) | ||
| .arg2Lo(arg2B32.hi()) | ||
| .res(booleanToBytes(wcp.callLEQ(arg1B32, arg2B32))) | ||
| .build(); | ||
| } | ||
|
|
||
| public static BlockDataExoCall callToGEQ(final Wcp wcp, Bytes arg1, Bytes arg2) { | ||
|
|
||
| final EWord arg1B32 = EWord.of(arg1); | ||
| final EWord arg2B32 = EWord.of(arg2); | ||
|
|
||
| return BlockDataExoCall.builder() | ||
| .wcpFlag(true) | ||
| .instruction(WCP_INST_GEQ) | ||
| .arg1Hi(arg1B32.lo()) | ||
| .arg1Lo(arg1B32.hi()) | ||
| .arg2Hi(arg2B32.lo()) | ||
| .arg2Lo(arg2B32.hi()) | ||
| .res(booleanToBytes(wcp.callLEQ(arg1B32, arg2B32))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| .build(); | ||
| } | ||
|
|
||
| public static BlockDataExoCall callToIsZero(final Wcp wcp, Bytes arg1) { | ||
|
|
||
| final EWord arg1B32 = EWord.of(arg1); | ||
|
|
||
| return BlockDataExoCall.builder() | ||
| .wcpFlag(true) | ||
| .instruction(EVM_INST_ISZERO) | ||
| .arg1Hi(arg1B32.slice(0, LLARGE)) | ||
| .arg1Lo(arg1B32.slice(LLARGE, LLARGE)) | ||
| .res(booleanToBytes(wcp.callISZERO(arg1B32))) | ||
| .build(); | ||
| } | ||
|
|
||
| public static BlockDataExoCall callToEUC(final Euc euc, Bytes arg1, Bytes arg2) { | ||
|
|
||
| final EWord arg1B32 = EWord.of(arg1); | ||
| final EWord arg2B32 = EWord.of(arg2); | ||
|
|
||
| EucOperation eucOperation = euc.callEUC(arg1B32, arg2B32); | ||
|
|
||
| return BlockDataExoCall.builder() | ||
| .eucFlag(true) | ||
| .arg1Lo(arg1B32.hi()) | ||
| .arg2Lo(arg2B32.hi()) | ||
| .res(eucOperation.quotient()) | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Comparison Methods Return Incorrect Values
The
callToGTmethod callswcp.callLTinstead ofwcp.callGT, andcallToGEQcallswcp.callLEQinstead ofwcp.callGEQ. This copy-paste error results in both methods returning the opposite boolean value for their intended comparisons.Additional Locations (1)
arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/BlockDataExoCall.java#L106-L107