subtract by the overhead from running gasleft() (#74)
* subtract by the overhead from running gasleft() * Rename variable * forge fmt * Clamp to the upper gas limit * Forge fmt * Update ethereum/contracts/coreRelayer/CoreRelayer.sol Co-authored-by: scnale <sebinale@gmail.com> --------- Co-authored-by: scnale <sebinale@gmail.com>
This commit is contained in:
parent
20bb4c7f8e
commit
fc06699266
|
@ -417,11 +417,19 @@ contract CoreRelayer is CoreRelayerGovernance {
|
|||
}(abi.encodeWithSignature("receiveWormholeMessages(bytes[],bytes[])", encodedVMs, new bytes[](0)));
|
||||
|
||||
uint256 postGas = gasleft();
|
||||
// There's no easy way to measure the exact cost of the CALL instruction.
|
||||
// This is due to the fact that the compiler probably emits DUPN or MSTORE instructions
|
||||
// to setup the arguments for the call just after our measurement.
|
||||
// This means the refund could be off by a few units of gas.
|
||||
// Thus, we ensure the overhead doesn't cause an overflow in our refund formula here.
|
||||
uint256 gasUsed = (preGas - postGas) > internalInstruction.executionParameters.gasLimit
|
||||
? internalInstruction.executionParameters.gasLimit
|
||||
: (preGas - postGas);
|
||||
|
||||
// refund unused gas budget
|
||||
uint256 weiToRefund = internalInstruction.applicationBudgetTarget;
|
||||
if (success) {
|
||||
weiToRefund = (internalInstruction.executionParameters.gasLimit - (preGas - postGas))
|
||||
weiToRefund = (internalInstruction.executionParameters.gasLimit - gasUsed)
|
||||
* internalInstruction.maximumRefundTarget / internalInstruction.executionParameters.gasLimit;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue