Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ func (diff *StateOverride) Apply(state state.StateDB) error {
}
// Override account(contract) code.
if account.Code != nil {
state.SetCode(addr, *account.Code)
state.SetCode(addr, *account.Code, tracing.CodeChangeUnspecified)
}
// Override account balance.
if account.Balance != nil {
Expand Down
14 changes: 13 additions & 1 deletion ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func runEstimateGasOverrideTest(t *testing.T, test stateOverrideEstimateGasTest)
mockBackend.EXPECT().GetPoolNonce(any, any).Return(uint64(0), nil).AnyTimes()

mockState.EXPECT().GetBalance(any).Return(uint256.NewInt(12345678901234567890)).AnyTimes()
mockState.EXPECT().SetCode(any, any).AnyTimes()
mockState.EXPECT().SetCode(any, any, any).AnyTimes()
mockState.EXPECT().SetBalance(any, any).AnyTimes()
mockState.EXPECT().SetStorage(any, any).AnyTimes()
mockState.EXPECT().SetState(any, any, any).AnyTimes()
Expand Down Expand Up @@ -1299,10 +1299,22 @@ func (fcc *FakeChainContext) Engine() consensus.Engine {
return nil
}

func (fcc *FakeChainContext) CurrentHeader() *types.Header {
return fcc.header
}

func (fcc *FakeChainContext) GetHeader(common.Hash, uint64) *types.Header {
return fcc.header
}

func (fcc *FakeChainContext) GetHeaderByNumber(uint64) *types.Header {
return fcc.header
}

func (fcc *FakeChainContext) GetHeaderByHash(common.Hash) *types.Header {
return fcc.header
}

func (fcc *FakeChainContext) Config() *params.ChainConfig {
return fcc.chainConfig
}
Expand Down
2 changes: 1 addition & 1 deletion ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int, lo
BlobHashes: args.BlobHashes,
SetCodeAuthorizations: args.AuthorizationList,
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipTransactionChecks: true,
}, nil
}

Expand Down
44 changes: 22 additions & 22 deletions ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ func TestTransactionArgs_ToMessage_TrivialFieldsAreCopied(t *testing.T) {
},

// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
}, *msg)
}

Expand All @@ -233,8 +233,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasTipCap: big.NewInt(0),

// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
},
"zero initialized and basefee uses eip1559 rules": {
Expand All @@ -248,8 +248,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasTipCap: big.NewInt(0),

// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
baseFee: big.NewInt(77),
},
Expand All @@ -265,8 +265,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasFeeCap: big.NewInt(10000000),
GasTipCap: big.NewInt(10000000),
// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
baseFee: big.NewInt(77),
},
Expand All @@ -282,8 +282,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasFeeCap: big.NewInt(10000000),
GasTipCap: big.NewInt(10000000),
// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
},
"maxFeePerGas and no basefee uses pre-eip1559 rules": {
Expand All @@ -299,8 +299,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasTipCap: big.NewInt(0),

// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
},
"maxFeePerGas and basefee uses eip1559 rules": {
Expand All @@ -316,8 +316,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasTipCap: big.NewInt(0),

// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
baseFee: big.NewInt(77),
},
Expand All @@ -334,8 +334,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasTipCap: big.NewInt(0),

// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
},
"maxPriorityFeePerGas and basefee uses eip1559 rules": {
Expand All @@ -351,8 +351,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasTipCap: big.NewInt(1234),

// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
baseFee: big.NewInt(77),
},
Expand All @@ -370,8 +370,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasTipCap: big.NewInt(0),

// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
},
"maxFeePerGas, maxPriorityFeePerGas and basefee uses eip1559 rules": {
Expand All @@ -388,8 +388,8 @@ func TestTransactionArgs_ToMessage_GasPriceFollowsEIP1559Rules(t *testing.T) {
GasTipCap: big.NewInt(5678),

// Hardcoded values
SkipNonceChecks: true,
SkipFromEOACheck: true,
SkipNonceChecks: true,
SkipTransactionChecks: true,
},
baseFee: big.NewInt(77),
},
Expand Down
28 changes: 14 additions & 14 deletions evmcore/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,20 +575,20 @@ func TxAsMessage(tx *types.Transaction, signer types.Signer, baseFee *big.Int) (
return core.TransactionToMessage(tx, signer, baseFee)
} else {
return &core.Message{ // internal tx - no signature checking
From: internaltx.InternalSender(tx),
To: tx.To(),
Nonce: tx.Nonce(),
Value: tx.Value(),
GasLimit: tx.Gas(),
GasPrice: tx.GasPrice(),
GasFeeCap: tx.GasFeeCap(),
GasTipCap: tx.GasTipCap(),
Data: tx.Data(),
AccessList: tx.AccessList(),
BlobGasFeeCap: tx.BlobGasFeeCap(),
BlobHashes: tx.BlobHashes(),
SkipNonceChecks: true, // don't check sender nonce and being EOA
SkipFromEOACheck: true,
From: internaltx.InternalSender(tx),
To: tx.To(),
Nonce: tx.Nonce(),
Value: tx.Value(),
GasLimit: tx.Gas(),
GasPrice: tx.GasPrice(),
GasFeeCap: tx.GasFeeCap(),
GasTipCap: tx.GasTipCap(),
Data: tx.Data(),
AccessList: tx.AccessList(),
BlobGasFeeCap: tx.BlobGasFeeCap(),
BlobHashes: tx.BlobHashes(),
SkipNonceChecks: true, // don't check sender nonce and being EOA
SkipTransactionChecks: true,
}, nil
}
}
28 changes: 14 additions & 14 deletions evmcore/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,10 @@ func TestApplyTransaction_InternalTransactionsSkipBaseFeeCharges(t *testing.T) {
// this is not relevant. We just want to check if the base fee
// configuration flag is updated to match the SkipAccountChecks flag.
_, _, err := applyTransaction(&core.Message{
SkipNonceChecks: internal,
SkipFromEOACheck: internal,
GasPrice: big.NewInt(0),
Value: big.NewInt(0),
SkipNonceChecks: internal,
SkipTransactionChecks: internal,
GasPrice: big.NewInt(0),
Value: big.NewInt(0),
}, gp, state, nil, nil, nil, evm, nil)
if err == nil {
t.Errorf("expected transaction to fail")
Expand Down Expand Up @@ -541,16 +541,16 @@ func TestApplyTransaction_ApplyMessageError_RevertsSnapshotIfPrague(t *testing.T

initCode := make([]byte, 50000) // large init code to trigger error
msg := &core.Message{
From: common.Address{1},
To: nil, // contract creation
GasLimit: 1000000,
GasPrice: big.NewInt(1),
GasFeeCap: big.NewInt(0),
GasTipCap: big.NewInt(0),
Value: big.NewInt(0),
Data: initCode,
SkipNonceChecks: true,
SkipFromEOACheck: true,
From: common.Address{1},
To: nil, // contract creation
GasLimit: 1000000,
GasPrice: big.NewInt(1),
GasFeeCap: big.NewInt(0),
GasTipCap: big.NewInt(0),
Value: big.NewInt(0),
Data: initCode,
SkipNonceChecks: true,
SkipTransactionChecks: true,
}

gomock.InOrder(
Expand Down
3 changes: 2 additions & 1 deletion evmcore/tx_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/0xsoniclabs/sonic/gossip/blockproc/subsidies"
"github.com/0xsoniclabs/sonic/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
Expand Down Expand Up @@ -485,7 +486,7 @@ func (h *priceHeap) Less(i, j int) bool {
func (h *priceHeap) cmp(a, b *types.Transaction) int {
if h.baseFee != nil {
// Compare effective tips if baseFee is specified
if c := a.EffectiveGasTipCmp(b, h.baseFee); c != 0 {
if c := a.EffectiveGasTipCmp(b, utils.BigIntToUint256Clamped(h.baseFee)); c != 0 {
return c
}
}
Expand Down
4 changes: 3 additions & 1 deletion evmcore/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,15 @@ func (pool *TxPool) Pending(enforceTips bool) (map[common.Address]types.Transact
defer pool.mu.Unlock()

pending := make(map[common.Address]types.Transactions)
minTip := utils.BigIntToUint256Clamped(pool.minTip)
baseFee := utils.BigIntToUint256Clamped(pool.priced.urgent.baseFee)
for addr, list := range pool.pending {
txs := list.Flatten()

// If the miner requests tip enforcement, cap the lists now
if enforceTips && !pool.locals.contains(addr) {
for i, tx := range txs {
if tx.EffectiveGasTipIntCmp(pool.minTip, pool.priced.urgent.baseFee) < 0 && !subsidies.IsSponsorshipRequest(tx) {
if tx.EffectiveGasTipIntCmp(minTip, baseFee) < 0 && !subsidies.IsSponsorshipRequest(tx) {
txs = txs[:i]
break
}
Expand Down
9 changes: 5 additions & 4 deletions evmcore/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/0xsoniclabs/sonic/utils"
"github.com/ethereum/go-ethereum/common"

"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"
Expand Down Expand Up @@ -118,7 +119,7 @@ func (t testTxPoolStateDb) GetCodeHash(addr common.Address) common.Hash {
return hash
}

func (t testTxPoolStateDb) SetCode(addr common.Address, code []byte) []byte {
func (t testTxPoolStateDb) SetCode(addr common.Address, code []byte, _ tracing.CodeChangeReason) []byte {
if len(code) == 0 {
delete(t.codeHashes, addr)
} else {
Expand Down Expand Up @@ -652,8 +653,8 @@ func TestSetCodeTransactions(t *testing.T) {
pending: 1,
test: func(t *testing.T, pool *TxPool) {
aa := common.Address{0xaa, 0xaa}
db.SetCode(addrA, append(types.DelegationPrefix, aa.Bytes()...))
db.SetCode(aa, []byte{byte(vm.ADDRESS), byte(vm.PUSH0), byte(vm.SSTORE)})
db.SetCode(addrA, append(types.DelegationPrefix, aa.Bytes()...), tracing.CodeChangeUnspecified)
db.SetCode(aa, []byte{byte(vm.ADDRESS), byte(vm.PUSH0), byte(vm.SSTORE)}, tracing.CodeChangeUnspecified)

// Send gapped transaction, it should be rejected.
if err := pool.addRemoteSync(pricedTransaction(2, 100000, big.NewInt(1), keyA)); !errors.Is(err, ErrOutOfOrderTxFromDelegated) {
Expand All @@ -677,7 +678,7 @@ func TestSetCodeTransactions(t *testing.T) {
}

// Reset the delegation, avoid leaking state into the other tests
db.SetCode(addrA, nil)
db.SetCode(addrA, nil, tracing.CodeChangeUnspecified)
},
},
"only one transaction from delegating account in flight": {
Expand Down
2 changes: 1 addition & 1 deletion evmcore/tx_validation_fuzzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func stateExpectCalls(state *state.MockStateDB) {
state.EXPECT().AddLog(any).AnyTimes()
state.EXPECT().AddRefund(any).AnyTimes()

state.EXPECT().SetCode(any, any).Return([]byte{}).AnyTimes()
state.EXPECT().SetCode(any, any, any).Return([]byte{}).AnyTimes()
state.EXPECT().SetNonce(any, any, any).AnyTimes()
state.EXPECT().SetState(any, any, any).Return(common.Hash{}).AnyTimes()

Expand Down
Loading