Skip to content

Commit

Permalink
Merge pull request #1512 from input-output-hk/ensemble/1470/implement…
Browse files Browse the repository at this point in the history
…-cardano-transactions-verification-wasm

Implement Cardano transactions verification in `mithril-client-wasm`
  • Loading branch information
dlachaume authored Feb 21, 2024
2 parents 9eb6467 + f93058a commit e1f37ee
Show file tree
Hide file tree
Showing 170 changed files with 6,078 additions and 638 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ on:
required: false
type: string
default: https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/pre-release-preview/genesis.vkey
transactions_hashes_to_certify:
description: Comma separated list of transactions hashes to test certification on.
required: false
type: string
enable_debug:
description: Enable debug output ("-vvv") for the mithril-client calls
required: true
Expand Down Expand Up @@ -193,6 +197,7 @@ jobs:
run: |
echo "AGGREGATOR_ENDPOINT=${{ inputs.aggregator_endpoint }}" > ./www-test/.env
echo "GENESIS_VERIFICATION_KEY=$(curl -s ${{ inputs.genesis_verification_key }})" >> ./www-test/.env
echo "TRANSACTIONS_HASHES_TO_CERTIFY=${{ inputs.transactions_hashes_to_certify }}" >> ./www-test/.env
- name: Start the server
working-directory: mithril-client-wasm
Expand Down
18 changes: 13 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"examples/client-mithril-stake-distribution",
"examples/client-snapshot",
"mithril-aggregator",
"mithril-build-script",
"mithril-client",
"mithril-client-cli",
"mithril-client-wasm",
Expand Down
6 changes: 6 additions & 0 deletions docs/website/root/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ A Cardano node is a node that runs in a [Cardano network](#cardano-network). The

A Cardano key pair is an asymmetric key pair used to identify a [stake pool operator](#stake-pool-operator-spo) on the [Cardano network](#cardano-network).

## Cardano transaction

A Cardano transaction proof is a cryptographic proof that a sub-set of Cardano transactions is included in the Cardano transactions set. It is generated upon request from a [Mithril client](#mithril-client) and is signed by a [certificate](#certificate).

A Cardano transactions set commitment represents, in a succinct way, the Cardano transactions set that was signed by Mithril at a given [Beacon](#beacon).

## Certificate

The Mithril aggregator combines the produced [multi-signature](#multi-signature) and some metadata into a Mithril certificate that will be later used by the [Mithril client](#mithril-client) to verify the authenticity of a [snapshot](#snapshot). The certificates are chained so that the [stake distribution](#stake-distribution) used to create the signatures is verifiably genuine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Mithril client library WASM can be used by Javascript developers to use the Mith
It is responsible for handling the different types of data certified by Mithril, and available through a Mithril aggregator:
- [**Snapshot**](../../../glossary.md#snapshot): list and get.
- [**Mithril stake distribution**](../../../glossary.md#stake-distribution): list and get.
- [**Cardano transaction**](../../../glossary.md#cardano-transaction): list & get commitments, get proofs
- [**Certificate**](../../../glossary.md#certificate): list, get, and chain validation.

:::
Expand Down Expand Up @@ -113,6 +114,36 @@ let valid_stake_distribution_message = await client.verify_message_match_certifi
console.log("valid_stake_distribution_message:", valid_stake_distribution_message);
```

If the aggregator signs **CardanoTransactions**, you can add the code below to the previous example:

:::tip

You can verify that the aggregator signs **CardanoTransactions** by running the command below:

```bash
wget -q -O - YOUR_AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])'
```

For example with the aggregator on `testing-sanchonet` Mithril network:

```bash
wget -q -O - https://aggregator.testing-sanchonet.api.mithril.network/aggregator | jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])'
```

:::

```js
const proof = await client.unstable.get_cardano_transaction_proofs(["CARDANO_TRANSACTION_HASH_1", "CARDANO_TRANSACTION_HASH_2"]);
console.log("Proof tx hash", proof.transactions_hashes);
console.log("Proof certificate hash", proof.certificate_hash);

let proof_certificate = await client.verify_certificate_chain(proof.certificate_hash);
console.log("verify_certificate_chain OK, last_certificate_from_chain:", proof_certificate);

let valid_cardano_transaction_proof = await client.unstable.verify_cardano_transaction_proof_then_compute_message(proof, proof_certificate);
console.log("valid_cardano_transaction_proof:", valid_cardano_transaction_proof);
```

:::tip

You can read the complete [Rust developer documentation](https://mithril.network/rust-doc/mithril_client_wasm/index.html).
Expand Down
3 changes: 3 additions & 0 deletions mithril-build-script/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
.DS_Store

11 changes: 11 additions & 0 deletions mithril-build-script/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "mithril-build-script"
version = "0.1.0"
description = "A toolbox for Mithril crates build scripts"
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }

[dependencies]
5 changes: 5 additions & 0 deletions mithril-build-script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Mithril-build-script

A toolbox for Mithril crates that need a [build scripts phase](https://doc.rust-lang.org/cargo/reference/build-scripts.html).

Moreover, this crate allows to test the build scripts, which is not supported directly in `build.rs` (see: [rust-lang/cargo#1581](https://github.com/rust-lang/cargo/issues/1581)).
Loading

0 comments on commit e1f37ee

Please sign in to comment.