@aztec/stdlib 5.0.0-rc.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/abi/buffer.d.ts +6 -2
- package/dest/abi/buffer.d.ts.map +1 -1
- package/dest/abi/buffer.js +13 -1
- package/dest/avm/avm.js +1 -1
- package/dest/aztec-address/index.d.ts +35 -5
- package/dest/aztec-address/index.d.ts.map +1 -1
- package/dest/aztec-address/index.js +32 -8
- package/dest/block/attestation_info.d.ts +1 -1
- package/dest/block/attestation_info.d.ts.map +1 -1
- package/dest/block/attestation_info.js +7 -4
- package/dest/block/l2_block_source.d.ts +44 -27
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/block/l2_block_source.js +15 -1
- package/dest/block/l2_block_stream/event_driven_l2_block_stream.d.ts +39 -0
- package/dest/block/l2_block_stream/event_driven_l2_block_stream.d.ts.map +1 -0
- package/dest/block/l2_block_stream/event_driven_l2_block_stream.js +165 -0
- package/dest/block/l2_block_stream/index.d.ts +2 -1
- package/dest/block/l2_block_stream/index.d.ts.map +1 -1
- package/dest/block/l2_block_stream/index.js +1 -0
- package/dest/block/l2_block_stream/interfaces.d.ts +40 -6
- package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
- package/dest/block/l2_block_stream/interfaces.js +25 -1
- package/dest/block/l2_block_stream/l2_block_stream.d.ts +23 -15
- package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.js +140 -152
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +10 -2
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_tips_store_base.js +33 -15
- package/dest/block/proposal/attestations_and_signers.d.ts +19 -1
- package/dest/block/proposal/attestations_and_signers.d.ts.map +1 -1
- package/dest/block/proposal/attestations_and_signers.js +47 -7
- package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
- package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
- package/dest/block/test/l2_tips_store_test_suite.js +94 -3
- package/dest/block/validate_block_result.d.ts +16 -1
- package/dest/block/validate_block_result.d.ts.map +1 -1
- package/dest/block/validate_block_result.js +18 -3
- package/dest/checkpoint/index.d.ts +2 -1
- package/dest/checkpoint/index.d.ts.map +1 -1
- package/dest/checkpoint/index.js +1 -0
- package/dest/checkpoint/simulation_overrides.d.ts +61 -0
- package/dest/checkpoint/simulation_overrides.d.ts.map +1 -0
- package/dest/checkpoint/simulation_overrides.js +98 -0
- package/dest/config/network-consensus-config.d.ts +1 -1
- package/dest/config/network-consensus-config.d.ts.map +1 -1
- package/dest/config/network-consensus-config.js +2 -10
- package/dest/contract/contract_address.d.ts +5 -4
- package/dest/contract/contract_address.d.ts.map +1 -1
- package/dest/contract/contract_instance.d.ts +16 -2
- package/dest/contract/contract_instance.d.ts.map +1 -1
- package/dest/contract/contract_instance.js +45 -0
- package/dest/contract/interfaces/contract_data_source.d.ts +3 -5
- package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
- package/dest/contract/interfaces/contract_instance.d.ts +71 -10
- package/dest/contract/interfaces/contract_instance.d.ts.map +1 -1
- package/dest/contract/interfaces/contract_instance.js +7 -2
- package/dest/contract/partial_address.d.ts +9 -3
- package/dest/contract/partial_address.d.ts.map +1 -1
- package/dest/contract/partial_address.js +8 -2
- package/dest/database-version/version_manager.d.ts +18 -4
- package/dest/database-version/version_manager.d.ts.map +1 -1
- package/dest/database-version/version_manager.js +76 -6
- package/dest/file-store/factory.d.ts +1 -1
- package/dest/file-store/factory.d.ts.map +1 -1
- package/dest/file-store/factory.js +7 -0
- package/dest/file-store/index.d.ts +2 -1
- package/dest/file-store/index.d.ts.map +1 -1
- package/dest/file-store/index.js +1 -0
- package/dest/file-store/memory.d.ts +24 -0
- package/dest/file-store/memory.d.ts.map +1 -0
- package/dest/file-store/memory.js +80 -0
- package/dest/ha-signing/config.d.ts +19 -5
- package/dest/ha-signing/config.d.ts.map +1 -1
- package/dest/ha-signing/config.js +9 -3
- package/dest/ha-signing/local_config.d.ts +10 -2
- package/dest/ha-signing/local_config.d.ts.map +1 -1
- package/dest/ha-signing/local_config.js +8 -2
- package/dest/hash/hash.d.ts +1 -2
- package/dest/hash/hash.d.ts.map +1 -1
- package/dest/hash/hash.js +0 -7
- package/dest/interfaces/archiver.d.ts +8 -1
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +3 -2
- package/dest/interfaces/aztec-node-admin.d.ts +5 -2
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-debug.d.ts +26 -1
- package/dest/interfaces/aztec-node-debug.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-debug.js +20 -0
- package/dest/interfaces/aztec-node.d.ts +20 -20
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +8 -15
- package/dest/interfaces/chain_tips.d.ts +8 -47
- package/dest/interfaces/chain_tips.d.ts.map +1 -1
- package/dest/interfaces/chain_tips.js +1 -6
- package/dest/interfaces/checkpoint_parameter.d.ts +3 -3
- package/dest/interfaces/checkpoint_parameter.d.ts.map +1 -1
- package/dest/interfaces/checkpoint_parameter.js +3 -3
- package/dest/interfaces/configs.d.ts +4 -1
- package/dest/interfaces/configs.d.ts.map +1 -1
- package/dest/interfaces/configs.js +1 -0
- package/dest/interfaces/private_kernel_prover.d.ts +9 -11
- package/dest/interfaces/private_kernel_prover.d.ts.map +1 -1
- package/dest/interfaces/prover-node.d.ts +6 -7
- package/dest/interfaces/prover-node.d.ts.map +1 -1
- package/dest/interfaces/prover-node.js +15 -10
- package/dest/interfaces/proving-job.d.ts +87 -74
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/proving-job.js +13 -4
- package/dest/interfaces/server_circuit_prover.d.ts +3 -3
- package/dest/interfaces/server_circuit_prover.d.ts.map +1 -1
- package/dest/interfaces/validator.d.ts +7 -3
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/interfaces/world_state.d.ts +14 -1
- package/dest/interfaces/world_state.d.ts.map +1 -1
- package/dest/kernel/hints/find_private_kernel_reset_dimensions.d.ts +8 -2
- package/dest/kernel/hints/find_private_kernel_reset_dimensions.d.ts.map +1 -1
- package/dest/kernel/hints/find_private_kernel_reset_dimensions.js +12 -74
- package/dest/kernel/hints/read_request.js +1 -1
- package/dest/kernel/index.d.ts +2 -2
- package/dest/kernel/index.d.ts.map +1 -1
- package/dest/kernel/index.js +1 -1
- package/dest/kernel/log_hash.d.ts +1 -1
- package/dest/kernel/log_hash.d.ts.map +1 -1
- package/dest/kernel/log_hash.js +2 -2
- package/dest/kernel/note_hash.js +1 -1
- package/dest/kernel/nullifier.js +1 -1
- package/dest/kernel/private_circuit_public_inputs.d.ts +13 -3
- package/dest/kernel/private_circuit_public_inputs.d.ts.map +1 -1
- package/dest/kernel/private_circuit_public_inputs.js +14 -7
- package/dest/kernel/private_context_inputs.d.ts +4 -3
- package/dest/kernel/private_context_inputs.d.ts.map +1 -1
- package/dest/kernel/private_context_inputs.js +7 -3
- package/dest/kernel/private_kernel_circuit_public_inputs.d.ts +7 -1
- package/dest/kernel/private_kernel_circuit_public_inputs.d.ts.map +1 -1
- package/dest/kernel/private_kernel_circuit_public_inputs.js +7 -0
- package/dest/kernel/private_kernel_init_2_circuit_private_inputs.d.ts +2 -3
- package/dest/kernel/private_kernel_init_2_circuit_private_inputs.d.ts.map +1 -1
- package/dest/kernel/private_kernel_init_2_circuit_private_inputs.js +3 -5
- package/dest/kernel/private_kernel_init_3_circuit_private_inputs.d.ts +2 -3
- package/dest/kernel/private_kernel_init_3_circuit_private_inputs.d.ts.map +1 -1
- package/dest/kernel/private_kernel_init_3_circuit_private_inputs.js +3 -5
- package/dest/kernel/private_kernel_init_circuit_private_inputs.d.ts +1 -9
- package/dest/kernel/private_kernel_init_circuit_private_inputs.d.ts.map +1 -1
- package/dest/kernel/private_kernel_init_circuit_private_inputs.js +2 -6
- package/dest/kernel/private_kernel_reset_dimensions.d.ts +7 -8
- package/dest/kernel/private_kernel_reset_dimensions.d.ts.map +1 -1
- package/dest/kernel/private_kernel_reset_tail_circuit_private_inputs.d.ts +29 -0
- package/dest/kernel/private_kernel_reset_tail_circuit_private_inputs.d.ts.map +1 -0
- package/dest/kernel/private_kernel_reset_tail_circuit_private_inputs.js +36 -0
- package/dest/kernel/private_log_data.d.ts +1 -1
- package/dest/kernel/private_log_data.d.ts.map +1 -1
- package/dest/kernel/private_log_data.js +1 -1
- package/dest/keys/derivation.d.ts +41 -6
- package/dest/keys/derivation.d.ts.map +1 -1
- package/dest/keys/derivation.js +49 -26
- package/dest/logs/app_tagging_secret.d.ts +30 -7
- package/dest/logs/app_tagging_secret.d.ts.map +1 -1
- package/dest/logs/app_tagging_secret.js +46 -39
- package/dest/logs/contract_class_log.d.ts +1 -2
- package/dest/logs/contract_class_log.d.ts.map +1 -1
- package/dest/logs/contract_class_log.js +0 -4
- package/dest/logs/index.d.ts +1 -3
- package/dest/logs/index.d.ts.map +1 -1
- package/dest/logs/index.js +0 -2
- package/dest/logs/shared_secret_derivation.d.ts +19 -6
- package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
- package/dest/logs/shared_secret_derivation.js +26 -11
- package/dest/messaging/l1_to_l2_message.d.ts +23 -2
- package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
- package/dest/messaging/l1_to_l2_message.js +36 -11
- package/dest/p2p/attestation_utils.d.ts +1 -1
- package/dest/p2p/attestation_utils.d.ts.map +1 -1
- package/dest/p2p/attestation_utils.js +8 -1
- package/dest/p2p/checkpoint_attestation.d.ts +10 -1
- package/dest/p2p/checkpoint_attestation.d.ts.map +1 -1
- package/dest/p2p/checkpoint_attestation.js +10 -0
- package/dest/p2p/checkpoint_proposal.d.ts +2 -1
- package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
- package/dest/p2p/consensus_payload.d.ts +2 -1
- package/dest/p2p/consensus_payload.d.ts.map +1 -1
- package/dest/p2p/signature_utils.d.ts +10 -1
- package/dest/p2p/signature_utils.d.ts.map +1 -1
- package/dest/p2p/signature_utils.js +9 -1
- package/dest/rollup/avm_proof_data.d.ts +3 -3
- package/dest/rollup/avm_proof_data.d.ts.map +1 -1
- package/dest/rollup/checkpoint_header.d.ts +8 -3
- package/dest/rollup/checkpoint_header.d.ts.map +1 -1
- package/dest/rollup/checkpoint_header.js +20 -10
- package/dest/stats/stats.d.ts +2 -2
- package/dest/stats/stats.d.ts.map +1 -1
- package/dest/tests/factories.d.ts +1 -1
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +7 -15
- package/dest/trees/nullifier_membership_witness.d.ts +5 -8
- package/dest/trees/nullifier_membership_witness.d.ts.map +1 -1
- package/dest/trees/nullifier_membership_witness.js +0 -9
- package/dest/trees/public_data_witness.d.ts +7 -17
- package/dest/trees/public_data_witness.d.ts.map +1 -1
- package/dest/trees/public_data_witness.js +0 -27
- package/dest/tx/execution_payload.d.ts +1 -1
- package/dest/tx/execution_payload.d.ts.map +1 -1
- package/dest/tx/execution_payload.js +1 -1
- package/dest/tx/global_variable_builder.d.ts +2 -12
- package/dest/tx/global_variable_builder.d.ts.map +1 -1
- package/dest/tx/global_variables.js +2 -2
- package/dest/tx/private_tx_constant_data.d.ts +18 -2
- package/dest/tx/private_tx_constant_data.d.ts.map +1 -1
- package/dest/tx/private_tx_constant_data.js +13 -4
- package/dest/tx/simulated_tx.d.ts +10 -6
- package/dest/tx/simulated_tx.d.ts.map +1 -1
- package/dest/world-state/genesis_data.d.ts +9 -1
- package/dest/world-state/genesis_data.d.ts.map +1 -1
- package/dest/world-state/genesis_data.js +1 -0
- package/package.json +8 -8
- package/src/abi/buffer.ts +13 -1
- package/src/avm/avm.ts +1 -1
- package/src/aztec-address/index.ts +36 -6
- package/src/block/attestation_info.ts +7 -2
- package/src/block/l2_block_source.ts +64 -17
- package/src/block/l2_block_stream/event_driven_l2_block_stream.ts +207 -0
- package/src/block/l2_block_stream/index.ts +1 -0
- package/src/block/l2_block_stream/interfaces.ts +60 -6
- package/src/block/l2_block_stream/l2_block_stream.ts +201 -178
- package/src/block/l2_block_stream/l2_tips_store_base.ts +36 -15
- package/src/block/proposal/attestations_and_signers.ts +53 -7
- package/src/block/test/l2_tips_store_test_suite.ts +73 -4
- package/src/block/validate_block_result.ts +48 -2
- package/src/checkpoint/index.ts +1 -0
- package/src/checkpoint/simulation_overrides.ts +171 -0
- package/src/config/network-consensus-config.ts +2 -13
- package/src/contract/contract_address.ts +4 -3
- package/src/contract/contract_instance.ts +62 -1
- package/src/contract/interfaces/contract_data_source.ts +2 -4
- package/src/contract/interfaces/contract_instance.ts +26 -8
- package/src/contract/partial_address.ts +8 -2
- package/src/database-version/version_manager.ts +96 -6
- package/src/file-store/factory.ts +7 -0
- package/src/file-store/index.ts +1 -0
- package/src/file-store/memory.ts +94 -0
- package/src/ha-signing/config.ts +23 -5
- package/src/ha-signing/local_config.ts +20 -1
- package/src/hash/hash.ts +0 -8
- package/src/interfaces/archiver.ts +9 -1
- package/src/interfaces/aztec-node-debug.ts +37 -0
- package/src/interfaces/aztec-node.ts +30 -33
- package/src/interfaces/chain_tips.ts +8 -16
- package/src/interfaces/checkpoint_parameter.ts +3 -3
- package/src/interfaces/configs.ts +3 -0
- package/src/interfaces/private_kernel_prover.ts +10 -12
- package/src/interfaces/prover-node.ts +19 -11
- package/src/interfaces/proving-job.ts +15 -3
- package/src/interfaces/server_circuit_prover.ts +2 -2
- package/src/interfaces/world_state.ts +14 -0
- package/src/kernel/hints/find_private_kernel_reset_dimensions.ts +22 -112
- package/src/kernel/hints/read_request.ts +1 -1
- package/src/kernel/index.ts +1 -1
- package/src/kernel/log_hash.ts +5 -2
- package/src/kernel/note_hash.ts +1 -1
- package/src/kernel/nullifier.ts +1 -1
- package/src/kernel/private_circuit_public_inputs.ts +12 -1
- package/src/kernel/private_context_inputs.ts +10 -3
- package/src/kernel/private_kernel_circuit_public_inputs.ts +9 -0
- package/src/kernel/private_kernel_init_2_circuit_private_inputs.ts +0 -3
- package/src/kernel/private_kernel_init_3_circuit_private_inputs.ts +0 -3
- package/src/kernel/private_kernel_init_circuit_private_inputs.ts +0 -6
- package/src/kernel/private_kernel_reset_dimensions.ts +15 -5
- package/src/kernel/private_kernel_reset_tail_circuit_private_inputs.ts +69 -0
- package/src/kernel/private_log_data.ts +4 -1
- package/src/keys/derivation.ts +69 -24
- package/src/logs/app_tagging_secret.ts +62 -39
- package/src/logs/contract_class_log.ts +0 -9
- package/src/logs/index.ts +0 -2
- package/src/logs/shared_secret_derivation.ts +31 -15
- package/src/messaging/l1_to_l2_message.ts +51 -13
- package/src/p2p/attestation_utils.ts +8 -1
- package/src/p2p/checkpoint_attestation.ts +12 -0
- package/src/p2p/signature_utils.ts +9 -0
- package/src/rollup/avm_proof_data.ts +2 -2
- package/src/rollup/checkpoint_header.ts +16 -2
- package/src/stats/stats.ts +2 -2
- package/src/tests/factories.ts +6 -12
- package/src/trees/nullifier_membership_witness.ts +0 -11
- package/src/trees/public_data_witness.ts +0 -31
- package/src/tx/execution_payload.ts +2 -1
- package/src/tx/global_variable_builder.ts +1 -17
- package/src/tx/global_variables.ts +2 -2
- package/src/tx/private_tx_constant_data.ts +25 -2
- package/src/world-state/genesis_data.ts +10 -0
- package/dest/kernel/private_kernel_tail_circuit_private_inputs.d.ts +0 -47
- package/dest/kernel/private_kernel_tail_circuit_private_inputs.d.ts.map +0 -1
- package/dest/kernel/private_kernel_tail_circuit_private_inputs.js +0 -38
- package/dest/logs/message_context.d.ts +0 -27
- package/dest/logs/message_context.d.ts.map +0 -1
- package/dest/logs/message_context.js +0 -74
- package/dest/logs/pending_tagged_log.d.ts +0 -13
- package/dest/logs/pending_tagged_log.d.ts.map +0 -1
- package/dest/logs/pending_tagged_log.js +0 -34
- package/src/kernel/private_kernel_tail_circuit_private_inputs.ts +0 -58
- package/src/logs/message_context.ts +0 -76
- package/src/logs/pending_tagged_log.ts +0 -39
|
@@ -68,14 +68,24 @@ export const privateKernelResetDimensionNames: DimensionName[] = [
|
|
|
68
68
|
'PRIVATE_LOG_SILOING',
|
|
69
69
|
];
|
|
70
70
|
|
|
71
|
-
export interface
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
export interface ResetCatalogEntry {
|
|
72
|
+
name: string;
|
|
73
|
+
dimensions: number[];
|
|
74
|
+
// Measured gate count (circuit_size) of the compiled variant. Used by the selector to pick the
|
|
75
|
+
// cheapest variant that covers the requested dimensions, e.g. if the required dimensions are
|
|
76
|
+
// `6 - 2 - 2` then a variant with capacity `8 - 2 - 2` might be cheaper than one with capacity
|
|
77
|
+
// `6 - 4 - 4`.
|
|
74
78
|
cost: number;
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
// Must match the config in noir-projects/noir-protocol-circuits/private_kernel_reset_config.json
|
|
78
82
|
export interface PrivateKernelResetDimensionsConfig {
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
// Variants used for mid-tx resets that prevent overflow. Never the last kernel in the chain.
|
|
84
|
+
inner: ResetCatalogEntry[];
|
|
85
|
+
// Variants used as the terminal kernel for the rollup-bound private-only path. Each runs
|
|
86
|
+
// final-reset siloing and tail finalisation in one proof.
|
|
87
|
+
finalTail: ResetCatalogEntry[];
|
|
88
|
+
// Terminal variants for the public-bound path (transactions with public function calls). Runs
|
|
89
|
+
// final-reset siloing and tail-to-public partitioning by revertibility in one proof.
|
|
90
|
+
finalTailToPublic: ResetCatalogEntry[];
|
|
81
91
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MAX_KEY_VALIDATION_REQUESTS_PER_TX,
|
|
3
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
|
|
4
|
+
MAX_NULLIFIERS_PER_TX,
|
|
5
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
6
|
+
} from '@aztec/constants';
|
|
7
|
+
import { bigintToUInt64BE, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
8
|
+
|
|
9
|
+
import type { UInt64 } from '../types/shared.js';
|
|
10
|
+
import type { PrivateKernelResetHints } from './hints/private_kernel_reset_hints.js';
|
|
11
|
+
import type { PaddedSideEffectAmounts, PaddedSideEffects } from './padded_side_effects.js';
|
|
12
|
+
import { kernelStateIsForPublic } from './private_kernel_circuit_public_inputs.js';
|
|
13
|
+
import type { PrivateKernelData } from './private_kernel_data.js';
|
|
14
|
+
import { PrivateKernelResetCircuitPrivateInputsVariants } from './private_kernel_reset_circuit_private_inputs.js';
|
|
15
|
+
import type { PrivateKernelResetDimensions } from './private_kernel_reset_dimensions.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Input to a terminal reset+tail circuit. `isForPublic()` selects the rollup-bound (`reset_tail`)
|
|
19
|
+
* or public-bound (`reset_tail_to_public`) family.
|
|
20
|
+
*/
|
|
21
|
+
export class PrivateKernelResetTailCircuitPrivateInputs {
|
|
22
|
+
constructor(
|
|
23
|
+
public previousKernel: PrivateKernelData,
|
|
24
|
+
public paddedSideEffects: PaddedSideEffects,
|
|
25
|
+
public hints: PrivateKernelResetHints<
|
|
26
|
+
typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
|
|
27
|
+
typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
|
|
28
|
+
typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
29
|
+
typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
30
|
+
typeof MAX_KEY_VALIDATION_REQUESTS_PER_TX,
|
|
31
|
+
typeof MAX_NULLIFIERS_PER_TX
|
|
32
|
+
>,
|
|
33
|
+
public dimensions: PrivateKernelResetDimensions,
|
|
34
|
+
public paddedSideEffectAmounts: PaddedSideEffectAmounts,
|
|
35
|
+
public expirationTimestampUpperBound: UInt64,
|
|
36
|
+
) {}
|
|
37
|
+
|
|
38
|
+
isForPublic() {
|
|
39
|
+
return kernelStateIsForPublic(this.previousKernel.publicInputs);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns a dimension-trimmed view of the reset portion of these inputs (without the tail
|
|
44
|
+
* fields). The prover uses this to feed witness generation of the variant matching the chosen
|
|
45
|
+
* dimensions.
|
|
46
|
+
*/
|
|
47
|
+
trimResetToSizes() {
|
|
48
|
+
const hints = this.hints.trimToSizes(
|
|
49
|
+
this.dimensions.NOTE_HASH_PENDING_READ,
|
|
50
|
+
this.dimensions.NOTE_HASH_SETTLED_READ,
|
|
51
|
+
this.dimensions.NULLIFIER_PENDING_READ,
|
|
52
|
+
this.dimensions.NULLIFIER_SETTLED_READ,
|
|
53
|
+
this.dimensions.KEY_VALIDATION,
|
|
54
|
+
this.dimensions.TRANSIENT_DATA_SQUASHING,
|
|
55
|
+
);
|
|
56
|
+
return new PrivateKernelResetCircuitPrivateInputsVariants(this.previousKernel, this.paddedSideEffects, hints);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
toBuffer() {
|
|
60
|
+
return serializeToBuffer(
|
|
61
|
+
this.previousKernel,
|
|
62
|
+
this.paddedSideEffects,
|
|
63
|
+
this.hints,
|
|
64
|
+
this.dimensions,
|
|
65
|
+
this.paddedSideEffectAmounts,
|
|
66
|
+
bigintToUInt64BE(this.expirationTimestampUpperBound),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -85,7 +85,10 @@ export class ScopedPrivateLogData {
|
|
|
85
85
|
|
|
86
86
|
static fromFields(fields: Fr[] | FieldReader) {
|
|
87
87
|
const reader = FieldReader.asReader(fields);
|
|
88
|
-
return new ScopedPrivateLogData(
|
|
88
|
+
return new ScopedPrivateLogData(
|
|
89
|
+
reader.readObject(PrivateLogData),
|
|
90
|
+
AztecAddress.fromFieldUnsafe(reader.readField()),
|
|
91
|
+
);
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
isEmpty() {
|
package/src/keys/derivation.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DomainSeparator } from '@aztec/constants';
|
|
2
2
|
import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
|
|
3
3
|
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
4
4
|
import { sha512ToGrumpkinScalar } from '@aztec/foundation/crypto/sha512';
|
|
@@ -11,8 +11,11 @@ import { PublicKey, hashPublicKey } from './public_key.js';
|
|
|
11
11
|
import { PublicKeys } from './public_keys.js';
|
|
12
12
|
import { getKeyGenerator } from './utils.js';
|
|
13
13
|
|
|
14
|
-
export function computeAppNullifierHidingKey(
|
|
15
|
-
|
|
14
|
+
export function computeAppNullifierHidingKey(
|
|
15
|
+
masterNullifierHidingSecretKey: GrumpkinScalar,
|
|
16
|
+
app: AztecAddress,
|
|
17
|
+
): Promise<Fr> {
|
|
18
|
+
return computeAppSecretKey(masterNullifierHidingSecretKey, app, 'n'); // 'n' is the key prefix for nullifier hiding key
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
export function computeAppSecretKey(skM: GrumpkinScalar, app: AztecAddress, keyPrefix: KeyPrefix): Promise<Fr> {
|
|
@@ -27,7 +30,7 @@ export async function computeOvskApp(ovsk: GrumpkinScalar, app: AztecAddress): P
|
|
|
27
30
|
return GrumpkinScalar.fromBuffer(ovskAppFr.toBuffer());
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
export function
|
|
33
|
+
export function deriveMasterNullifierHidingSecretKey(secretKey: Fr): GrumpkinScalar {
|
|
31
34
|
return sha512ToGrumpkinScalar([secretKey, DomainSeparator.NHK_M]);
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -39,9 +42,12 @@ export function deriveMasterOutgoingViewingSecretKey(secretKey: Fr): GrumpkinSca
|
|
|
39
42
|
return sha512ToGrumpkinScalar([secretKey, DomainSeparator.OVSK_M]);
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
export function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
export function deriveMasterMessageSigningSecretKey(secretKey: Fr): GrumpkinScalar {
|
|
46
|
+
return sha512ToGrumpkinScalar([secretKey, DomainSeparator.MSSK_M]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function deriveMasterFallbackSecretKey(secretKey: Fr): GrumpkinScalar {
|
|
50
|
+
return sha512ToGrumpkinScalar([secretKey, DomainSeparator.FBSK_M]);
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
export function computePreaddress(publicKeysHash: Fr, partialAddress: Fr) {
|
|
@@ -85,52 +91,91 @@ export async function computeAddressSecret(preaddress: Fr, ivsk: Fq) {
|
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
export function derivePublicKeyFromSecretKey(secretKey: Fq): Promise<PublicKey> {
|
|
94
|
+
// 0 * G is the point at infinity. The WASM encodes infinity with an out-of-field x coordinate that Point cannot
|
|
95
|
+
// deserialize, so return the point directly instead of calling into it.
|
|
96
|
+
if (secretKey.isZero()) {
|
|
97
|
+
return Promise.resolve(PublicKey.INFINITY);
|
|
98
|
+
}
|
|
88
99
|
return Grumpkin.mul(Grumpkin.generator, secretKey);
|
|
89
100
|
}
|
|
90
101
|
|
|
102
|
+
/**
|
|
103
|
+
* The six master secret keys that fully define an account's privacy keys.
|
|
104
|
+
*/
|
|
105
|
+
export type MasterSecretKeys = {
|
|
106
|
+
masterNullifierHidingSecretKey: GrumpkinScalar;
|
|
107
|
+
masterIncomingViewingSecretKey: GrumpkinScalar;
|
|
108
|
+
masterOutgoingViewingSecretKey: GrumpkinScalar;
|
|
109
|
+
masterTaggingSecretKey: GrumpkinScalar;
|
|
110
|
+
masterMessageSigningSecretKey: GrumpkinScalar;
|
|
111
|
+
masterFallbackSecretKey: GrumpkinScalar;
|
|
112
|
+
};
|
|
113
|
+
|
|
91
114
|
/**
|
|
92
115
|
* Computes secret and public keys and public keys hash from a secret key.
|
|
93
116
|
* @param secretKey - The secret key to derive keys from.
|
|
94
117
|
* @returns The derived keys.
|
|
95
118
|
*/
|
|
96
|
-
export
|
|
119
|
+
export function deriveKeys(secretKey: Fr) {
|
|
97
120
|
// First we derive master secret/hiding keys - we use sha512 here because this derivation will never take place
|
|
98
121
|
// in a circuit
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
122
|
+
return deriveKeysFromMasterSecretKeys({
|
|
123
|
+
masterNullifierHidingSecretKey: deriveMasterNullifierHidingSecretKey(secretKey),
|
|
124
|
+
masterIncomingViewingSecretKey: deriveMasterIncomingViewingSecretKey(secretKey),
|
|
125
|
+
masterOutgoingViewingSecretKey: deriveMasterOutgoingViewingSecretKey(secretKey),
|
|
126
|
+
masterTaggingSecretKey: sha512ToGrumpkinScalar([secretKey, DomainSeparator.TSK_M]),
|
|
127
|
+
masterMessageSigningSecretKey: deriveMasterMessageSigningSecretKey(secretKey),
|
|
128
|
+
masterFallbackSecretKey: deriveMasterFallbackSecretKey(secretKey),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
103
131
|
|
|
104
|
-
|
|
105
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Derives the master public keys and the {@link PublicKeys} struct from a set of master secret keys.
|
|
134
|
+
* @param secretKeys - The master secret keys to derive public keys from.
|
|
135
|
+
* @returns The provided secret keys alongside the derived public keys.
|
|
136
|
+
*/
|
|
137
|
+
export async function deriveKeysFromMasterSecretKeys(secretKeys: MasterSecretKeys) {
|
|
138
|
+
const {
|
|
139
|
+
masterNullifierHidingSecretKey,
|
|
140
|
+
masterIncomingViewingSecretKey,
|
|
141
|
+
masterOutgoingViewingSecretKey,
|
|
142
|
+
masterTaggingSecretKey,
|
|
143
|
+
masterMessageSigningSecretKey,
|
|
144
|
+
masterFallbackSecretKey,
|
|
145
|
+
} = secretKeys;
|
|
146
|
+
|
|
147
|
+
const masterNullifierHidingPublicKey = await derivePublicKeyFromSecretKey(masterNullifierHidingSecretKey);
|
|
106
148
|
const masterIncomingViewingPublicKey = await derivePublicKeyFromSecretKey(masterIncomingViewingSecretKey);
|
|
107
149
|
const masterOutgoingViewingPublicKey = await derivePublicKeyFromSecretKey(masterOutgoingViewingSecretKey);
|
|
108
150
|
const masterTaggingPublicKey = await derivePublicKeyFromSecretKey(masterTaggingSecretKey);
|
|
151
|
+
const masterMessageSigningPublicKey = await derivePublicKeyFromSecretKey(masterMessageSigningSecretKey);
|
|
152
|
+
const masterFallbackPublicKey = await derivePublicKeyFromSecretKey(masterFallbackSecretKey);
|
|
109
153
|
|
|
110
154
|
// The non-owner-visible PublicKeys carries hashes for npk/ovpk/tpk/mspk/fbpk and the raw
|
|
111
|
-
// point only for ivpk_m. The npk/ovpk/tpk raw points are also returned alongside so the key
|
|
112
|
-
// store can persist them under `${account}-{n|ov|t}pk_m` (only their hashes live in publicKeys).
|
|
155
|
+
// point only for ivpk_m. The npk/ovpk/tpk/mspk/fbpk raw points are also returned alongside so the key
|
|
156
|
+
// store can persist them under `${account}-{n|ov|t|ms|fb}pk_m` (only their hashes live in publicKeys).
|
|
113
157
|
// The ivpk_m point isn't returned separately because it already lives in publicKeys.ivpkM.
|
|
114
|
-
//
|
|
115
|
-
// TODO: There isn't a derivation path for the message signing(msk) and fallback(fbk) keys yet. So we just use the the
|
|
116
|
-
// default values for now.
|
|
117
158
|
const publicKeys = new PublicKeys(
|
|
118
|
-
await hashPublicKey(
|
|
159
|
+
await hashPublicKey(masterNullifierHidingPublicKey),
|
|
119
160
|
masterIncomingViewingPublicKey,
|
|
120
161
|
await hashPublicKey(masterOutgoingViewingPublicKey),
|
|
121
162
|
await hashPublicKey(masterTaggingPublicKey),
|
|
122
|
-
|
|
123
|
-
|
|
163
|
+
await hashPublicKey(masterMessageSigningPublicKey),
|
|
164
|
+
await hashPublicKey(masterFallbackPublicKey),
|
|
124
165
|
);
|
|
125
166
|
|
|
126
167
|
return {
|
|
127
|
-
|
|
168
|
+
masterNullifierHidingSecretKey,
|
|
128
169
|
masterIncomingViewingSecretKey,
|
|
129
170
|
masterOutgoingViewingSecretKey,
|
|
130
171
|
masterTaggingSecretKey,
|
|
131
|
-
|
|
172
|
+
masterMessageSigningSecretKey,
|
|
173
|
+
masterFallbackSecretKey,
|
|
174
|
+
masterNullifierHidingPublicKey,
|
|
132
175
|
masterOutgoingViewingPublicKey,
|
|
133
176
|
masterTaggingPublicKey,
|
|
177
|
+
masterMessageSigningPublicKey,
|
|
178
|
+
masterFallbackPublicKey,
|
|
134
179
|
publicKeys,
|
|
135
180
|
};
|
|
136
181
|
}
|
|
@@ -9,6 +9,7 @@ import { AztecAddress } from '../aztec-address/index.js';
|
|
|
9
9
|
import type { CompleteAddress } from '../contract/complete_address.js';
|
|
10
10
|
import { computeAddressSecret, computePreaddress } from '../keys/derivation.js';
|
|
11
11
|
import { AppTaggingSecretKind } from './app_tagging_secret_kind.js';
|
|
12
|
+
import { appSiloEcdhSharedSecretPoint } from './shared_secret_derivation.js';
|
|
12
13
|
|
|
13
14
|
const AppTaggingSecretKindSchema = z.union([
|
|
14
15
|
z.literal(AppTaggingSecretKind.UNCONSTRAINED),
|
|
@@ -30,17 +31,49 @@ export class AppTaggingSecret {
|
|
|
30
31
|
) {}
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
|
-
* Derives
|
|
34
|
-
* secret. Returns undefined if `externalAddress` is an invalid address.
|
|
34
|
+
* Derives an app-siloed, recipient-directional tagging secret from a shared tagging secret point.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* App-silos the point via {@link appSiloEcdhSharedSecretPoint}, then directs the result to `recipient`:
|
|
37
|
+
* `h([s_app, recipient])`. The directional step stops a symmetric shared secret (ECDH against an address, or an
|
|
38
|
+
* arbitrary registered point) from colliding bidirectionally, so two parties never share a tag sequence.
|
|
39
|
+
*
|
|
40
|
+
* The point is obtained either via {@link computeSharedTaggingSecret} (an ECDH key exchange against a sender) or
|
|
41
|
+
* registered directly as a pre-shared secret.
|
|
42
|
+
*
|
|
43
|
+
* @param taggingSecretPoint - The shared tagging secret point (ECDH output, or a directly registered pre-shared secret)
|
|
39
44
|
* @param app - Contract address to silo the secret to
|
|
40
45
|
* @param recipient - Recipient of the log. Defines the "direction of the secret".
|
|
41
46
|
* @returns The secret that can be used along with an index to compute a tag to be included in a log.
|
|
42
47
|
*/
|
|
43
|
-
static async
|
|
48
|
+
static async computeDirectional(
|
|
49
|
+
taggingSecretPoint: Point,
|
|
50
|
+
app: AztecAddress,
|
|
51
|
+
recipient: AztecAddress,
|
|
52
|
+
): Promise<AppTaggingSecret> {
|
|
53
|
+
const appSiloedSecret = await appSiloEcdhSharedSecretPoint(taggingSecretPoint, app);
|
|
54
|
+
const directionalAppTaggingSecret = await poseidon2Hash([appSiloedSecret, recipient]);
|
|
55
|
+
|
|
56
|
+
return new AppTaggingSecret(directionalAppTaggingSecret, app);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Derives the bare app-siloed tagging secret from a shared secret point via {@link appSiloEcdhSharedSecretPoint},
|
|
61
|
+
* under the given delivery-mode kind.
|
|
62
|
+
*/
|
|
63
|
+
static async computeAppSiloed(
|
|
64
|
+
taggingSecretPoint: Point,
|
|
65
|
+
app: AztecAddress,
|
|
66
|
+
kind: AppTaggingSecretKind,
|
|
67
|
+
): Promise<AppTaggingSecret> {
|
|
68
|
+
return new AppTaggingSecret(await appSiloEcdhSharedSecretPoint(taggingSecretPoint, app), app, kind);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Derives the tagging secret for `(externalAddress, recipient, app)` by performing an ECDH key exchange against
|
|
73
|
+
* `externalAddress` to obtain the shared point, then siloing and directing it via {@link computeDirectional}.
|
|
74
|
+
* Returns undefined if `externalAddress` is not a valid address.
|
|
75
|
+
*/
|
|
76
|
+
static async computeViaEcdh(
|
|
44
77
|
localAddress: CompleteAddress,
|
|
45
78
|
localIvsk: Fq,
|
|
46
79
|
externalAddress: AztecAddress,
|
|
@@ -52,36 +85,24 @@ export class AppTaggingSecret {
|
|
|
52
85
|
return undefined;
|
|
53
86
|
}
|
|
54
87
|
|
|
55
|
-
|
|
56
|
-
const directionalAppTaggingSecret = await poseidon2Hash([appTaggingSecret, recipient]);
|
|
57
|
-
|
|
58
|
-
return new AppTaggingSecret(directionalAppTaggingSecret, app);
|
|
88
|
+
return AppTaggingSecret.computeDirectional(taggingSecretPoint, app, recipient);
|
|
59
89
|
}
|
|
60
90
|
|
|
61
91
|
toString(): string {
|
|
62
|
-
// TODO(F-680): Migrate stored tagging keys and remove the legacy unconstrained format.
|
|
63
|
-
if (this.kind === AppTaggingSecretKind.UNCONSTRAINED) {
|
|
64
|
-
return `${this.secret.toString()}:${this.app.toString()}`;
|
|
65
|
-
}
|
|
66
92
|
return `${this.kind}:${this.secret.toString()}:${this.app.toString()}`;
|
|
67
93
|
}
|
|
68
94
|
|
|
69
95
|
static fromString(str: string): AppTaggingSecret {
|
|
70
96
|
const parts = str.split(':');
|
|
71
|
-
if (parts.length
|
|
72
|
-
|
|
73
|
-
const [secretStr, appStr] = parts;
|
|
74
|
-
return new AppTaggingSecret(Fr.fromString(secretStr), AztecAddress.fromString(appStr));
|
|
75
|
-
}
|
|
76
|
-
if (parts.length === 3) {
|
|
77
|
-
const [kindStr, secretStr, appStr] = parts;
|
|
78
|
-
return new AppTaggingSecret(
|
|
79
|
-
Fr.fromString(secretStr),
|
|
80
|
-
AztecAddress.fromString(appStr),
|
|
81
|
-
appTaggingSecretKindFromString(kindStr),
|
|
82
|
-
);
|
|
97
|
+
if (parts.length !== 3) {
|
|
98
|
+
throw new Error(`Invalid AppTaggingSecret string: ${str}`);
|
|
83
99
|
}
|
|
84
|
-
|
|
100
|
+
const [kindStr, secretStr, appStr] = parts;
|
|
101
|
+
return new AppTaggingSecret(
|
|
102
|
+
Fr.fromString(secretStr),
|
|
103
|
+
AztecAddress.fromStringUnsafe(appStr),
|
|
104
|
+
appTaggingSecretKindFromString(kindStr),
|
|
105
|
+
);
|
|
85
106
|
}
|
|
86
107
|
}
|
|
87
108
|
|
|
@@ -111,18 +132,17 @@ function appTaggingSecretKindFromString(kind: string): AppTaggingSecretKind {
|
|
|
111
132
|
}
|
|
112
133
|
}
|
|
113
134
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Computes the shared tagging secret point between a local address (i.e. one for which the privacy keys are known) and
|
|
137
|
+
* an external one via a Diffie-Hellman key exchange.
|
|
138
|
+
*
|
|
139
|
+
* Returns undefined if `externalAddress` is an invalid address.
|
|
140
|
+
*/
|
|
141
|
+
export async function computeSharedTaggingSecret(
|
|
117
142
|
localAddress: CompleteAddress,
|
|
118
143
|
localIvsk: Fq,
|
|
119
144
|
externalAddress: AztecAddress,
|
|
120
145
|
): Promise<Point | undefined> {
|
|
121
|
-
// Given A (local complete address) -> B (external address) and h == preaddress
|
|
122
|
-
// Compute shared secret as S = (h_A + local_ivsk_A) * Addr_Point_B
|
|
123
|
-
|
|
124
|
-
const knownPreaddress = await computePreaddress(await localAddress.publicKeys.hash(), localAddress.partialAddress);
|
|
125
|
-
|
|
126
146
|
// An invalid address has no corresponding address point
|
|
127
147
|
if (!(await externalAddress.isValid())) {
|
|
128
148
|
return undefined;
|
|
@@ -130,8 +150,11 @@ async function computeSharedTaggingSecret(
|
|
|
130
150
|
|
|
131
151
|
const externalAddressPoint = await externalAddress.toAddressPoint();
|
|
132
152
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
153
|
+
const localPreaddress = await computePreaddress(await localAddress.publicKeys.hash(), localAddress.partialAddress);
|
|
154
|
+
const localAddressSecret = await computeAddressSecret(localPreaddress, localIvsk);
|
|
155
|
+
|
|
156
|
+
// For a given local address A and external address B, the shared tagging secret S is (h_A + ivsk_A) * Addr_Point_B
|
|
157
|
+
// (conceptually, in reality we don't use h_A + ivsk_A directly but rather the actual address secret, which is the
|
|
158
|
+
// same but with an optional sign adjustment to prevent A's address point from having a negative y-coordinate).
|
|
159
|
+
return Grumpkin.mul(externalAddressPoint, localAddressSecret);
|
|
137
160
|
}
|
|
@@ -138,15 +138,6 @@ export class ContractClassLog {
|
|
|
138
138
|
);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
static fromFields(fields: Fr[] | FieldReader) {
|
|
142
|
-
const reader = FieldReader.asReader(fields);
|
|
143
|
-
return new ContractClassLog(
|
|
144
|
-
reader.readObject(AztecAddress),
|
|
145
|
-
reader.readObject(ContractClassLogFields),
|
|
146
|
-
reader.readU32(),
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
141
|
getEmittedFields() {
|
|
151
142
|
return this.fields.getEmittedFields(this.emittedLength);
|
|
152
143
|
}
|
package/src/logs/index.ts
CHANGED
|
@@ -5,13 +5,11 @@ export * from './tagging_index_range.js';
|
|
|
5
5
|
export * from './contract_class_log.js';
|
|
6
6
|
export * from './public_log.js';
|
|
7
7
|
export * from './private_log.js';
|
|
8
|
-
export * from './pending_tagged_log.js';
|
|
9
8
|
export * from './log_result.js';
|
|
10
9
|
export * from './log_cursor.js';
|
|
11
10
|
export * from './logs_query.js';
|
|
12
11
|
export * from './query_all_logs_by_tags.js';
|
|
13
12
|
export * from './shared_secret_derivation.js';
|
|
14
|
-
export * from './message_context.js';
|
|
15
13
|
export * from './debug_log.js';
|
|
16
14
|
export * from './debug_log_store.js';
|
|
17
15
|
export * from './tag.js';
|
|
@@ -2,16 +2,28 @@ import { DomainSeparator } from '@aztec/constants';
|
|
|
2
2
|
import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
|
|
3
3
|
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
4
4
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
-
import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
5
|
+
import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
|
|
6
6
|
|
|
7
7
|
import type { AztecAddress } from '../aztec-address/index.js';
|
|
8
8
|
import type { PublicKey } from '../keys/public_key.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Derives
|
|
11
|
+
* Derives the raw ECDH shared secret point `S = secretKey * publicKey`.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
|
|
13
|
+
* @throws If the publicKey is zero.
|
|
14
|
+
*/
|
|
15
|
+
export function deriveEcdhSharedSecretPoint(secretKey: GrumpkinScalar, publicKey: PublicKey): Promise<Point> {
|
|
16
|
+
if (publicKey.isZero()) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Attempting to derive a shared secret with a zero public key. You have probably passed a zero public key in your Noir code somewhere thinking that the note won't be broadcast... but it was.`,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return Grumpkin.mul(publicKey, secretKey);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Derives an app-siloed ECDH shared secret from keys: ECDHs `S = secretKey * publicKey` via
|
|
26
|
+
* {@link deriveEcdhSharedSecretPoint}, then app-silos it via {@link appSiloEcdhSharedSecretPoint}.
|
|
15
27
|
*
|
|
16
28
|
* @param secretKey - The secret key used to derive shared secret.
|
|
17
29
|
* @param publicKey - The public key used to derive shared secret.
|
|
@@ -19,19 +31,23 @@ import type { PublicKey } from '../keys/public_key.js';
|
|
|
19
31
|
* @returns The app-siloed shared secret as a Field.
|
|
20
32
|
* @throws If the publicKey is zero.
|
|
21
33
|
*/
|
|
22
|
-
export async function
|
|
34
|
+
export async function appSiloEcdhSharedSecret(
|
|
23
35
|
secretKey: GrumpkinScalar,
|
|
24
36
|
publicKey: PublicKey,
|
|
25
37
|
contractAddress: AztecAddress,
|
|
26
38
|
): Promise<Fr> {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
const rawSharedSecret = await deriveEcdhSharedSecretPoint(secretKey, publicKey);
|
|
40
|
+
return appSiloEcdhSharedSecretPoint(rawSharedSecret, contractAddress);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* App-silos a shared secret point: `s_app = h(DOM_SEP__APP_SILOED_ECDH_SHARED_SECRET, S.x, S.y, app)`.
|
|
45
|
+
*
|
|
46
|
+
* Mirrors `compute_app_siloed_shared_secret` in aztec-nr.
|
|
47
|
+
*
|
|
48
|
+
* @param point - The raw shared secret point `S`.
|
|
49
|
+
* @param app - The contract address to silo to.
|
|
50
|
+
*/
|
|
51
|
+
export function appSiloEcdhSharedSecretPoint(point: Point, app: AztecAddress): Promise<Fr> {
|
|
52
|
+
return poseidon2HashWithSeparator([point.x, point.y, app], DomainSeparator.APP_SILOED_ECDH_SHARED_SECRET);
|
|
37
53
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { DomainSeparator, type L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
2
3
|
import { sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
3
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
@@ -7,7 +8,7 @@ import { SiblingPath } from '@aztec/foundation/trees';
|
|
|
7
8
|
|
|
8
9
|
import type { AztecAddress } from '../aztec-address/index.js';
|
|
9
10
|
import type { BlockParameter } from '../block/block_parameter.js';
|
|
10
|
-
import {
|
|
11
|
+
import { siloNullifier } from '../hash/hash.js';
|
|
11
12
|
import type { AztecNode } from '../interfaces/aztec-node.js';
|
|
12
13
|
import { MerkleTreeId } from '../trees/merkle_tree_id.js';
|
|
13
14
|
import { L1Actor } from './l1_actor.js';
|
|
@@ -74,28 +75,65 @@ export class L1ToL2Message {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
/**
|
|
79
|
+
* The unsiloed nullifier a message consumer derives, together with the contract address needed to silo it.
|
|
80
|
+
*/
|
|
81
|
+
export interface UnsiloedMessageNullifier {
|
|
82
|
+
contractAddress: AztecAddress;
|
|
83
|
+
nullifier: Fr;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Computes the unsiloed nullifier that the fee juice contract (and any consumer following the same scheme) derives when
|
|
88
|
+
* consuming an L1 to L2 message.
|
|
89
|
+
*
|
|
90
|
+
* This is not a general-purpose utility: other contracts may derive the secret hash and hence the nullifier
|
|
91
|
+
* differently. The result is unsiloed — callers silo it (with the consuming contract's address) before looking it up
|
|
92
|
+
* in the nullifier tree.
|
|
93
|
+
*/
|
|
94
|
+
export function computeFeeJuiceMessageNullifier(messageHash: Fr, secret: Fr): Promise<Fr> {
|
|
95
|
+
return poseidon2HashWithSeparator([messageHash, secret], DomainSeparator.MESSAGE_NULLIFIER);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Fetches the membership witness of an L1 to L2 message. When `unsiloedNullifier` is provided, the message is
|
|
100
|
+
* additionally required to be un-nullified.
|
|
101
|
+
*/
|
|
102
|
+
export async function getL1ToL2MessageWitness(
|
|
79
103
|
node: AztecNode,
|
|
80
|
-
contractAddress: AztecAddress,
|
|
81
104
|
messageHash: Fr,
|
|
82
|
-
|
|
105
|
+
unsiloedNullifier?: UnsiloedMessageNullifier,
|
|
83
106
|
referenceBlock: BlockParameter = 'latest',
|
|
84
107
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
// Both requests are dispatched before awaiting so they run concurrently.
|
|
109
|
+
const l1ToL2ResponsePromise = node.getL1ToL2MessageMembershipWitness(referenceBlock, messageHash);
|
|
110
|
+
const nullifierResponsePromise = unsiloedNullifier
|
|
111
|
+
? siloNullifier(unsiloedNullifier.contractAddress, unsiloedNullifier.nullifier).then(siloed =>
|
|
112
|
+
node.findLeavesIndexes(referenceBlock, MerkleTreeId.NULLIFIER_TREE, [siloed]),
|
|
113
|
+
)
|
|
114
|
+
: undefined;
|
|
91
115
|
|
|
116
|
+
const l1ToL2Response = await l1ToL2ResponsePromise;
|
|
92
117
|
if (!l1ToL2Response) {
|
|
93
118
|
throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
94
119
|
}
|
|
95
120
|
|
|
96
|
-
|
|
121
|
+
const nullifierResponse = await nullifierResponsePromise;
|
|
122
|
+
if (nullifierResponse?.[0] !== undefined) {
|
|
97
123
|
throw new Error(`No non-nullified L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
98
124
|
}
|
|
99
125
|
|
|
100
126
|
return l1ToL2Response;
|
|
101
127
|
}
|
|
128
|
+
|
|
129
|
+
// This functionality is not on the node because we do not want to pass the node the secret, and give the node the ability to derive a valid nullifer for an L1 to L2 message.
|
|
130
|
+
export async function getNonNullifiedL1ToL2MessageWitness(
|
|
131
|
+
node: AztecNode,
|
|
132
|
+
contractAddress: AztecAddress,
|
|
133
|
+
messageHash: Fr,
|
|
134
|
+
secret: Fr,
|
|
135
|
+
referenceBlock: BlockParameter = 'latest',
|
|
136
|
+
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
|
|
137
|
+
const nullifier = await computeFeeJuiceMessageNullifier(messageHash, secret);
|
|
138
|
+
return getL1ToL2MessageWitness(node, messageHash, { contractAddress, nullifier }, referenceBlock);
|
|
139
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeSignature } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
1
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
3
|
|
|
3
4
|
import { CommitteeAttestation } from '../block/index.js';
|
|
@@ -18,9 +19,15 @@ export function orderAttestations(
|
|
|
18
19
|
for (const attestation of attestations) {
|
|
19
20
|
const sender = attestation.getSender();
|
|
20
21
|
if (sender) {
|
|
22
|
+
// Canonicalize the recovery byte to v ∈ {27, 28} before it reaches the L1 bundle. A committee
|
|
23
|
+
// member (or a peer mutating the byte in flight) can emit an equivalent signature in yParity form
|
|
24
|
+
// (v = 0/1); left as-is it makes `packAttestations` (empty iff v === 0) and `getSigners` (empty iff
|
|
25
|
+
// r,s,v all zero) disagree, reverting `propose()` with SignersSizeMismatch, and a v = 1 byte would
|
|
26
|
+
// later revert epoch proving in ECDSA.recover. `sender` recovered, so the signature is non-empty
|
|
27
|
+
// and low-s, and normalizeSignature preserves the recovered address.
|
|
21
28
|
attestationMap.set(
|
|
22
29
|
sender.toString(),
|
|
23
|
-
CommitteeAttestation.fromAddressAndSignature(sender, attestation.signature),
|
|
30
|
+
CommitteeAttestation.fromAddressAndSignature(sender, normalizeSignature(attestation.signature)),
|
|
24
31
|
);
|
|
25
32
|
}
|
|
26
33
|
}
|