Skip to content

Commit

Permalink
refactor: updated all the structs, removed emitted events from everyw…
Browse files Browse the repository at this point in the history
…here
  • Loading branch information
benesjan committed May 23, 2023
1 parent 9a7e24c commit da58fe6
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 112 deletions.
33 changes: 13 additions & 20 deletions circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ template <typename NCT> struct OptionallyRevealedData {

fr call_stack_item_hash = 0;
FunctionData<NCT> function_data{};
std::array<fr, EMITTED_EVENTS_LENGTH> emitted_events = zero_array<fr, EMITTED_EVENTS_LENGTH>();
fr vk_hash = 0;
address portal_contract_address = 0;
boolean pay_fee_from_l1 = false;
Expand All @@ -31,7 +30,6 @@ template <typename NCT> struct OptionallyRevealedData {
// for serialization: update up with new fields
MSGPACK_FIELDS(call_stack_item_hash,
function_data,
emitted_events,
vk_hash,
portal_contract_address,
pay_fee_from_l1,
Expand All @@ -41,10 +39,9 @@ template <typename NCT> struct OptionallyRevealedData {
boolean operator==(OptionallyRevealedData<NCT> const& other) const
{
return call_stack_item_hash == other.call_stack_item_hash && function_data == other.function_data &&
emitted_events == other.emitted_events && vk_hash == other.vk_hash &&
portal_contract_address == other.portal_contract_address && pay_fee_from_l1 == other.pay_fee_from_l1 &&
pay_fee_from_public_l2 == other.pay_fee_from_public_l2 && called_from_l1 == other.called_from_l1 &&
called_from_public_l2 == other.called_from_public_l2;
vk_hash == other.vk_hash && portal_contract_address == other.portal_contract_address &&
pay_fee_from_l1 == other.pay_fee_from_l1 && pay_fee_from_public_l2 == other.pay_fee_from_public_l2 &&
called_from_l1 == other.called_from_l1 && called_from_public_l2 == other.called_from_public_l2;
};

template <typename Composer>
Expand All @@ -56,10 +53,13 @@ template <typename NCT> struct OptionallyRevealedData {
auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); };

OptionallyRevealedData<CircuitTypes<Composer>> data = {
to_ct(call_stack_item_hash), function_data.to_circuit_type(composer),
to_ct(emitted_events), to_ct(vk_hash),
to_ct(portal_contract_address), to_ct(pay_fee_from_l1),
to_ct(pay_fee_from_public_l2), to_ct(called_from_l1),
to_ct(call_stack_item_hash),
function_data.to_circuit_type(composer),
to_ct(vk_hash),
to_ct(portal_contract_address),
to_ct(pay_fee_from_l1),
to_ct(pay_fee_from_public_l2),
to_ct(called_from_l1),
to_ct(called_from_public_l2),
};

Expand All @@ -73,11 +73,9 @@ template <typename NCT> struct OptionallyRevealedData {
auto to_native_type = []<typename T>(T& e) { return e.template to_native_type<Composer>(); };

OptionallyRevealedData<NativeTypes> data = {
to_nt(call_stack_item_hash), to_native_type(function_data),
to_nt(emitted_events), to_nt(vk_hash),
to_nt(portal_contract_address), to_nt(pay_fee_from_l1),
to_nt(pay_fee_from_public_l2), to_nt(called_from_l1),
to_nt(called_from_public_l2),
to_nt(call_stack_item_hash), to_native_type(function_data), to_nt(vk_hash),
to_nt(portal_contract_address), to_nt(pay_fee_from_l1), to_nt(pay_fee_from_public_l2),
to_nt(called_from_l1), to_nt(called_from_public_l2),
};

return data;
Expand All @@ -89,7 +87,6 @@ template <typename NCT> struct OptionallyRevealedData {

call_stack_item_hash.set_public();
function_data.set_public();
set_array_public(emitted_events);
vk_hash.set_public();
portal_contract_address.to_field().set_public();
fr(pay_fee_from_l1).set_public();
Expand All @@ -113,7 +110,6 @@ template <typename NCT> void read(uint8_t const*& it, OptionallyRevealedData<NCT

read(it, data.call_stack_item_hash);
read(it, data.function_data);
read(it, data.emitted_events);
read(it, data.vk_hash);
read(it, data.portal_contract_address);
read(it, data.pay_fee_from_l1);
Expand All @@ -128,7 +124,6 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, OptionallyRevealed

write(buf, data.call_stack_item_hash);
write(buf, data.function_data);
write(buf, data.emitted_events);
write(buf, data.vk_hash);
write(buf, data.portal_contract_address);
write(buf, data.pay_fee_from_l1);
Expand All @@ -142,8 +137,6 @@ template <typename NCT> std::ostream& operator<<(std::ostream& os, OptionallyRev
return os << "call_stack_item_hash: " << data.call_stack_item_hash << "\n"
<< "function_data:\n"
<< data.function_data << "\n"
<< "emitted_events:\n"
<< data.emitted_events << "\n"
<< "vk_hash: " << data.vk_hash << "\n"
<< "portal_contract_address: " << data.portal_contract_address << "\n"
<< "pay_fee_from_l1: " << data.pay_fee_from_l1 << "\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ template <typename NCT> struct PublicCircuitPublicInputs {
std::array<fr, ARGS_LENGTH> args = zero_array<fr, ARGS_LENGTH>();
std::array<fr, RETURN_VALUES_LENGTH> return_values = zero_array<fr, RETURN_VALUES_LENGTH>();

std::array<fr, EMITTED_EVENTS_LENGTH> emitted_events = zero_array<fr, EMITTED_EVENTS_LENGTH>();

std::array<ContractStorageUpdateRequest<NCT>, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH>
contract_storage_update_requests{};
std::array<ContractStorageRead<NCT>, KERNEL_PUBLIC_DATA_READS_LENGTH> contract_storage_reads{};
Expand All @@ -44,7 +42,6 @@ template <typename NCT> struct PublicCircuitPublicInputs {
boolean operator==(PublicCircuitPublicInputs<NCT> const& other) const
{
return call_context == other.call_context && args == other.args && return_values == other.return_values &&
emitted_events == other.emitted_events &&
contract_storage_update_requests == other.contract_storage_update_requests &&
contract_storage_reads == other.contract_storage_reads && public_call_stack == other.public_call_stack &&
new_l2_to_l1_msgs == other.new_l2_to_l1_msgs &&
Expand All @@ -67,8 +64,6 @@ template <typename NCT> struct PublicCircuitPublicInputs {
.args = to_ct(args),
.return_values = to_ct(return_values),

.emitted_events = to_ct(emitted_events),

.contract_storage_update_requests = map(contract_storage_update_requests, to_circuit_type),
.contract_storage_reads = map(contract_storage_reads, to_circuit_type),

Expand Down Expand Up @@ -96,8 +91,6 @@ template <typename NCT> struct PublicCircuitPublicInputs {
spread_arr_into_vec(args, inputs);
spread_arr_into_vec(return_values, inputs);

spread_arr_into_vec(emitted_events, inputs);

spread_arr_into_vec(map(contract_storage_update_requests, to_hashes), inputs);
spread_arr_into_vec(map(contract_storage_reads, to_hashes), inputs);

Expand All @@ -124,7 +117,6 @@ template <typename NCT> void read(uint8_t const*& it, PublicCircuitPublicInputs<
read(it, pis.call_context);
read(it, pis.args);
read(it, pis.return_values);
read(it, pis.emitted_events);

read(it, pis.contract_storage_update_requests);
read(it, pis.contract_storage_reads);
Expand All @@ -147,7 +139,6 @@ void write(std::vector<uint8_t>& buf, PublicCircuitPublicInputs<NCT> const& publ
write(buf, pis.call_context);
write(buf, pis.args);
write(buf, pis.return_values);
write(buf, pis.emitted_events);

write(buf, pis.contract_storage_update_requests);
write(buf, pis.contract_storage_reads);
Expand All @@ -168,7 +159,6 @@ std::ostream& operator<<(std::ostream& os, PublicCircuitPublicInputs<NCT> const&
return os << "call_context: " << pis.call_context << "\n"
<< "args: " << pis.args << "\n"
<< "return_values: " << pis.return_values << "\n"
<< "emitted_events: " << pis.emitted_events << "\n"

<< "contract_storage_update_requests: " << pis.contract_storage_update_requests << "\n"
<< "contract_storage_reads: " << pis.contract_storage_reads << "\n"
Expand Down
5 changes: 0 additions & 5 deletions circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ PublicCallStackItem generate_call_stack_item(NT::fr contract_address,
};
std::array<NT::fr, ARGS_LENGTH> const args = array_of_values<ARGS_LENGTH>(count);
std::array<NT::fr, RETURN_VALUES_LENGTH> const return_values = array_of_values<RETURN_VALUES_LENGTH>(count);
std::array<NT::fr, EMITTED_EVENTS_LENGTH> const emitted_events = array_of_values<EMITTED_EVENTS_LENGTH>(count);
std::array<NT::fr, PUBLIC_CALL_STACK_LENGTH> const public_call_stack =
array_of_values<PUBLIC_CALL_STACK_LENGTH>(count);
std::array<NT::fr, NEW_L2_TO_L1_MSGS_LENGTH> const new_l2_to_l1_msgs =
Expand All @@ -138,7 +137,6 @@ PublicCallStackItem generate_call_stack_item(NT::fr contract_address,
.call_context = call_context,
.args = args,
.return_values = return_values,
.emitted_events = emitted_events,
.contract_storage_update_requests = update_requests,
.contract_storage_reads = reads,
.public_call_stack = public_call_stack,
Expand Down Expand Up @@ -235,8 +233,6 @@ PublicKernelInputsNoPreviousKernel<NT> get_kernel_inputs_no_previous_kernel()

std::array<fr, RETURN_VALUES_LENGTH> const return_values =
array_of_values<RETURN_VALUES_LENGTH>(seed, RETURN_VALUES_LENGTH / 2);
std::array<fr, EMITTED_EVENTS_LENGTH> const emitted_events =
array_of_values<EMITTED_EVENTS_LENGTH>(seed, EMITTED_EVENTS_LENGTH / 2);
std::array<ContractStorageUpdateRequest<NT>, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const update_requests =
generate_contract_storage_update_requests(seed, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH / 2);
std::array<ContractStorageRead<NT>, KERNEL_PUBLIC_DATA_READS_LENGTH> const reads =
Expand All @@ -250,7 +246,6 @@ PublicKernelInputsNoPreviousKernel<NT> get_kernel_inputs_no_previous_kernel()
.call_context = call_context,
.args = args,
.return_values = return_values,
.emitted_events = emitted_events,
.contract_storage_update_requests = update_requests,
.contract_storage_reads = reads,
.public_call_stack = call_stack_hashes,
Expand Down
1 change: 0 additions & 1 deletion circuits/cpp/src/aztec3/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace aztec3 {
// Note: must be kept in sync with ts/structs/constants.ts
constexpr size_t ARGS_LENGTH = 8;
constexpr size_t RETURN_VALUES_LENGTH = 4;
constexpr size_t EMITTED_EVENTS_LENGTH = 4;

constexpr size_t NEW_COMMITMENTS_LENGTH = 4;
constexpr size_t NEW_NULLIFIERS_LENGTH = 4;
Expand Down
12 changes: 9 additions & 3 deletions yarn-project/acir-simulator/src/acvm/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ARGS_LENGTH,
CallContext,
ContractDeploymentData,
EMITTED_EVENTS_LENGTH,
NEW_L2_TO_L1_MSGS_LENGTH,
NEW_COMMITMENTS_LENGTH,
NEW_NULLIFIERS_LENGTH,
Expand Down Expand Up @@ -121,13 +120,17 @@ export function extractPublicInputs(partialWitness: ACVMWitness, acir: Buffer):

const args = witnessReader.readFieldArray(ARGS_LENGTH);
const returnValues = witnessReader.readFieldArray(RETURN_VALUES_LENGTH);
const emittedEvents = witnessReader.readFieldArray(EMITTED_EVENTS_LENGTH);
const newCommitments = witnessReader.readFieldArray(NEW_COMMITMENTS_LENGTH);
const newNullifiers = witnessReader.readFieldArray(NEW_NULLIFIERS_LENGTH);
const privateCallStack = witnessReader.readFieldArray(PRIVATE_CALL_STACK_LENGTH);
const publicCallStack = witnessReader.readFieldArray(PUBLIC_CALL_STACK_LENGTH);
const newL2ToL1Msgs = witnessReader.readFieldArray(NEW_L2_TO_L1_MSGS_LENGTH);

const encryptedLogsHash = witnessReader.readFieldArray(2);
const unencryptedLogsHash = witnessReader.readFieldArray(2);
const encryptedLogPreimagesLength = witnessReader.readField();
const unencryptedLogPreimagesLength = witnessReader.readField();

const privateDataTreeRoot = witnessReader.readField();
const nullifierTreeRoot = witnessReader.readField();
const contractTreeRoot = witnessReader.readField();
Expand All @@ -144,12 +147,15 @@ export function extractPublicInputs(partialWitness: ACVMWitness, acir: Buffer):
callContext,
args,
returnValues,
emittedEvents,
newCommitments,
newNullifiers,
privateCallStack,
publicCallStack,
newL2ToL1Msgs,
encryptedLogsHash,
unencryptedLogsHash,
encryptedLogPreimagesLength,
unencryptedLogPreimagesLength,
privateDataTreeRoot,
nullifierTreeRoot,
contractTreeRoot,
Expand Down
5 changes: 4 additions & 1 deletion yarn-project/acir-simulator/src/acvm/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ export function toACVMPublicInputs(publicInputs: PrivateCircuitPublicInputs): AC

...publicInputs.args.map(toACVMField),
...publicInputs.returnValues.map(toACVMField),
...publicInputs.emittedEvents.map(toACVMField),
...publicInputs.newCommitments.map(toACVMField),
...publicInputs.newNullifiers.map(toACVMField),
...publicInputs.privateCallStack.map(toACVMField),
...publicInputs.publicCallStack.map(toACVMField),
...publicInputs.newL2ToL1Msgs.map(toACVMField),
...publicInputs.encryptedLogsHash.map(toACVMField),
...publicInputs.unencryptedLogsHash.map(toACVMField),

toACVMField(publicInputs.encryptedLogPreimagesLength),
toACVMField(publicInputs.unencryptedLogPreimagesLength),
toACVMField(publicInputs.historicPrivateDataTreeRoot),
toACVMField(publicInputs.historicPrivateNullifierTreeRoot),
toACVMField(publicInputs.historicContractTreeRoot),
Expand Down
45 changes: 36 additions & 9 deletions yarn-project/circuits.js/src/cbind/circuits.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ export function fromFunctionData(o: FunctionData): MsgpackFunctionData {
export interface MsgpackOptionallyRevealedData {
call_stack_item_hash: Buffer;
function_data: MsgpackFunctionData;
emitted_events: Tuple<Buffer, 4>;
vk_hash: Buffer;
portal_contract_address: Buffer;
pay_fee_from_l1: boolean;
Expand All @@ -209,9 +208,6 @@ export function toOptionallyRevealedData(o: MsgpackOptionallyRevealedData): Opti
if (o.function_data === undefined) {
throw new Error('Expected function_data in OptionallyRevealedData deserialization');
}
if (o.emitted_events === undefined) {
throw new Error('Expected emitted_events in OptionallyRevealedData deserialization');
}
if (o.vk_hash === undefined) {
throw new Error('Expected vk_hash in OptionallyRevealedData deserialization');
}
Expand All @@ -233,7 +229,6 @@ export function toOptionallyRevealedData(o: MsgpackOptionallyRevealedData): Opti
return new OptionallyRevealedData(
Fr.fromBuffer(o.call_stack_item_hash),
toFunctionData(o.function_data),
mapTuple(o.emitted_events, (v: Buffer) => Fr.fromBuffer(v)),
Fr.fromBuffer(o.vk_hash),
Address.fromBuffer(o.portal_contract_address),
o.pay_fee_from_l1,
Expand All @@ -250,9 +245,6 @@ export function fromOptionallyRevealedData(o: OptionallyRevealedData): MsgpackOp
if (o.functionData === undefined) {
throw new Error('Expected functionData in OptionallyRevealedData serialization');
}
if (o.emittedEvents === undefined) {
throw new Error('Expected emittedEvents in OptionallyRevealedData serialization');
}
if (o.vkHash === undefined) {
throw new Error('Expected vkHash in OptionallyRevealedData serialization');
}
Expand All @@ -274,7 +266,6 @@ export function fromOptionallyRevealedData(o: OptionallyRevealedData): MsgpackOp
return {
call_stack_item_hash: o.callStackItemHash.toBuffer(),
function_data: fromFunctionData(o.functionData),
emitted_events: mapTuple(o.emittedEvents, (v: Fr) => v.toBuffer()),
vk_hash: o.vkHash.toBuffer(),
portal_contract_address: o.portalContractAddress.toBuffer(),
pay_fee_from_l1: o.payFeeFromL1,
Expand Down Expand Up @@ -359,6 +350,10 @@ export interface MsgpackCombinedAccumulatedData {
private_call_stack: Tuple<Buffer, 8>;
public_call_stack: Tuple<Buffer, 8>;
new_l2_to_l1_msgs: Tuple<Buffer, 2>;
encrypted_logs_hash: Tuple<Buffer, 2>;
unencrypted_logs_hash: Tuple<Buffer, 2>;
encrypted_log_preimages_length: Buffer;
unencrypted_log_preimages_length: Buffer;
new_contracts: Tuple<MsgpackNewContractData, 1>;
optionally_revealed_data: Tuple<MsgpackOptionallyRevealedData, 4>;
public_data_update_requests: Tuple<MsgpackPublicDataUpdateRequest, 4>;
Expand All @@ -384,6 +379,18 @@ export function toCombinedAccumulatedData(o: MsgpackCombinedAccumulatedData): Co
if (o.new_l2_to_l1_msgs === undefined) {
throw new Error('Expected new_l2_to_l1_msgs in CombinedAccumulatedData deserialization');
}
if (o.encrypted_logs_hash === undefined) {
throw new Error('Expected encrypted_logs_hash in CombinedAccumulatedData deserialization');
}
if (o.unencrypted_logs_hash === undefined) {
throw new Error('Expected unencrypted_logs_hash in CombinedAccumulatedData deserialization');
}
if (o.encrypted_log_preimages_length === undefined) {
throw new Error('Expected encrypted_log_preimages_length in CombinedAccumulatedData deserialization');
}
if (o.unencrypted_log_preimages_length === undefined) {
throw new Error('Expected unencrypted_log_preimages_length in CombinedAccumulatedData deserialization');
}
if (o.new_contracts === undefined) {
throw new Error('Expected new_contracts in CombinedAccumulatedData deserialization');
}
Expand All @@ -403,6 +410,10 @@ export function toCombinedAccumulatedData(o: MsgpackCombinedAccumulatedData): Co
mapTuple(o.private_call_stack, (v: Buffer) => Fr.fromBuffer(v)),
mapTuple(o.public_call_stack, (v: Buffer) => Fr.fromBuffer(v)),
mapTuple(o.new_l2_to_l1_msgs, (v: Buffer) => Fr.fromBuffer(v)),
mapTuple(o.encrypted_logs_hash, (v: Buffer) => Fr.fromBuffer(v)),
mapTuple(o.unencrypted_logs_hash, (v: Buffer) => Fr.fromBuffer(v)),
Fr.fromBuffer(o.encrypted_log_preimages_length),
Fr.fromBuffer(o.unencrypted_log_preimages_length),
mapTuple(o.new_contracts, (v: MsgpackNewContractData) => toNewContractData(v)),
mapTuple(o.optionally_revealed_data, (v: MsgpackOptionallyRevealedData) => toOptionallyRevealedData(v)),
mapTuple(o.public_data_update_requests, (v: MsgpackPublicDataUpdateRequest) => toPublicDataUpdateRequest(v)),
Expand All @@ -429,6 +440,18 @@ export function fromCombinedAccumulatedData(o: CombinedAccumulatedData): Msgpack
if (o.newL2ToL1Msgs === undefined) {
throw new Error('Expected newL2ToL1Msgs in CombinedAccumulatedData serialization');
}
if (o.encryptedLogsHash === undefined) {
throw new Error('Expected encryptedLogsHash in CombinedAccumulatedData serialization');
}
if (o.unencryptedLogsHash === undefined) {
throw new Error('Expected unencryptedLogsHash in CombinedAccumulatedData serialization');
}
if (o.encryptedLogPreimagesLength === undefined) {
throw new Error('Expected encryptedLogPreimagesLength in CombinedAccumulatedData serialization');
}
if (o.unencryptedLogPreimagesLength === undefined) {
throw new Error('Expected unencryptedLogPreimagesLength in CombinedAccumulatedData serialization');
}
if (o.newContracts === undefined) {
throw new Error('Expected newContracts in CombinedAccumulatedData serialization');
}
Expand All @@ -448,6 +471,10 @@ export function fromCombinedAccumulatedData(o: CombinedAccumulatedData): Msgpack
private_call_stack: mapTuple(o.privateCallStack, (v: Fr) => v.toBuffer()),
public_call_stack: mapTuple(o.publicCallStack, (v: Fr) => v.toBuffer()),
new_l2_to_l1_msgs: mapTuple(o.newL2ToL1Msgs, (v: Fr) => v.toBuffer()),
encrypted_logs_hash: mapTuple(o.encryptedLogsHash, (v: Fr) => v.toBuffer()),
unencrypted_logs_hash: mapTuple(o.unencryptedLogsHash, (v: Fr) => v.toBuffer()),
encrypted_log_preimages_length: o.encryptedLogPreimagesLength.toBuffer(),
unencrypted_log_preimages_length: o.unencryptedLogPreimagesLength.toBuffer(),
new_contracts: mapTuple(o.newContracts, (v: NewContractData) => fromNewContractData(v)),
optionally_revealed_data: mapTuple(o.optionallyRevealedData, (v: OptionallyRevealedData) =>
fromOptionallyRevealedData(v),
Expand Down
1 change: 0 additions & 1 deletion yarn-project/circuits.js/src/structs/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// In future: structured serialization?
export const ARGS_LENGTH = 8;
export const RETURN_VALUES_LENGTH = 4;
export const EMITTED_EVENTS_LENGTH = 4;

export const NEW_COMMITMENTS_LENGTH = 4;
export const NEW_NULLIFIERS_LENGTH = 4;
Expand Down
Loading

0 comments on commit da58fe6

Please sign in to comment.