Skip to content

Commit

Permalink
minor: use explicit builder.assert_zero for readability (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare authored Oct 16, 2023
1 parent c9391be commit 29fdd3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
15 changes: 6 additions & 9 deletions evm/src/fixed_recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,12 +819,11 @@ where
// Connect intermediary values for gas_used and bloom filters to the block's final values. We only plug on the right, so there is no need to check the left-handside block.
Self::connect_final_block_values_to_intermediary(builder, rhs);

let zero = builder.zero();
let has_not_parent_block = builder.sub(one, has_parent_block.target);

// Check that the genesis block number is 0.
let gen_block_constr = builder.mul(has_not_parent_block, rhs.block_metadata.block_number);
builder.connect(gen_block_constr, zero);
builder.assert_zero(gen_block_constr);

// Check that the genesis block has the predetermined state trie root in `ExtraBlockData`.
Self::connect_genesis_block(builder, rhs, has_not_parent_block);
Expand All @@ -837,7 +836,6 @@ where
) where
F: RichField + Extendable<D>,
{
let zero = builder.zero();
for (&limb0, limb1) in x
.trie_roots_before
.state_root
Expand All @@ -846,7 +844,7 @@ where
{
let mut constr = builder.sub(limb0, limb1);
constr = builder.mul(has_not_parent_block, constr);
builder.connect(constr, zero);
builder.assert_zero(constr);
}
}

Expand Down Expand Up @@ -879,16 +877,15 @@ where
where
F: RichField + Extendable<D>,
{
let zero = builder.constant(F::ZERO);
// The initial number of transactions is 0.
builder.connect(x.extra_block_data.txn_number_before, zero);
builder.assert_zero(x.extra_block_data.txn_number_before);
// The initial gas used is 0.
builder.connect(x.extra_block_data.gas_used_before[0], zero);
builder.connect(x.extra_block_data.gas_used_before[1], zero);
builder.assert_zero(x.extra_block_data.gas_used_before[0]);
builder.assert_zero(x.extra_block_data.gas_used_before[1]);

// The initial bloom filter is all zeroes.
for t in x.extra_block_data.block_bloom_before {
builder.connect(t, zero);
builder.assert_zero(t);
}

// The transactions and receipts tries are empty at the beginning of the block.
Expand Down
19 changes: 9 additions & 10 deletions evm/src/recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,11 @@ fn add_data_write<F: RichField + Extendable<D>, const D: usize>(
debug_assert!(val.len() <= VALUE_LIMBS);
let len = core::cmp::min(val.len(), VALUE_LIMBS);

let zero = builder.zero();
let one = builder.one();

let row = builder.add_virtual_targets(13);
// is_read
builder.connect(row[0], zero);
// context
builder.connect(row[1], zero);
// is_read = false
builder.assert_zero(row[0]);
// context = 0
builder.assert_zero(row[1]);
// segment
builder.connect(row[2], segment);
// virtual
Expand All @@ -635,14 +632,16 @@ fn add_data_write<F: RichField + Extendable<D>, const D: usize>(

// values
for j in 0..len {
// connect the actual value limbs
builder.connect(row[4 + j], val[j]);
}
for j in len..VALUE_LIMBS {
builder.connect(row[4 + j], zero);
// assert that the remaining limbs are 0
builder.assert_zero(row[4 + j]);
}

// timestamp
builder.connect(row[12], one);
// timestamp = 1
builder.assert_one(row[12]);

let combined = challenge.combine_base_circuit(builder, &row);
builder.mul(running_product, combined)
Expand Down

0 comments on commit 29fdd3e

Please sign in to comment.