Skip to content

Commit

Permalink
chore: remove unimplemented headermember opcode from avm (#8407)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 authored Sep 5, 2024
1 parent 94006a9 commit cfea06e
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 152 deletions.
2 changes: 0 additions & 2 deletions avm-transpiler/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub enum AvmOpcode {
NULLIFIEREXISTS,
EMITNULLIFIER,
L1TOL2MSGEXISTS,
HEADERMEMBER,
GETCONTRACTINSTANCE,
EMITUNENCRYPTEDLOG,
SENDL2TOL1MSG,
Expand Down Expand Up @@ -147,7 +146,6 @@ impl AvmOpcode {
AvmOpcode::NULLIFIEREXISTS => "NULLIFIEREXISTS", // Notes & Nullifiers
AvmOpcode::EMITNULLIFIER => "EMITNULLIFIER", // Notes & Nullifiers
AvmOpcode::L1TOL2MSGEXISTS => "L1TOL2MSGEXISTS", // Messages
AvmOpcode::HEADERMEMBER => "HEADERMEMBER", // Archive tree & Headers

// Accrued Substate
AvmOpcode::EMITUNENCRYPTEDLOG => "EMITUNENCRYPTEDLOG",
Expand Down
3 changes: 1 addition & 2 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/fixed_gas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const std::unordered_map<OpCode, FixedGasTable::GasRow> GAS_COST_TABLE = {
{ OpCode::NULLIFIEREXISTS, make_cost(AVM_NULLIFIEREXISTS_BASE_L2_GAS, 0, AVM_NULLIFIEREXISTS_DYN_L2_GAS, 0) },
{ OpCode::EMITNULLIFIER, make_cost(AVM_EMITNULLIFIER_BASE_L2_GAS, 0, AVM_EMITNULLIFIER_DYN_L2_GAS, 0) },
{ OpCode::L1TOL2MSGEXISTS, make_cost(AVM_L1TOL2MSGEXISTS_BASE_L2_GAS, 0, AVM_L1TOL2MSGEXISTS_DYN_L2_GAS, 0) },
{ OpCode::HEADERMEMBER, make_cost(AVM_HEADERMEMBER_BASE_L2_GAS, 0, AVM_HEADERMEMBER_DYN_L2_GAS, 0) },
{ OpCode::GETCONTRACTINSTANCE,
make_cost(AVM_GETCONTRACTINSTANCE_BASE_L2_GAS, 0, AVM_GETCONTRACTINSTANCE_DYN_L2_GAS, 0) },
{ OpCode::EMITUNENCRYPTEDLOG,
Expand Down Expand Up @@ -108,4 +107,4 @@ const FixedGasTable& FixedGasTable::get()
return table;
}

} // namespace bb::avm_trace
} // namespace bb::avm_trace
2 changes: 0 additions & 2 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ std::string to_string(OpCode opcode)
return "EMITNULLIFIER";
case OpCode::L1TOL2MSGEXISTS:
return "L1TOL2MSGEXISTS";
case OpCode::HEADERMEMBER:
return "HEADERMEMBER";
case OpCode::GETCONTRACTINSTANCE:
return "GETCONTRACTINSTANCE";
// Accrued Substate
Expand Down
1 change: 0 additions & 1 deletion barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ enum class OpCode : uint8_t {
NULLIFIEREXISTS, // Notes & Nullifiers
EMITNULLIFIER, // Notes & Nullifiers
L1TOL2MSGEXISTS, // Messages
HEADERMEMBER, // Archive tree & Headers
GETCONTRACTINSTANCE,

// Accrued Substate
Expand Down
2 changes: 0 additions & 2 deletions barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
#define AVM_NULLIFIEREXISTS_BASE_L2_GAS 260
#define AVM_EMITNULLIFIER_BASE_L2_GAS 260
#define AVM_L1TOL2MSGEXISTS_BASE_L2_GAS 260
#define AVM_HEADERMEMBER_BASE_L2_GAS 0
#define AVM_GETCONTRACTINSTANCE_BASE_L2_GAS 480
#define AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS 180
#define AVM_SENDL2TOL1MSG_BASE_L2_GAS 260
Expand Down Expand Up @@ -173,7 +172,6 @@
#define AVM_NULLIFIEREXISTS_DYN_L2_GAS 0
#define AVM_EMITNULLIFIER_DYN_L2_GAS 0
#define AVM_L1TOL2MSGEXISTS_DYN_L2_GAS 0
#define AVM_HEADERMEMBER_DYN_L2_GAS 0
#define AVM_GETCONTRACTINSTANCE_DYN_L2_GAS 0
#define AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS 180
#define AVM_SENDL2TOL1MSG_DYN_L2_GAS 0
Expand Down
4 changes: 0 additions & 4 deletions docs/docs/protocol-specs/public-vm/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ The AVM's exceptional halting conditions area listed below:
// Read L1 to L2 messages
assert instructions[machineState.pc].opcode != L1TOL2MSGEXISTS
OR worldStateAccessTrace.l1ToL2MessagesChecks.length < 1024
// Archive tree & Headers
assert instructions[machineState.pc].opcode != HEADERMEMBER
OR archiveChecks.length < 1024
```
1. **Maximum accrued substate entries (per-category) exceeded**
```
Expand Down
91 changes: 17 additions & 74 deletions docs/docs/protocol-specs/public-vm/gen/_instruction-set.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,6 @@ M[existsOffset] = exists`}
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x2e</td>
<td style={{'text-align': 'center'}}><a id='isa-table-headermember'/><Markdown>\[\`HEADERMEMBER\`\](#isa-section-headermember)</Markdown></td>
<td><Markdown>(UNIMPLEMENTED) Check if a header exists in the [archive tree](../state/archive) and retrieve the specified member if so</Markdown></td>
<td><CodeBlock language="jsx">
{`exists = context.worldState.header.has({
leafIndex: M[blockIndexOffset], leaf: M[msgKeyOffset]
})
M[existsOffset] = exists
if exists:
header = context.worldState.headers.get(M[blockIndexOffset])
M[dstOffset] = header[M[memberIndexOffset]] // member`}
</CodeBlock></td>
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x2f</td>
<td style={{'text-align': 'center'}}><a id='isa-table-getcontractinstance'/><Markdown>\[\`GETCONTRACTINSTANCE\`\](#isa-section-getcontractinstance)</Markdown></td>
<td><Markdown>Copies contract instance data to memory</Markdown></td>
<td><CodeBlock language="jsx">
Expand All @@ -427,7 +413,7 @@ if exists:
</CodeBlock></td>
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x30</td>
<td style={{'text-align': 'center'}}>0x2f</td>
<td style={{'text-align': 'center'}}><a id='isa-table-emitunencryptedlog'/><Markdown>\[\`EMITUNENCRYPTEDLOG\`\](#isa-section-emitunencryptedlog)</Markdown></td>
<td><Markdown>Emit an unencrypted log</Markdown></td>
<td><CodeBlock language="jsx">
Expand All @@ -440,7 +426,7 @@ if exists:
</CodeBlock></td>
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x31</td>
<td style={{'text-align': 'center'}}>0x30</td>
<td style={{'text-align': 'center'}}><a id='isa-table-sendl2tol1msg'/><Markdown>\[\`SENDL2TOL1MSG\`\](#isa-section-sendl2tol1msg)</Markdown></td>
<td><Markdown>Send an L2-to-L1 message</Markdown></td>
<td><CodeBlock language="jsx">
Expand All @@ -454,7 +440,7 @@ if exists:
</CodeBlock></td>
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x32</td>
<td style={{'text-align': 'center'}}>0x31</td>
<td style={{'text-align': 'center'}}><a id='isa-table-call'/><Markdown>\[\`CALL\`\](#isa-section-call)</Markdown></td>
<td><Markdown>Call into another contract</Markdown></td>
<td><CodeBlock language="jsx">
Expand All @@ -469,7 +455,7 @@ updateContextAfterNestedCall(context, instr.args, nestedContext)`}
</CodeBlock></td>
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x33</td>
<td style={{'text-align': 'center'}}>0x32</td>
<td style={{'text-align': 'center'}}><a id='isa-table-staticcall'/><Markdown>\[\`STATICCALL\`\](#isa-section-staticcall)</Markdown></td>
<td><Markdown>Call into another contract, disallowing World State and Accrued Substate modifications</Markdown></td>
<td><CodeBlock language="jsx">
Expand All @@ -484,7 +470,7 @@ updateContextAfterNestedCall(context, instr.args, nestedContext)`}
</CodeBlock></td>
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x34</td>
<td style={{'text-align': 'center'}}>0x33</td>
<td style={{'text-align': 'center'}}><a id='isa-table-delegatecall'/><Markdown>\[\`DELEGATECALL\`\](#isa-section-delegatecall)</Markdown></td>
<td><Markdown>(UNIMPLEMENTED) Call into another contract, but keep the caller's `sender` and `storageAddress`</Markdown></td>
<td><CodeBlock language="jsx">
Expand All @@ -499,7 +485,7 @@ updateContextAfterNestedCall(context, instr.args, nestedContext)`}
</CodeBlock></td>
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x35</td>
<td style={{'text-align': 'center'}}>0x34</td>
<td style={{'text-align': 'center'}}><a id='isa-table-return'/><Markdown>\[\`RETURN\`\](#isa-section-return)</Markdown></td>
<td><Markdown>Halt execution within this context (without revert), optionally returning some data</Markdown></td>
<td><CodeBlock language="jsx">
Expand All @@ -508,7 +494,7 @@ halt`}
</CodeBlock></td>
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x36</td>
<td style={{'text-align': 'center'}}>0x35</td>
<td style={{'text-align': 'center'}}><a id='isa-table-revert'/><Markdown>\[\`REVERT\`\](#isa-section-revert)</Markdown></td>
<td><Markdown>Halt execution within this context as `reverted`, optionally returning some data</Markdown></td>
<td><CodeBlock language="jsx">
Expand All @@ -518,7 +504,7 @@ halt`}
</CodeBlock></td>
</tr>
<tr>
<td style={{'text-align': 'center'}}>0x37</td>
<td style={{'text-align': 'center'}}>0x36</td>
<td style={{'text-align': 'center'}}><a id='isa-table-to_radix_le'/><Markdown>\[\`TORADIXLE\`\](#isa-section-to_radix_le)</Markdown></td>
<td><Markdown>Convert a word to an array of limbs in little-endian radix form</Markdown></td>
<td><Markdown>TBD: Storage of limbs and if T[dstOffset] is constrained to U8</Markdown></td>
Expand Down Expand Up @@ -1519,55 +1505,12 @@ M[existsOffset] = exists`}
- **Bit-size**: 120


### <a id='isa-section-headermember'/>`HEADERMEMBER`
(UNIMPLEMENTED) Check if a header exists in the [archive tree](../state/archive) and retrieve the specified member if so

[See in table.](#isa-table-headermember)

- **Opcode**: 0x2e
- **Category**: World State - Archive Tree & Headers
- **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**:
- **blockIndexOffset**: memory offset of the block index (same as archive tree leaf index) of the header to access
- **memberIndexOffset**: memory offset of the index of the member to retrieve from the header of the specified block
- **existsOffset**: memory offset specifying where to store operation's result (whether the leaf exists in the archive tree)
- **dstOffset**: memory offset specifying where to store operation's result (the retrieved header member)
- **Expression**:
<CodeBlock language="jsx">
{`exists = context.worldState.header.has({
leafIndex: M[blockIndexOffset], leaf: M[msgKeyOffset]
})
M[existsOffset] = exists
if exists:
header = context.worldState.headers.get(M[blockIndexOffset])
M[dstOffset] = header[M[memberIndexOffset]] // member`}
</CodeBlock>
- **World State access tracing**:
<CodeBlock language="jsx">
{`context.worldStateAccessTrace.archiveChecks.append(
TracedArchiveLeafCheck {
leafIndex: M[blockIndexOffset], // leafIndex == blockIndex
leaf: exists ? hash(header) : 0, // "exists" defined above
}
)`}
</CodeBlock>
- **Additional AVM circuit checks**: Hashes entire header to archive leaf for tracing. Aggregates header accesses and so that a header need only be hashed once.
- **Triggers downstream circuit operations**: Archive tree membership check
- **Tag updates**:
<CodeBlock language="jsx">
{`T[existsOffset] = u8
T[dstOffset] = field`}
</CodeBlock>
- **Bit-size**: 152


### <a id='isa-section-getcontractinstance'/>`GETCONTRACTINSTANCE`
Copies contract instance data to memory

[See in table.](#isa-table-getcontractinstance)

- **Opcode**: 0x2f
- **Opcode**: 0x2e
- **Category**: Other
- **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]`.
Expand Down Expand Up @@ -1597,7 +1540,7 @@ Emit an unencrypted log

[See in table.](#isa-table-emitunencryptedlog)

- **Opcode**: 0x30
- **Opcode**: 0x2f
- **Category**: Accrued Substate - Logging
- **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]`.
Expand All @@ -1622,7 +1565,7 @@ Send an L2-to-L1 message

[See in table.](#isa-table-sendl2tol1msg)

- **Opcode**: 0x31
- **Opcode**: 0x30
- **Category**: Accrued Substate - Messaging
- **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]`.
Expand All @@ -1648,7 +1591,7 @@ Call into another contract

[See in table.](#isa-table-call)

- **Opcode**: 0x32
- **Opcode**: 0x31
- **Category**: Control Flow - Contract Calls
- **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]`.
Expand Down Expand Up @@ -1695,7 +1638,7 @@ Call into another contract, disallowing World State and Accrued Substate modific

[See in table.](#isa-table-staticcall)

- **Opcode**: 0x33
- **Opcode**: 0x32
- **Category**: Control Flow - Contract Calls
- **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]`.
Expand Down Expand Up @@ -1739,7 +1682,7 @@ T[retOffset:retOffset+retSize] = field`}

[See in table.](#isa-table-delegatecall)

- **Opcode**: 0x34
- **Opcode**: 0x33
- **Category**: Control Flow - Contract Calls
- **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]`.
Expand Down Expand Up @@ -1783,7 +1726,7 @@ Halt execution within this context (without revert), optionally returning some d

[See in table.](#isa-table-return)

- **Opcode**: 0x35
- **Opcode**: 0x34
- **Category**: Control Flow - Contract Calls
- **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]`.
Expand All @@ -1805,7 +1748,7 @@ Halt execution within this context as `reverted`, optionally returning some data

[See in table.](#isa-table-revert)

- **Opcode**: 0x36
- **Opcode**: 0x35
- **Category**: Control Flow - Contract Calls
- **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]`.
Expand All @@ -1828,7 +1771,7 @@ Convert a word to an array of limbs in little-endian radix form

[See in table.](#isa-table-to_radix_le)

- **Opcode**: 0x37
- **Opcode**: 0x36
- **Category**: Conversions
- **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]`.
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/protocol-specs/public-vm/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ The following table defines an AVM context's world state interface:
| `noteHashes` | [`NOTEHASHEXISTS`](./instruction-set#isa-section-notehashexists) (membership-checks (start-of-block)), [`EMITNOTEHASH`](./instruction-set#isa-section-emitnotehash) (appends) |
| `nullifiers` | [`NULLIFIERSEXISTS`](./instruction-set#isa-section-nullifierexists) membership-checks (latest), [`EMITNULLIFIER`](./instruction-set#isa-section-emitnullifier) (appends) |
| `l1ToL2Messages` | [`L1TOL2MSGEXISTS`](./instruction-set#isa-section-l1tol2msgexists) (membership-checks (start-of-block)) |
| `headers` | [`HEADERMEMBER`](./instruction-set#isa-section-headermember) (membership-checks & leaf-preimage-reads) |

> \* `*CALL` is short for `CALL`/`STATICCALL`/`DELEGATECALL`.
Expand Down Expand Up @@ -81,7 +80,6 @@ Each entry in the world state access trace is listed below along with its type a
| `nullifierChecks` | Nullifiers | `Vector<TracedNullifierCheck>` | [`NULLIFIERSEXISTS`](./instruction-set#isa-section-nullifierexists) |
| `nullifiers` | Nullifiers | `Vector<TracedNullifier>` | [`EMITNULLIFIER`](./instruction-set#isa-section-emitnullifier) |
| `l1ToL2MessageChecks` | L1-To-L2 Messages | `Vector<TracedL1ToL2MessageCheck>` | [`L1TOL2MSGEXISTS`](./instruction-set#isa-section-l1tol2msgexists) |
| `archiveChecks` | Headers | `Vector<TracedArchiveLeafCheck>` | [`HEADERMEMBER`](./instruction-set#isa-section-headermember) |

> The types tracked in these trace vectors are defined [here](./type-structs).
Expand Down
55 changes: 0 additions & 55 deletions docs/src/preprocess/InstructionSet/InstructionSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1247,61 +1247,6 @@ context.worldStateAccessTrace.l1ToL2MessagesChecks.append(
"Tag checks": "",
"Tag updates": `
T[existsOffset] = u8,
`,
},
{
id: "headermember",
Name: "`HEADERMEMBER`",
Category: "World State - Archive Tree & Headers",
Flags: [{ name: "indirect", description: INDIRECT_FLAG_DESCRIPTION }],
Args: [
{
name: "blockIndexOffset",
description:
"memory offset of the block index (same as archive tree leaf index) of the header to access",
},
{
name: "memberIndexOffset",
description:
"memory offset of the index of the member to retrieve from the header of the specified block",
},
{
name: "existsOffset",
description:
"memory offset specifying where to store operation's result (whether the leaf exists in the archive tree)",
},
{
name: "dstOffset",
description:
"memory offset specifying where to store operation's result (the retrieved header member)",
},
],
Expression: `
exists = context.worldState.header.has({
leafIndex: M[blockIndexOffset], leaf: M[msgKeyOffset]
})
M[existsOffset] = exists
if exists:
header = context.worldState.headers.get(M[blockIndexOffset])
M[dstOffset] = header[M[memberIndexOffset]] // member
`,
Summary:
"(UNIMPLEMENTED) Check if a header exists in the [archive tree](../state/archive) and retrieve the specified member if so",
"World State access tracing": `
context.worldStateAccessTrace.archiveChecks.append(
TracedArchiveLeafCheck {
leafIndex: M[blockIndexOffset], // leafIndex == blockIndex
leaf: exists ? hash(header) : 0, // "exists" defined above
}
)
`,
"Additional AVM circuit checks":
"Hashes entire header to archive leaf for tracing. Aggregates header accesses and so that a header need only be hashed once.",
"Triggers downstream circuit operations": "Archive tree membership check",
"Tag checks": "",
"Tag updates": `
T[existsOffset] = u8
T[dstOffset] = field
`,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ global AVM_EMITNOTEHASH_BASE_L2_GAS: u16 = 260;
global AVM_NULLIFIEREXISTS_BASE_L2_GAS: u16 = 260;
global AVM_EMITNULLIFIER_BASE_L2_GAS: u16 = 260;
global AVM_L1TOL2MSGEXISTS_BASE_L2_GAS: u16 = 260;
global AVM_HEADERMEMBER_BASE_L2_GAS: u16 = 0;
global AVM_GETCONTRACTINSTANCE_BASE_L2_GAS: u16 = 480;
global AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS: u16 = 180;
global AVM_SENDL2TOL1MSG_BASE_L2_GAS: u16 = 260;
Expand Down Expand Up @@ -521,7 +520,6 @@ global AVM_EMITNOTEHASH_DYN_L2_GAS: u16 = 0;
global AVM_NULLIFIEREXISTS_DYN_L2_GAS: u16 = 0;
global AVM_EMITNULLIFIER_DYN_L2_GAS: u16 = 0;
global AVM_L1TOL2MSGEXISTS_DYN_L2_GAS: u16 = 0;
global AVM_HEADERMEMBER_DYN_L2_GAS: u16 = 0;
global AVM_GETCONTRACTINSTANCE_DYN_L2_GAS: u16 = 0;
global AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS: u16 = 180;
global AVM_SENDL2TOL1MSG_DYN_L2_GAS: u16 = 0;
Expand Down
Loading

0 comments on commit cfea06e

Please sign in to comment.