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

test: update spec tests #143

Closed matthewkeil closed 5 months ago

matthewkeil commented 5 months ago

Split into #144, #145 and #146

Motivations

Updates the spec tests and code to remove all JS glue code that was being implemented to get specs to pass. Originally this repo was based on the SWIG version of the code which was not editable. To accommodate the specs some try/catch and conditionals were added to get things compliant.

This PR removed all the glue code in the testing files and ensured that all conditions are handled directly by the native code.

These changes were driven by the removal of bls from lodestar. There was some glue code in there in addition to the spec tests.

Now all functions take the spec data input and pass it directly to the function calls. All output is also directly taken and passed to the expectation to ensure the base layer is 100% compliant with the spec.

In order to DRY the code and make it easier to maintain the two async functions were refactored so that there is only one implementation for both sync and async versions. Makes it easier to ensure that the code for both is identical and that changes made to comply with specs were applied equally. Also makes sure that only need to test sync version but with surety that the async versions will work identically.

IMPORTANT NOTE The spec-test-utils and test-utils in lodestar are esm only. Was not able to import them directly. Have a PR almost ready to do dual module exports for the utils so they can be used here. Several of the files in the PR will be deleted once those modules are ready. Please ignore them in this review. They are copy/paste directly from lodestar.

Description of Inclusions

github-actions[bot] commented 5 months ago

Performance Report

✔️ no performance regression detected

Full benchmark results | Benchmark suite | Current: 20b85afcb5ac69eb9aa69bbbf199a1e36ae8d813 | Previous: - | Ratio | |-|-|-|-| | PublicKey serialization | 959.00 ns/op | | PublicKey deserialize | 22.410 us/op | | PublicKey deserialize and validate - 1 keys | 83.458 us/op | | PublicKey deserialize and validate - 100 keys | 8.3830 ms/op | | PublicKey deserialize and validate - 10000 keys | 831.46 ms/op | | SecretKey.fromKeygen | 2.5140 us/op | | SecretKey serialization | 855.00 ns/op | | SecretKey deserialization | 1.4760 us/op | | SecretKey.toPublicKey | 138.42 us/op | | SecretKey.sign | 531.15 us/op | | Signature serialization | 1.0310 us/op | | Signature deserialize | 44.044 us/op | | Signatures deserialize and validate - 1 sets | 120.62 us/op | | Signatures deserialize and validate - 100 sets | 11.991 ms/op | | Signatures deserialize and validate - 10000 sets | 1.1990 s/op | | aggregatePublicKeys - 1 sets | 2.4520 us/op | | aggregatePublicKeys - 8 sets | 10.724 us/op | | aggregatePublicKeys - 32 sets | 38.185 us/op | | aggregatePublicKeys - 128 sets | 148.38 us/op | | aggregatePublicKeys - 256 sets | 295.94 us/op | | aggregateSignatures - 1 sets | 4.1460 us/op | | aggregateSignatures - 8 sets | 24.090 us/op | | aggregateSignatures - 32 sets | 90.783 us/op | | aggregateSignatures - 128 sets | 359.24 us/op | | aggregateSignatures - 256 sets | 717.91 us/op | | aggregateVerify - 1 sets | 1.5743 ms/op | | aggregateVerify - 8 sets | 5.7552 ms/op | | aggregateVerify - 32 sets | 20.330 ms/op | | aggregateVerify - 128 sets | 78.825 ms/op | | aggregateVerify - 256 sets | 156.80 ms/op | | verifyMultipleAggregateSignatures - 1 sets | 1.7433 ms/op | | verifyMultipleAggregateSignatures - 8 sets | 7.0484 ms/op | | verifyMultipleAggregateSignatures - 32 sets | 25.683 ms/op | | verifyMultipleAggregateSignatures - 128 sets | 99.979 ms/op | | verifyMultipleAggregateSignatures - 256 sets | 198.82 ms/op | | Same message - 1 sets | 1.7031 ms/op | | Same message - 8 sets | 2.5725 ms/op | | Same message - 32 sets | 5.5245 ms/op | | Same message - 128 sets | 17.384 ms/op | | Same message - 256 sets | 33.164 ms/op | | libuv multithreading - addVerificationRandomness true | 23.795 s/op | | libuv multithreading - addVerificationRandomness false | 23.762 s/op |

by benchmarkbot/action

matthewkeil commented 5 months ago

Closing in favor of split version. Broke into pieces #144, #145, #146