Skip to content

Commit c49d363

Browse files
authored
bug(anvil): incorrectly adds +1 gas when estimating transactions with explicit empty data field (#10786)
* no input + empty input / test * indent * fmt * clippy * add no account auth verif
1 parent 2ddd74a commit c49d363

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

crates/anvil/src/eth/api.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2905,7 +2905,9 @@ impl EthApi {
29052905
let to = request.to.as_ref().and_then(TxKind::to);
29062906

29072907
// check certain fields to see if the request could be a simple transfer
2908-
let maybe_transfer = request.input.input().is_none() &&
2908+
let maybe_transfer = (request.input.input().is_none() ||
2909+
request.input.input().is_some_and(|data| data.is_empty())) &&
2910+
request.authorization_list.is_none() &&
29092911
request.access_list.is_none() &&
29102912
request.blob_versioned_hashes.is_none();
29112913

crates/anvil/tests/it/gas.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,46 @@ async fn test_can_use_fee_history() {
215215
assert_eq!(latest_fee_history_fee, next_base_fee as u64);
216216
}
217217
}
218+
219+
#[tokio::test(flavor = "multi_thread")]
220+
async fn test_estimate_gas_empty_data() {
221+
let (api, handle) = spawn(NodeConfig::test()).await;
222+
let accounts = handle.dev_accounts().collect::<Vec<_>>();
223+
let from = accounts[0];
224+
let to = accounts[1];
225+
226+
let tx_without_data =
227+
TransactionRequest::default().with_from(from).with_to(to).with_value(U256::from(1));
228+
229+
let gas_without_data = api
230+
.estimate_gas(WithOtherFields::new(tx_without_data), None, Default::default())
231+
.await
232+
.unwrap();
233+
234+
let tx_with_empty_data = TransactionRequest::default()
235+
.with_from(from)
236+
.with_to(to)
237+
.with_value(U256::from(1))
238+
.with_input(vec![]);
239+
240+
let gas_with_empty_data = api
241+
.estimate_gas(WithOtherFields::new(tx_with_empty_data), None, Default::default())
242+
.await
243+
.unwrap();
244+
245+
let tx_with_data = TransactionRequest::default()
246+
.with_from(from)
247+
.with_to(to)
248+
.with_value(U256::from(1))
249+
.with_input(vec![0x12, 0x34]);
250+
251+
let gas_with_data = api
252+
.estimate_gas(WithOtherFields::new(tx_with_data), None, Default::default())
253+
.await
254+
.unwrap();
255+
256+
assert_eq!(gas_without_data, U256::from(GAS_TRANSFER));
257+
assert_eq!(gas_with_empty_data, U256::from(GAS_TRANSFER));
258+
assert!(gas_with_data > U256::from(GAS_TRANSFER));
259+
assert_eq!(gas_without_data, gas_with_empty_data);
260+
}

0 commit comments

Comments
 (0)