Feature: QuarkChain Multi-Native Token (MNT) Support for goshard EVM#18
Open
ping-ke wants to merge 8 commits into
Open
Feature: QuarkChain Multi-Native Token (MNT) Support for goshard EVM#18ping-ke wants to merge 8 commits into
ping-ke wants to merge 8 commits into
Conversation
… EVM - Add TokenBalances type with RLP encoding for QKC multi-token account model - Add QuarkChain StateAccount extension (6-field RLP with full_shard_key) - Add token_id codec (36-base encoding) matching goquarkchain - Add QKC precompile contracts: transferMnt, deployNativeToken - Wire MNT balance reads/writes into EVM state transition and journal - Add tools/verify_trie_root to cross-check trie root against goquarkchain - Add tools/generatedata scripts for test data generation from RocksDB Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ansition MNT wiring Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Remove the duplicate const in core/vm/evm.go and use the canonical types.DefaultTokenID everywhere; add types import to contracts_qkc.go. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ned dump script - Rename tools/generatedata → tools/dump_state - Rename tools/verify_trie_root → tools/verify_state - Delete test_mainnet_compat.sh (replaced by tools/README.md) - Add tools/README.md documenting the two-step workflow - dump_qkc_state_trie.py: parse MinorBlock bytes directly via _parse_minor_block() — no pyquarkchain import needed - Use binary search over mi_N keys to find chain tip (O(log N), no hardcoded height ceiling) - .gitignore: exclude trie_dump.json and *.exe from tools/verify_state
- dump_qkc_state_trie.py: add _parse_minor_block() to extract hash_evm_state_root directly from raw bytes — no pyquarkchain import - Replace hardcoded height scan with binary search over mi_N keys (O(log N), no ceiling assumption) - Update tools/README.md: no pyquarkchain install needed - Update tools/verify_state/main.go package comment path - .gitignore: exclude trie_dump.json and *.exe under tools/verify_state
…ck FullShardKey
refactor TokenBal encoding to avoid rawTokenBal cache:
- Remove rawTokenBal field and InvalidateRawTokenBal() from StateAccount
- DecodeRLP: always set MntBalances when TokenBal has content (even if
empty after stripping QKC), preserving nil vs empty list distinction
- EncodeRLP: three-way switch — MntBalances==nil → 0x80, MntBalances
empty list → 0x8200c0, normal → mergeSerializeToBytes
- Remove InvalidateRawTokenBal calls from state_object.go and
state_object_qkc.go
- Remove unused GetFakeChainId() from params/config.go
This preserves byte-identical round-trip for the 9194 accounts with
0x8200c0 TokenBal (EOA that touched TokenBalances then emptied it)
without caching raw wire bytes. 26018 accounts all verified round-trip.
track FullShardKey end-to-end:
- Add FullShardKey field to StateAccount (with Copy/Encode/Decode)
- Add fullShardKey field and SetFullShardKey() to StateDB
- Preserve existing account FullShardKey in createObject
- Set fullShardKey in StateDB.Copy()
tests:
- StateAccountEncodeDecodeRoundtrip: FullShardKey assertions
- Pyquarkchain compatibility: FullShardKey in decode/encode checks
- Slim round-trip: add FullShardKey=0 note
- verify_state: read fullShardKey, TokenBalances strip & re-encode
- Separate 0x80 / 0x8200c0 cases into separate JSON files
Co-Authored-By: Claude <noreply@anthropic.com>
Optial was a typo carried over from goquarkchain. The field name is now Optional to match its intended meaning. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
QuarkChain Multi-Native Token (MNT) Support for goshard EVM
Summary
Port QuarkChain's multi-native token (MNT) account model and EVM extensions from goquarkchain into goshard, enabling state-root compatibility with the original pyquarkchain/goquarkchain chain. Add tooling to export and verify state trie correctness against a live pyquarkchain database.
Changes
common/token_codec.go— 36-base token name ↔ uint64 ID codec (TokenIDEncode/TokenIDDecode), byte-compatible with goquarkchaincore/types/token.go—TokenBalancestype: list-format RLP encoding (0x00 prefix, ≤16 tokens); trie format (>16 tokens) unsupported with clear errorstate_account_qkc.go—StateAccount.EncodeRLP/DecodeRLPoverrides implementing QKC's 6-field wire format[nonce, tokenBal, root, codeHash, fullShardKey, optional], byte-compatible with pyquarkchainDefaultTokenID = 35760(TokenIDEncode("QKC"))core/state/state_object_qkc.go—SetMntBalance,AddMntBalance,SubMntBalance,GetMntBalanceonstateObjectstatedb_qkc.go— same set onStateDB;SubBalanceByTokenID/GetBalanceByTokenIDdispatch by token IDjournal.go—mntBalanceChangejournal entry + revertmnt_test.go— unit tests for MNT balance state transitionscore/vm/contracts_qkc.go— 5 MNT precompiles at QKC system addresses:0x…514b430001currentMntID— returns active MNT token ID0x…514b430002transferMnt— transfer MNT between accounts0x…514b430003deploySystemContract— deploy NonReserved / General native token contracts0x…514b430004mintMNT— mint new MNT tokens (only callable by authorised system contract)0x…514b430005balanceMNT— query MNT balancecore/evm.go/core/state_transition.goBlockContextandMessageso precompiles and gas payment operate on the correct tokentools/tools/verify_trie_root/main.go— loadstrie_dump.jsonexported from a pyquarkchain DB, feeds all trie nodes into goshard's trie package, and asserts the recomputed root matches — verified ✓ on mainnet shard-1tools/generatedata/dump_qkc_state_trie.py— exports the full state trie from a pyquarkchain RocksDB to JSON; handles latest-block lookup, backwards scan to find a persisted snapshot (~128-block checkpoint interval), outputs anode_storemap consumable byverify_trie_rootVerification
Dump pyquarkchain trie data
Verify goshard mnt by trie root
Out of scope / follow-up
QKCChainConfig(Constantinople-level gas rules matching goquarkchain's go-ethereum v1.8.20)TokenBalancestrie format (accounts with >16 MNT tokens)