civkit / civkit-node

CivKit Node
Other
66 stars 12 forks source link

Attestation proof verification #70

Open tomt1664 opened 1 year ago

tomt1664 commented 1 year ago

Functions required to verify event commitment proofs.

For a given sequence (https://commerceblock.readthedocs.io/en/latest/mainstay-con/index.html#proof-of-immutable-sequence) of proofs, Verification comes in 3 stages:

  1. Verify the sequence of commitments in the hash chain. This involves taking the latest retrieved proof and the list of saved Events (e.g. retrieved from the DB) and repeating the computation of the hash chain of event_ids and then confirming the slot commitment of hash chain in the latest proof (this then gives the latest event that is fully attested).

  2. Verify the proof path. For the latest slot proof, verify that the the commitment is included in the merkle_root this is done by successively concatenating the commitment along the path proof ("ops") as is done here: https://github.com/commerceblock/pymainstay/blob/a84c5f295143c4ac2eed8a3726c3bf1c88399338/mst/verify.py#L158

  3. Finally, we need to verify that the merkle_root is included in the specified bitcoin transaction. This requires a connection to a bitcoin-cli. For the specified txid, first getrawtransaction and then get the pay to address. Confirm the address is tweaked with the merkle_root (like https://github.com/commerceblock/pymainstay/blob/a84c5f295143c4ac2eed8a3726c3bf1c88399338/mst/verify.py#L126) and then go back along the tx staychain to check the initial anchor state.

ariard commented 1 year ago

Okay, so we have 3 steps (verify the sequence of commitments in the hash chain, verify the proof path and verify the merkle root in the specified bitcoin transaction).

I think it’s interesting to have this implemented client-side in civkit-sample: