Skip to content

Commit

Permalink
update tx_signed_length
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamWuGit committed May 29, 2024
1 parent da53bc2 commit 5af852d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
17 changes: 14 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ pub(crate) struct BeginTxGadget<F> {
tx_call_data_gas_cost: Cell<F>,
// The gas cost for rlp-encoded bytes of unsigned tx
tx_data_gas_cost: Cell<F>,
#[cfg(feature = "l1_fee_curie")]
// rlp signed tx bytes' length
tx_signed_length: Cell<F>,
reversion_info: ReversionInfo<F>,
intrinsic_gas_cost: Cell<F>,
sufficient_gas_left: RangeCheckGadget<F, N_BYTES_GAS>,
Expand Down Expand Up @@ -132,8 +135,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
.map(|field_tag| cb.tx_context(tx_id.expr(), field_tag, None));

#[cfg(feature = "l1_fee_curie")]
let tx_signed_hash_length =
cb.tx_context(tx_id.expr(), TxContextFieldTag::TxHashLength, None);
let tx_signed_length = cb.tx_context(tx_id.expr(), TxContextFieldTag::TxHashLength, None);
let tx_access_list = TxAccessListGadget::construct(cb, tx_id.expr(), tx_type.expr());
let is_call_data_empty = IsZeroGadget::construct(cb, tx_call_data_length.expr());

Expand All @@ -149,7 +151,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
tx_id.expr(),
tx_data_gas_cost.expr(),
#[cfg(feature = "l1_fee_curie")]
tx_signed_hash_length.expr(),
tx_signed_length.expr(),
)
});
cb.condition(tx_l1_msg.is_l1_msg(), |cb| {
Expand Down Expand Up @@ -810,6 +812,8 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
is_call_data_empty,
tx_call_data_word_length,
tx_call_data_gas_cost,
#[cfg(feature = "l1_fee_curie")]
tx_signed_length,
tx_data_gas_cost,
reversion_info,
intrinsic_gas_cost,
Expand Down Expand Up @@ -1092,6 +1096,13 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
)?;
self.tx_data_gas_cost
.assign(region, offset, Value::known(F::from(tx.tx_data_gas_cost)))?;
#[cfg(feature = "l1_fee_curie")]
self.tx_signed_length.assign(
region,
offset,
Value::known(F::from(tx.rlp_signed.len() as u64)),
)?;

self.reversion_info.assign(
region,
offset,
Expand Down
10 changes: 5 additions & 5 deletions zkevm-circuits/src/evm_circuit/util/common_gadget/tx_l1_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ impl<F: Field> TxL1FeeGadget<F> {
cb: &mut EVMConstraintBuilder<F>,
tx_id: Expression<F>,
tx_data_gas_cost: Expression<F>,
#[cfg(feature = "l1_fee_curie")] tx_signed_hash_length: Expression<F>,
#[cfg(feature = "l1_fee_curie")] tx_signed_length: Expression<F>,
) -> Self {
#[cfg(feature = "l1_fee_curie")]
let this = Self::raw_construct(cb, tx_data_gas_cost, tx_signed_hash_length);
let this = Self::raw_construct(cb, tx_data_gas_cost, tx_signed_length);
#[cfg(not(feature = "l1_fee_curie"))]
let this = Self::raw_construct(cb, tx_data_gas_cost);

Expand Down Expand Up @@ -257,7 +257,7 @@ impl<F: Field> TxL1FeeGadget<F> {
fn raw_construct(
cb: &mut EVMConstraintBuilder<F>,
tx_data_gas_cost: Expression<F>,
#[cfg(feature = "l1_fee_curie")] tx_signed_hash_length: Expression<F>,
#[cfg(feature = "l1_fee_curie")] tx_signed_length: Expression<F>,
) -> Self {
let tx_l1_fee_word = cb.query_word_rlc();
let remainder_word = cb.query_word_rlc();
Expand Down Expand Up @@ -301,7 +301,7 @@ impl<F: Field> TxL1FeeGadget<F> {
#[cfg(feature = "l1_fee_curie")]
cb.require_equal(
"commitScalar * l1BaseFee + blobScalar * _data.length * l1BlobBaseFee == tx_l1_fee * 10e9 + remainder",
commit_scalar * base_fee + blob_scalar * tx_signed_hash_length * l1_blob_basefee,
commit_scalar * base_fee + blob_scalar * tx_signed_length * l1_blob_basefee,
// * tx_l1_gas,
tx_l1_fee * TX_L1_FEE_PRECISION.expr() + remainder,
);
Expand Down Expand Up @@ -407,7 +407,7 @@ mod tests {
let tx_data_gas_cost = cb.query_cell();
let expected_tx_l1_fee = cb.query_cell();

// for non "l1_fee_curie" feature, tx_signed_hash_length is not used, can
// for non "l1_fee_curie" feature, tx_signed_length is not used, can
// set to zero
let gadget = TxL1FeeGadget::<F>::raw_construct(cb, tx_data_gas_cost.expr());

Expand Down

0 comments on commit 5af852d

Please sign in to comment.