Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: estimateGas edge case #11764

Merged
merged 2 commits into from
Oct 15, 2024
Merged

fix: estimateGas edge case #11764

merged 2 commits into from
Oct 15, 2024

Conversation

klkvr
Copy link
Collaborator

@klkvr klkvr commented Oct 15, 2024

Looks like in some cases we may end up with mid_gas_limit being lower than initial gas transaction consumes.

Can be reproduced like this:

let signer = PrivateKeySigner::from_bytes(&b256!(
    "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
))?;

let provider = ProviderBuilder::new().on_http("https://odyssey.ithaca.xyz".parse()?);

let auth = Authorization {
    chain_id: U256::from(provider.get_chain_id().await?),
    address: address!("23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f"),
    nonce: provider.get_transaction_count(signer.address()).await?,
};

let signature = signer.sign_hash_sync(&auth.signature_hash())?;
let auth = auth.into_signed(signature);

let tx = TransactionRequest::default()
    .with_authorization_list(vec![auth])
    .with_to(signer.address());

// Error: ErrorResp(ErrorPayload { code: -32000, message: "intrinsic gas too low", data: None })
println!("{:?}", provider.estimate_gas(&tx).await?);

Such transaction needs 46000 of gas with 9200 getting refunded. because of lowest_gas_limit being set to just gas_used we're ending up trying to transact with gas limit of 38k which is not enough

Solution is to add handling of insufficient initial gas

@klkvr klkvr changed the title fix: estimateGas edge case fix: estimateGas edge case Oct 15, 2024
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes perfect sense,
great find

@mattsse mattsse added C-bug An unexpected or incorrect behavior A-rpc Related to the RPC implementation labels Oct 15, 2024
@klkvr klkvr enabled auto-merge October 15, 2024 18:37
@klkvr klkvr added this pull request to the merge queue Oct 15, 2024
Merged via the queue into main with commit 7f92760 Oct 15, 2024
39 checks passed
@klkvr klkvr deleted the klkvr/estimate-gas-fix branch October 15, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation C-bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants