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

Feat/challenge evm circuit#1020

Merged
adria0 merged 24 commits into
mainfrom
feat/challenge-evm-circuit
Jan 12, 2023
Merged

Feat/challenge evm circuit#1020
adria0 merged 24 commits into
mainfrom
feat/challenge-evm-circuit

Conversation

@adria0

@adria0 adria0 commented Jan 2, 2023

Copy link
Copy Markdown
Contributor

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

Depends on privacy-ethereum/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
@adria0 adria0 force-pushed the feat/challenge-evm-circuit branch from b5ee253 to 5ba2cf1 Compare January 3, 2023 13:20
@han0110 han0110 self-requested a review January 4, 2023 15:14

@han0110 han0110 left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

leftover?

Copy link
Copy Markdown
Contributor 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
Copy Markdown
Contributor

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 🤣

Comment thread zkevm-circuits/src/witness/block.rs Outdated
Comment thread zkevm-circuits/src/evm_circuit/util/math_gadget/batched_is_zero.rs Outdated
Comment thread zkevm-circuits/src/evm_circuit/execution.rs Outdated
Comment thread zkevm-circuits/src/evm_circuit/util.rs Outdated
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
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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.

@han0110 han0110 Jan 9, 2023

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Contributor 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
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed in 61710e8

@ChihChengLiang ChihChengLiang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

First pass

Comment thread Cargo.toml Outdated
@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
@adria0 adria0 force-pushed the feat/challenge-evm-circuit branch from e69e704 to 75149e6 Compare January 10, 2023 09:38
@adria0 adria0 force-pushed the feat/challenge-evm-circuit branch from 75149e6 to c755ee2 Compare January 10, 2023 09:39

@han0110 han0110 left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread zkevm-circuits/src/evm_circuit/execution.rs Outdated
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
Copy Markdown
Contributor

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 🤣

Comment thread zkevm-circuits/src/evm_circuit/util.rs Outdated
Comment thread zkevm-circuits/src/evm_circuit/util.rs
Comment thread zkevm-circuits/src/witness/block.rs Outdated
Comment thread zkevm-circuits/src/witness/block.rs Outdated

@han0110 han0110 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work!

@ChihChengLiang ChihChengLiang left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread zkevm-circuits/src/evm_circuit/execution/callop.rs Outdated
Comment thread zkevm-circuits/src/evm_circuit/execution/callop.rs Outdated
Comment thread zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs Outdated
Comment thread zkevm-circuits/src/evm_circuit/execution/extcodehash.rs Outdated
@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