ICRC3 | Implementing block certification

Hello everyone,

I’m working on implementing ICRC-3 ledger in Rust and would like to get some guidance on the best way to approach this efficiently.

The ICRC-3 standard requires the ledger to:

  1. Certify the last block (tip) and expose it via icrc3_get_tip_certificate.
  2. Provide a certificate that contains:
    • last_block_index
    • last_block_hash

I am considering using the ic-certification crate to handle certification. Something like this:

        let leaf1 = leaf(last_block_index.to_string());
        let leaf2 = leaf(last_block_hash);

        let hash_tree = fork(leaf1, leaf2);
        ic_cdk::api::set_certified_data(&hash_tree.digest());
        let certificate = ic_cdk::api::data_certificate().expect("No data certificate available");
        Certificate {
            tree: hash_tree,
            signature: certificate,
            delegation: None,
        }

I also came across this implementation in the icp-icrc3-evm-adapter project:

However, I’m not sure I know a right way to do it, because the standard doesn’t define it in details. Has anyone implemented this in Rust? Would love to hear your thoughts on the best approach!

Thanks!

1 Like

Here is how the cycles ledger does it: cycles-ledger/cycles-ledger/src/storage.rs at f9c43d7c3ba971f50077a66ac0a784d0e6eea751 · dfinity/cycles-ledger · GitHub

Not sure which one is easier though. The nice thing about the cycles ledger way is that it’s compatible with other functionality using the hash tree, but it’s not likely that you’re doing that.

1 Like