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

feat: add ckb mbt proof verify precompile contract #1578

Merged
merged 5 commits into from
Dec 1, 2023
Merged

Conversation

KaoImin
Copy link
Contributor

@KaoImin KaoImin commented Nov 20, 2023

What this PR does / why we need it?

This PR add ckb-mbt(aka merkle binary tree) proof verify precompile contract. The input struct is

#[derive(EthAbiCodec, EthAbiType, Clone, Debug, PartialEq, Eq)]
pub struct VerifyProofPayload {
    /// If the verify_type is 0, the leaves should be in the
    /// raw_transactions_root, otherwise in the witnesses_root.
    pub verify_type:           u8,
    pub transactions_root:     [u8; 32],
    pub witnesses_root:        [u8; 32],
    pub raw_transactions_root: [u8; 32],
    pub proof:                 Proof,
}

#[derive(EthAbiCodec, EthAbiType, Clone, Debug, PartialEq, Eq)]
pub struct Proof {
    pub indices: Vec<u32>,
    pub lemmas:  Vec<[u8; 32]>,
    pub leaves:  Vec<[u8; 32]>,
}

Because of the transactions_root in a CKB block header is consist of two layers:

                                                                          
                                  Transactions Root                        
                                        /   \                              
                                       /     \                             
                                      /       \                            
                                     /         \                           
                                    v           v                          
                  Raw Transactions Root          Witnesses Root            
                    /       |     \               |         \              
                   /        |      \              |          \             
                  /         |       \             |           \            
                 v          v        v            v            v           
            TxHash00    TxHash01   TxHash02   WitnessHash00   WitnessHash01
                                                                           

So apart from the transactions, witnesses root also needs. And it should be use ABI encode to bytes such as:

abi.encode(VerifyProofPayload(transactions_root, witnesses_root, raw_transactions_root, indices, lemmas, leaves))

What is the impact of this PR?

No Breaking Change

PR relation:

  • Ref #
CI Settings

CI Usage

Tip: Check the CI you want to run below, and then comment /run-ci.

CI Switch

  • Web3 Compatible Tests
  • OCT 1-5 And 12-15
  • OCT 6-10
  • OCT 11
  • OCT 16-19
  • v3 Core Tests

CI Description

CI Name Description
Web3 Compatible Test Test the Web3 compatibility of Axon
v3 Core Test Run the compatibility tests provided by Uniswap V3
OCT 1-5 | 6-10 | 11 | 12-15 | 16-19 Run the compatibility tests provided by OpenZeppelin

@KaoImin KaoImin requested a review from a team as a code owner November 20, 2023 11:13
@KaoImin KaoImin requested review from ashuralyk and yangby-cryptape and removed request for Simon-Tl November 20, 2023 11:13
@jjyr
Copy link
Contributor

jjyr commented Nov 21, 2023

This contract only supports verify raw_transaction, but users may want to also verify the witness transaction(to ensure the witness part is valid on CKB). This contract must support merkle verify the witness_root.

I suggest to add another input field tx_verify_type: u8 to indicates wether we want to verify a raw_transaction or a witness_transaction.

If the tx_verify_type is 0, the merkle root must equals raw_transaction_root, if the tx_verify_type is 1 the merkle root must equals to witness_transaction_root.

@KaoImin
Copy link
Contributor Author

KaoImin commented Nov 22, 2023

This contract only supports verify raw_transaction, but users may want to also verify the witness transaction(to ensure the witness part is valid on CKB). This contract must support merkle verify the witness_root.

I suggest to add another input field tx_verify_type: u8 to indicates wether we want to verify a raw_transaction or a witness_transaction.

If the tx_verify_type is 0, the merkle root must equals raw_transaction_root, if the tx_verify_type is 1 the merkle root must equals to witness_transaction_root.

Sounds good.

@KaoImin KaoImin added this pull request to the merge queue Dec 1, 2023
Merged via the queue into main with commit e6082f5 Dec 1, 2023
21 checks passed
@KaoImin KaoImin deleted the add-ckb-mmr branch December 1, 2023 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants