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

[WIP] Enable blockchain EEST #223

Draft
wants to merge 16 commits into
base: dev
Choose a base branch
from
Draft

[WIP] Enable blockchain EEST #223

wants to merge 16 commits into from

Conversation

ulbqb
Copy link
Contributor

@ulbqb ulbqb commented Jan 22, 2025

This PR is under refactoring.

refactoring Tasks:

  • main code
    • remove common.IsPrecompiledContractAddress
    • remove blockchain.UseKaiaCancunExtCodeHashFee
    • remove blockchain.GasLimitInExecutionSpecTest
    • remove blockchain.CreateContractWithCodeFormatInExecutionSpecTest
    • remove types.IsPragueInExecutionSpecTest
    • remove gxhash.CustomInitialize
    • remove change of main code in decode
  • test code

Comment on lines +315 to +317
if CreateContractWithCodeFormatInExecutionSpecTest {
stateDB.CreateSmartContractAccount(addr, params.CodeFormatEVM, g.Config.Rules(new(big.Int).SetUint64(g.Number)))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a code has delegation prefix, SetCodeToEOA should be used for 7702.

Copy link
Contributor Author

@ulbqb ulbqb Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done in test code. Or this is bug.

"github.com/kaiachain/kaia/blockchain/types"
"github.com/kaiachain/kaia/common"
"github.com/kaiachain/kaia/consensus/gxhash"
"github.com/stretchr/testify/suite"
)

func TestBlockchain(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok to remove this.

@@ -223,7 +224,7 @@ func (tm *testMatcher) runTestFile(t *testing.T, path, name string, runTest inte
t.Skip("Skipped by whitelist")
}
}
t.Parallel()
// t.Parallel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have: Enable this

@@ -159,11 +199,13 @@ See https://github.com/ethereum/tests/wiki/Blockchain-Tests-II
expected we are expected to ignore it and continue processing and then validate the
post state.
*/
func (t *BlockTest) insertBlocks(blockchain *blockchain.BlockChain) ([]btBlock, error) {
func (t *BlockTest) insertBlocks(bc *blockchain.BlockChain, preBlock *types.Block) ([]btBlock, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may not need to change insertBlock since it is no longer used.
We can also consider deleting it.


// Because it is a eth test, we don't have to think about fee payer
// Because the baseFee is set to 0, Kaia's gas fee may be 0 if the transaction has a dynamic fee.
senderMap[tx.ValidatedSender()] = new(big.Int).Sub(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tx.ValidatedSender() is already present in the map, you must add it to it.

}

// Modify the decode function
func (bb *btBlock) decode(latestParentHash common.Hash, latestRoot common.Hash) (*types.Block, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that decode is no longer necessary.

}

// Decode header
var header TestHeader
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use btHeader?

Comment on lines +2770 to +2772
if GasLimitInExecutionSpecTest != 0 {
blockContext.GasLimit = GasLimitInExecutionSpecTest
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, it's correct that Kaia's GasLimit is zero?

Comment on lines +2777 to +2783

// when execution spec test, we can insert test GasLimit to blockContext.
if UseKaiaCancunExtCodeHashFee && chainConfig.Rules(header.Number).IsCancun {
// EIP-1052 must be activated for backward compatibility on Kaia. But EIP-2929 is activated instead of it on Ethereum
vm.ChangeGasCostForTest(&vmenv.Config.JumpTable, vm.EXTCODEHASH, params.WarmStorageReadCostEIP2929)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be implemented in test code.

@@ -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)))) {
Copy link
Contributor Author

@ulbqb ulbqb Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed, executing test for each fork?

Comment on lines +72 to +80
func (suite *ExecutionSpecBlockTestSuite) TearDownSuite() {
// Reset global variables for test
common.IsPrecompiledContractAddress = suite.originalIsPrecompiledContractAddress
blockchain.UseKaiaCancunExtCodeHashFee = false
blockchain.GasLimitInExecutionSpecTest = 0
blockchain.CreateContractWithCodeFormatInExecutionSpecTest = false
types.IsPragueInExecutionSpecTest = false
gxhash.CustomInitialize = nil
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using build tag, can these be switched?

if gblock.Hash() != t.json.Genesis.Hash {
return fmt.Errorf("genesis block hash doesn't match test: computed=%x, test=%x", gblock.Hash().Bytes()[:6], t.json.Genesis.Hash[:6])

st := MakePreState(db, t.json.Pre, true, config.Rules(gblock.Number()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this, can we overwrite pre state?

Comment on lines +119 to +128
config.SetDefaults()
// Since we calculate the baseFee differently than eth, we will set it to 0 to turn off the gas fee.
config.Governance.KIP71 = &params.KIP71Config{
LowerBoundBaseFee: 0,
UpperBoundBaseFee: 0,
GasTarget: 0,
MaxBlockGasUsedForBaseFee: 0,
BaseFeeDenominator: 0,
}
blockchain.InitDeriveSha(config)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to know how config is. Description of blockchain config is needed.

ethReward: ethReward,
}

i, err := bc.InsertChain(blocks)
Copy link
Contributor Author

@ulbqb ulbqb Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the same block executed twice?

Comment on lines +377 to +381
if rewardList, exist := rewardMap[addr]; exist {
// In the case of rewardBaseAddress, the Kaia reward will be deducted once.
statedb.SubBalance(addr, rewardList.kaiaReward)
statedb.AddBalance(addr, rewardList.ethReward)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be run before loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants