Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Different roots in header use different algorithms, and not Eth2.0-compatible #1318

Closed
yangby-cryptape opened this issue Aug 14, 2023 · 0 comments
Labels
t:bug Something isn't working

Comments

@yangby-cryptape
Copy link
Collaborator

yangby-cryptape commented Aug 14, 2023

Contact Details

No response

Current Behavior

Different roots in block header use different algorithms and different default values.

  • The default value for TrieMerkle.root_hash, when there are no data, is hash(rlp(null)).

              root: Node::Empty,
              root_hash: hasher.digest(rlp::NULL_RLP.as_ref()),

    Ref: citahub/cita-trie

  • Transactions root for empty list is hash(rlp(null)).

    let txs_root = if !txs.hashes.is_empty() {
    TrieMerkle::from_iter(txs.hashes.iter().enumerate())
    .root_hash()
    .unwrap_or_else(|err| {
    panic!("failed to calculate trie root hash for transactions since {err}")
    })
    } else {
    RLP_NULL
    };

    I checked that RLP_NULL == hash(rlp(null)), and a unit test will be added later.

  • Receipts root for empty list is hash(rlp(null)).

    let receipt_root = TrieMerkle::from_iter(hashes.iter().enumerate())
    .root_hash()
    .unwrap_or_else(|err| {
    panic!("failed to calculate trie root hash for receipts since {err}")
    });

  • Signed transactions hash for empty list is hash(rlp([])).

    signed_txs_hash: digest_signed_transactions(&signed_txs),

    pub fn digest_signed_transactions(stxs: &[SignedTransaction]) -> Hash {
    Hasher::digest(rlp::encode_list(stxs))
    }

  • Default value for metadata_root and cell_header_root is 0x0000..0000.

    pub fn get_metadata_root(&self) -> H256 {
    self.storage(METADATA_CONTRACT_ADDRESS, *METADATA_ROOT_KEY)
    }
    pub fn get_image_cell_root(&self) -> H256 {
    self.storage(IMAGE_CELL_CONTRACT_ADDRESS, *HEADER_CELL_ROOT_KEY)
    }

    fn storage(&self, address: H160, index: H256) -> H256 {
    if let Ok(raw) = self.trie.get(address.as_bytes()) {
    if raw.is_none() {
    return H256::default();
    }
    Account::decode(raw.unwrap())
    .and_then(|account| {
    let storage_root = account.storage_root;
    if storage_root == RLP_NULL {
    Ok(H256::default())
    } else {
    MPTTrie::from_root(storage_root, Arc::clone(&self.db)).map(
    |trie| match trie.get(index.as_bytes()) {
    Ok(Some(res)) => H256::from_slice(res.as_ref()),
    _ => H256::default(),
    },
    )
    }
    })
    .unwrap_or_default()
    } else {
    H256::default()
    }
    }

Ethereum has defined the following roots, as of today (2023-08-15):

  • transactions_root

    • Eth1.0: Default value is hash(rlp(null)).

    • Eth2.0: Default value is ssz_root(null).

    Ref: EIP-6404.

  • receipts_root

    Default value is hash(rlp(null)).

Expected Behavior

Default values:

  • transactions_root: hash(rlp(null))
  • receipts_root: hash(rlp(null)).
  • signed_txs_hash: hash(rlp([]))
    Different with above roots, the inner is an empty list.
  • metadata_root: H256::default().
    metadata_root should be treated as an optional value:
    • H256::default() means it's null.
    • hash(rlp(null)) is the default value when it's not null.
  • cell_header_root: H256::default().
    Same as metadata_root.

OS

Not Associated

Axon version

No response

Kernel

Not Associated

Relevant log output

No response

Anything else?

Since Axon uses MPT root for all roots, but Ethereum uses SSZ root for all roots.

Maybe Axon has to update the README.md as following:

- Axon is compatible with Ethereum so that all of the develop utilities can be used on it directly.
+ Axon is compatible with Ethereum 1.0 so that all of the develop utilities can be used on it directly.
@yangby-cryptape yangby-cryptape added the t:bug Something isn't working label Aug 14, 2023
@yangby-cryptape yangby-cryptape changed the title [WIP] Different roots in block header use different algorithms and different default values Different roots in header use different algorithms; and not Eth2.0-compatible Aug 14, 2023
@yangby-cryptape yangby-cryptape changed the title Different roots in header use different algorithms; and not Eth2.0-compatible Different roots in header use different algorithms, and not Eth2.0-compatible Aug 14, 2023
@axonweb3 axonweb3 locked and limited conversation to collaborators Aug 22, 2023
@Flouse Flouse converted this issue into discussion #1342 Aug 22, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
t:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant