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

chore(yellowpaper): fix notehashexists nullifierexists instructions #4625

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions yellow-paper/docs/public-vm/gen/_instruction-set.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ context.machineState.pc = loc`}
<td><CodeBlock language="jsx">
{`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`}
</CodeBlock></td>
Expand Down Expand Up @@ -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**:
<CodeBlock language="jsx">
{`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`}
</CodeBlock>
- **World State access tracing**:
<CodeBlock language="jsx">
{`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,
}
Expand Down Expand Up @@ -1433,9 +1433,9 @@ M[existsOffset] = exists`}
- **World State access tracing**:
<CodeBlock language="jsx">
{`context.worldStateAccessTrace.nullifierChecks.append(
TracedIndexedLeafCheck {
TracedNullifierCheck {
callPointer: context.environment.callPointer,
leaf: M[nullifierOffset],
nullifier: M[nullifierOffset],
exists: exists, // defined above
counter: ++context.worldStateAccessTrace.accessCounter,
}
Expand Down
4 changes: 2 additions & 2 deletions yellow-paper/docs/public-vm/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ Each entry in the world state access trace is listed below along with its type a
| `contractCalls` | Contracts | `Vector<TracedContractCall>` | [`*CALL`](./instruction-set#isa-section-call) |
| `publicStorageReads` | Public Storage | `Vector<TracedStorageRead>` | [`SLOAD`](./instruction-set#isa-section-sload) |
| `publicStorageWrites` | Public Storage | `Vector<TracedStorageWrite>` | [`SSTORE`](./instruction-set#isa-section-sstore) |
| `noteHashChecks` | Note Hashes | `Vector<TracedLeafCheck>` | [`NOTEHASHEXISTS`](./instruction-set#isa-section-notehashexists) |
| `noteHashChecks` | Note Hashes | `Vector<TracedNoteHashCheck>` | [`NOTEHASHEXISTS`](./instruction-set#isa-section-notehashexists) |
| `newNoteHashes` | Note Hashes | `Vector<TracedNoteHash>` | [`EMITNOTEHASH`](./instruction-set#isa-section-emitnotehash) |
| `nullifierChecks` | Nullifiers | `Vector<TracedIndexedLeafCheck>` | [`NULLIFIERSEXISTS`](./instruction-set#isa-section-nullifierexists) |
| `nullifierChecks` | Nullifiers | `Vector<TracedNullifierCheck>` | [`NULLIFIERSEXISTS`](./instruction-set#isa-section-nullifierexists) |
| `newNullifiers` | Nullifiers | `Vector<TracedNullifier>` | [`EMITNULLIFIER`](./instruction-set#isa-section-emitnullifier) |
| `l1ToL2MessageReads` | L1-To-L2 Messages | `Vector<TracedL1ToL2MessageRead>` | [`READL1TOL2MSG`](./instruction-set#isa-section-readl1tol2msg) |
| `archiveChecks` | Headers | `Vector<TracedArchiveLeafCheck>` | [`HEADERMEMBER`](./instruction-set#isa-section-headermember) |
Expand Down
26 changes: 13 additions & 13 deletions yellow-paper/docs/public-vm/type-structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| --- | --- | --- |
Expand All @@ -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_

Expand Down
12 changes: 6 additions & 6 deletions yellow-paper/src/preprocess/InstructionSet/InstructionSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
Loading