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

Feat/challenge evm circuit #1020

Merged
merged 24 commits into from
Jan 12, 2023
Merged

Feat/challenge evm circuit #1020

merged 24 commits into from
Jan 12, 2023

Conversation

adria0
Copy link
Member

@adria0 adria0 commented Jan 2, 2023

The original PR was #990 but after renaming the branch to feat/challenge-evm-circuit github automatically closed it.

Depends on privacy-scaling-explorations/halo2#115

@github-actions github-actions bot added crate-bus-mapping Issues related to the bus-mapping workspace member crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member crate-eth-types Issues related to the eth-types workspace member crate-gadgets Issues related to the gadgets workspace member crate-integration-tests Issues related to the integration-tests workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member T-bench Type: benchmark improvements labels Jan 2, 2023
@adria0 adria0 linked an issue Jan 2, 2023 that may be closed by this pull request
Copy link
Collaborator

@han0110 han0110 left a comment

Choose a reason for hiding this comment

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

First round pass. Overall looks good to me! Only left some small questions.

Comment on lines 909 to 918
#[test]
fn callop_base() {
test_ok(
caller(&OpcodeId::CALL, Stack::default(), true),
callee(bytecode! {}),
);
// use crate::evm_circuit::util::print_op_count;
// print_op_count();
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

leftover?

Copy link
Member Author

Choose a reason for hiding this comment

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

oops! fixed in 8aa678d

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to be still here 🤣

zkevm-circuits/src/witness/block.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/evm_circuit/execution.rs Outdated Show resolved Hide resolved
pub(crate) fn storage_for_inv<F: FieldExt>(value: &Expression<F>) -> CellType {
match Self::expr_phase(value) {
0 => CellType::StoragePhase1,
1 => CellType::StoragePhase3,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't think about the reason to require phase 3 here? Would you like to explain it more?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the idea is is that which is the "storage requiered to store the inverse of an expression", and this function is really only used in IsZeroGadget.

IIRC, we need an extra phase when computing the inverse of an expression (this is why is_zero in the IsZeroGadget) when it was not in the first phase.

Copy link
Collaborator

@han0110 han0110 Jan 9, 2023

Choose a reason for hiding this comment

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

hmm but the expr_phase returns max_phase_challenge_usable_after, which seems to be "this expression will be evaluateable after such phase", so the inverse should also be in max_phase_challenge_usable_after + 1, right?

For example, an expression advice_at_phase_1 + challenge_usable_after_phase_1, we can store its inverse in phase 2.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 8bfda72

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm sorry I think I'm confused about this function now, so what's the difference between storage_for and storage_for_inv? Inverse of a value should be able to live in the same phase as the value, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea was:

  • storage_for -> storage for an expression
  • storage_for_inv -> storage for the inverse of an expression

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand, my question is more like, what makes inverse storage need one extra phase to be stored? For example advice_at_phase_1 + challenge_usable_after_phase_1 we should be able to store its inverse in phase 2 right? Because this expression is evaluateable in phase 2.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in 61710e8

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.

First pass

Cargo.toml Outdated Show resolved Hide resolved
@github-actions github-actions bot removed crate-bus-mapping Issues related to the bus-mapping workspace member crate-eth-types Issues related to the eth-types workspace member crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member labels Jan 10, 2023
@github-actions github-actions bot removed crate-gadgets Issues related to the gadgets workspace member T-bench Type: benchmark improvements labels Jan 10, 2023
Copy link
Collaborator

@han0110 han0110 left a comment

Choose a reason for hiding this comment

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

Finished my second review, only left some nitpicks. Also I think now it might be a good time to try to run integration test for this PR before being merged.

zkevm-circuits/src/evm_circuit/execution.rs Outdated Show resolved Hide resolved
Comment on lines 909 to 918
#[test]
fn callop_base() {
test_ok(
caller(&OpcodeId::CALL, Stack::default(), true),
callee(bytecode! {}),
);
// use crate::evm_circuit::util::print_op_count;
// print_op_count();
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to be still here 🤣

zkevm-circuits/src/evm_circuit/util.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/evm_circuit/util.rs Show resolved Hide resolved
zkevm-circuits/src/witness/block.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@han0110 han0110 left a comment

Choose a reason for hiding this comment

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

Nice work!

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

zkevm-circuits/src/evm_circuit/execution/callop.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/evm_circuit/execution/callop.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/evm_circuit/execution/extcodehash.rs Outdated Show resolved Hide resolved
@adria0 adria0 merged commit 6d12683 into main Jan 12, 2023
SuccinctPaul pushed a commit to SuccinctPaul/zkevm-circuits that referenced this pull request Jan 13, 2023
@lispc lispc mentioned this pull request Jan 16, 2023
@adria0 adria0 deleted the feat/challenge-evm-circuit branch January 23, 2023 09:52
noel2004 pushed a commit to noel2004/zkevm-circuits that referenced this pull request Nov 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crate-integration-tests Issues related to the integration-tests workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member trigger-integration-tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor EVM circuit with challenge API
4 participants