AztecProtocol / aztec-packages

Apache License 2.0
207 stars 241 forks source link

[EPIC] AVM simulator & witgen perform all tree accesses, siloing & preimage hashing #9444

Open dbanks12 opened 1 month ago

dbanks12 commented 1 month ago

This ticket is only for simulator & witgen tasks. There is a follow-up task for circuit/constraining: https://github.com/AztecProtocol/aztec-packages/issues/9457

Simulator tasks

These will be changes to AvmPersistableStateManager to perform siloing, hashing, & membership checks.

### \[SIMULATOR] Siloing & hashing
- [x] Silo storage slot to public data leaf index (`SLOAD` & `SSTORE`)
- [x] Silo nullifiers (`NULLIFIEREXISTS` & `EMITNULLIFIER`)
- [x] Hash nullifier leaf preimages to leaf (`NULLIFIEREXISTS` & `EMITNULLIFIER`)
- [x] Derive contract address nullifier from contract instance preimage (`GETCONTRACTINSTANCE`)
- [ ] Hash unencrypted log preimages (`EMITUNENCRYPTEDLOG`)
### \[SIMULATOR] General tree access
- [x] Support tree root updates, snapshots, rollbacks (based on current phase), & place final roots in public inputs
- [ ] Insert all _non-revertible_ side effects from *private* at public simulation startup (before setup phase)
- [ ] Insert all _revertible_ side effects from *private* after setup phase, before app-logic phase
### \[SIMULATOR] Read opcodes
- [x] Membership check for `SLOAD`
- [x] Membership check for `NOTEHASHEXISTS`
- [x] Low-leaf membership check for `NULLIFIEREXISTS`
- [x] Membership check for `L1TOL2MESSAGEEXISTS`
- [ ] Low-leaf nullifier membership check for `GETCONTRACTINSTANCE`
### \[SIMULATOR] Write opcodes
- [x] Membership check & update for `SSTORE`
- [x] Membership check & insertion for `EMITNOTEHASH`
- [x] Low-leaf membership check & update, insertion path empty check & insertion for `EMITNULLIFIER`
### [SIMULATOR] Contract bytecode
- [ ] Contract address membership check per bytecode

Hinting tasks

These will be changes to AvmPersistableStateManager & the SideEffectTrace. The state manager will pass preimages and membership witnesses to the trace which will then craft hints.

### Hinting tasks
- [x] Simulator sends public data tree read membership check hints to witgen
- [x] Simulator sends note hash read membership check hints to witgen
- [x] Simulator sends nullifier read membership check hints to witgen
- [x] Simulator sends l1 to l2 message read membership check hints to witgen
- [x] Simulator sends public data tree update membership check hints to witgen
- [x] Simulator sends note hash insertion membership check hints to witgen
- [x] Simulator sends nullifier insertion membership check hints to witgen

Witgen tasks

Witgen will accept hints from TS, perform siloing, hashing, membership checks.

### [WITGEN] Siloing & hashing
- [ ] Silo storage slot to public data leaf index (`SLOAD` & `SSTORE`)
- [ ] Silo nullifiers (`NULLIFIEREXISTS` & `EMITNULLIFIER`)
- [ ] Hash nullifier leaf preimages to leaf (`NULLIFIEREXISTS` & `EMITNULLIFIER`)
- [ ] Derive contract address nullifier from contract instance preimage (`GETCONTRACTINSTANCE`)
- [ ] Hash unencrypted log preimages (`EMITUNENCRYPTEDLOG`)
### \[WITGEN] General tree access
- [ ] Support tree root updates, snapshots, rollbacks (based on current phase), & place final roots in public inputs
- [ ] Insert all _non-revertible_ side effects from *private* at public simulation startup (before setup phase)
- [ ] Insert all _revertible_ side effects from *private* after setup phase, before app-logic phase
### [WITGEN] Read opcodes
- [ ] Membership check for `SLOAD`
- [ ] Membership check for `NOTEHASHEXISTS`
- [ ] Low-leaf membership check for `NULLIFIEREXISTS`
- [ ] Membership check for `L1TOL2MESSAGEEXISTS`
- [ ] Low-leaf nullifier membership check for `GETCONTRACTINSTANCE`
### [WITGEN] Write opcodes
- [ ] Membership check & update for `SSTORE`
- [ ] Membership check & insertion for `EMITNOTEHASH`
- [ ] Low-leaf membership check & update, insertion path empty check & insertion for `EMITNULLIFIER`
### [WITGEN] Contract bytecode
- [ ] Contract address membership check per bytecode
dbanks12 commented 1 month ago

Related: https://github.com/AztecProtocol/aztec-packages/issues/8287