Skip to content

Commit

Permalink
refactor(evm): improve estimate gas error handling (#881)
Browse files Browse the repository at this point in the history
* return error instead of panicking when passing invalid gas params

* pass error message to rpc error when tx is invalid

* style: resolve style guide violations

* update test
  • Loading branch information
oXtxNt9U authored Mar 10, 2025
1 parent 6cbe176 commit ead336e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/api-evm/source/actions/eth-estimate-gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export class EthEstimateGasAction implements Contracts.Api.RPC.Action {
if (success) {
return `0x${gasUsed.toString(16)}`;
}
} catch {}
} catch (error) {
throw new Exceptions.RpcError(`execution reverted: ${error.message}`);
}

throw new Exceptions.RpcError("execution reverted");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/evm-service/source/instances/evm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ describe<{
blockContext: { ...blockContext, commitKey: { height: BigInt(0), round: BigInt(0) } },
...deployConfig,
}),
"Panic in async function",
"transaction validation error: lack of funds (0) for max fee (2)",
);
});

Expand Down
11 changes: 4 additions & 7 deletions packages/evm/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,14 +656,11 @@ impl EvmInner {
match err {
revm::primitives::InvalidTransaction::CallGasCostMoreThanGasLimit
| revm::primitives::InvalidTransaction::NonceTooHigh { .. }
| revm::primitives::InvalidTransaction::NonceTooLow { .. } => {
return Err(EVMError::Transaction(err));
}
revm::primitives::InvalidTransaction::LackOfFundForMaxFee {
fee,
balance,
| revm::primitives::InvalidTransaction::NonceTooLow { .. }
| revm::primitives::InvalidTransaction::LackOfFundForMaxFee {
..
} => {
todo!("lack of funds (fee={} balance={})", fee, balance);
return Err(EVMError::Transaction(err));
}
// revm::primitives::InvalidTransaction::PriorityFeeGreaterThanMaxFee => todo!(),
// revm::primitives::InvalidTransaction::GasPriceLessThanBasefee => todo!(),
Expand Down

0 comments on commit ead336e

Please sign in to comment.