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

Commit

Permalink
formalized api uncheck suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Jun 19, 2023
1 parent 03a9218 commit 498c502
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 48 deletions.
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<F: Field> ExecutionGadget<F> for BalanceGadget<F> {
let tx_id = cb.call_context(None, CallContextFieldTag::TxId);
let mut reversion_info = cb.reversion_info_read(None);
let is_warm = cb.query_bool();
cb.account_access_list_write(
cb.account_access_list_write_unchecked(
tx_id.expr(),
address.to_word(),
1.expr(),
Expand Down
16 changes: 8 additions & 8 deletions zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
let call_id = cb.curr.state.rw_counter.clone();

let tx_id = cb.query_u64();
cb.call_context_lookup_write_unchecked(
cb.call_context_lookup_write(
Some(call_id.expr()),
CallContextFieldTag::TxId,
tx_id.to_word(),
); // rwc_delta += 1
let mut reversion_info = cb.reversion_info_write(None); // rwc_delta += 2
cb.call_context_lookup_write_unchecked(
let mut reversion_info = cb.reversion_info_write_unchecked(None); // rwc_delta += 2
cb.call_context_lookup_write(
Some(call_id.expr()),
CallContextFieldTag::IsSuccess,
Word::from_lo_unchecked(reversion_info.is_persistent()),
Expand Down Expand Up @@ -171,15 +171,15 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
let sufficient_gas_left = RangeCheckGadget::construct(cb, gas_left.clone());

// Prepare access list of caller and callee
cb.account_access_list_write(
cb.account_access_list_write_unchecked(
tx_id.expr(),
tx_caller_address.to_word(),
1.expr(),
0.expr(),
None,
); // rwc_delta += 1
let is_caller_callee_equal = cb.query_bool();
cb.account_access_list_write(
cb.account_access_list_write_unchecked(
tx_id.expr(),
tx_callee_address.to_word(),
1.expr(),
Expand All @@ -197,7 +197,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
None,
coinbase.to_word(),
);
cb.account_access_list_write(
cb.account_access_list_write_unchecked(
tx_id.expr(),
coinbase.to_word(),
1.expr(),
Expand Down Expand Up @@ -311,7 +311,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
cb.curr.state.code_hash.to_word(),
),
] {
cb.call_context_lookup_write_unchecked(Some(call_id.expr()), field_tag, value);
cb.call_context_lookup_write(Some(call_id.expr()), field_tag, value);
}

cb.require_step_state_transition(StepStateTransition {
Expand Down Expand Up @@ -431,7 +431,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
),
(CallContextFieldTag::CodeHash, code_hash.to_word()),
] {
cb.call_context_lookup_write_unchecked(Some(call_id.expr()), field_tag, value);
cb.call_context_lookup_write(Some(call_id.expr()), field_tag, value);
}

cb.require_step_state_transition(StepStateTransition {
Expand Down
27 changes: 8 additions & 19 deletions zkevm-circuits/src/evm_circuit/execution/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
// Add callee to access list
let is_warm = cb.query_bool();
let is_warm_prev = cb.query_bool();
cb.account_access_list_write(
cb.account_access_list_write_unchecked(
tx_id.expr(),
call_gadget.callee_address_word(),
is_warm.expr(),
Expand All @@ -129,7 +129,8 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
);

// Propagate rw_counter_end_of_reversion and is_persistent
let mut callee_reversion_info = cb.reversion_info_write(Some(callee_call_id.expr()));
let mut callee_reversion_info =
cb.reversion_info_write_unchecked(Some(callee_call_id.expr()));
cb.require_equal(
"callee_is_persistent == is_persistent ⋅ is_success",
callee_reversion_info.is_persistent(),
Expand Down Expand Up @@ -241,7 +242,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
CallContextFieldTag::LastCalleeReturnDataOffset,
CallContextFieldTag::LastCalleeReturnDataLength,
] {
cb.call_context_lookup_write_unchecked(None, field_tag, Word::zero());
cb.call_context_lookup_write(None, field_tag, Word::zero());
}

// For CALL opcode, it has an extra stack pop `value` (+1) and if the value is
Expand Down Expand Up @@ -286,7 +287,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
CallContextFieldTag::LastCalleeReturnDataOffset,
CallContextFieldTag::LastCalleeReturnDataLength,
] {
cb.call_context_lookup_write_unchecked(None, field_tag, Word::zero());
cb.call_context_lookup_write(None, field_tag, Word::zero());
}

cb.require_step_state_transition(StepStateTransition {
Expand Down Expand Up @@ -329,11 +330,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
cb.curr.state.reversible_write_counter.expr() + 1.expr(),
),
] {
cb.call_context_lookup_write_unchecked(
None,
field_tag,
Word::from_lo_unchecked(value),
);
cb.call_context_lookup_write(None, field_tag, Word::from_lo_unchecked(value));
}

// Setup next call's context.
Expand Down Expand Up @@ -402,19 +399,11 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
call_gadget.callee_code_hash.to_word(),
),
] {
cb.call_context_lookup_write_unchecked(
Some(callee_call_id.expr()),
field_tag,
value,
);
cb.call_context_lookup_write(Some(callee_call_id.expr()), field_tag, value);
}

for (field_tag, value) in [] {
cb.call_context_lookup_write_unchecked(
Some(callee_call_id.expr()),
field_tag,
value,
);
cb.call_context_lookup_write(Some(callee_call_id.expr()), field_tag, value);
}

// Give gas stipend if value is not zero
Expand Down
17 changes: 7 additions & 10 deletions zkevm-circuits/src/evm_circuit/execution/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
);

// add callee to access list
cb.account_access_list_write(
cb.account_access_list_write_unchecked(
tx_id.expr(),
contract_addr.to_word(),
1.expr(),
Expand Down Expand Up @@ -238,10 +238,11 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
Word::from_lo_unchecked(cb.curr.state.reversible_write_counter.expr() + 2.expr()),
),
] {
cb.call_context_lookup_write_unchecked(None, field_tag, value);
cb.call_context_lookup_write(None, field_tag, value);
}

let mut callee_reversion_info = cb.reversion_info_write(Some(callee_call_id.expr()));
let mut callee_reversion_info =
cb.reversion_info_write_unchecked(Some(callee_call_id.expr()));
let transfer = cb.condition(
and::expr([is_precheck_ok.clone(), not_address_collision.expr()]),
|cb| {
Expand Down Expand Up @@ -343,11 +344,7 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
),
(CallContextFieldTag::CodeHash, create.code_hash_word()),
] {
cb.call_context_lookup_write_unchecked(
Some(callee_call_id.expr()),
field_tag,
value,
);
cb.call_context_lookup_write(Some(callee_call_id.expr()), field_tag, value);
}

cb.require_step_state_transition(StepStateTransition {
Expand All @@ -372,7 +369,7 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
CallContextFieldTag::LastCalleeReturnDataOffset,
CallContextFieldTag::LastCalleeReturnDataLength,
] {
cb.call_context_lookup_write_unchecked(None, field_tag, Word::zero());
cb.call_context_lookup_write(None, field_tag, Word::zero());
}
cb.require_step_state_transition(StepStateTransition {
rw_counter: Delta(cb.rw_counter_offset()),
Expand Down Expand Up @@ -415,7 +412,7 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
CallContextFieldTag::LastCalleeReturnDataOffset,
CallContextFieldTag::LastCalleeReturnDataLength,
] {
cb.call_context_lookup_write_unchecked(None, field_tag, Word::zero());
cb.call_context_lookup_write(None, field_tag, Word::zero());
}

cb.require_step_state_transition(StepStateTransition {
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<F: Field> ExecutionGadget<F> for EndTxGadget<F> {
cb.condition(
cb.next.execution_state_selector([ExecutionState::BeginTx]),
|cb| {
cb.call_context_lookup_write_unchecked(
cb.call_context_lookup_write(
Some(cb.next.state.rw_counter.expr()),
CallContextFieldTag::TxId,
// tx_id has been lookup and range_check above
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<F: Field> ExecutionGadget<F> for ExtcodecopyGadget<F> {
let tx_id = cb.call_context(None, CallContextFieldTag::TxId);
let mut reversion_info = cb.reversion_info_read(None);
let is_warm = cb.query_bool();
cb.account_access_list_write(
cb.account_access_list_write_unchecked(
tx_id.expr(),
external_address.to_word(),
1.expr(),
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/extcodehash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<F: Field> ExecutionGadget<F> for ExtcodehashGadget<F> {
let mut reversion_info = cb.reversion_info_read(None);

let is_warm = cb.query_bool();
cb.account_access_list_write(
cb.account_access_list_write_unchecked(
tx_id.expr(),
address.to_word(),
1.expr(),
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/extcodesize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<F: Field> ExecutionGadget<F> for ExtcodesizeGadget<F> {
let tx_id = cb.call_context(None, CallContextFieldTag::TxId);
let mut reversion_info = cb.reversion_info_read(None);
let is_warm = cb.query_bool();
cb.account_access_list_write(
cb.account_access_list_write_unchecked(
tx_id.expr(),
address.to_word(),
1.expr(),
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/util/common_gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<F: Field> RestoreContextGadget<F> {
),
] {
// TODO review and assure range check
cb.call_context_lookup_write_unchecked(
cb.call_context_lookup_write(
Some(caller_id.expr()),
field_tag,
Word::from_lo_unchecked(value),
Expand Down
9 changes: 4 additions & 5 deletions zkevm-circuits/src/evm_circuit/util/constraint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
}

// Access list
pub(crate) fn account_access_list_write(
pub(crate) fn account_access_list_write_unchecked(
&mut self,
tx_id: Expression<F>,
account_address: Word<Expression<F>>,
Expand Down Expand Up @@ -1173,7 +1173,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
);
}

pub(crate) fn call_context_lookup_write_unchecked(
pub(crate) fn call_context_lookup_write(
&mut self,
call_id: Option<Expression<F>>,
field_tag: CallContextFieldTag,
Expand Down Expand Up @@ -1207,10 +1207,9 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
.map(|field_tag| {
let cell = self.query_cell();
if is_write {
self.call_context_lookup_write_unchecked(
self.call_context_lookup_write(
call_id.clone(),
field_tag,
// TODO assure range check since write=true also possible
Word::from_lo_unchecked(cell.expr()),
);
} else {
Expand Down Expand Up @@ -1242,7 +1241,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
self.reversion_info(call_id, false)
}

pub(crate) fn reversion_info_write(
pub(crate) fn reversion_info_write_unchecked(
&mut self,
call_id: Option<Expression<F>>,
) -> ReversionInfo<F> {
Expand Down

0 comments on commit 498c502

Please sign in to comment.