Skip to content

feat: historical access of key getters, fixing logic in contracts after rotation#6656

Merged
sklppy88 merged 7 commits into
masterfrom
ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback
May 24, 2024
Merged

feat: historical access of key getters, fixing logic in contracts after rotation#6656
sklppy88 merged 7 commits into
masterfrom
ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback

Conversation

@sklppy88

@sklppy88 sklppy88 commented May 23, 2024

Copy link
Copy Markdown
Contributor

Resolves #6312.

sklppy88 commented May 23, 2024

Copy link
Copy Markdown
Contributor Author

@sklppy88 sklppy88 changed the title Initial feat: fix contract issues with key rotation, introduce get npk_m_hash_at May 23, 2024
@sklppy88 sklppy88 changed the title feat: fix contract issues with key rotation, introduce get npk_m_hash_at feat: fix contract issues with key rotation addressing feedback May 23, 2024
@sklppy88 sklppy88 force-pushed the ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test-mitigation branch from d50a4ba to 7b5ba09 Compare May 23, 2024 23:38
@sklppy88 sklppy88 force-pushed the ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback branch from 60a7517 to 407c44e Compare May 23, 2024 23:38
@sklppy88 sklppy88 force-pushed the ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test-mitigation branch from 7b5ba09 to e0d4166 Compare May 24, 2024 01:08
@sklppy88 sklppy88 force-pushed the ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback branch from 407c44e to 62189cd Compare May 24, 2024 01:08
@AztecBot

AztecBot commented May 24, 2024

Copy link
Copy Markdown
Collaborator

Benchmark results

Metrics with a significant change:

  • protocol_circuit_witness_generation_time_in_ms (private-kernel-reset-small): 2,589 (+26%)
  • protocol_circuit_witness_generation_time_in_ms (root-parity): 86.3 (+40%)
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 5,747 1,560 739 (+4%) 780 (+3%) 791 (+1%)

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,428 9,440 9,476
l1_rollup_execution_gas 616,069 616,081 616,117
l2_block_processing_time_in_ms 1,303 (+1%) 4,811 9,565
l2_block_building_time_in_ms 47,083 186,582 (-1%) 373,071
l2_block_rollup_simulation_time_in_ms 46,913 185,948 (-1%) 371,821
l2_block_public_tx_process_time_in_ms 25,091 105,052 (-1%) 214,107

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,720 (+3%) 14,393
node_database_size_in_bytes 14,487,632 21,377,104
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 164 3,508 (-1%) 24,259 (-1%) 20,630 64,614 89,536 2,731 1,048,576
private-kernel-inner 626 4,018 (-1%) 52,768 92,318 64,614 89,536 2,731 2,097,152
private-kernel-tail 549 2,699 (-2%) 43,442 (+3%) 90,237 77,498 10,656 266 2,097,152
base-parity 6.61 (+2%) 1,164 (-8%) 2,810 (+1%) 128 64.0 2,208 2.00 131,072
root-parity 49.3 (+1%) ⚠️ 86.3 (+40%) 50,592 27,084 64.0 2,720 18.0 2,097,152
base-rollup 783 (+1%) 2,396 (-2%) 88,751 (+1%) 119,610 756 3,648 47.0 4,194,304
root-rollup 112 76.0 (-10%) 23,013 (+1%) 25,297 620 3,456 41.0 1,048,576
public-kernel-app-logic 529 (+1%) 2,791 (-5%) 50,966 (-1%) 104,941 86,302 114,784 3,520 2,097,152
public-kernel-tail 1,198 (+1%) 23,994 178,413 (-2%) 395,386 7,522 10,656 266 8,388,608
private-kernel-reset-small 597 (+1%) ⚠️ 2,589 (+26%) 48,288 (-2%) 120,733 64,614 89,536 2,731 2,097,152
merge-rollup 29.5 (+3%) N/A N/A 16,534 756 N/A N/A N/A
public-kernel-setup 629 (+1%) N/A N/A 104,941 86,302 N/A N/A N/A
public-kernel-teardown 532 (+2%) N/A N/A 104,941 86,302 N/A N/A N/A
private-kernel-tail-to-public N/A 8,230 92,637 (-2%) N/A N/A 114,784 3,520 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 41.3 (+1%) N/A N/A N/A N/A
MultiCallEntrypoint:entrypoint 1,920 9,944 1,431 N/A N/A N/A N/A
SchnorrAccount:constructor 1,312 9,944 1,000 N/A N/A N/A N/A
SchnorrAccount:entrypoint 2,304 9,944 2,128 (+1%) 16,768 50,455 (-4%) 2,097,152 457
Token:privately_mint_private_note 1,280 9,944 1,099 (-1%) N/A N/A N/A N/A
Token:transfer 1,376 9,944 4,014 (-1%) 16,768 56,992 (-1%) 2,097,152 457
Benchmarking:create_note 1,312 9,944 988 (+1%) N/A N/A N/A N/A
FPC:fee_entrypoint_public 1,344 9,944 229 N/A N/A N/A N/A
SchnorrAccount:spend_private_authwit 1,280 9,944 77.3 N/A N/A N/A N/A
Token:unshield 1,376 9,944 3,261 N/A N/A N/A N/A
FPC:fee_entrypoint_private 1,376 9,944 4,061 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.4 17.0 (-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.603 0.520 (-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.9 (-1%) 76.3 247 479 929 1,843 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.496 (-1%) 0.470 0.449 0.447 (+1%) 0.440 0.439 N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 58.2 112 (-1%) 354 (-1%) 704 (+1%) 1,386 2,757 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.504 0.504 0.480 (-1%) 0.484 (+1%) 0.479 0.478 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.554

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 83,794 665,117

Transaction size based on fee payment method

| Metric | |
| - | |

@sklppy88 sklppy88 force-pushed the ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback branch from 62189cd to 269b51b Compare May 24, 2024 12:17
Base automatically changed from ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test-mitigation to ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test May 24, 2024 12:57
@sklppy88 sklppy88 force-pushed the ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test branch from 20fb637 to 4443965 Compare May 24, 2024 13:31
@sklppy88 sklppy88 force-pushed the ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test branch from 4443965 to 9994faa Compare May 24, 2024 13:39

@LHerskind LHerskind left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I quite like this as it is very explicit about the keys that you are picking 👀

There are a few things that are related to diff from earlier, but should be addressed with a gt sync, likely because it have not been rebased after partial merges higher up. When merged it this should be good to go 👍

// docs:start:key-getters
pub fn get_npk_m(context: &mut PrivateContext, address: AztecAddress) -> GrumpkinPoint {
get_master_key(context, address, NULLIFIER_INDEX)
trait GetIvpkM {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the keys might makes sense just to do a single trait for these? Not as separated as the other inclusions so reduces the boilerplate a bit 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, I like this too. Thanks for the shout.

Comment thread noir-projects/noir-contracts/contracts/auth_contract/src/main.nr Outdated
let y_coordinate = y_coordinate_registry.get_value_in_private(header);

GrumpkinPoint::new(x_coordinate, y_coordinate)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[Re: line 114]

Unrelated to this pr, but this one is still slightly painful in my eyes as it is just calling the oracle so we have just "hidden" that we are doing an oracle call and not a constrained call. Think it would be better if we deal with this as an oracle directly to not mix it up, but should likely be done as part of #6543

See this comment inline on Graphite.

fn cast_vote(candidate: Field) {
let msg_sender_npk_m_hash = get_npk_m_hash(&mut context, context.msg_sender());
// TODO (#6312): This will break with key rotation. Fix this. Can vote multiple times by rotating keys.
// Below, we make sure to get our nullifier public key at a specific block. By pinning the nullifier public key at a specific block,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Winnie The Pooh Happy Dance GIF by Leon Denise


describe('votes', () => {
it('votes', async () => {
it('votes, rotates nullifier keys, then tries to vote again', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@sklppy88 sklppy88 force-pushed the ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test branch from 9994faa to bf7019a Compare May 24, 2024 14:16
@sklppy88 sklppy88 force-pushed the ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback branch from 269b51b to 008bf7d Compare May 24, 2024 14:21
@sklppy88 sklppy88 force-pushed the ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test branch from bf7019a to f094691 Compare May 24, 2024 14:49
@sklppy88 sklppy88 force-pushed the ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback branch from 008bf7d to 51ce776 Compare May 24, 2024 14:49
@sklppy88 sklppy88 force-pushed the ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test branch from f094691 to 511478a Compare May 24, 2024 15:07
@sklppy88 sklppy88 force-pushed the ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback branch from 51ce776 to 73b1a4a Compare May 24, 2024 15:11
@sklppy88 sklppy88 force-pushed the ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback branch from 73b1a4a to df6258e Compare May 24, 2024 15:20
Base automatically changed from ek/fix/shared-mutable-private-getter-delay-change-fix-failing-test to ek/fix/shared-mutable-private-getter-context-fix-failing-test May 24, 2024 15:23
@sklppy88 sklppy88 changed the title feat: fix contract issues with key rotation addressing feedback feat: historical access of key getters, fixing logic in contracts after rotation May 24, 2024
…g-test' into ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback
@sklppy88 sklppy88 marked this pull request as ready for review May 24, 2024 15:29
Base automatically changed from ek/fix/shared-mutable-private-getter-context-fix-failing-test to master May 24, 2024 16:34
@sklppy88 sklppy88 force-pushed the ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback branch from 2ddb7cc to 8a25055 Compare May 24, 2024 16:48
@sklppy88 sklppy88 merged commit d9d0193 into master May 24, 2024
@sklppy88 sklppy88 deleted the ek/fix/logic-issues-in-contracts-with-key-rotation-after-feedback branch May 24, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(Keys_Nullifier): Fix security issues / broken contract logic from key rotation

3 participants