EVMC refundGas not breaching host/evm separation anymore (#2395)

This commit is contained in:
andri lim 2024-06-19 19:15:23 +07:00 committed by GitHub
parent 0e5fd3ffc9
commit 035ef696a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 11 deletions

View File

@ -372,9 +372,6 @@ template chainTo*(c: Computation,
c.continuation = nil
after
func merge*(c, child: Computation) =
c.gasMeter.refundGas(child.gasMeter.gasRefunded)
proc execSelfDestruct*(c: Computation, beneficiary: EthAddress) =
c.vmState.mutateStateDB:
let localBalance = c.getBalance(c.msg.contractAddress)

View File

@ -162,7 +162,8 @@ when evmc_enabled:
? c.memory.write(p.memOutPos,
c.returnData.toOpenArray(0, actualOutputSize - 1))
c.gasMeter.returnGas(GasInt c.res.gas_left)
c.gasMeter.returnGas(c.res.gas_left)
c.gasMeter.refundGas(c.res.gas_refund)
if c.res.status_code == EVMC_SUCCESS:
? c.stack.top(1)
@ -185,7 +186,7 @@ else:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.gasMeter.refundGas(child.gasMeter.gasRefunded)
? c.stack.top(1)
c.returnData = child.output

View File

@ -45,7 +45,8 @@ when not defined(evmc_enabled):
when evmc_enabled:
template execSubCreate(c: Computation; msg: ref nimbus_message) =
c.chainTo(msg):
c.gasMeter.returnGas(GasInt c.res.gas_left)
c.gasMeter.returnGas(c.res.gas_left)
c.gasMeter.refundGas(c.res.gas_refund)
if c.res.status_code == EVMC_SUCCESS:
? c.stack.top(c.res.create_address)
elif c.res.status_code == EVMC_REVERT:
@ -69,7 +70,7 @@ else:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.gasMeter.refundGas(child.gasMeter.gasRefunded)
? c.stack.top child.msg.contractAddress
elif not child.error.burnsGas: # Means return was `REVERT`.
# From create, only use `outputData` if child returned with `REVERT`.

View File

@ -62,8 +62,8 @@ proc evmcExecute(vm: ptr evmc_vm, hostInterface: ptr evmc_host_interface,
status_code: c.evmcStatus,
# Gas left is required to be zero when not `EVMC_SUCCESS` or `EVMC_REVERT`.
gas_left: if result.status_code notin {EVMC_SUCCESS, EVMC_REVERT}: 0'i64
else: c.gasMeter.gasRemaining.int64,
gas_refund: if result.status_code == EVMC_SUCCESS: c.gasMeter.gasRefunded.int64
else: c.gasMeter.gasRemaining,
gas_refund: if result.status_code == EVMC_SUCCESS: c.gasMeter.gasRefunded
else: 0'i64,
output_data: output_data,
output_size: output_size.csize_t,

View File

@ -42,7 +42,7 @@ proc afterExecCreateEvmcNested(host: TransactionHost, child: Computation,
res.gas_left = child.gasMeter.gasRemaining
if child.isSuccess:
host.computation.merge(child)
res.gas_refund = child.gasMeter.gasRefunded
res.status_code = EVMC_SUCCESS
res.create_address = child.msg.contractAddress.toEvmc
else:
@ -78,7 +78,7 @@ proc afterExecCallEvmcNested(host: TransactionHost, child: Computation,
res.gas_left = child.gasMeter.gasRemaining
if child.isSuccess:
host.computation.merge(child)
res.gas_refund = child.gasMeter.gasRefunded
res.status_code = EVMC_SUCCESS
else:
res.status_code = child.evmcStatus