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

feat: cycle scalar <> bigfield interactions #6744

Merged
merged 28 commits into from
May 31, 2024

Conversation

maramihali
Copy link
Contributor

@maramihali maramihali commented May 29, 2024

Adds missing methods in cycle_group and cycle_scalar required for the PCS in the ECCVM recursive verifier. As a summary, we add missing cycle_group constructors, a cycle group representation of one, a naive method to convert bigfield to cycle_scalar (but that adds constraints) and unify the batch_mul interface with the others present in our codebase (i.e. swap points and scalars).

@AztecBot
Copy link
Collaborator

AztecBot commented May 29, 2024

Benchmark results

No metrics with a significant change found.

Detailed results

All benchmarks are run on txs on the Benchmarking contract on the repository. Each tx consists of a batch call to create_note and increment_balance, which guarantees that each tx has a private call, a nested private call, a public call, and a nested public call, as well as an emitted private note, an unencrypted log, and public storage read and write.

This benchmark source data is available in JSON format on S3 here.

Proof generation

Each column represents the number of threads used in proof generation.

Metric 1 threads 4 threads 16 threads 32 threads 64 threads
proof_construction_time_sha256_ms 5,709 1,542 708 744 (-1%) 776
proof_construction_time_sha256_30_ms 11,423 3,066 (+1%) 1,374 1,437 1,454
proof_construction_time_sha256_100_ms 43,700 11,694 5,431 5,432 5,372
proof_construction_time_poseidon_hash_ms 79.0 (+1%) 34.0 34.0 59.0 (+4%) 89.0 (+3%)
proof_construction_time_poseidon_hash_30_ms 1,515 416 200 (+1%) 227 (+1%) 269 (+1%)
proof_construction_time_poseidon_hash_100_ms 5,739 1,559 726 770 (+1%) 789

L2 block published to L1

Each column represents the number of txs on an L2 block published to L1.

Metric 8 txs 32 txs 64 txs
l1_rollup_calldata_size_in_bytes 1,412 1,412 1,412
l1_rollup_calldata_gas 9,440 9,464 9,476
l1_rollup_execution_gas 616,081 616,105 616,117
l2_block_processing_time_in_ms 1,281 (-1%) 4,789 9,489 (-1%)
l2_block_building_time_in_ms 44,218 175,466 350,394
l2_block_rollup_simulation_time_in_ms 44,021 174,725 348,912
l2_block_public_tx_process_time_in_ms 38,274 171,364 340,557

L2 chain processing

Each column represents the number of blocks on the L2 chain where each block has 16 txs.

Metric 3 blocks 5 blocks
node_history_sync_time_in_ms 9,425 14,496
node_database_size_in_bytes 14,504,016 21,332,048
pxe_database_size_in_bytes 18,071 29,868

Circuits stats

Stats on running time and I/O sizes collected for every kernel circuit run across all benchmarks.

Circuit simulation_time_in_ms witness_generation_time_in_ms proving_time_in_ms input_size_in_bytes output_size_in_bytes proof_size_in_bytes num_public_inputs size_in_gates
private-kernel-init 135 (-2%) 472 (+2%) 13,167 (+4%) 20,634 64,614 89,536 2,731 524,288
private-kernel-inner 405 931 49,824 (+1%) 92,326 64,614 89,536 2,731 2,097,152
private-kernel-tail 585 (-1%) 2,592 (-1%) 52,008 (+2%) 96,545 77,732 11,648 297 2,097,152
base-parity 6.41 (-1%) 1,020 2,892 (+1%) 128 64.0 2,208 2.00 131,072
root-parity 49.1 (+1%) 62.4 (+1%) 39,037 (-5%) 27,100 64.0 2,720 18.0 2,097,152
base-rollup 9,054 (-3%) 2,363 (-1%) 77,980 (+3%) 119,738 756 3,648 47.0 4,194,304
root-rollup 109 77.5 (+3%) 23,216 (+1%) 25,309 620 3,456 41.0 1,048,576
public-kernel-app-logic 571 (-1%) 3,486 (-2%) 44,694 (-5%) 108,073 86,550 116,768 3,582 2,097,152
public-kernel-tail 1,127 21,988 (-7%) 179,288 (-4%) 403,238 7,646 11,648 297 8,388,608
private-kernel-reset-small 590 (-1%) 2,203 (+12%) 45,014 (-1%) 120,737 64,614 89,536 2,731 2,097,152
public-kernel-setup 657 2,728 (+1%) 42,796 (-5%) 108,073 86,550 116,768 3,582 2,097,152
public-kernel-teardown 563 3,582 (+2%) 46,808 (+3%) 108,073 86,550 116,768 3,582 2,097,152
merge-rollup 29.5 (-6%) N/A N/A 16,542 756 N/A N/A N/A
private-kernel-tail-to-public N/A 8,504 (-4%) 98,623 (-1%) N/A N/A 116,768 3,582 4,194,304

Stats on running time collected for app circuits

Function input_size_in_bytes output_size_in_bytes witness_generation_time_in_ms proof_size_in_bytes proving_time_in_ms size_in_gates num_public_inputs
ContractClassRegisterer:register 1,344 9,944 460 N/A N/A N/A N/A
ContractInstanceDeployer:deploy 1,408 9,944 40.9 N/A N/A N/A N/A
MultiCallEntrypoint:entrypoint 1,920 9,944 1,753 N/A N/A N/A N/A
SchnorrAccount:constructor 1,312 9,944 1,414 N/A N/A N/A N/A
SchnorrAccount:entrypoint 2,304 9,944 2,733 (-1%) 16,768 54,021 (+2%) 2,097,152 457
Token:privately_mint_private_note 1,280 9,944 1,541 (-1%) N/A N/A N/A N/A
FPC:fee_entrypoint_public 1,344 9,944 1,015 16,768 10,814 524,288 457
Token:transfer 1,376 9,944 5,311 16,768 51,753 (+1%) 2,097,152 457
Benchmarking:create_note 1,344 9,944 1,386 (-1%) N/A N/A N/A N/A
SchnorrAccount:spend_private_authwit 1,280 9,944 87.2 (+11%) N/A N/A N/A N/A
Token:unshield 1,376 9,944 3,917 (+1%) N/A N/A N/A N/A
FPC:fee_entrypoint_private 1,376 9,944 4,793 N/A N/A N/A N/A

Tree insertion stats

The duration to insert a fixed batch of leaves into each tree type.

Metric 1 leaves 16 leaves 64 leaves 128 leaves 512 leaves 1024 leaves 2048 leaves 4096 leaves 32 leaves
batch_insert_into_append_only_tree_16_depth_ms 10.3 (-1%) 16.8 (-1%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.7 31.8 N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.599 0.515 (-1%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 48.3 76.0 246 474 (-1%) 929 (+1%) 1,841 N/A
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 95.9 159 543 1,055 2,079 4,127 N/A
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A 0.493 0.469 0.447 0.442 (-1%) 0.440 0.440 N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 58.0 113 (+1%) 357 (+1%) 697 (-2%) 1,385 2,759 N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 106 208 692 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.501 0.505 0.484 0.479 (-1%) 0.480 0.479 N/A
batch_insert_into_indexed_tree_40_depth_ms N/A N/A N/A N/A N/A N/A N/A N/A 62.5
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A N/A N/A N/A N/A N/A N/A 107
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A N/A N/A N/A N/A N/A N/A 0.552

Miscellaneous

Transaction sizes based on how many contract classes are registered in the tx.

Metric 0 registered classes 1 registered classes
tx_size_in_bytes 84,053 665,267

Transaction size based on fee payment method

| Metric | |
| - | |

@codygunton codygunton changed the title Mm/cycle-scalar-group-work feat: cycle scalar <> bigfield interactions May 30, 2024
Copy link
Collaborator

@AztecBot AztecBot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'C++ Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.05.

Benchmark suite Current: 32feb75 Previous: 70926fc Ratio
nativeconstruct_proof_ultrahonk_power_of_2/20 5866.837777000001 ms/iter 5513.648204000006 ms/iter 1.06

This comment was automatically generated by workflow using github-action-benchmark.

CC: @ludamad @codygunton

@@ -34,7 +34,7 @@ template <typename Builder> void create_multi_scalar_mul_constraint(Builder& bui
}

// Call batch_mul to multiply the points and scalars and sum the results
auto output_point = cycle_group_ct::batch_mul(scalars, points);
auto output_point = cycle_group_ct::batch_mul(points, scalars);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the signature of batch_mul in cycle_group was different from native and biggroup (scalars and points order was switched) so I modified it to be consistent.

@maramihali maramihali marked this pull request as ready for review May 30, 2024 11:35
@maramihali maramihali added the crypto cryptography label May 30, 2024
@maramihali maramihali requested a review from Rumata888 May 30, 2024 11:38
EXPECT_EQ(one_native.x, expected_one_native.x);
EXPECT_EQ(one_native.y, expected_one_native.y);

EXPECT_TRUE(CircuitChecker::check(builder));
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this line, it doesn't do anything

cycle_scalar_ct scalar_from_elt = (elt);
EXPECT_EQ(elt, scalar_from_elt.get_value());

EXPECT_TRUE(CircuitChecker::check(builder));
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't do anything

cycle_group_ct result2 = cycle_group_ct::batch_mul({ TestFixture::generators[0], TestFixture::generators[1] },
{ cycle_scalar_ct(scalar1), cycle_scalar_ct(scalar2) });

AffineElement result1_native = resut1.get_value();
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo "resut1"

EXPECT_EQ(result1_native.x, result2_native.x);
EXPECT_EQ(result1_native.y, result2_native.y);

EXPECT_TRUE(CircuitChecker::check(builder));
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't do anything

Copy link
Contributor

@Rumata888 Rumata888 left a comment

Choose a reason for hiding this comment

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

The tests need to have a witness variant. Currently new tests just check if the constant conversion is correct

(lo + hi * shift).assert_equal(_in);
lo = witness_t(in.get_context(), lo_v);
hi = witness_t(in.get_context(), hi_v);
(lo + hi * shift).assert_equal(in);
Copy link
Contributor

Choose a reason for hiding this comment

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

These values have to be range constrained with borrow, otherwise there are too many ways this split can happen (we are just checking the linear combination)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it is possible to represent two fq scalars with one fr

hi = value_hi;
// N.B. to be able to call assert equal, these cannot be constants
} else {
lo = witness_t(ctx, value_lo);
Copy link
Contributor

Choose a reason for hiding this comment

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

These values have to be range constrained with borrow in the same way

Copy link
Contributor

@Rumata888 Rumata888 left a comment

Choose a reason for hiding this comment

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

LGTM

@maramihali maramihali enabled auto-merge (squash) May 31, 2024 15:08
@maramihali maramihali merged commit 6e363ec into master May 31, 2024
90 of 91 checks passed
@maramihali maramihali deleted the mm/cycle-scalar-group-work branch May 31, 2024 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto cryptography
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants