From e2d877cf0c53206e6a57b72722acce4dc2dc1996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Fri, 27 Sep 2024 09:21:43 +0200 Subject: [PATCH] refactor: nuking encryption oracles (#8817) We've had encryption oracles which were completely unused. I originally created them when we didn't have a functional Noir ones. No point in keeping them around as at this point it was just an unnecessary maintenance cost. --- .../aztec-nr/aztec/src/oracle/encryption.nr | 12 -- .../aztec-nr/aztec/src/oracle/logs.nr | 103 ++---------------- .../aztec-nr/aztec/src/oracle/mod.nr | 1 - .../contracts/test_contract/src/main.nr | 20 ++-- .../aes128_encrypt/src/main.nr | 27 ++--- .../simulator/src/acvm/oracle/oracle.ts | 82 +------------- .../simulator/src/acvm/oracle/typed_oracle.ts | 29 ----- .../src/client/client_execution_context.ts | 85 +-------------- yarn-project/txe/src/oracle/txe_oracle.ts | 50 +-------- .../txe/src/txe_service/txe_service.ts | 36 ------ 10 files changed, 33 insertions(+), 412 deletions(-) delete mode 100644 noir-projects/aztec-nr/aztec/src/oracle/encryption.nr diff --git a/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr b/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr deleted file mode 100644 index cc9969fa7c7..00000000000 --- a/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr +++ /dev/null @@ -1,12 +0,0 @@ -#[oracle(aes128Encrypt)] -unconstrained pub fn aes128_encrypt_oracle( - input: [u8; N], - iv: [u8; 16], - key: [u8; 16] -) -> [u8; M] {} - -// AES 128 CBC with PKCS7 is padding to multiples of 16 bytes so M has to be a multiple of 16! -// (e.g. from 65 bytes long input you get 80 bytes long output and M has to be set to `80`) -unconstrained pub fn aes128_encrypt(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8; M] { - aes128_encrypt_oracle(input, iv, key) -} diff --git a/noir-projects/aztec-nr/aztec/src/oracle/logs.nr b/noir-projects/aztec-nr/aztec/src/oracle/logs.nr index e1384ffc17a..a84be6e54b8 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/logs.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/logs.nr @@ -1,116 +1,33 @@ -use dep::protocol_types::{address::AztecAddress, point::Point}; +use dep::protocol_types::address::AztecAddress; // = 480 + 32 * N bytes #[oracle(emitEncryptedNoteLog)] unconstrained fn emit_encrypted_note_log_oracle(_note_hash_counter: u32, _encrypted_note: [u8; M], _counter: u32) {} -unconstrained pub fn emit_encrypted_note_log( - note_hash_counter: u32, - encrypted_note: [u8; M], - counter: u32 -) { +unconstrained pub fn emit_encrypted_note_log(note_hash_counter: u32, encrypted_note: [u8; M], counter: u32) { emit_encrypted_note_log_oracle(note_hash_counter, encrypted_note, counter) } #[oracle(emitEncryptedEventLog)] -unconstrained fn emit_encrypted_event_log_oracle(_contract_address: AztecAddress, _randomness: Field, _encrypted_event: [u8; M], _counter: u32) {} - -unconstrained pub fn emit_encrypted_event_log( - contract_address: AztecAddress, - randomness: Field, - encrypted_event: [u8; M], - counter: u32 -) { - emit_encrypted_event_log_oracle(contract_address, randomness, encrypted_event, counter) -} - -// = 480 + 32 * N bytes -#[oracle(computeEncryptedNoteLog)] -unconstrained fn compute_encrypted_note_log_oracle( - _contract_address: AztecAddress, - _storage_slot: Field, - _note_type_id: Field, - _ovsk_app: Field, - _ovpk_m: Point, - _ivpk_m: Point, - _recipient: AztecAddress, - _preimage: [Field; N] -) -> [u8; M] {} - -unconstrained pub fn compute_encrypted_note_log( - contract_address: AztecAddress, - storage_slot: Field, - note_type_id: Field, - ovsk_app: Field, - ovpk_m: Point, - ivpk_m: Point, - recipient: AztecAddress, - preimage: [Field; N] -) -> [u8; M] { - compute_encrypted_note_log_oracle( - contract_address, - storage_slot, - note_type_id, - ovsk_app, - ovpk_m, - ivpk_m, - recipient, - preimage - ) -} - -// = 480 + 32 * N bytes -#[oracle(computeEncryptedEventLog)] -unconstrained fn compute_encrypted_event_log_oracle( +unconstrained fn emit_encrypted_event_log_oracle( _contract_address: AztecAddress, _randomness: Field, - _event_type_id: Field, - _ovsk_app: Field, - _ovpk_m: Point, - _ivpk_m: Point, - _recipient: AztecAddress, - _preimage: [Field; N] -) -> [u8; M] {} + _encrypted_event: [u8; M], + _counter: u32 +) {} -unconstrained pub fn compute_encrypted_event_log( - contract_address: AztecAddress, - randomness: Field, - event_type_id: Field, - ovsk_app: Field, - ovpk_m: Point, - ivpk_m: Point, - recipient: AztecAddress, - preimage: [Field; N] -) -> [u8; M] { - compute_encrypted_event_log_oracle( - contract_address, - randomness, - event_type_id, - ovsk_app, - ovpk_m, - ivpk_m, - recipient, - preimage - ) +unconstrained pub fn emit_encrypted_event_log(contract_address: AztecAddress, randomness: Field, encrypted_event: [u8; M], counter: u32) { + emit_encrypted_event_log_oracle(contract_address, randomness, encrypted_event, counter) } - #[oracle(emitUnencryptedLog)] unconstrained fn emit_unencrypted_log_oracle_private(_contract_address: AztecAddress, _message: T, _counter: u32) -> Field {} -unconstrained pub fn emit_unencrypted_log_private_internal( - contract_address: AztecAddress, - message: T, - counter: u32 -) -> Field { +unconstrained pub fn emit_unencrypted_log_private_internal(contract_address: AztecAddress, message: T, counter: u32) -> Field { emit_unencrypted_log_oracle_private(contract_address, message, counter) } #[oracle(emitContractClassUnencryptedLog)] -unconstrained fn emit_contract_class_unencrypted_log_private( - contract_address: AztecAddress, - message: [Field; N], - counter: u32 -) -> Field {} +unconstrained fn emit_contract_class_unencrypted_log_private(contract_address: AztecAddress, message: [Field; N], counter: u32) -> Field {} unconstrained pub fn emit_contract_class_unencrypted_log_private_internal(contract_address: AztecAddress, message: [Field; N], counter: u32) -> Field { emit_contract_class_unencrypted_log_private(contract_address, message, counter) diff --git a/noir-projects/aztec-nr/aztec/src/oracle/mod.nr b/noir-projects/aztec-nr/aztec/src/oracle/mod.nr index 81d06c48a63..140742b555f 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/mod.nr @@ -4,7 +4,6 @@ mod arguments; mod call_private_function; -mod encryption; mod execution; mod get_contract_instance; mod get_l1_to_l2_membership_witness; diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 6ea2ad6f0a0..e87a1ddcf4f 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -7,17 +7,13 @@ use dep::aztec::macros::aztec; contract Test { use dep::aztec::prelude::{ - AztecAddress, EthAddress, FunctionSelector, NoteHeader, NoteGetterOptions, NoteViewerOptions, - PrivateContext, PrivateImmutable, PrivateSet, SharedImmutable + AztecAddress, EthAddress, FunctionSelector, NoteGetterOptions, NoteViewerOptions, + PrivateImmutable, PrivateSet }; use dep::aztec::encrypted_logs::encrypted_note_emission::encode_and_encrypt_note; use dep::aztec::encrypted_logs::encrypted_event_emission::encode_and_encrypt_event_with_keys_with_randomness; - use dep::aztec::protocol_types::{ - abis::private_circuit_public_inputs::PrivateCircuitPublicInputs, - constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, traits::{Serialize, ToField, FromField}, - point::Point, scalar::Scalar, storage::map::derive_storage_slot_in_map - }; + use dep::aztec::protocol_types::{constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, traits::Serialize, point::Point, scalar::Scalar}; use dep::aztec::encrypted_logs::header::EncryptedLogHeader; use dep::aztec::encrypted_logs::payload::{compute_incoming_body_ciphertext, compute_outgoing_body_ciphertext}; @@ -26,14 +22,13 @@ contract Test { use dep::aztec::keys::getters::get_public_keys; use dep::aztec::{ - context::inputs::private_context_inputs::PrivateContextInputs, hash::{pedersen_hash, compute_secret_hash, ArgsHasher}, keys::public_keys::IvpkM, note::{ lifecycle::{create_note, destroy_note_unsafe}, note_getter::{get_notes, view_notes}, note_getter_options::NoteStatus }, - deploy::deploy_contract as aztec_deploy_contract, - oracle::{encryption::aes128_encrypt, unsafe_rand::unsafe_rand}, utils::comparison::Comparator, + deploy::deploy_contract as aztec_deploy_contract, oracle::unsafe_rand::unsafe_rand, + utils::comparison::Comparator, macros::{storage::storage, events::event, functions::{private, public, internal}} }; use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash}; @@ -41,6 +36,7 @@ contract Test { // TODO investigate why the macros require EmbeddedCurvePoint and EmbeddedCurveScalar use std::embedded_curve_ops::{EmbeddedCurveScalar, EmbeddedCurvePoint, fixed_base_scalar_mul as derive_public_key}; use std::meta::derive; + use std::aes128::aes128_encrypt; use crate::test_note::TestNote; @@ -406,12 +402,12 @@ contract Test { #[private] fn encrypt(input: [u8; 64], iv: [u8; 16], key: [u8; 16]) -> [u8; 80] { - aes128_encrypt(input, iv, key) + aes128_encrypt(input, iv, key).as_array() } #[private] fn encrypt_with_padding(input: [u8; 65], iv: [u8; 16], key: [u8; 16]) -> [u8; 80] { - aes128_encrypt(input, iv, key) + aes128_encrypt(input, iv, key).as_array() } #[private] diff --git a/noir/noir-repo/test_programs/execution_success/aes128_encrypt/src/main.nr b/noir/noir-repo/test_programs/execution_success/aes128_encrypt/src/main.nr index b937c801860..31d907fea10 100644 --- a/noir/noir-repo/test_programs/execution_success/aes128_encrypt/src/main.nr +++ b/noir/noir-repo/test_programs/execution_success/aes128_encrypt/src/main.nr @@ -21,29 +21,20 @@ unconstrained fn decode_hex(s: str) -> [u8; M] { } unconstrained fn cipher(plaintext: [u8; 12], iv: [u8; 16], key: [u8; 16]) -> [u8; 16] { - let slice_res = std::aes128::aes128_encrypt(plaintext, iv, key); - let mut result = [0; 16]; - for i in 0..16 { - result[i] = slice_res[i]; - } - result + let result = std::aes128::aes128_encrypt(plaintext, iv, key); + result.as_array() } fn main(inputs: str<12>, iv: str<16>, key: str<16>, output: str<32>) { - let result = std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()); + let result: [u8; 16] = std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()).as_array(); let output_bytes: [u8; 16] = unsafe { - let output_bytes: [u8; 16] = decode_hex(output); - for i in 0..16 { - assert(result[i] == output_bytes[i]); - } - output_bytes + decode_hex(output) }; + assert(result == output_bytes); - unsafe { - let unconstrained_result = cipher(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()); - for i in 0..16 { - assert(unconstrained_result[i] == output_bytes[i]); - } - } + let unconstrained_result = unsafe { + cipher(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()) + }; + assert(unconstrained_result == output_bytes); } diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index cab30078dc7..cb3bf8041b2 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -1,8 +1,7 @@ import { MerkleTreeId, UnencryptedL2Log } from '@aztec/circuit-types'; -import { KeyValidationRequest } from '@aztec/circuits.js'; import { FunctionSelector, NoteSelector } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { Fr, Point } from '@aztec/foundation/fields'; +import { Fr } from '@aztec/foundation/fields'; import { type ACVMField } from '../acvm_types.js'; import { frToBoolean, frToNumber, fromACVMField } from '../deserialize.js'; @@ -329,72 +328,6 @@ export class Oracle { this.typedOracle.emitEncryptedNoteLog(+noteHashCounter, processedInput, +counter); } - computeEncryptedEventLog( - [contractAddress]: ACVMField[], - [randomness]: ACVMField[], - [eventTypeId]: ACVMField[], - [ovskApp]: ACVMField[], - [ovpkMX]: ACVMField[], - [ovpkMY]: ACVMField[], - [ovpkMIsInfinite]: ACVMField[], - [ivpkMX]: ACVMField[], - [ivpkMY]: ACVMField[], - [ivpkMIsInfinite]: ACVMField[], - [recipient]: ACVMField[], - preimage: ACVMField[], - ): ACVMField[] { - const ovpkM = new Point(fromACVMField(ovpkMX), fromACVMField(ovpkMY), !fromACVMField(ovpkMIsInfinite).isZero()); - const ovKeys = new KeyValidationRequest(ovpkM, Fr.fromString(ovskApp)); - const ivpkM = new Point(fromACVMField(ivpkMX), fromACVMField(ivpkMY), !fromACVMField(ivpkMIsInfinite).isZero()); - const encLog = this.typedOracle.computeEncryptedEventLog( - AztecAddress.fromString(contractAddress), - Fr.fromString(randomness), - Fr.fromString(eventTypeId), - ovKeys, - ivpkM, - AztecAddress.fromString(recipient), - preimage.map(fromACVMField), - ); - const bytes: ACVMField[] = []; - encLog.forEach(v => { - bytes.push(toACVMField(v)); - }); - return bytes; - } - - computeEncryptedNoteLog( - [contractAddress]: ACVMField[], - [storageSlot]: ACVMField[], - [noteTypeId]: ACVMField[], - [ovskApp]: ACVMField[], - [ovpkMX]: ACVMField[], - [ovpkMY]: ACVMField[], - [ovpkMIsInfinite]: ACVMField[], - [ivpkMX]: ACVMField[], - [ivpkMY]: ACVMField[], - [ivpkMIsInfinite]: ACVMField[], - [recipient]: ACVMField[], - preimage: ACVMField[], - ): ACVMField[] { - const ovpkM = new Point(fromACVMField(ovpkMX), fromACVMField(ovpkMY), !fromACVMField(ovpkMIsInfinite).isZero()); - const ovKeys = new KeyValidationRequest(ovpkM, Fr.fromString(ovskApp)); - const ivpkM = new Point(fromACVMField(ivpkMX), fromACVMField(ivpkMY), !fromACVMField(ivpkMIsInfinite).isZero()); - const encLog = this.typedOracle.computeEncryptedNoteLog( - AztecAddress.fromString(contractAddress), - Fr.fromString(storageSlot), - NoteSelector.fromField(Fr.fromString(noteTypeId)), - ovKeys, - ivpkM, - AztecAddress.fromString(recipient), - preimage.map(fromACVMField), - ); - const bytes: ACVMField[] = []; - encLog.forEach(v => { - bytes.push(toACVMField(v)); - }); - return bytes; - } - emitUnencryptedLog([contractAddress]: ACVMField[], message: ACVMField[], [counter]: ACVMField[]): ACVMField { const logPayload = Buffer.concat(message.map(fromACVMField).map(f => f.toBuffer())); const log = new UnencryptedL2Log(AztecAddress.fromString(contractAddress), logPayload); @@ -479,17 +412,4 @@ export class Oracle { notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]) { this.typedOracle.notifySetMinRevertibleSideEffectCounter(frToNumber(fromACVMField(minRevertibleSideEffectCounter))); } - - aes128Encrypt(input: ACVMField[], initializationVector: ACVMField[], key: ACVMField[]): ACVMField[] { - // Convert each field to a number and then to a buffer (1 byte is stored in 1 field) - const processedInput = Buffer.from(input.map(fromACVMField).map(f => f.toNumber())); - const processedIV = Buffer.from(initializationVector.map(fromACVMField).map(f => f.toNumber())); - const processedKey = Buffer.from(key.map(fromACVMField).map(f => f.toNumber())); - - // Encrypt the input - const ciphertext = this.typedOracle.aes128Encrypt(processedInput, processedIV, processedKey); - - // Convert each byte of ciphertext to a field and return it - return Array.from(ciphertext).map(byte => toACVMField(byte)); - } } diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index 1b9dae81e8a..63dcb34a735 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -5,7 +5,6 @@ import { type NoteStatus, type NullifierMembershipWitness, type PublicDataWitness, - type PublicKey, type SiblingPath, type UnencryptedL2Log, } from '@aztec/circuit-types'; @@ -204,30 +203,6 @@ export abstract class TypedOracle { throw new OracleMethodNotAvailableError('emitEncryptedNoteLog'); } - computeEncryptedEventLog( - _contractAddress: AztecAddress, - _randomness: Fr, - _eventTypeId: Fr, - _ovKeys: KeyValidationRequest, - _ivpkM: PublicKey, - _recipient: AztecAddress, - _preimage: Fr[], - ): Buffer { - throw new OracleMethodNotAvailableError('computeEncryptedEventLog'); - } - - computeEncryptedNoteLog( - _contractAddress: AztecAddress, - _storageSlot: Fr, - _noteTypeId: NoteSelector, - _ovKeys: KeyValidationRequest, - _ivpkM: PublicKey, - _recipient: AztecAddress, - _preimage: Fr[], - ): Buffer { - throw new OracleMethodNotAvailableError('computeEncryptedNoteLog'); - } - emitUnencryptedLog(_log: UnencryptedL2Log, _counter: number): void { throw new OracleMethodNotAvailableError('emitUnencryptedLog'); } @@ -273,10 +248,6 @@ export abstract class TypedOracle { throw new OracleMethodNotAvailableError('notifySetMinRevertibleSideEffectCounter'); } - aes128Encrypt(_input: Buffer, _initializationVector: Buffer, _key: Buffer): Buffer { - throw new OracleMethodNotAvailableError('encrypt'); - } - debugLog(_message: string, _fields: Fr[]): void { throw new OracleMethodNotAvailableError('debugLog'); } diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 79b1f913ef4..3fc8a537916 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -3,35 +3,17 @@ import { type AztecNode, EncryptedL2Log, EncryptedL2NoteLog, - Event, - L1EventPayload, - L1NotePayload, Note, type NoteStatus, PublicExecutionRequest, - TaggedLog, type UnencryptedL2Log, } from '@aztec/circuit-types'; -import { - CallContext, - FunctionSelector, - type Header, - type KeyValidationRequest, - PrivateContextInputs, - type TxContext, -} from '@aztec/circuits.js'; -import { Aes128 } from '@aztec/circuits.js/barretenberg'; +import { CallContext, FunctionSelector, type Header, PrivateContextInputs, type TxContext } from '@aztec/circuits.js'; import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash'; -import { - EventSelector, - type FunctionAbi, - type FunctionArtifact, - type NoteSelector, - countArgumentsSize, -} from '@aztec/foundation/abi'; +import { type FunctionAbi, type FunctionArtifact, type NoteSelector, countArgumentsSize } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; -import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields'; +import { Fr } from '@aztec/foundation/fields'; import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log'; import { type NoteData, toACVMWitness } from '../acvm/index.js'; @@ -373,62 +355,6 @@ export class ClientExecutionContext extends ViewDataOracle { this.noteEncryptedLogs.push(encryptedLog); } - /** - * Encrypt an event - * @param contractAddress - The contract emitting the encrypted event. - * @param randomness - A value used to mask the contract address we are siloing with. - * @param eventTypeId - The type ID of the event (function selector). - * @param ovKeys - The outgoing viewing keys to use to encrypt. - * @param ivpkM - The master incoming viewing public key. - * @param recipient - The recipient of the encrypted event log. - * @param preimage - The event preimage. - */ - public override computeEncryptedEventLog( - contractAddress: AztecAddress, - randomness: Fr, - eventTypeId: Fr, - ovKeys: KeyValidationRequest, - ivpkM: Point, - recipient: AztecAddress, - preimage: Fr[], - ) { - const event = new Event(preimage); - const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId)); - const taggedEvent = new TaggedLog(l1EventPayload); - - const ephSk = GrumpkinScalar.random(); - - return taggedEvent.encrypt(ephSk, recipient, ivpkM, ovKeys); - } - - /** - * Encrypt a note - * @param contractAddress - The contract address of the note. - * @param storageSlot - The storage slot the note is at. - * @param noteTypeId - The type ID of the note. - * @param ovKeys - The outgoing viewing keys to use to encrypt. - * @param ivpkM - The master incoming viewing public key. - * @param recipient - The recipient of the encrypted note log. - * @param preimage - The note preimage. - */ - public override computeEncryptedNoteLog( - contractAddress: AztecAddress, - storageSlot: Fr, - noteTypeId: NoteSelector, - ovKeys: KeyValidationRequest, - ivpkM: Point, - recipient: AztecAddress, - preimage: Fr[], - ) { - const note = new Note(preimage); - const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId); - const taggedNote = new TaggedLog(l1NotePayload); - - const ephSk = GrumpkinScalar.random(); - - return taggedNote.encrypt(ephSk, recipient, ivpkM, ovKeys); - } - /** * Emit an unencrypted log. * @param log - The unencrypted log to be emitted. @@ -698,11 +624,6 @@ export class ClientExecutionContext extends ViewDataOracle { return values; } - public override aes128Encrypt(input: Buffer, initializationVector: Buffer, key: Buffer): Buffer { - const aes128 = new Aes128(); - return aes128.encryptBufferCBC(input, initializationVector, key); - } - public override debugLog(message: string, fields: Fr[]) { this.log.verbose(`debug_log ${applyStringFormatting(message, fields)}`); } diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index a2fdb9df74d..6bd3aef063e 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -1,8 +1,5 @@ import { AuthWitness, - Event, - L1EventPayload, - L1NotePayload, MerkleTreeId, Note, type NoteStatus, @@ -10,7 +7,6 @@ import { PublicDataWitness, PublicDataWrite, PublicExecutionRequest, - TaggedLog, type UnencryptedL2Log, } from '@aztec/circuit-types'; import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats'; @@ -34,18 +30,17 @@ import { deriveKeys, getContractClassFromArtifact, } from '@aztec/circuits.js'; -import { Aes128, Schnorr } from '@aztec/circuits.js/barretenberg'; +import { Schnorr } from '@aztec/circuits.js/barretenberg'; import { computePublicDataTreeLeafSlot, siloNoteHash, siloNullifier } from '@aztec/circuits.js/hash'; import { type ContractArtifact, - EventSelector, type FunctionAbi, FunctionSelector, type NoteSelector, countArgumentsSize, } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields'; +import { Fr } from '@aztec/foundation/fields'; import { type Logger, applyStringFormatting } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; import { type KeyStore } from '@aztec/key-store'; @@ -543,24 +538,6 @@ export class TXE implements TypedOracle { return; } - computeEncryptedNoteLog( - contractAddress: AztecAddress, - storageSlot: Fr, - noteTypeId: NoteSelector, - ovKeys: KeyValidationRequest, - ivpkM: Point, - recipient: AztecAddress, - preimage: Fr[], - ): Buffer { - const note = new Note(preimage); - const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId); - const taggedNote = new TaggedLog(l1NotePayload); - - const ephSk = GrumpkinScalar.random(); - - return taggedNote.encrypt(ephSk, recipient, ivpkM, ovKeys); - } - emitUnencryptedLog(_log: UnencryptedL2Log, counter: number): void { this.sideEffectsCounter = counter + 1; return; @@ -838,11 +815,6 @@ export class TXE implements TypedOracle { this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter); } - aes128Encrypt(input: Buffer, initializationVector: Buffer, key: Buffer): Buffer { - const aes128 = new Aes128(); - return aes128.encryptBufferCBC(input, initializationVector, key); - } - debugLog(message: string, fields: Fr[]): void { this.logger.verbose(`debug_log ${applyStringFormatting(message, fields)}`); } @@ -856,22 +828,4 @@ export class TXE implements TypedOracle { this.sideEffectsCounter = counter + 1; return; } - - computeEncryptedEventLog( - contractAddress: AztecAddress, - randomness: Fr, - eventTypeId: Fr, - ovKeys: KeyValidationRequest, - ivpkM: Point, - recipient: AztecAddress, - preimage: Fr[], - ): Buffer { - const event = new Event(preimage); - const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId)); - const taggedEvent = new TaggedLog(l1EventPayload); - - const ephSk = GrumpkinScalar.random(); - - return taggedEvent.encrypt(ephSk, recipient, ivpkM, ovKeys); - } } diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index ea4b2c0088f..f9c0db63d40 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -4,9 +4,7 @@ import { Fr, FunctionSelector, Header, - KeyValidationRequest, PUBLIC_DATA_SUBTREE_HEIGHT, - Point, PublicDataTreeLeaf, computePartialAddress, getContractInstanceFromDeployParams, @@ -614,40 +612,6 @@ export class TXEService { return toForeignCallResult([toArray(keyValidationRequest.toFields())]); } - computeEncryptedNoteLog( - contractAddress: ForeignCallSingle, - storageSlot: ForeignCallSingle, - noteTypeId: ForeignCallSingle, - ovskApp: ForeignCallSingle, - ovpkMX: ForeignCallSingle, - ovpkMY: ForeignCallSingle, - ovpkMIsInfinite: ForeignCallSingle, - ivpkMX: ForeignCallSingle, - ivpkMY: ForeignCallSingle, - ivpkMIsInfinite: ForeignCallSingle, - recipient: ForeignCallSingle, - preimage: ForeignCallArray, - ) { - const ovpkM = new Point(fromSingle(ovpkMX), fromSingle(ovpkMY), !fromSingle(ovpkMIsInfinite).isZero()); - const ovKeys = new KeyValidationRequest(ovpkM, Fr.fromString(fromSingle(ovskApp).toString())); - const ivpkM = new Point(fromSingle(ivpkMX), fromSingle(ivpkMY), !fromSingle(ivpkMIsInfinite).isZero()); - const encLog = this.typedOracle.computeEncryptedNoteLog( - AztecAddress.fromString(fromSingle(contractAddress).toString()), - Fr.fromString(fromSingle(storageSlot).toString()), - NoteSelector.fromField(Fr.fromString(fromSingle(noteTypeId).toString())), - ovKeys, - ivpkM, - AztecAddress.fromString(fromSingle(recipient).toString()), - fromArray(preimage), - ); - const bytes: Fr[] = []; - - encLog.forEach(v => { - bytes.push(new Fr(v)); - }); - return toForeignCallResult([toArray(bytes)]); - } - emitEncryptedLog( _contractAddress: ForeignCallSingle, _randomness: ForeignCallSingle,