fix: Add l1fee to the balanceCheck (#229)

Add l1fee to the balanceCheck

Co-authored-by: HAOYUatHZ <haoyu@protonmail.com>
This commit is contained in:
Haichen Shen 2023-02-23 16:31:37 -08:00 committed by GitHub
parent 96642f5be6
commit 3c5f532ef3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,6 +26,7 @@ import (
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/core/vm"
"github.com/scroll-tech/go-ethereum/crypto/codehash"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/rollup/fees"
)
@ -207,6 +208,7 @@ func (st *StateTransition) buyGas() error {
if st.evm.ChainConfig().UsingScroll {
// always add l1fee, because all tx are L2-to-L1 ATM
log.Debug("Adding L1 fee", "l1_fee", st.l1Fee)
mgval = mgval.Add(mgval, st.l1Fee)
}
@ -215,6 +217,10 @@ func (st *StateTransition) buyGas() error {
balanceCheck = new(big.Int).SetUint64(st.msg.Gas())
balanceCheck = balanceCheck.Mul(balanceCheck, st.gasFeeCap)
balanceCheck.Add(balanceCheck, st.value)
if st.evm.ChainConfig().UsingScroll {
// always add l1fee, because all tx are L2-to-L1 ATM
balanceCheck.Add(balanceCheck, st.l1Fee)
}
}
if have, want := st.state.GetBalance(st.msg.From()), balanceCheck; have.Cmp(want) < 0 {
return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want)