Skip to content

Commit

Permalink
Ensure the actual executed proof base size is the same as the estimat…
Browse files Browse the repository at this point in the history
…e approach
  • Loading branch information
boundless-forest committed Dec 12, 2023
1 parent 2f50992 commit 99f8c40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl<T: Config> Pallet<T> {
) {
weight_limit if weight_limit.proof_size() > 0 => (
Some(weight_limit),
Some(transaction_data.proof_size_base_cost.unwrap_or_default()),
Some(transaction_data.proof_size_base_cost()),
),
_ => (None, None),
}
Expand Down
30 changes: 8 additions & 22 deletions primitives/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub struct TransactionData {
pub value: U256,
pub chain_id: Option<u64>,
pub access_list: Vec<(H160, Vec<H256>)>,
pub proof_size_base_cost: Option<u64>,
}

impl TransactionData {
Expand All @@ -64,7 +63,7 @@ impl TransactionData {
chain_id: Option<u64>,
access_list: Vec<(H160, Vec<H256>)>,
) -> Self {
let mut transaction_data = Self {
Self {
action,
input,
nonce,
Expand All @@ -75,20 +74,19 @@ impl TransactionData {
value,
chain_id,
access_list,
proof_size_base_cost: None,
};
let proof_size_base_cost = transaction_data
.encode()
}
}

// The transact call wrapped in the extrinsic is part of the PoV, record this as a base cost for the size of the proof.
pub fn proof_size_base_cost(&self) -> u64 {
self.encode()
.len()
// signature
.saturating_add(65)
// pallet index
.saturating_add(1)
// call index
.saturating_add(1) as u64;
transaction_data.proof_size_base_cost = Some(proof_size_base_cost);

transaction_data
.saturating_add(1) as u64
}
}

Expand All @@ -115,15 +113,6 @@ impl From<TransactionData> for CheckEvmTransactionInput {

impl From<&Transaction> for TransactionData {
fn from(t: &Transaction) -> Self {
// The call wrapped in the extrinsic is part of the PoV, record this as a base cost for the size of the proof.
let proof_size_base_cost = t
.encode()
.len()
// pallet index
.saturating_add(1)
// call index
.saturating_add(1) as u64;

match t {
Transaction::Legacy(t) => TransactionData {
action: t.action,
Expand All @@ -136,7 +125,6 @@ impl From<&Transaction> for TransactionData {
value: t.value,
chain_id: t.signature.chain_id(),
access_list: Vec::new(),
proof_size_base_cost: Some(proof_size_base_cost),
},
Transaction::EIP2930(t) => TransactionData {
action: t.action,
Expand All @@ -153,7 +141,6 @@ impl From<&Transaction> for TransactionData {
.iter()
.map(|d| (d.address, d.storage_keys.clone()))
.collect(),
proof_size_base_cost: Some(proof_size_base_cost),
},
Transaction::EIP1559(t) => TransactionData {
action: t.action,
Expand All @@ -170,7 +157,6 @@ impl From<&Transaction> for TransactionData {
.iter()
.map(|d| (d.address, d.storage_keys.clone()))
.collect(),
proof_size_base_cost: Some(proof_size_base_cost),
},
}
}
Expand Down

0 comments on commit 99f8c40

Please sign in to comment.