-
Notifications
You must be signed in to change notification settings - Fork 599
feat(aztec-nr): Get tagging index for constrained delivery #23359
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
base: merge-train/fairies
Are you sure you want to change the base?
Changes from 12 commits
98b9784
27e5a5e
381858d
fff3541
3202ab1
49bfefc
d00136d
76c025e
75554b1
9a451ef
14d22ca
bfb03bf
aa3d1e6
df3f982
36d355d
3bad347
cbc905b
0d1e1c5
cc18df1
a018a02
cbf7fed
8188a7d
ccf6647
4e77dc0
6446fa6
f6dd2da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,24 @@ pub unconstrained fn get_next_app_tag_as_sender(sender: AztecAddress, recipient: | |
| #[oracle(aztec_prv_getNextAppTagAsSender)] | ||
| unconstrained fn get_next_app_tag_as_sender_oracle(_sender: AztecAddress, _recipient: AztecAddress) -> Field {} | ||
|
|
||
| /// Returns the next sender-side index for a constrained-delivery shared secret. | ||
| /// | ||
| /// Unlike [`get_next_app_tag_as_sender`], which derives the full tag from a `(sender, recipient)` pair that only the | ||
| /// simulator knows the directional secret for, the constrained-delivery flow has the app contract holding the | ||
| /// app-siloed shared secret directly. The app computes the tag itself as | ||
| /// `compute_log_tag(poseidon2_hash([app_siloed_secret, index]), DOM_SEP__CONSTRAINED_MSG_LOG_TAG)`, so the simulator | ||
| /// only needs to hand out a fresh per-secret index. | ||
| /// | ||
| /// As with the unconstrained variant, the simulator persists the index increment only if the tagged log is found in | ||
| /// an actual block - a reverting transaction can otherwise cause the sender to accidentally skip indices and later | ||
| /// produce notes that are not found by the recipient. | ||
| pub unconstrained fn get_next_constrained_index(app_siloed_secret: Field) -> u32 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a few thoughts about this:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not saying we should extend or replace While I don't see a use case for it today, I'm thinking that it might make sense to make the oracle as generic as possible. Specially when the cost to do so is close to 0, right? I'm not completely sold on the idea, but I wanted to bring it up
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I brought up
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, makes sense. But let's rename to |
||
| get_next_constrained_index_oracle(app_siloed_secret) | ||
| } | ||
|
|
||
| #[oracle(aztec_prv_getNextConstrainedIndex)] | ||
| unconstrained fn get_next_constrained_index_oracle(_app_siloed_secret: Field) -> u32 {} | ||
|
|
||
| /// Gets the sender for tags. | ||
| /// | ||
| /// This unconstrained value is used as the sender when computing an unconstrained shared secret for a tag in order to | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,21 +111,29 @@ export const MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; | |
| export const MAX_PACKED_BYTECODE_SIZE_PER_UTILITY_FUNCTION_IN_FIELDS = 3000; | ||
| export const CLASS_REGISTRY_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 23; | ||
| export const CLASS_REGISTRY_UTILITY_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 14; | ||
| export const CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE = 14907836659448373306373608164128296596488873008270905914742877230397948162628n; | ||
| export const CONTRACT_CLASS_REGISTRY_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE = 6632427679359753950122686582223287785801228472790519808071945107172278003224n; | ||
| export const CONTRACT_CLASS_REGISTRY_UTILITY_FUNCTION_BROADCASTED_MAGIC_VALUE = 2863388930963370662477859081312917957786876946407365497018765359301074232169n; | ||
| export const CONTRACT_INSTANCE_PUBLISHED_MAGIC_VALUE = 10538216027419913765597387738085647348651103543680388181336823392401502757423n; | ||
| export const CONTRACT_INSTANCE_UPDATED_MAGIC_VALUE = 20721543224513346060908370400407150739273836456436647488068002302723900469047n; | ||
| export const CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE = | ||
| 14907836659448373306373608164128296596488873008270905914742877230397948162628n; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a lot of the changes here are not related to your change. Can we revert them? |
||
| export const CONTRACT_CLASS_REGISTRY_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE = | ||
| 6632427679359753950122686582223287785801228472790519808071945107172278003224n; | ||
| export const CONTRACT_CLASS_REGISTRY_UTILITY_FUNCTION_BROADCASTED_MAGIC_VALUE = | ||
| 2863388930963370662477859081312917957786876946407365497018765359301074232169n; | ||
| export const CONTRACT_INSTANCE_PUBLISHED_MAGIC_VALUE = | ||
| 10538216027419913765597387738085647348651103543680388181336823392401502757423n; | ||
| export const CONTRACT_INSTANCE_UPDATED_MAGIC_VALUE = | ||
| 20721543224513346060908370400407150739273836456436647488068002302723900469047n; | ||
| export const MAX_PROTOCOL_CONTRACTS = 11; | ||
| export const CANONICAL_AUTH_REGISTRY_ADDRESS = 1; | ||
| export const CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS = 2; | ||
| export const CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS = 3; | ||
| export const MULTI_CALL_ENTRYPOINT_ADDRESS = 4; | ||
| export const FEE_JUICE_ADDRESS = 5; | ||
| export const PUBLIC_CHECKS_ADDRESS = 6; | ||
| export const SIDE_EFFECT_MASKING_ADDRESS = 19523154334483583633304358390644137470227519736821975910774528428729027989987n; | ||
| export const NULL_MSG_SENDER_CONTRACT_ADDRESS = 21888242871839275222246405745257275088548364400416034343698204186575808495616n; | ||
| export const CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT = 14193106819744442689484501689686180698286338820089744102289275815863062044599n; | ||
| export const SIDE_EFFECT_MASKING_ADDRESS = | ||
| 19523154334483583633304358390644137470227519736821975910774528428729027989987n; | ||
| export const NULL_MSG_SENDER_CONTRACT_ADDRESS = | ||
| 21888242871839275222246405745257275088548364400416034343698204186575808495616n; | ||
| export const CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT = | ||
| 14193106819744442689484501689686180698286338820089744102289275815863062044599n; | ||
| export const FEE_JUICE_BALANCES_SLOT = 1; | ||
| export const UPDATED_CLASS_IDS_SLOT = 1; | ||
| export const DEFAULT_NPK_M_X = 582240093077765400562621227108555700500271598878376310175765873770292988861n; | ||
|
|
@@ -487,10 +495,12 @@ export const PROOF_TYPE_HN_TAIL = 8; | |
| export const PROOF_TYPE_CHONK = 9; | ||
| export const TWO_POW_64 = 18446744073709551616n; | ||
| export const AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_HEIGHT = 6; | ||
| export const AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT = 8857725174171741160013581538021104168730942281584695363072221389187184558934n; | ||
| export const AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT = | ||
| 8857725174171741160013581538021104168730942281584695363072221389187184558934n; | ||
| export const AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_SIZE = 1; | ||
| export const AVM_RETRIEVED_BYTECODES_TREE_HEIGHT = 5; | ||
| export const AVM_RETRIEVED_BYTECODES_TREE_INITIAL_ROOT = 7219963955978612430652135562469971022121082503142071142433583613738272177170n; | ||
| export const AVM_RETRIEVED_BYTECODES_TREE_INITIAL_ROOT = | ||
| 7219963955978612430652135562469971022121082503142071142433583613738272177170n; | ||
| export const AVM_RETRIEVED_BYTECODES_TREE_INITIAL_SIZE = 1; | ||
| export const TIMESTAMP_OF_CHANGE_BIT_SIZE = 32; | ||
| export const DEFAULT_UPDATE_DELAY = 86400; | ||
|
|
@@ -517,6 +527,7 @@ export enum DomainSeparator { | |
| EVENT_LOG_TAG = 926040838, | ||
| NOTE_COMPLETION_LOG_TAG = 3372669888, | ||
| UNCONSTRAINED_MSG_LOG_TAG = 1485357192, | ||
| CONSTRAINED_MSG_LOG_TAG = 3715244738, | ||
| NON_INTERACTIVE_HANDSHAKE_LOG_TAG = 4046403018, | ||
| PRIVATE_LOG_FIRST_FIELD = 2769976252, | ||
| PUBLIC_LEAF_SLOT = 1247650290, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,13 @@ import { | |
| import { AztecAddress } from '@aztec/stdlib/aztec-address'; | ||
| import { siloNullifier } from '@aztec/stdlib/hash'; | ||
| import { PrivateContextInputs } from '@aztec/stdlib/kernel'; | ||
| import { type ContractClassLog, ExtendedDirectionalAppTaggingSecret, type TaggingIndexRange } from '@aztec/stdlib/logs'; | ||
| import { | ||
| type AppTaggingSecret, | ||
| ConstrainedAppTaggingSecret, | ||
| type ContractClassLog, | ||
| ExtendedDirectionalAppTaggingSecret, | ||
| type TaggingIndexRange, | ||
| } from '@aztec/stdlib/logs'; | ||
| import { Tag } from '@aztec/stdlib/logs'; | ||
| import { Note, type NoteStatus } from '@aztec/stdlib/note'; | ||
| import { | ||
|
|
@@ -198,7 +204,11 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP | |
| } | ||
|
|
||
| /** | ||
| * Returns the next app tag for a given sender and recipient pair. | ||
| * Returns the next app tag for a given sender and recipient pair (unconstrained delivery). | ||
| * | ||
| * The simulator owns the directional tagging secret (derived via ECDH from `(sender, recipient, contract)`), so it | ||
| * computes the full siloed tag here and hands the opaque value back to the caller. | ||
| * | ||
| * @param sender - The address sending the log | ||
| * @param recipient - The address receiving the log | ||
| * @returns An app tag to be used in a log. | ||
|
|
@@ -220,15 +230,40 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP | |
| return Tag.random(); | ||
| } | ||
|
|
||
| const index = await this.#getIndexToUseForSecret(extendedSecret); | ||
| const index = await this.#reserveNextIndexForSecret(extendedSecret); | ||
| this.logger.debug( | ||
| `Incrementing tagging index for sender: ${sender}, recipient: ${recipient}, contract: ${this.contractAddress} to ${index}`, | ||
| ); | ||
| this.taggingIndexCache.setLastUsedIndex(extendedSecret, index); | ||
|
|
||
| return Tag.compute({ extendedSecret, index }); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the next sender-side index for a constrained-delivery app-siloed shared secret. | ||
| * | ||
| * Unlike the unconstrained variant, the simulator does not own the secret: it was supplied by the calling contract | ||
| * (which retrieved it from an onchain handshake registry). The simulator only acts as a per-secret index counter. The caller | ||
| * computes the onchain tag itself. | ||
| * | ||
| * @param appSiloedSecret - The app-siloed shared secret retrieved from the handshake registry by the caller. | ||
| * @returns The next index to use for this secret. | ||
| */ | ||
| public async getNextConstrainedIndex(appSiloedSecret: Fr): Promise<number> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this detect already if another PXE with the same recipient-sender pair used an index? For example, PXE A uses 1, so PXE B detects it and moves on to index 2 Maybe the unconstrained path already did it, what why I'm asking. It would be a nice e2e test to have if I'm being honest
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized I edited the tag computation in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, that is exactly what we needed. I love it when the code already works as expected 🎉 No need to do anything else
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The siloing only checks unconstrained tags still though. So I will extend that one test to check both tag kinds. |
||
| const secret = new ConstrainedAppTaggingSecret(appSiloedSecret, this.contractAddress); | ||
| const index = await this.#reserveNextIndexForSecret(secret); | ||
| this.logger.debug( | ||
| `Incrementing tagging index for constrained-delivery secret in contract ${this.contractAddress} to ${index}`, | ||
| ); | ||
| return index; | ||
| } | ||
|
|
||
| /** Resolves the next index for a given tagging secret, syncing from chain if it is missing from the in-tx cache. */ | ||
| async #reserveNextIndexForSecret(secret: AppTaggingSecret): Promise<number> { | ||
| const index = await this.#getIndexToUseForSecret(secret); | ||
| this.taggingIndexCache.setLastUsedIndex(secret, index); | ||
| return index; | ||
| } | ||
|
|
||
| async #calculateExtendedDirectionalAppTaggingSecret( | ||
| contractAddress: AztecAddress, | ||
| sender: AztecAddress, | ||
|
|
@@ -245,7 +280,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP | |
| ); | ||
| } | ||
|
|
||
| async #getIndexToUseForSecret(secret: ExtendedDirectionalAppTaggingSecret): Promise<number> { | ||
| async #getIndexToUseForSecret(secret: AppTaggingSecret): Promise<number> { | ||
| // If we have the tagging index in the cache, we use it. If not we obtain it from the execution data provider. | ||
| const lastUsedIndexInTx = this.taggingIndexCache.getLastUsedIndex(secret); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.