ergoplatform / ergoplatform/sigma-rust

Payment verification workflow for SPV with UTXO proof

Open
#502 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
78
Forks
63
Avg merge
22h 5m
Merged PRs (30d)
3

Description

After https://github.com/ergoplatform/ergo/issues/1525 is implemented we can get the UTXO proof (unspent box) in the current state (block). See details in https://github.com/ergoplatform/ergo/issues/1525#issuecomment-993311481

For a recent payment, we can get the UTXO proof in the current block and wait for n blocks for confirmation.

For an old payment, it's faster to use NiPoPoW proof described in #495

## Goal
Confirm that boxes with the given ids are in the UTXO, i.e. are not spent. Confirm that the contents of the boxes are indeed as expected.

### Step 1. Choose randomly N nodes from the known nodes list.

### Step 2. Ask each node for:
- 2.1 `blocks/lastHeaders/1` to get the last header and verify the received header with `AutolykosPowScheme::validate()` and check that `header.timestamp` is no more than block time(5 min) old. Also, verify that the received block is in the chain via Step 1.1 from NiPoPoW workflow #495.
- 2.2 [`utxo/getBoxesBinaryProof`](https://github.com/ergoplatform/ergo/blob/1171c2af7a375900306e1168d4812678909b424b/src/main/resources/api/openapi.yaml#L4149-L4183) with the given boxes id;

### Step 3. Verify the boxes.
- 3.1 Verify UTXO proof from every node (from 2.2) via `AdProofs::verify` using last header's `stateRoot` (from 2.1) as previous hash(digest) and Lookup op(state change) for every box. **Where to get the expected hash?** For all N nodes UTXO proofs must be verified. The only reason for the verification to fail is either node's last header is too old (before the box was created) or the box was already spent.
- 3.2 Ask any node from the list of known nodes for `/utxo/byId/{boxId}` for each box id to get the box contents;
- 3.3 Verify that the received box content corresponds to the box id by checking that the id of the parsed box from JSON is the same.
- 3.4 Verify that box content is as expected (guarding script == your PK, coins and/or tokens amount, etc.).

### Needs to be implemented
Rust equivalent of
- [`AdProofs.verify`](https://github.com/ergoplatform/ergo/blob/1171c2af7a375900306e1168d4812678909b424b/src/main/scala/org/ergoplatform/modifiers/history/ADProofs.scala#L35-L69)
- [`AutolykosPowScheme.validate()`](https://github.com/ergoplatform/ergo/blob/1171c2af7a375900306e1168d4812678909b424b/src/main/scala/org/ergoplatform/mining/AutolykosPowScheme.scala#L96-L109)

Contributor guide

Open the contributing guide

Research direction

Start with the Scala implementations in src/main/scala/org/ergoplatform/modifiers/history/ADProofs.scala and src/main/scala/org/ergoplatform/mining/AutolykosPowScheme.scala, along with the utxo/getBoxesBinaryProof API definition in openapi.yaml. Review the dependent workflows in issues #1525 and #495 before determining the Rust entry points and expected proof inputs. Done means Rust equivalents verify UTXO proofs and Autolykos PoW headers as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, scala
Domain
blockchain, cryptography
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.