Skip to content

Commit 5b6c22e

Browse files
Correct a bug in the gas accounting of REVM (#4007)
## Motivation There was an error in the gas accounting ## Proposal The following is done: * The `Gas::new(0)` is replaced by a `Gas::new(gas_limit)`. * The `EvmExecutionError` errors are now more precise. ## Test Plan The CI. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links None
1 parent ae51d83 commit 5b6c22e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

linera-execution/src/evm/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ pub enum EvmExecutionError {
3131
TransactError(String),
3232
#[error("Transact commit error {0}")]
3333
TransactCommitError(String),
34-
#[error("The operation was reverted")]
34+
#[error("The operation was reverted with {gas_used} gas used and output {output:?}")]
3535
Revert {
3636
gas_used: u64,
3737
output: revm_primitives::Bytes,
3838
},
39-
#[error("The operation was halted")]
39+
#[error("The operation was halted with {gas_used} gas used due to {reason:?}")]
4040
Halt { gas_used: u64, reason: HaltReason },
4141
}

linera-execution/src/evm/revm.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,17 @@ enum PrecompileTag {
324324
Service(ServicePrecompileTag),
325325
}
326326

327-
fn get_precompile_output(output: Vec<u8>) -> Result<Option<InterpreterResult>, String> {
328-
// The gas usage is set to zero since the proper accounting is done
329-
// by the called application
327+
fn get_precompile_output(
328+
output: Vec<u8>,
329+
gas_limit: u64,
330+
) -> Result<Option<InterpreterResult>, String> {
331+
// The gas usage is set to `gas_limit` and no spending is being done on it.
332+
// This means that for REVM, it looks like the precompile call costs nothing.
333+
// This is because the costs of the EVM precompile calls is accounted for
334+
// separately in Linera.
330335
let output = Bytes::copy_from_slice(&output);
331336
let result = InstructionResult::default();
332-
let gas = Gas::new(0);
337+
let gas = Gas::new(gas_limit);
333338
Ok(Some(InterpreterResult {
334339
result,
335340
output,
@@ -415,7 +420,7 @@ impl<'a, Runtime: ContractRuntime> PrecompileProvider<Ctx<'a, Runtime>> for Cont
415420
if address == &PRECOMPILE_ADDRESS {
416421
let input = get_precompile_argument(context, &inputs.input);
417422
let output = Self::call_or_fail(&input, gas_limit, context)?;
418-
return get_precompile_output(output);
423+
return get_precompile_output(output, gas_limit);
419424
}
420425
self.inner
421426
.run(context, address, inputs, is_static, gas_limit)
@@ -593,7 +598,7 @@ impl<'a, Runtime: ServiceRuntime> PrecompileProvider<Ctx<'a, Runtime>> for Servi
593598
if address == &PRECOMPILE_ADDRESS {
594599
let input = get_precompile_argument(context, &inputs.input);
595600
let output = Self::call_or_fail(&input, gas_limit, context)?;
596-
return get_precompile_output(output);
601+
return get_precompile_output(output, gas_limit);
597602
}
598603
self.inner
599604
.run(context, address, inputs, is_static, gas_limit)

0 commit comments

Comments
 (0)