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

Commit

Permalink
chores: code cosmetics and assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Jun 20, 2023
1 parent b81a860 commit ad221d8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
7 changes: 2 additions & 5 deletions zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
cb.account_write_word(
call_callee_address.to_word(),
AccountFieldTag::Nonce,
Word::from_lo_unchecked(1.expr()),
Word::one(),
Word::zero(),
Some(&mut reversion_info),
);
Expand Down Expand Up @@ -394,10 +394,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
|cb| {
// Setup first call's context.
for (field_tag, value) in [
(
CallContextFieldTag::Depth,
Word::from_lo_unchecked(1.expr()),
),
(CallContextFieldTag::Depth, Word::one()),
(
CallContextFieldTag::CallerAddress,
tx_caller_address.to_word(),
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
cb.account_write_word(
contract_addr.to_word(),
AccountFieldTag::Nonce,
Word::from_lo_unchecked(1.expr()),
Word::from_lo_unchecked(0.expr()),
Word::one(),
Word::zero(),
Some(&mut callee_reversion_info),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorWriteProtectionGadget<F> {
});

// current call context is readonly
cb.call_context_lookup_read(
None,
CallContextFieldTag::IsStatic,
Word::from_lo_unchecked(1.expr()),
);
cb.call_context_lookup_read(None, CallContextFieldTag::IsStatic, Word::one());

// constrain not root call as at least one previous staticcall preset.
cb.require_zero(
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/sar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<F: Field> ExecutionGadget<F> for SarGadget<F> {
for idx in 0..4 {
cb.require_equal(
"a64s[idx] == a64s_lo[idx] + a64s_hi[idx] * p_lo",
a64s.limbs[0].clone(),
a64s.limbs[idx].clone(),
a64s_lo[idx].expr() + a64s_hi[idx].expr() * p_lo.expr(),
);
}
Expand Down
6 changes: 1 addition & 5 deletions zkevm-circuits/src/evm_circuit/execution/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ impl<F: Field> ExecutionGadget<F> for StopGadget<F> {
);

// Call ends with STOP must be successful
cb.call_context_lookup_read(
None,
CallContextFieldTag::IsSuccess,
Word::from_lo_unchecked(1.expr()),
);
cb.call_context_lookup_read(None, CallContextFieldTag::IsSuccess, Word::one());

let is_to_end_tx = cb.next.execution_state_selector([ExecutionState::EndTx]);
cb.require_equal(
Expand Down
13 changes: 10 additions & 3 deletions zkevm-circuits/src/util/int_decomposition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ impl<F: Field, const N_LIMBS: usize> IntDecomposition<F, N_LIMBS> {
}

/// assign bytes to cells
pub fn assign<const N_LIMBS_ASSIGN: usize>(
pub fn assign<const N_BYTES: usize>(
&self,
region: &mut CachedRegion<'_, '_, F>,
offset: usize,
bytes: Option<[u8; N_LIMBS_ASSIGN]>,
bytes: Option<[u8; N_BYTES]>,
) -> Result<Vec<AssignedCell<F, F>>, Error> {
assert!(N_LIMBS_ASSIGN >= N_LIMBS);
assert!(N_BYTES >= N_LIMBS);
if let Some(bytes) = bytes {
if N_BYTES > N_LIMBS {
for byte in &bytes[N_BYTES - N_LIMBS..] {
assert_eq!(*byte, 0);
}
}
}
bytes.map_or(Err(Error::Synthesis), |bytes| {
self.limbs
.iter()
Expand Down

0 comments on commit ad221d8

Please sign in to comment.