Skip to content

Commit

Permalink
rusk: embed circuits verification data
Browse files Browse the repository at this point in the history
Resolves #3507
  • Loading branch information
herr-seppia committed Feb 17, 2025
1 parent 13d2700 commit e655adf
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 24 deletions.
5 changes: 5 additions & 0 deletions rusk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Change plonk verification to use embed verification data by default [#3507]

## [1.1.0] - 2025-02-14

### Added
Expand Down Expand Up @@ -339,6 +343,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add build system that generates keys for circuits and caches them.

<!-- Issues -->
[#3507]: https://github.com/dusk-network/rusk/issues/3507
[#3494]: https://github.com/dusk-network/rusk/issues/3494
[#3481]: https://github.com/dusk-network/rusk/issues/3481
[#3359]: https://github.com/dusk-network/rusk/issues/3359
Expand Down
1 change: 1 addition & 0 deletions rusk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ chain = ["dep:node", "dep:dusk-consensus", "dep:node-data"]
archive = ["chain", "node/archive"]
network-trace = ["node/network-trace"]
http-wasm = []
dynamic-verifier = []

[[bench]]
name = "block_ingestion"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
70 changes: 46 additions & 24 deletions rusk/src/lib/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,58 @@
use crate::error::Error;
use crate::Result;

use dusk_core::transfer::{
moonlight::Transaction as MoonlightTransaction,
phoenix::Transaction as PhoenixTransaction,
};
use dusk_core::transfer::moonlight::Transaction as MoonlightTransaction;
use dusk_core::transfer::phoenix::Transaction as PhoenixTransaction;
use dusk_vm::host_queries;
use rusk_profile::Circuit as CircuitProfile;

use std::sync::LazyLock;
#[cfg(not(feature = "dynamic-verifier"))]
mod embed {
pub static VD_EXEC_1_2: &[u8] =
include_bytes!("../assets/vd/c8fed2bfcc0e0e64709586b56636fc1831be5f0227e533363e9a49b8fae5cd2f.vd");

pub static VD_EXEC_1_2: LazyLock<Vec<u8>> =
LazyLock::new(|| fetch_verifier("TxCircuitOneTwo"));
pub static VD_EXEC_2_2: &[u8] =
include_bytes!("../assets/vd/98c9786a8cf36f19bcbdf97f4bc140fe402ae5f72cef3f60f24b96071c0faa73.vd");

pub static VD_EXEC_2_2: LazyLock<Vec<u8>> =
LazyLock::new(|| fetch_verifier("TxCircuitTwoTwo"));
pub static VD_EXEC_3_2: &[u8] =
include_bytes!("../assets/vd/1210b96327d25a0403be7b8e027cfe964370700b94ec7f47d22128ecbe7e9803.vd");

pub static VD_EXEC_3_2: LazyLock<Vec<u8>> =
LazyLock::new(|| fetch_verifier("TxCircuitThreeTwo"));
pub static VD_EXEC_4_2: &[u8] =
include_bytes!("../assets/vd/0095785bd378e5cd3c7427c03b6d4420966c03156bf045b556f22419252fc8bc.vd");
}
#[cfg(not(feature = "dynamic-verifier"))]
use embed::*;

#[cfg(feature = "dynamic-verifier")]
mod runtime {
use rusk_profile::Circuit as CircuitProfile;
use std::sync::LazyLock;
pub static VD_EXEC_1_2: LazyLock<Vec<u8>> =
LazyLock::new(|| fetch_verifier("TxCircuitOneTwo"));

pub static VD_EXEC_2_2: LazyLock<Vec<u8>> =
LazyLock::new(|| fetch_verifier("TxCircuitTwoTwo"));

pub static VD_EXEC_3_2: LazyLock<Vec<u8>> =
LazyLock::new(|| fetch_verifier("TxCircuitThreeTwo"));

pub static VD_EXEC_4_2: LazyLock<Vec<u8>> =
LazyLock::new(|| fetch_verifier("TxCircuitFourTwo"));
pub static VD_EXEC_4_2: LazyLock<Vec<u8>> =
LazyLock::new(|| fetch_verifier("TxCircuitFourTwo"));

fn fetch_verifier(circuit_name: &str) -> Vec<u8> {
let circuit_profile = CircuitProfile::from_name(circuit_name)
.unwrap_or_else(|_| {
panic!(
"There should be circuit data stored for {}",
circuit_name
)
});
circuit_profile.get_verifier().unwrap_or_else(|_| {
panic!("there should be a verifier key stored for {}", circuit_name)
})
}
}
#[cfg(feature = "dynamic-verifier")]
use runtime::*;

/// Verifies the proof of the incoming transaction.
pub fn verify_proof(tx: &PhoenixTransaction) -> Result<bool> {
Expand Down Expand Up @@ -64,13 +96,3 @@ pub fn verify_signature(tx: &MoonlightTransaction) -> Result<bool> {
*tx.signature(),
))
}

fn fetch_verifier(circuit_name: &str) -> Vec<u8> {
let circuit_profile = CircuitProfile::from_name(circuit_name)
.unwrap_or_else(|_| {
panic!("There should be circuit data stored for {}", circuit_name)
});
circuit_profile.get_verifier().unwrap_or_else(|_| {
panic!("there should be a verifier key stored for {}", circuit_name)
})
}

0 comments on commit e655adf

Please sign in to comment.