ergoplatform / ergoplatform/sigma-rust
Payment verification workflow for SPV with NiPoPoW
- Dominant language
- Rust
- Stars
- 78
- Forks
- 63
- Avg merge
- 22h 5m
- Merged PRs (30d)
- 3
Description
Using NiPoPoW described in [KMZ17](https://fc20.ifca.ai/preproceedings/74.pdf)
## Goal
Prove that a payment (ERG and/or tokens) was made on the blockchain.
**EDIT: For a recent payment it would be faster to use UTXO proof described in #502**
## Step 1. Prove that a tx with a given id in a block with a given id exists in the blockchain.
### Step 1.1. Prove that a block with a given id exists in the blockchain.
- 1.1.1. Ask proofs from known nodes via [`/nipopow/proof/{m}/{k}/{headerId}`](https://github.com/ergoplatform/ergo/blob/95139ec990fc91f8f4c70a61468edf8834143329/src/main/scala/org/ergoplatform/modifiers/history/popow/NipopowAlgos.scala#L188-L271) #545
- 1.1.2. Create [`NipopowVerifier`](https://github.com/ergoplatform/ergo/blob/95139ec990fc91f8f4c70a61468edf8834143329/src/main/scala/org/ergoplatform/local/NipopowVerifier.scala#L14-L28) Rust equvalent and feed all received proofs into `NipopowVerifier::process`; #499
- 1.1.3. Check that `verifier.bestProof().suffixHead.id` is our block id; #499
### Step 1.2. Prove that a tx with a given id exists in the blockchain.
- 1.2.1. Ask any node for [`MerkleProof`](https://github.com/ergoplatform/ergo/blob/95139ec990fc91f8f4c70a61468edf8834143329/.metals/readonly/dependencies/scrypto_2.12-2.1.10-sources.jar/scorex/crypto/authds/merkle/MerkleProof.scala#L25-L26) via [`/blocks/{headerId}/proofFor/{txId}`](https://github.com/ergoplatform/ergo/blob/95139ec990fc91f8f4c70a61468edf8834143329/src/main/scala/org/ergoplatform/http/api/BlocksApiRoute.scala#L72-L85); #515
- 1.2.2. Confirm the tx id is in the block with [`merkleProof.valid(header.transactionsRoot)`](https://github.com/input-output-hk/scrypto/blob/2237785131ee0946e44d6a5aec2ef0fc0731efce/src/main/scala/scorex/crypto/authds/merkle/MerkleProof.scala#L28-L38) Rust equivalent; #515
## Step 2. Check the box with the payment
### Step 2.1 Get the whole tx for tx id from Step 1
It can either be provided along with the tx id in Step 1 or fetched from the node. It is verified by serializing the tx and calculating its id and then comparing it to the tx id confirmed in Step 1.2.
### Step 2.2. Confirm the payment is in this tx
Find the output box protected with a certain script (e.g certain PK) and check that its value and/or tokens are as expected.
Contributor guide
Assessment
This issue has not been assessed yet.