Skip to content

Commit

Permalink
benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
gshep committed Mar 29, 2024
1 parent bffe3f0 commit c1c1a8b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[registries]
gear-registry = { index = "sparse+http://3.75.247.246:50000/index/" }
7 changes: 7 additions & 0 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 node/service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl sc_executor::NativeExecutionDispatch for VaraExecutorDispatch {
gear_ri::sandbox::HostFunctions,
sp_crypto_ec_utils::bls12_381::host_calls::HostFunctions,
gear_ri::specific_plonky_2::HostFunctions,
gear_ri::gear_debug::HostFunctions,
);
/// Otherwise we only use the default Substrate host functions.
#[cfg(not(feature = "runtime-benchmarks"))]
Expand Down
2 changes: 2 additions & 0 deletions pallets/gear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ demo-constructor = { workspace = true, optional = true }
demo-waiter = { workspace = true, optional = true }
demo-init-wait = { workspace = true, optional = true }
demo-signal-entry = { workspace = true, optional = true }
plonky2-benchmarks-data = { version = "0.1.0", optional = true, registry = "gear-registry" }

# Some of tests require `debug` feature enabled
[dev-dependencies]
Expand Down Expand Up @@ -195,6 +196,7 @@ runtime-benchmarks = [
"demo-init-wait/wasm-wrapper",
"demo-signal-entry/wasm-wrapper",
"core-processor/mock",
"plonky2-benchmarks-data",
]
runtime-benchmarks-checkers = []
try-runtime = ["frame-support/try-runtime"]
Expand Down
22 changes: 22 additions & 0 deletions pallets/gear/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,28 @@ benchmarks! {
ext_manager.remove_from_mailbox(user.cast(), message_id);
}

plonky2_verify {
let i in 1..100;
let n in 10..28;

let proof_of_work_bits = 16;

let file_name = ::alloc::format!("{}{i}_{n}_{proof_of_work_bits}_common_curcuit_data", plonky2_benchmarks_data::get_path());

Check warning on line 2621 in pallets/gear/src/benchmarking/mod.rs

View workflow job for this annotation

GitHub Actions / typos

"curcuit" should be "circuit".
let common_curcuit_data = gear_runtime_interface::gear_debug::file_read(&file_name);

Check warning on line 2622 in pallets/gear/src/benchmarking/mod.rs

View workflow job for this annotation

GitHub Actions / typos

"curcuit" should be "circuit".

let file_name = ::alloc::format!("{}{i}_{n}_{proof_of_work_bits}_verifier_only_data", plonky2_benchmarks_data::get_path());
let verifier_only_data = gear_runtime_interface::gear_debug::file_read(&file_name);

let file_name = ::alloc::format!("{}{i}_{n}_{proof_of_work_bits}_proof", plonky2_benchmarks_data::get_path());
let proof = gear_runtime_interface::gear_debug::file_read(&file_name);
let mut _result = 0u32;
} : {
_result = gear_runtime_interface::specific_plonky_2::verify(common_curcuit_data, verifier_only_data, proof);

Check warning on line 2631 in pallets/gear/src/benchmarking/mod.rs

View workflow job for this annotation

GitHub Actions / typos

"curcuit" should be "circuit".
}
verify {
assert_eq!(_result, u32::from(gear_runtime_interface::Plonky2VerifyResult::Verified));
}

// This is no benchmark. It merely exist to have an easy way to pretty print the currently
// configured `Schedule` during benchmark development.
// It can be outputted using the following command:
Expand Down
7 changes: 7 additions & 0 deletions runtime-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ pub enum Plonky2VerifyResult {
FailedToDecodeCommonData,
FailedToDecodeVerifierData,
FailedToDecodeProof,
ConfigNotSupported,
}

impl From<Plonky2VerifyResult> for u32 {
Expand Down Expand Up @@ -344,6 +345,12 @@ pub trait SpecificPlonky2 {
return Plonky2VerifyResult::FailedToDecodeCommonData.into();
};

if common.config.fri_config.rate_bits != 3
|| common.config.fri_config.proof_of_work_bits != 16
{
return Plonky2VerifyResult::ConfigNotSupported.into();
}

let Ok(verifier_only) = VerifierOnlyCircuitData::from_bytes(verifier_circuit_data) else {
return Plonky2VerifyResult::FailedToDecodeVerifierData.into();
};
Expand Down

0 comments on commit c1c1a8b

Please sign in to comment.