From 2d98a74ef350928eae6359b0871100da3ded0ea9 Mon Sep 17 00:00:00 2001 From: Rodrigo Herrera Date: Tue, 7 May 2024 14:51:05 -0600 Subject: [PATCH 1/3] support eth transfer to proposers with code --- mev-build-rs/src/payload/builder.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mev-build-rs/src/payload/builder.rs b/mev-build-rs/src/payload/builder.rs index eac4a1be..9a991ba2 100644 --- a/mev-build-rs/src/payload/builder.rs +++ b/mev-build-rs/src/payload/builder.rs @@ -51,13 +51,14 @@ fn make_payment_transaction( config: &PayloadFinalizerConfig, chain_id: ChainId, nonce: u64, + gas_limit: u64, max_fee_per_gas: u128, value: U256, ) -> Result { let tx = Transaction::Eip1559(TxEip1559 { chain_id, nonce, - gas_limit: BASE_TX_GAS_LIMIT, + gas_limit, max_fee_per_gas, max_priority_fee_per_gas: 0, to: TxKind::Call(config.proposer_fee_recipient), @@ -95,10 +96,26 @@ fn append_payment( let signer_account = db.load_cache_account(signer.address())?; let nonce = signer_account.account_info().map(|info| info.nonce).unwrap_or_default(); + + let proposer_fee_recipient_account = db.load_cache_account(config.proposer_fee_recipient)?; + let is_empty_code_hash = + proposer_fee_recipient_account.account_info().unwrap_or_default().is_empty_code_hash(); + + // If the proposer (fee recipient) has associated code, we hardcode 250_000 for gas payment. + // If it is a regular EOA, we send the base gas 21_000. + let gas_limit = if is_empty_code_hash { BASE_TX_GAS_LIMIT } else { 250_000 }; + // SAFETY: cast to bigger type always succeeds let max_fee_per_gas = block.header().base_fee_per_gas.unwrap_or_default() as u128; - let payment_tx = - make_payment_transaction(signer, config, chain_id, nonce, max_fee_per_gas, value)?; + let payment_tx = make_payment_transaction( + signer, + config, + chain_id, + nonce, + gas_limit, + max_fee_per_gas, + value, + )?; // TODO: skip clones here let mut env: EnvWithHandlerCfg = EnvWithHandlerCfg::new_with_cfg_env( From 67fdbd9454d51142d6ccf6e80e980d1229e2983a Mon Sep 17 00:00:00 2001 From: Rodrigo Herrera Date: Tue, 7 May 2024 17:23:05 -0600 Subject: [PATCH 2/3] refactor --- mev-build-rs/src/payload/builder.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mev-build-rs/src/payload/builder.rs b/mev-build-rs/src/payload/builder.rs index 9a991ba2..a994271e 100644 --- a/mev-build-rs/src/payload/builder.rs +++ b/mev-build-rs/src/payload/builder.rs @@ -46,6 +46,8 @@ pub enum Error { pub const BASE_TX_GAS_LIMIT: u64 = 21000; +pub const PAYMENT_TO_CONTRACT_GAS_LIMIT: u64 = 100_000; + fn make_payment_transaction( signer: &LocalWallet, config: &PayloadFinalizerConfig, @@ -95,15 +97,18 @@ fn append_payment( .build(); let signer_account = db.load_cache_account(signer.address())?; - let nonce = signer_account.account_info().map(|info| info.nonce).unwrap_or_default(); + let nonce = signer_account.account_info().map(|account| account.nonce).unwrap_or_default(); let proposer_fee_recipient_account = db.load_cache_account(config.proposer_fee_recipient)?; - let is_empty_code_hash = - proposer_fee_recipient_account.account_info().unwrap_or_default().is_empty_code_hash(); - - // If the proposer (fee recipient) has associated code, we hardcode 250_000 for gas payment. - // If it is a regular EOA, we send the base gas 21_000. - let gas_limit = if is_empty_code_hash { BASE_TX_GAS_LIMIT } else { 250_000 }; + let is_empty_code_hash = proposer_fee_recipient_account + .account_info() + .map(|account| account.is_empty_code_hash()) + .unwrap_or_default(); + + // Use a fixed gas limit for the payment transaction reflecting the recipient's status + // as asmart contract or EOA. + let gas_limit = + if is_empty_code_hash { BASE_TX_GAS_LIMIT } else { PAYMENT_TO_CONTRACT_GAS_LIMIT }; // SAFETY: cast to bigger type always succeeds let max_fee_per_gas = block.header().base_fee_per_gas.unwrap_or_default() as u128; From 5a55edede2510d387c7a6f1a046b9f1aa6b1ecc3 Mon Sep 17 00:00:00 2001 From: Rodrigo Herrera Date: Tue, 7 May 2024 17:24:42 -0600 Subject: [PATCH 3/3] typo --- mev-build-rs/src/payload/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mev-build-rs/src/payload/builder.rs b/mev-build-rs/src/payload/builder.rs index a994271e..f7dadae4 100644 --- a/mev-build-rs/src/payload/builder.rs +++ b/mev-build-rs/src/payload/builder.rs @@ -106,7 +106,7 @@ fn append_payment( .unwrap_or_default(); // Use a fixed gas limit for the payment transaction reflecting the recipient's status - // as asmart contract or EOA. + // as smart contract or EOA. let gas_limit = if is_empty_code_hash { BASE_TX_GAS_LIMIT } else { PAYMENT_TO_CONTRACT_GAS_LIMIT };