Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable BLS aggregate verify #1684

Merged
merged 4 commits into from
Jan 18, 2024
Merged

Conversation

lrubasze
Copy link
Contributor

@lrubasze lrubasze commented Jan 17, 2024

Summary

Enable BLS aggregate verify for Radix Engine and Scrypto.

Details

For wasm32 and no_std added our local implementation of aggregate_verify_bls12381_v1_no_threads() which does not rely on threads.
It follows CoreAggregateVerify description.
And is inspired with aggregate_verify() implementation from blst crate.

Testing

Added a few positive and negative tests.

Copy link

github-actions bot commented Jan 17, 2024

Benchmark for c5fa330

Click to view benchmark
Test Base PR %
costing::bench_prepare_wasm 63.3±0.57ms 63.7±0.60ms +0.63%
costing::decode_sbor 13.0±0.02µs 13.3±0.01µs +2.31%
costing::decode_sbor_bytes 35.7±0.10µs 35.8±0.12µs +0.28%
costing::deserialize_wasm 1238.6±1.02µs 1248.8±7.06µs +0.82%
costing::instantiate_flash_loan 3.9±0.46ms 3.7±0.13ms -5.13%
costing::instantiate_radiswap 5.0±0.05ms 5.1±0.06ms +2.00%
costing::spin_loop 22.9±0.03ms 21.4±0.02ms -6.55%
costing::validate_sbor_payload 26.2±0.02µs 25.9±0.03µs -1.15%
costing::validate_sbor_payload_bytes 368.7±2.24ns 351.9±0.31ns -4.56%
costing::validate_secp256k1 80.4±0.04µs 80.3±0.05µs -0.12%
costing::validate_wasm 34.7±0.06ms 34.5±0.07ms -0.58%
decimal::add/0 7.2±0.01ns 7.2±0.00ns 0.00%
decimal::add/rust-native 8.9±0.06ns 9.0±0.05ns +1.12%
decimal::add/wasmer 136.4±0.15ns 136.9±0.17ns +0.37%
decimal::add/wasmer-call-native 525.3±0.17ns 522.1±0.29ns -0.61%
decimal::add/wasmi 437.9±0.07ns 441.2±0.17ns +0.75%
decimal::add/wasmi-call-native 3.3±0.02µs 3.4±0.02µs +3.03%
decimal::div/0 164.2±0.08ns 166.1±0.05ns +1.16%
decimal::from_string/0 153.8±0.09ns 153.4±0.13ns -0.26%
decimal::mul/0 128.0±0.12ns 129.8±0.07ns +1.41%
decimal::mul/rust-native 132.8±0.07ns 131.8±0.06ns -0.75%
decimal::mul/wasmer 1721.7±3.81ns 1737.8±0.33ns +0.94%
decimal::mul/wasmer-call-native 652.4±0.17ns 655.0±0.20ns +0.40%
decimal::mul/wasmi 25.9±0.03µs 26.5±0.04µs +2.32%
decimal::mul/wasmi-call-native 3.5±0.01µs 3.5±0.02µs 0.00%
decimal::pow/0 621.7±0.50ns 621.7±0.23ns 0.00%
decimal::pow/rust-native 607.6±0.22ns 606.8±0.34ns -0.13%
decimal::pow/wasmer 7.5±0.00µs 7.5±0.00µs 0.00%
decimal::pow/wasmer-call-native 1073.2±0.31ns 1078.6±0.34ns +0.50%
decimal::pow/wasmi 125.0±0.18µs 125.1±0.20µs +0.08%
decimal::pow/wasmi-call-native 3.5±0.01µs 3.4±0.01µs -2.86%
decimal::root/0 9.1±0.00µs 9.4±0.00µs +3.30%
decimal::sub/0 7.2±0.01ns 7.2±0.01ns 0.00%
decimal::to_string/0 489.9±0.31ns 489.0±0.19ns -0.18%
precise_decimal::add/0 8.0±0.00ns 8.7±0.00ns +8.75%
precise_decimal::add/rust-native 10.3±0.03ns 10.4±0.05ns +0.97%
precise_decimal::add/wasmer 139.1±0.06ns 142.7±0.20ns +2.59%
precise_decimal::add/wasmer-call-native 531.3±0.20ns 532.4±0.17ns +0.21%
precise_decimal::add/wasmi 529.6±0.06ns 530.3±0.11ns +0.13%
precise_decimal::add/wasmi-call-native 3.6±0.01µs 3.6±0.01µs 0.00%
precise_decimal::div/0 261.8±0.06ns 261.3±0.06ns -0.19%
precise_decimal::from_string/0 194.8±0.12ns 196.3±0.17ns +0.77%
precise_decimal::mul/0 281.7±0.09ns 278.4±0.10ns -1.17%
precise_decimal::mul/rust-native 262.3±0.08ns 261.1±0.26ns -0.46%
precise_decimal::mul/wasmer 4.1±0.00µs 4.0±0.00µs -2.44%
precise_decimal::mul/wasmer-call-native 823.7±0.39ns 818.7±0.28ns -0.61%
precise_decimal::mul/wasmi 73.9±0.03µs 74.1±0.02µs +0.27%
precise_decimal::mul/wasmi-call-native 3.8±0.02µs 3.9±0.03µs +2.63%
precise_decimal::pow/0 1572.2±0.20ns 1567.2±0.59ns -0.32%
precise_decimal::pow/rust-native 1270.7±0.58ns 1272.4±0.53ns +0.13%
precise_decimal::pow/wasmer 19.0±0.01µs 19.0±0.01µs 0.00%
precise_decimal::pow/wasmer-call-native 2.0±0.00µs 2.0±0.00µs 0.00%
precise_decimal::pow/wasmi 357.5±0.14µs 358.8±0.16µs +0.36%
precise_decimal::pow/wasmi-call-native 7.7±0.03µs 7.6±0.02µs -1.30%
precise_decimal::root/0 61.3±0.03µs 60.6±0.02µs -1.14%
precise_decimal::sub/0 8.3±0.01ns 8.9±0.00ns +7.23%
precise_decimal::to_string/0 742.5±0.16ns 745.0±0.45ns +0.34%
schema::validate_payload 332.1±0.31µs 323.0±0.33µs -2.74%
transaction::radiswap 5.2±0.04ms 5.2±0.03ms 0.00%
transaction::transfer 1682.6±3.66µs 1681.6±10.79µs -0.06%
transaction_processing::prepare 2.4±0.00ms 2.4±0.00ms 0.00%
transaction_processing::prepare_and_decompile 6.1±0.01ms 6.0±0.01ms -1.64%
transaction_processing::prepare_and_decompile_and_recompile 23.0±0.20ms 23.1±0.21ms +0.43%
transaction_validation::validate_manifest 43.8±0.04µs 43.8±0.03µs 0.00%
transaction_validation::verify_bls_2KB 999.6±1.52µs 1001.3±1.69µs +0.17%
transaction_validation::verify_bls_32B 1010.1±16.42µs 1008.1±8.91µs -0.20%
transaction_validation::verify_ecdsa 78.0±0.06µs 78.0±0.18µs 0.00%
transaction_validation::verify_ed25519 51.4±0.04µs 51.5±0.05µs +0.19%

@lrubasze lrubasze changed the title Feature/bls enable aggregate verify Reenable BLS aggregate verify Jan 17, 2024
/// Local implementation of aggregated verify for no_std and WASM32 variants (no threads)
/// see: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-05#name-coreaggregateverify
/// Inspired with blst::min_pk::Signature::aggregate_verify
fn aggregate_verify_bls12381_v1_no_threads(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively I could fork blst crate and modify it accordingly.
But I decided not to fork for easier maintenance in the future (eg. bumping versions).

@lrubasze lrubasze marked this pull request as ready for review January 17, 2024 14:42
@lrubasze lrubasze changed the title Reenable BLS aggregate verify Enable BLS aggregate verify Jan 17, 2024
Copy link
Member

@iamyulong iamyulong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lrubasze lrubasze merged commit 6809816 into develop Jan 18, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants