ChainSafe / blst-ts

Typescript wrapper for https://github.com/supranational/blst native bindings, a highly performant BLS12-381 signature library
Other
18 stars 13 forks source link

feat: aggregate with randomness #139

Closed matthewkeil closed 4 months ago

matthewkeil commented 5 months ago

NOTE: This PR is based on code in #144, #145, #146. Need to update merge branch to master once those PR's are merged. Do not merge until that happens but is ready for review

Motivation

Aggregation of signatures in lodestar can take up to 25% of cpu thread time. The process includes a lot of generated JS objects that immediately get thrown away once the signatures are aggregated. This PR is designed to create a single signature call that will do the deserialization and aggregation, with added randomness, in a single function call. By moving this to native the JS objects do not need to be created so only the native deserialization is necessary. Created an async version as well to move this time-intensive work to the worker pool.

Description of Inclusions

github-actions[bot] commented 5 months ago

Performance Report

✔️ no performance regression detected

Full benchmark results | Benchmark suite | Current: 27e7d7afb1b1a7b9ff668cc8c711b18c1b88b234 | Previous: - | Ratio | |-|-|-|-| | PublicKey serialization | 923.00 ns/op | | PublicKey deserialize | 22.550 us/op | | PublicKey deserialize and validate - 1 keys | 85.251 us/op | | PublicKey deserialize and validate - 100 keys | 8.3387 ms/op | | PublicKey deserialize and validate - 10000 keys | 831.12 ms/op | | SecretKey.fromKeygen | 2.5860 us/op | | SecretKey serialization | 861.00 ns/op | | SecretKey deserialization | 1.4180 us/op | | SecretKey.toPublicKey | 139.34 us/op | | SecretKey.sign | 530.91 us/op | | Signature serialization | 1.0940 us/op | | Signature deserialize | 44.427 us/op | | Signatures deserialize and validate - 1 sets | 120.46 us/op | | Signatures deserialize and validate - 100 sets | 12.045 ms/op | | Signatures deserialize and validate - 10000 sets | 1.1974 s/op | | aggregatePublicKeys - 1 sets | 2.4410 us/op | | aggregatePublicKeys - 8 sets | 10.364 us/op | | aggregatePublicKeys - 32 sets | 37.900 us/op | | aggregatePublicKeys - 128 sets | 147.73 us/op | | aggregatePublicKeys - 256 sets | 294.38 us/op | | aggregateSignatures - 1 sets | 4.1760 us/op | | aggregateSignatures - 8 sets | 23.720 us/op | | aggregateSignatures - 32 sets | 91.500 us/op | | aggregateSignatures - 128 sets | 360.94 us/op | | aggregateSignatures - 256 sets | 723.85 us/op | | JS version of aggregateWithRandomness | 295.57 ms/op | | native version of aggregateWithRandomness | 289.17 ms/op | | aggregateVerify - 1 sets | 1.5742 ms/op | | aggregateVerify - 8 sets | 5.7259 ms/op | | aggregateVerify - 32 sets | 20.403 ms/op | | aggregateVerify - 128 sets | 78.775 ms/op | | aggregateVerify - 256 sets | 156.67 ms/op | | verifyMultipleAggregateSignatures - 1 sets | 1.7510 ms/op | | verifyMultipleAggregateSignatures - 8 sets | 7.0457 ms/op | | verifyMultipleAggregateSignatures - 32 sets | 25.562 ms/op | | verifyMultipleAggregateSignatures - 128 sets | 99.930 ms/op | | verifyMultipleAggregateSignatures - 256 sets | 198.74 ms/op | | Same message - 1 sets | 1.7027 ms/op | | Same message - 8 sets | 2.5719 ms/op | | Same message - 32 sets | 5.5196 ms/op | | Same message - 128 sets | 17.749 ms/op | | Same message - 256 sets | 33.192 ms/op | | libuv multithreading - addVerificationRandomness true | 23.774 s/op | | libuv multithreading - addVerificationRandomness false | 23.802 s/op |

by benchmarkbot/action