Skip to content

Commit

Permalink
feat/privacy-scaling-explorations#1576 refactor rw counter delta for …
Browse files Browse the repository at this point in the history
…CommonErrorGadget (privacy-scaling-explorations#1577)

### Description

refactor  rw counter delta for CommonErrorGadget

### Issue Link

privacy-scaling-explorations#1576 

### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
  • Loading branch information
KimiWu123 authored Aug 31, 2023
1 parent 851b92d commit 818ecbc
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorCodeStoreGadget<F> {
let common_error_gadget = CommonErrorGadget::construct_with_return_data(
cb,
opcode.expr(),
5.expr(),
cb.rw_counter_offset(),
memory_address.offset(),
memory_address.length(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorInvalidCreationCodeGadget<F> {
let common_error_gadget = CommonErrorGadget::construct_with_return_data(
cb,
opcode.expr(),
5.expr(),
cb.rw_counter_offset(),
memory_address.offset(),
memory_address.length(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorInvalidJumpGadget<F> {
});

let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), 3.expr() + is_jumpi.expr());
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());

Self {
opcode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorInvalidOpcodeGadget<F> {
},
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 2.expr());
let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 0.expr());

Self {
opcode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGAccountAccessGadget<F> {
1.expr(),
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 5.expr());
let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());
Self {
opcode,
address,
Expand Down
7 changes: 2 additions & 5 deletions zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGCallGadget<F> {

// Both CALL and CALLCODE opcodes have an extra stack pop `value` relative to
// DELEGATECALL and STATICCALL.
let common_error_gadget = CommonErrorGadget::construct(
cb,
opcode.expr(),
13.expr() + is_call.expr() + is_callcode.expr(),
);
let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());

Self {
opcode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGConstantGadget<F> {
1.expr(),
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 2.expr());
let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 0.expr());

Self {
opcode,
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/error_oog_exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGExpGadget<F> {
1.expr(),
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 4.expr());
let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());
Self {
opcode,
base,
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/error_oog_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGLogGadget<F> {
1.expr(),
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 5.expr());
let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());

Self {
opcode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGMemoryCopyGadget<F> {
1.expr(),
);

let common_error_gadget = CommonErrorGadget::construct(
cb,
opcode.expr(),
// EXTCODECOPY has extra 1 call context lookup (tx_id), 1 account access list
// read (is_warm), and 1 stack pop (external_address).
5.expr() + 3.expr() * is_extcodecopy.expr(),
);
let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());

Self {
opcode,
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/error_oog_sha3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGSha3Gadget<F> {
1.expr(),
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 4.expr());
let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());

Self {
opcode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGSloadSstoreGadget<F> {
1.expr(),
);

let common_error_gadget = CommonErrorGadget::construct(
cb,
opcode.expr(),
7.expr() + 2.expr() * is_sstore.expr().0,
);
let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());

Self {
opcode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGStaticMemoryGadget<F> {
1.expr(),
);

// TODO: `+2` bcs CommonErrorGadget looks up IsSuccess and RwCounterEndOfReversion,
// ,but `+2` should be moved inside CommonErrorGadget
let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset() + 2.expr());
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());

Self {
opcode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorReturnDataOutOfBoundGadget<F> {
1.expr(),
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 6.expr());
let common_error_gadget =
CommonErrorGadget::construct(cb, opcode.expr(), cb.rw_counter_offset());

Self {
opcode,
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/error_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorStackGadget<F> {
},
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 2.expr());
let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 0.expr());

Self {
opcode,
Expand Down
6 changes: 5 additions & 1 deletion zkevm-circuits/src/evm_circuit/util/common_gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,8 @@ impl<F: Field> CommonErrorGadget<F> {
CallContextFieldTag::RwCounterEndOfReversion,
rw_counter_end_of_reversion.to_word(),
);
// Have two rw lookups, `IsSuccess` and `RwCounterEndOfReversion` so we add `2` here.
let updated_rw_counter_delta = rw_counter_delta + 2.expr();

// Go to EndTx only when is_root
let is_to_end_tx = cb.next.execution_state_selector([ExecutionState::EndTx]);
Expand All @@ -987,7 +989,9 @@ impl<F: Field> CommonErrorGadget<F> {
// Do step state transition
cb.require_step_state_transition(StepStateTransition {
call_id: Same,
rw_counter: Delta(rw_counter_delta + cb.curr.state.reversible_write_counter.expr()),
rw_counter: Delta(
updated_rw_counter_delta + cb.curr.state.reversible_write_counter.expr(),
),
..StepStateTransition::any()
});
});
Expand Down

0 comments on commit 818ecbc

Please sign in to comment.