Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Enable EEST blockchainTests #238

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c278eb6
Exec blockchain test
Mdaiki0730 Dec 16, 2024
802eefc
Change common.IsPrecompiledContractAddress to a global variable
Mdaiki0730 Dec 25, 2024
24a5244
Resolve gas differences with eth
Mdaiki0730 Jan 16, 2025
e4d3eb4
Resolve concurrency issues
Mdaiki0730 Jan 16, 2025
43b8342
Changed to be able to decode eth tx types other than legacy
Mdaiki0730 Jan 16, 2025
877e495
Refactor
Mdaiki0730 Jan 17, 2025
b474ad6
Merge pull request #211 from Mdaiki0730/feat/shanghai-cancun-eets
Mdaiki0730 Jan 17, 2025
3a3b74b
Enable EIP7623 tests
Mdaiki0730 Jan 20, 2025
7db495f
Merge pull request #214 from Mdaiki0730/feat/enable-prague-7623
Mdaiki0730 Jan 20, 2025
ca0ff65
Enable eip2935 on Blockchain EEST (#213)
ulbqb Jan 20, 2025
10405e2
Enable checking storage (#215)
ulbqb Jan 21, 2025
ca8395e
Set precompile correctly
Mdaiki0730 Jan 22, 2025
b012898
Merge pull request #220 from Mdaiki0730/feat/set-precompile-correctly
Mdaiki0730 Jan 22, 2025
7baf716
Enable old forks for blockchain EEST (#221)
ulbqb Jan 22, 2025
af57de8
Reset global variables for gxhash (#222)
ulbqb Jan 22, 2025
b0a2516
Remove unused file (#224)
ulbqb Jan 22, 2025
0276a4e
Remove a gxhash global variable (#234)
ulbqb Jan 27, 2025
77ad493
Set reward in Finalize (#235)
ulbqb Jan 27, 2025
b4fc2d9
Self decode to convert to kaia's eth tx type
Mdaiki0730 Jan 27, 2025
bd1bee7
Remove global variables and aggregate them in the test engine
Mdaiki0730 Jan 27, 2025
64c368f
Merge pull request #231 from Mdaiki0730/feat/eets-refactor
Mdaiki0730 Jan 27, 2025
688ac24
Add CodeFormatEVM when setting SCA in genesis
Mdaiki0730 Jan 28, 2025
b05c85c
Refactor eest blockchain test flow
Mdaiki0730 Jan 28, 2025
00b640c
Restore the isExecutionSpecTest condition
Mdaiki0730 Jan 28, 2025
8fcead0
Remove linter warning
Mdaiki0730 Jan 28, 2025
621c6f2
Merge pull request #237 from Mdaiki0730/feat/eets-refactor-test-flow
Mdaiki0730 Jan 28, 2025
602b6cb
Update condition in evm.Call
Mdaiki0730 Jan 31, 2025
2399572
Fix lint error and typo
Mdaiki0730 Jan 31, 2025
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
10 changes: 10 additions & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2764,6 +2764,16 @@ func (bc *BlockChain) ApplyTransaction(chainConfig *params.ChainConfig, author *
// Create a new environment which holds all relevant information
// about the transaction and calling mechanisms.
vmenv := vm.NewEVM(blockContext, txContext, statedb, chainConfig, vmConfig)

// change evm and msg for eest
if bc != nil {
if e, hasMethod := bc.Engine().(interface {
BeforeApplyMessage(*vm.EVM, *types.Transaction)
}); hasMethod {
e.BeforeApplyMessage(vmenv, msg)
}
}

// Apply the transaction to the current state (included in the env)
result, err := ApplyMessage(vmenv, msg)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions blockchain/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) {
b.receipts = append(b.receipts, receipt)
}

// AddTxWithChainEvenHasError is an AddTx that inherits the vmConfig of the received chain
// and does not panic even if an error occurs.
func (b *BlockGen) AddTxWithChainEvenHasError(bc *BlockChain, tx *types.Transaction) error {
b.statedb.SetTxContext(tx.Hash(), common.Hash{}, len(b.txs))
var vmConfig vm.Config
if bc != nil {
vmConfig = bc.vmConfig
}
receipt, _, _ := bc.ApplyTransaction(b.config, &params.AuthorAddressForTesting, b.statedb, b.header, tx, &b.header.GasUsed, &vmConfig)
b.txs = append(b.txs, tx)
if receipt != nil {
b.receipts = append(b.receipts, receipt)
}
return nil
}

// AddUncheckedTx forcefully adds a transaction to the block without any
// validation.
//
Expand Down
12 changes: 11 additions & 1 deletion blockchain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,17 @@ func (g *Genesis) ToBlock(baseStateRoot common.Hash, db database.DBManager) *typ
for addr, account := range g.Alloc {
if len(account.Code) != 0 {
originalCode := stateDB.GetCode(addr)
stateDB.SetCode(addr, account.Code)
rules := g.Config.Rules(new(big.Int).SetUint64(g.Number))
if rules.IsPrague {
ulbqb marked this conversation as resolved.
Show resolved Hide resolved
if _, ok := types.ParseDelegation(account.Code); ok {
stateDB.SetCodeToEOA(addr, account.Code, rules)
} else {
stateDB.CreateSmartContractAccount(addr, params.CodeFormatEVM, rules)
stateDB.SetCode(addr, account.Code)
}
} else {
stateDB.SetCode(addr, account.Code)
}
// If originalCode is not nil,
// just update the code and don't change the other states
if originalCode != nil {
Expand Down
13 changes: 13 additions & 0 deletions blockchain/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,19 @@ func (s *StateDB) SetLegacyAccountForTest(addr common.Address, nonce uint64, bal
s.setStateObject(newobj)
}

func (s *StateDB) ForEachAccount(cb func(addr common.Address, data account.Account)) {
it := statedb.NewIterator(s.trie.NodeIterator(nil))
for it.Next() {
addr := s.trie.GetKey(it.Key)
serializer := account.NewAccountSerializer()
if err := rlp.DecodeBytes(it.Value, serializer); err != nil {
panic(err)
}
data := serializer.GetAccount()
cb(common.BytesToAddress(addr), data)
}
}

func (s *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) {
so := s.getStateObject(addr)
if so == nil {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/types/tx_internal_data_account_creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func (t *TxInternalDataAccountCreation) Validate(stateDB StateDB, currentBlockNu
//if t.HumanReadable {
// return kerrors.ErrHumanReadableNotSupported
//}
//if common.IsPrecompiledContractAddress(t.Recipient) {
//if common.IsPrecompiledContractAddress(t.Recipient, fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
// return kerrors.ErrPrecompiledContractAddress
//}
//if err := t.Key.CheckInstallable(currentBlockNumber); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func (t *TxInternalDataEthereumAccessList) String() string {

func (t *TxInternalDataEthereumAccessList) Validate(stateDB StateDB, currentBlockNumber uint64) error {
if t.Recipient != nil {
if common.IsPrecompiledContractAddress(*t.Recipient) {
if common.IsPrecompiledContractAddress(*t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (t *TxInternalDataEthereumDynamicFee) SenderTxHash() common.Hash {

func (t *TxInternalDataEthereumDynamicFee) Validate(stateDB StateDB, currentBlockNumber uint64) error {
if t.Recipient != nil {
if common.IsPrecompiledContractAddress(*t.Recipient) {
if common.IsPrecompiledContractAddress(*t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
}
Expand Down
2 changes: 1 addition & 1 deletion blockchain/types/tx_internal_data_ethereum_set_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (t *TxInternalDataEthereumSetCode) Validate(stateDB StateDB, currentBlockNu
if t.Recipient == (common.Address{}) {
return kerrors.ErrEmptyRecipient
} else {
if common.IsPrecompiledContractAddress(t.Recipient) {
if common.IsPrecompiledContractAddress(t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (t *TxInternalDataFeeDelegatedSmartContractDeploy) Validate(stateDB StateDB
} else {
to = crypto.CreateAddress(t.From, t.AccountNonce)
}
if common.IsPrecompiledContractAddress(to) {
if common.IsPrecompiledContractAddress(to, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
if t.HumanReadable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func (t *TxInternalDataFeeDelegatedSmartContractDeployWithRatio) Validate(stateD
} else {
to = crypto.CreateAddress(t.From, t.AccountNonce)
}
if common.IsPrecompiledContractAddress(to) {
if common.IsPrecompiledContractAddress(to, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
if t.HumanReadable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/kaiachain/kaia/common"
"github.com/kaiachain/kaia/common/hexutil"
"github.com/kaiachain/kaia/crypto/sha3"
"github.com/kaiachain/kaia/fork"
"github.com/kaiachain/kaia/kerrors"
"github.com/kaiachain/kaia/params"
"github.com/kaiachain/kaia/rlp"
Expand Down Expand Up @@ -316,7 +317,7 @@ func (t *TxInternalDataFeeDelegatedValueTransfer) SenderTxHash() common.Hash {
}

func (t *TxInternalDataFeeDelegatedValueTransfer) Validate(stateDB StateDB, currentBlockNumber uint64) error {
if common.IsPrecompiledContractAddress(t.Recipient) {
if common.IsPrecompiledContractAddress(t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
return t.ValidateMutableValue(stateDB, currentBlockNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (t *TxInternalDataFeeDelegatedValueTransferMemo) SenderTxHash() common.Hash
}

func (t *TxInternalDataFeeDelegatedValueTransferMemo) Validate(stateDB StateDB, currentBlockNumber uint64) error {
if common.IsPrecompiledContractAddress(t.Recipient) {
if common.IsPrecompiledContractAddress(t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
return t.ValidateMutableValue(stateDB, currentBlockNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (t *TxInternalDataFeeDelegatedValueTransferMemoWithRatio) SenderTxHash() co
}

func (t *TxInternalDataFeeDelegatedValueTransferMemoWithRatio) Validate(stateDB StateDB, currentBlockNumber uint64) error {
if common.IsPrecompiledContractAddress(t.Recipient) {
if common.IsPrecompiledContractAddress(t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
return t.ValidateMutableValue(stateDB, currentBlockNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/kaiachain/kaia/common"
"github.com/kaiachain/kaia/common/hexutil"
"github.com/kaiachain/kaia/crypto/sha3"
"github.com/kaiachain/kaia/fork"
"github.com/kaiachain/kaia/kerrors"
"github.com/kaiachain/kaia/params"
"github.com/kaiachain/kaia/rlp"
Expand Down Expand Up @@ -338,7 +339,7 @@ func (t *TxInternalDataFeeDelegatedValueTransferWithRatio) SenderTxHash() common
}

func (t *TxInternalDataFeeDelegatedValueTransferWithRatio) Validate(stateDB StateDB, currentBlockNumber uint64) error {
if common.IsPrecompiledContractAddress(t.Recipient) {
if common.IsPrecompiledContractAddress(t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
return t.ValidateMutableValue(stateDB, currentBlockNumber)
Expand Down
2 changes: 1 addition & 1 deletion blockchain/types/tx_internal_data_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (t *TxInternalDataLegacy) String() string {

func (t *TxInternalDataLegacy) Validate(stateDB StateDB, currentBlockNumber uint64) error {
if t.Recipient != nil {
if common.IsPrecompiledContractAddress(*t.Recipient) {
if common.IsPrecompiledContractAddress(*t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (t *TxInternalDataSmartContractDeploy) Validate(stateDB StateDB, currentBlo
} else {
to = crypto.CreateAddress(t.From, t.AccountNonce)
}
if common.IsPrecompiledContractAddress(to) {
if common.IsPrecompiledContractAddress(to, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
if t.HumanReadable {
Expand Down
3 changes: 2 additions & 1 deletion blockchain/types/tx_internal_data_value_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/kaiachain/kaia/common"
"github.com/kaiachain/kaia/common/hexutil"
"github.com/kaiachain/kaia/crypto/sha3"
"github.com/kaiachain/kaia/fork"
"github.com/kaiachain/kaia/kerrors"
"github.com/kaiachain/kaia/params"
"github.com/kaiachain/kaia/rlp"
Expand Down Expand Up @@ -284,7 +285,7 @@ func (t *TxInternalDataValueTransfer) SenderTxHash() common.Hash {
}

func (t *TxInternalDataValueTransfer) Validate(stateDB StateDB, currentBlockNumber uint64) error {
if common.IsPrecompiledContractAddress(t.Recipient) {
if common.IsPrecompiledContractAddress(t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
return t.ValidateMutableValue(stateDB, currentBlockNumber)
Expand Down
2 changes: 1 addition & 1 deletion blockchain/types/tx_internal_data_value_transfer_memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (t *TxInternalDataValueTransferMemo) SenderTxHash() common.Hash {
}

func (t *TxInternalDataValueTransferMemo) Validate(stateDB StateDB, currentBlockNumber uint64) error {
if common.IsPrecompiledContractAddress(t.Recipient) {
if common.IsPrecompiledContractAddress(t.Recipient, *fork.Rules(big.NewInt(int64(currentBlockNumber)))) {
return kerrors.ErrPrecompiledContractAddress
}
return t.ValidateMutableValue(stateDB, currentBlockNumber)
Expand Down
26 changes: 0 additions & 26 deletions blockchain/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package vm

import (
"bytes"
"crypto/ecdsa"
"crypto/sha256"
"encoding/binary"
Expand Down Expand Up @@ -218,31 +217,6 @@ func ActivePrecompiles(rules params.Rules) []common.Address {
}
}

// IsPrecompiledContractAddress returns true if this is used for TestExecutionSpecState and the input address is one of precompiled contract addresses.
func IsPrecompiledContractAddress(addr common.Address, rules params.Rules) bool {
if relaxPrecompileRangeForTest {
activePrecompiles := ActivePrecompiles(rules)
for _, pre := range activePrecompiles {
// skip 0x0a and 0x0b if before Prague
if !rules.IsPrague && (bytes.Compare(pre.Bytes(), []byte{10}) == 0 || bytes.Compare(pre.Bytes(), []byte{11}) == 0) {
continue
}
if bytes.Compare(pre.Bytes(), addr.Bytes()) == 0 {
return true
}
}
return false
}
return common.IsPrecompiledContractAddress(addr)
}

var relaxPrecompileRangeForTest bool

// Only for testing. Make sure to reset (false) after test.
func RelaxPrecompileRangeForTest(enable bool) {
relaxPrecompileRangeForTest = enable
}

// RunPrecompiledContract runs and evaluates the output of a precompiled contract.
func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *Contract, evm *EVM) (ret []byte, computationCost uint64, err error) {
gas, computationCost := p.GetRequiredGasAndComputationCost(input)
Expand Down
5 changes: 2 additions & 3 deletions blockchain/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ func (evm *EVM) Call(caller types.ContractRef, addr common.Address, input []byte
)

// Filter out invalid precompiled address calls, and create a precompiled contract object if it is not exist.
// Because IsPrecompiledContractAddress checks for 0..0x400 and ConsoleLog address is outside of the range, we add one more condition if UseConsoleLog.
if IsPrecompiledContractAddress(addr, evm.chainRules) || (addr == consoleLogContractAddress && evm.Config.UseConsoleLog) {
if common.IsPrecompiledContractAddress(addr, evm.chainRules) {
Mdaiki0730 marked this conversation as resolved.
Show resolved Hide resolved
precompiles := evm.GetPrecompiledContractMap(caller.Address())
if precompiles[addr] == nil || value.Sign() != 0 {
// Return an error if an enabled precompiled address is called or a value is transferred to a precompiled address.
Expand Down Expand Up @@ -540,7 +539,7 @@ func (evm *EVM) create(caller types.ContractRef, codeAndHash *codeAndHash, gas u
return nil, common.Address{}, 0, ErrContractAddressCollision
}

if IsPrecompiledContractAddress(address, evm.chainRules) {
if common.IsPrecompiledContractAddress(address, evm.chainRules) {
return nil, common.Address{}, gas, kerrors.ErrPrecompiledContractAddress
}

Expand Down
4 changes: 1 addition & 3 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,8 @@ func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) }
// If s is larger than len(h), s will be cropped from the left.
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }

var relaxPrecompileRangeForTest bool

// IsPrecompiledContractAddress returns true if the input address is in the range of precompiled contract addresses.
func IsPrecompiledContractAddress(addr Address) bool {
var IsPrecompiledContractAddress func(addr Address, rules interface{}) bool = func(addr Address, rules interface{}) bool {
if bytes.Compare(addr.Bytes(), lastPrecompiledContractAddressHex) > 0 || addr == (Address{}) {
return false
}
Expand Down
Loading
Loading