Skip to content

Commit

Permalink
Fix fee conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
cffls committed Sep 11, 2024
1 parent fc319f7 commit f9f774f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion common/math/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func BigMinUint256(x, y *uint256.Int) *uint256.Int {

// todo: @anshalshukla - check implementation correctness
func BigIntToUint256Int(x *big.Int) *uint256.Int {
return new(uint256.Int).SetUint64(x.Uint64())
return new(uint256.Int).SetBytes(x.Bytes())
}

// FirstBitSet returns the index of the first 1 bit in v, counting from LSB.
Expand Down
6 changes: 3 additions & 3 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
cmath "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
)

// StateProcessor is a basic Processor, which takes care of transitioning
Expand Down Expand Up @@ -160,11 +160,11 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
statedb.SetMVHashmap(nil)

if evm.ChainConfig().IsLondon(blockNumber) {
statedb.AddBalance(result.BurntContractAddress, uint256.NewInt(result.FeeBurnt.Uint64()), tracing.BalanceChangeTransfer)
statedb.AddBalance(result.BurntContractAddress, cmath.BigIntToUint256Int(result.FeeBurnt), tracing.BalanceChangeTransfer)
}

// TODO(raneet10) Double check
statedb.AddBalance(evm.Context.Coinbase, uint256.NewInt(result.FeeTipped.Uint64()), tracing.BalanceChangeTransfer)
statedb.AddBalance(evm.Context.Coinbase, cmath.BigIntToUint256Int(result.FeeTipped), tracing.BalanceChangeTransfer)
output1 := new(big.Int).SetBytes(result.SenderInitBalance.Bytes())
output2 := new(big.Int).SetBytes(coinbaseBalance.Bytes())

Expand Down
4 changes: 2 additions & 2 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,12 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
burnAmount = new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.evm.Context.BaseFee)

if !st.noFeeBurnAndTip {
st.state.AddBalance(burntContractAddress, uint256.NewInt(burnAmount.Uint64()), tracing.BalanceChangeTransfer)
st.state.AddBalance(burntContractAddress, cmath.BigIntToUint256Int(burnAmount), tracing.BalanceChangeTransfer)
}
}

if !st.noFeeBurnAndTip {
st.state.AddBalance(st.evm.Context.Coinbase, uint256.NewInt(amount.Uint64()), tracing.BalanceIncreaseRewardTransactionFee)
st.state.AddBalance(st.evm.Context.Coinbase, cmath.BigIntToUint256Int(amount), tracing.BalanceIncreaseRewardTransactionFee)

// add the coinbase to the witness iff the fee is greater than 0
if rules.IsEIP4762 && amount.Sign() != 0 {
Expand Down

0 comments on commit f9f774f

Please sign in to comment.