Skip to content

Commit

Permalink
Merge branch 'master' into piersy/correct-hardcoded-gas-limits
Browse files Browse the repository at this point in the history
  • Loading branch information
piersy authored Feb 29, 2024
2 parents f1a2a0b + b5848a7 commit ea03f97
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions contracts/erc20gas/erc20gas.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package erc20gas

import (
"fmt"
"math/big"

"github.com/celo-org/celo-blockchain/accounts/abi"
"github.com/celo-org/celo-blockchain/common"
"github.com/celo-org/celo-blockchain/common/hexutil"
"github.com/celo-org/celo-blockchain/contracts/internal/n"
Expand Down Expand Up @@ -35,9 +37,15 @@ func DebitFees(evm *vm.EVM, address common.Address, amount *big.Int, feeCurrency

rootCaller := vm.AccountRef(common.HexToAddress("0x0"))
// The caller was already charged for the cost of this operation via IntrinsicGas.
_, leftoverGas, err := evm.Call(rootCaller, *feeCurrency, transactionData, maxGasForDebitGasFeesTransactions, big.NewInt(0))
ret, leftoverGas, err := evm.Call(rootCaller, *feeCurrency, transactionData, maxGasForDebitGasFeesTransactions, big.NewInt(0))
gasUsed := maxGasForDebitGasFeesTransactions - leftoverGas
log.Trace("debitGasFees called", "feeCurrency", *feeCurrency, "gasUsed", gasUsed)
if err != nil {
revertReason, err2 := abi.UnpackRevert(ret)
if err2 == nil {
return fmt.Errorf("DebitFees reverted: %s", revertReason)
}
}
return err
}

Expand All @@ -64,8 +72,14 @@ func CreditFees(

rootCaller := vm.AccountRef(common.HexToAddress("0x0"))
// The caller was already charged for the cost of this operation via IntrinsicGas.
_, leftoverGas, err := evm.Call(rootCaller, *feeCurrency, transactionData, maxGasForCreditGasFeesTransactions, big.NewInt(0))
ret, leftoverGas, err := evm.Call(rootCaller, *feeCurrency, transactionData, maxGasForCreditGasFeesTransactions, big.NewInt(0))
gasUsed := maxGasForCreditGasFeesTransactions - leftoverGas
log.Trace("creditGas called", "feeCurrency", *feeCurrency, "gasUsed", gasUsed)
if err != nil {
revertReason, err2 := abi.UnpackRevert(ret)
if err2 == nil {
return fmt.Errorf("CreditFees reverted: %s", revertReason)
}
}
return err
}

0 comments on commit ea03f97

Please sign in to comment.