From 8b9f074305446c5ca80072922c1ec06cf672c002 Mon Sep 17 00:00:00 2001 From: dbanks12 Date: Thu, 15 Feb 2024 15:31:47 +0000 Subject: [PATCH] chore(yellowpaper): fix notehashexists nullifierexists instructions --- .../docs/public-vm/gen/_instruction-set.mdx | 14 +++++----- yellow-paper/docs/public-vm/state.md | 4 +-- yellow-paper/docs/public-vm/type-structs.md | 26 +++++++++---------- .../InstructionSet/InstructionSet.js | 12 ++++----- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/yellow-paper/docs/public-vm/gen/_instruction-set.mdx b/yellow-paper/docs/public-vm/gen/_instruction-set.mdx index 4975bd6da85..d5da4c5c1df 100644 --- a/yellow-paper/docs/public-vm/gen/_instruction-set.mdx +++ b/yellow-paper/docs/public-vm/gen/_instruction-set.mdx @@ -328,7 +328,7 @@ context.machineState.pc = loc`} {`exists = context.worldState.noteHashes.has({ leafIndex: M[leafIndexOffset] - leaf: hash(context.environment.storageAddress, M[leafOffset]), + leaf: hash(context.environment.storageAddress, M[noteHashOffset]), }) M[existsOffset] = exists`} @@ -1351,24 +1351,24 @@ Check whether a note hash exists in the note hash tree (as of the start of the c - **Flags**: - **indirect**: Toggles whether each memory-offset argument is an indirect offset. Rightmost bit corresponds to 0th offset arg, etc. Indirect offsets result in memory accesses like `M[M[offset]]` instead of the more standard `M[offset]`. - **Args**: - - **leafOffset**: memory offset of the leaf + - **noteHashOffset**: memory offset of the note hash - **leafIndexOffset**: memory offset of the leaf index - **existsOffset**: memory offset specifying where to store operation's result (whether the note hash leaf exists) - **Expression**: {`exists = context.worldState.noteHashes.has({ leafIndex: M[leafIndexOffset] - leaf: hash(context.environment.storageAddress, M[leafOffset]), + leaf: hash(context.environment.storageAddress, M[noteHashOffset]), }) M[existsOffset] = exists`} - **World State access tracing**: {`context.worldStateAccessTrace.noteHashChecks.append( - TracedLeafCheck { + TracedNoteHashCheck { callPointer: context.environment.callPointer, leafIndex: M[leafIndexOffset] - leaf: M[leafOffset], + noteHash: M[noteHashOffset], exists: exists, // defined above counter: ++context.worldStateAccessTrace.accessCounter, } @@ -1433,9 +1433,9 @@ M[existsOffset] = exists`} - **World State access tracing**: {`context.worldStateAccessTrace.nullifierChecks.append( - TracedIndexedLeafCheck { + TracedNullifierCheck { callPointer: context.environment.callPointer, - leaf: M[nullifierOffset], + nullifier: M[nullifierOffset], exists: exists, // defined above counter: ++context.worldStateAccessTrace.accessCounter, } diff --git a/yellow-paper/docs/public-vm/state.md b/yellow-paper/docs/public-vm/state.md index c3dfada2cdd..473168bb3e9 100644 --- a/yellow-paper/docs/public-vm/state.md +++ b/yellow-paper/docs/public-vm/state.md @@ -77,9 +77,9 @@ Each entry in the world state access trace is listed below along with its type a | `contractCalls` | Contracts | `Vector` | [`*CALL`](./instruction-set#isa-section-call) | | `publicStorageReads` | Public Storage | `Vector` | [`SLOAD`](./instruction-set#isa-section-sload) | | `publicStorageWrites` | Public Storage | `Vector` | [`SSTORE`](./instruction-set#isa-section-sstore) | -| `noteHashChecks` | Note Hashes | `Vector` | [`NOTEHASHEXISTS`](./instruction-set#isa-section-notehashexists) | +| `noteHashChecks` | Note Hashes | `Vector` | [`NOTEHASHEXISTS`](./instruction-set#isa-section-notehashexists) | | `newNoteHashes` | Note Hashes | `Vector` | [`EMITNOTEHASH`](./instruction-set#isa-section-emitnotehash) | -| `nullifierChecks` | Nullifiers | `Vector` | [`NULLIFIERSEXISTS`](./instruction-set#isa-section-nullifierexists) | +| `nullifierChecks` | Nullifiers | `Vector` | [`NULLIFIERSEXISTS`](./instruction-set#isa-section-nullifierexists) | | `newNullifiers` | Nullifiers | `Vector` | [`EMITNULLIFIER`](./instruction-set#isa-section-emitnullifier) | | `l1ToL2MessageReads` | L1-To-L2 Messages | `Vector` | [`READL1TOL2MSG`](./instruction-set#isa-section-readl1tol2msg) | | `archiveChecks` | Headers | `Vector` | [`HEADERMEMBER`](./instruction-set#isa-section-headermember) | diff --git a/yellow-paper/docs/public-vm/type-structs.md b/yellow-paper/docs/public-vm/type-structs.md index 2b1793b19cc..c61a52d2070 100644 --- a/yellow-paper/docs/public-vm/type-structs.md +++ b/yellow-paper/docs/public-vm/type-structs.md @@ -45,18 +45,18 @@ This section lists type definitions relevant to AVM State and Circuit I/O. | `counter` | `field` | | | `endLifetime` | `field` | Equivalent to `endLifetime` of the containing contract call. The last `counter` at which this read/write should be considered to "exist" if this call or a parent reverted. | -#### _TracedNoteHash_ +#### _TracedNoteHashCheck_ | Field | Type | Description | | --- | --- | --- | | `callPointer` | `field` | Associates this item with a `TracedContractCall` entry in `worldStateAccessTrace.contractCalls` | -| `value` | `field` | | +| `leafIndex` | `field` | | +| `noteHash` | `field` | unsiloed | +| `exists` | `field` | | | `counter` | `field` | | -| `endLifetime` | `field` | Equivalent to `endLifetime` of the containing contract call. The last `counter` at which this object should be considered to "exist" if this call or a parent reverted. | - -> Note: `value` here is not siloed by contract address nor is it made unique with a nonce. Note hashes are siloed and made unique by the public kernel. +| `endLifetime` | `field` | Equivalent to `endLifetime` of the containing contract call. | -#### _TracedNullifier_ +#### _TracedNoteHash_ | Field | Type | Description | | --- | --- | --- | @@ -65,26 +65,26 @@ This section lists type definitions relevant to AVM State and Circuit I/O. | `counter` | `field` | | | `endLifetime` | `field` | Equivalent to `endLifetime` of the containing contract call. The last `counter` at which this object should be considered to "exist" if this call or a parent reverted. | -#### _TracedIndexedLeafCheck_ +> Note: `value` here is not siloed by contract address nor is it made unique with a nonce. Note hashes are siloed and made unique by the public kernel. + +#### _TracedNullifierCheck_ | Field | Type | Description | | --- | --- | --- | | `callPointer` | `field` | Associates this item with a `TracedContractCall` entry in `worldStateAccessTrace.contractCalls` | -| `leaf` | `field` | | +| `nullifier` | `field` | unsiloed | | `exists` | `field` | | | `counter` | `field` | | | `endLifetime` | `field` | Equivalent to `endLifetime` of the containing contract call. | -#### _TracedLeafCheck_ +#### _TracedNullifier_ | Field | Type | Description | | --- | --- | --- | | `callPointer` | `field` | Associates this item with a `TracedContractCall` entry in `worldStateAccessTrace.contractCalls` | -| `leafIndex` | `field` | | -| `leaf` | `field` | | -| `exists` | `field` | | +| `value` | `field` | | | `counter` | `field` | | -| `endLifetime` | `field` | Equivalent to `endLifetime` of the containing contract call. | +| `endLifetime` | `field` | Equivalent to `endLifetime` of the containing contract call. The last `counter` at which this object should be considered to "exist" if this call or a parent reverted. | #### _TracedArchiveLeafCheck_ diff --git a/yellow-paper/src/preprocess/InstructionSet/InstructionSet.js b/yellow-paper/src/preprocess/InstructionSet/InstructionSet.js index 1eeff0fd346..5b89dfa10c5 100644 --- a/yellow-paper/src/preprocess/InstructionSet/InstructionSet.js +++ b/yellow-paper/src/preprocess/InstructionSet/InstructionSet.js @@ -829,24 +829,24 @@ context.worldStateAccessTrace.publicStorageWrites.append( {"name": "indirect", "description": INDIRECT_FLAG_DESCRIPTION}, ], "Args": [ - {"name": "leafOffset", "description": "memory offset of the leaf"}, + {"name": "noteHashOffset", "description": "memory offset of the note hash"}, {"name": "leafIndexOffset", "description": "memory offset of the leaf index"}, {"name": "existsOffset", "description": "memory offset specifying where to store operation's result (whether the note hash leaf exists)"}, ], "Expression": ` exists = context.worldState.noteHashes.has({ leafIndex: M[leafIndexOffset] - leaf: hash(context.environment.storageAddress, M[leafOffset]), + leaf: hash(context.environment.storageAddress, M[noteHashOffset]), }) M[existsOffset] = exists `, "Summary": "Check whether a note hash exists in the note hash tree (as of the start of the current block)", "World State access tracing": ` context.worldStateAccessTrace.noteHashChecks.append( - TracedLeafCheck { + TracedNoteHashCheck { callPointer: context.environment.callPointer, leafIndex: M[leafIndexOffset] - leaf: M[leafOffset], + noteHash: M[noteHashOffset], exists: exists, // defined above counter: ++context.worldStateAccessTrace.accessCounter, } @@ -905,9 +905,9 @@ M[existsOffset] = exists "Summary": "Check whether a nullifier exists in the nullifier tree (including nullifiers from earlier in the current transaction or from earlier in the current block)", "World State access tracing": ` context.worldStateAccessTrace.nullifierChecks.append( - TracedIndexedLeafCheck { + TracedNullifierCheck { callPointer: context.environment.callPointer, - leaf: M[nullifierOffset], + nullifier: M[nullifierOffset], exists: exists, // defined above counter: ++context.worldStateAccessTrace.accessCounter, }