Skip to content

Commit

Permalink
1407 - remove read request membership witnesses from public inputs of
Browse files Browse the repository at this point in the history
private kernel
  • Loading branch information
jeanmon committed Sep 1, 2023
1 parent 2f0e4aa commit aa36af2
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ template <typename NCT> struct CombinedAccumulatedData {
AggregationObject aggregation_object{};

std::array<fr, MAX_READ_REQUESTS_PER_TX> read_requests{};
std::array<ReadRequestMembershipWitness<NCT, PRIVATE_DATA_TREE_HEIGHT>, MAX_READ_REQUESTS_PER_TX>
read_request_membership_witnesses{};

std::array<fr, MAX_NEW_COMMITMENTS_PER_TX> new_commitments{};
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX> new_nullifiers{};
Expand Down Expand Up @@ -62,7 +60,6 @@ template <typename NCT> struct CombinedAccumulatedData {
// for serialization, update with new fields
MSGPACK_FIELDS(aggregation_object,
read_requests,
read_request_membership_witnesses,
new_commitments,
new_nullifiers,
nullified_commitments,
Expand All @@ -79,18 +76,7 @@ template <typename NCT> struct CombinedAccumulatedData {
public_data_reads);
boolean operator==(CombinedAccumulatedData<NCT> const& other) const
{
return aggregation_object == other.aggregation_object && read_requests == other.read_requests &&
read_request_membership_witnesses == other.read_request_membership_witnesses &&
new_commitments == other.new_commitments && new_nullifiers == other.new_nullifiers &&
nullified_commitments == other.nullified_commitments && private_call_stack == other.private_call_stack &&
public_call_stack == other.public_call_stack && new_l2_to_l1_msgs == other.new_l2_to_l1_msgs &&
encrypted_logs_hash == other.encrypted_logs_hash &&
unencrypted_logs_hash == other.unencrypted_logs_hash &&
encrypted_log_preimages_length == other.encrypted_log_preimages_length &&
unencrypted_log_preimages_length == other.unencrypted_log_preimages_length &&
new_contracts == other.new_contracts && optionally_revealed_data == other.optionally_revealed_data &&
public_data_update_requests == other.public_data_update_requests &&
public_data_reads == other.public_data_reads;
return msgpack_derived_equals<boolean>(*this, other);
};

template <typename Builder> CombinedAccumulatedData<CircuitTypes<Builder>> to_circuit_type(Builder& builder) const
Expand All @@ -112,7 +98,6 @@ template <typename NCT> struct CombinedAccumulatedData {
},

to_ct(read_requests),
map(read_request_membership_witnesses, to_circuit_type),

to_ct(new_commitments),
to_ct(new_nullifiers),
Expand Down Expand Up @@ -153,7 +138,6 @@ template <typename NCT> struct CombinedAccumulatedData {
},

to_nt(read_requests),
map(read_request_membership_witnesses, to_native_type),

to_nt(new_commitments),
to_nt(new_nullifiers),
Expand Down Expand Up @@ -184,7 +168,6 @@ template <typename NCT> struct CombinedAccumulatedData {
aggregation_object.add_proof_outputs_as_public_inputs();

set_array_public(read_requests);
set_array_public(read_request_membership_witnesses);

set_array_public(new_commitments);
set_array_public(new_nullifiers);
Expand All @@ -211,15 +194,6 @@ template <typename NCT> struct CombinedAccumulatedData {
}
}

template <size_t SIZE>
void set_array_public(std::array<ReadRequestMembershipWitness<NCT, PRIVATE_DATA_TREE_HEIGHT>, SIZE>& arr)
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
for (auto& e : arr) {
e.set_public();
}
}

template <size_t SIZE> void set_array_public(std::array<OptionallyRevealedData<NCT>, SIZE>& arr)
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ TEST_F(native_private_kernel_tests, native_accumulate_transient_read_requests)
<< " with code: " << builder.get_first_failure().code;
ASSERT_TRUE(array_length(public_inputs.end.new_commitments) == 1);
ASSERT_TRUE(array_length(public_inputs.end.read_requests) == 1);
ASSERT_TRUE(array_length(public_inputs.end.read_request_membership_witnesses) == 1);

auto private_inputs_inner = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args());

Expand All @@ -94,7 +93,6 @@ TEST_F(native_private_kernel_tests, native_accumulate_transient_read_requests)
<< " with code: " << builder.get_first_failure().code;
ASSERT_TRUE(array_length(public_inputs.end.new_commitments) == 2);
ASSERT_TRUE(array_length(public_inputs.end.read_requests) == 2);
ASSERT_TRUE(array_length(public_inputs.end.read_request_membership_witnesses) == 2);

auto& previous_kernel = private_inputs_inner.previous_kernel;
previous_kernel.public_inputs = public_inputs;
Expand Down Expand Up @@ -128,7 +126,6 @@ TEST_F(native_private_kernel_tests, native_transient_read_requests_no_match)
<< " with code: " << builder.get_first_failure().code;
ASSERT_TRUE(array_length(public_inputs.end.new_commitments) == 1);
ASSERT_TRUE(array_length(public_inputs.end.read_requests) == 1);
ASSERT_TRUE(array_length(public_inputs.end.read_request_membership_witnesses) == 1);

auto private_inputs_inner = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args());

Expand All @@ -153,7 +150,6 @@ TEST_F(native_private_kernel_tests, native_transient_read_requests_no_match)
<< " with code: " << builder.get_first_failure().code;
ASSERT_TRUE(array_length(public_inputs.end.new_commitments) == 2);
ASSERT_TRUE(array_length(public_inputs.end.read_requests) == 2);
ASSERT_TRUE(array_length(public_inputs.end.read_request_membership_witnesses) == 2);

auto& previous_kernel = private_inputs_inner.previous_kernel;
previous_kernel.public_inputs = public_inputs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ void update_end_values(DummyCircuitBuilder& builder,
builder.do_assert(is_array_empty(public_inputs.end.read_requests),
"public_inputs.end.read_requests must start as empty in initial kernel iteration",
CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP);
builder.do_assert(
is_array_empty(public_inputs.end.read_request_membership_witnesses),
"public_inputs.end.read_request_membership_witnesses must start as empty in initial kernel iteration",
CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP);
builder.do_assert(public_inputs.end.encrypted_log_preimages_length == NT::fr(0),
"public_inputs.end.encrypted_log_preimages_length must start as 0 in initial kernel iteration",
CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ TEST_F(native_private_kernel_ordering_tests, native_matching_some_read_requests_
previous_kernel.public_inputs.end.new_nullifiers = new_nullifiers;
previous_kernel.public_inputs.end.new_commitments = siloed_commitments;
previous_kernel.public_inputs.end.read_requests = read_requests;
previous_kernel.public_inputs.end.read_request_membership_witnesses = read_request_membership_witnesses;

PrivateKernelInputsOrdering<NT> private_inputs{ previous_kernel, std::array<fr, MAX_READ_REQUESTS_PER_TX>{} };

Expand Down
63 changes: 0 additions & 63 deletions yarn-project/circuits.js/src/cbind/circuits.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
PublicDataRead,
PublicDataUpdateRequest,
PublicKernelInputs,
ReadRequestMembershipWitness,
TxContext,
VerificationKeyData,
isCircuitError,
Expand Down Expand Up @@ -181,55 +180,6 @@ export function fromNativeAggregationState(o: NativeAggregationState): MsgpackNa
};
}

interface MsgpackReadRequestMembershipWitness {
leaf_index: Buffer;
sibling_path: Tuple<Buffer, 32>;
is_transient: boolean;
hint_to_commitment: Buffer;
}

export function toReadRequestMembershipWitness(o: MsgpackReadRequestMembershipWitness): ReadRequestMembershipWitness {
if (o.leaf_index === undefined) {
throw new Error('Expected leaf_index in ReadRequestMembershipWitness deserialization');
}
if (o.sibling_path === undefined) {
throw new Error('Expected sibling_path in ReadRequestMembershipWitness deserialization');
}
if (o.is_transient === undefined) {
throw new Error('Expected is_transient in ReadRequestMembershipWitness deserialization');
}
if (o.hint_to_commitment === undefined) {
throw new Error('Expected hint_to_commitment in ReadRequestMembershipWitness deserialization');
}
return new ReadRequestMembershipWitness(
Fr.fromBuffer(o.leaf_index),
mapTuple(o.sibling_path, (v: Buffer) => Fr.fromBuffer(v)),
o.is_transient,
Fr.fromBuffer(o.hint_to_commitment),
);
}

export function fromReadRequestMembershipWitness(o: ReadRequestMembershipWitness): MsgpackReadRequestMembershipWitness {
if (o.leafIndex === undefined) {
throw new Error('Expected leafIndex in ReadRequestMembershipWitness serialization');
}
if (o.siblingPath === undefined) {
throw new Error('Expected siblingPath in ReadRequestMembershipWitness serialization');
}
if (o.isTransient === undefined) {
throw new Error('Expected isTransient in ReadRequestMembershipWitness serialization');
}
if (o.hintToCommitment === undefined) {
throw new Error('Expected hintToCommitment in ReadRequestMembershipWitness serialization');
}
return {
leaf_index: toBuffer(o.leafIndex),
sibling_path: mapTuple(o.siblingPath, (v: Fr) => toBuffer(v)),
is_transient: o.isTransient,
hint_to_commitment: toBuffer(o.hintToCommitment),
};
}

interface MsgpackNewContractData {
contract_address: Buffer;
portal_contract_address: Buffer;
Expand Down Expand Up @@ -490,7 +440,6 @@ export function fromPublicDataRead(o: PublicDataRead): MsgpackPublicDataRead {
interface MsgpackCombinedAccumulatedData {
aggregation_object: MsgpackNativeAggregationState;
read_requests: Tuple<Buffer, 16>;
read_request_membership_witnesses: Tuple<MsgpackReadRequestMembershipWitness, 16>;
new_commitments: Tuple<Buffer, 16>;
new_nullifiers: Tuple<Buffer, 16>;
nullified_commitments: Tuple<Buffer, 16>;
Expand All @@ -514,9 +463,6 @@ export function toCombinedAccumulatedData(o: MsgpackCombinedAccumulatedData): Co
if (o.read_requests === undefined) {
throw new Error('Expected read_requests in CombinedAccumulatedData deserialization');
}
if (o.read_request_membership_witnesses === undefined) {
throw new Error('Expected read_request_membership_witnesses in CombinedAccumulatedData deserialization');
}
if (o.new_commitments === undefined) {
throw new Error('Expected new_commitments in CombinedAccumulatedData deserialization');
}
Expand Down Expand Up @@ -562,9 +508,6 @@ export function toCombinedAccumulatedData(o: MsgpackCombinedAccumulatedData): Co
return new CombinedAccumulatedData(
toNativeAggregationState(o.aggregation_object),
mapTuple(o.read_requests, (v: Buffer) => Fr.fromBuffer(v)),
mapTuple(o.read_request_membership_witnesses, (v: MsgpackReadRequestMembershipWitness) =>
toReadRequestMembershipWitness(v),
),
mapTuple(o.new_commitments, (v: Buffer) => Fr.fromBuffer(v)),
mapTuple(o.new_nullifiers, (v: Buffer) => Fr.fromBuffer(v)),
mapTuple(o.nullified_commitments, (v: Buffer) => Fr.fromBuffer(v)),
Expand All @@ -589,9 +532,6 @@ export function fromCombinedAccumulatedData(o: CombinedAccumulatedData): Msgpack
if (o.readRequests === undefined) {
throw new Error('Expected readRequests in CombinedAccumulatedData serialization');
}
if (o.readRequestMembershipWitnesses === undefined) {
throw new Error('Expected readRequestMembershipWitnesses in CombinedAccumulatedData serialization');
}
if (o.newCommitments === undefined) {
throw new Error('Expected newCommitments in CombinedAccumulatedData serialization');
}
Expand Down Expand Up @@ -637,9 +577,6 @@ export function fromCombinedAccumulatedData(o: CombinedAccumulatedData): Msgpack
return {
aggregation_object: fromNativeAggregationState(o.aggregationObject),
read_requests: mapTuple(o.readRequests, (v: Fr) => toBuffer(v)),
read_request_membership_witnesses: mapTuple(o.readRequestMembershipWitnesses, (v: ReadRequestMembershipWitness) =>
fromReadRequestMembershipWitness(v),
),
new_commitments: mapTuple(o.newCommitments, (v: Fr) => toBuffer(v)),
new_nullifiers: mapTuple(o.newNullifiers, (v: Fr) => toBuffer(v)),
nullified_commitments: mapTuple(o.nullifiedCommitments, (v: Fr) => toBuffer(v)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import {
NUM_FIELDS_PER_SHA256,
} from '../../cbind/constants.gen.js';
import { assertMemberLength, makeTuple } from '../../index.js';
import { makeEmptyReadRequestMembershipWitness } from '../../tests/factories.js';
import { serializeToBuffer } from '../../utils/serialize.js';
import {
AggregationObject,
AztecAddress,
EthAddress,
Fr,
FunctionData,
ReadRequestMembershipWitness,
} from '../index.js';

/**
Expand Down Expand Up @@ -295,10 +293,6 @@ export class CombinedAccumulatedData {
* All the read requests made in this transaction.
*/
public readRequests: Tuple<Fr, typeof MAX_READ_REQUESTS_PER_TX>,
/**
* All the read request membership witnesses made in this transaction.
*/
public readRequestMembershipWitnesses: Tuple<ReadRequestMembershipWitness, typeof MAX_READ_REQUESTS_PER_TX>,
/**
* The new commitments made in this transaction.
*/
Expand Down Expand Up @@ -360,7 +354,6 @@ export class CombinedAccumulatedData {
public publicDataReads: Tuple<PublicDataRead, typeof MAX_PUBLIC_DATA_READS_PER_TX>,
) {
assertMemberLength(this, 'readRequests', MAX_READ_REQUESTS_PER_TX);
assertMemberLength(this, 'readRequestMembershipWitnesses', MAX_READ_REQUESTS_PER_TX);
assertMemberLength(this, 'newCommitments', MAX_NEW_COMMITMENTS_PER_TX);
assertMemberLength(this, 'newNullifiers', MAX_NEW_NULLIFIERS_PER_TX);
assertMemberLength(this, 'nullifiedCommitments', MAX_NEW_NULLIFIERS_PER_TX);
Expand All @@ -379,7 +372,6 @@ export class CombinedAccumulatedData {
return serializeToBuffer(
this.aggregationObject,
this.readRequests,
this.readRequestMembershipWitnesses,
this.newCommitments,
this.newNullifiers,
this.nullifiedCommitments,
Expand Down Expand Up @@ -411,7 +403,6 @@ export class CombinedAccumulatedData {
return new CombinedAccumulatedData(
reader.readObject(AggregationObject),
reader.readArray(MAX_READ_REQUESTS_PER_TX, Fr),
reader.readArray(MAX_READ_REQUESTS_PER_TX, ReadRequestMembershipWitness),
reader.readArray(MAX_NEW_COMMITMENTS_PER_TX, Fr),
reader.readArray(MAX_NEW_NULLIFIERS_PER_TX, Fr),
reader.readArray(MAX_NEW_NULLIFIERS_PER_TX, Fr),
Expand All @@ -433,7 +424,6 @@ export class CombinedAccumulatedData {
return new CombinedAccumulatedData(
finalData.aggregationObject,
makeTuple(MAX_READ_REQUESTS_PER_TX, Fr.zero),
makeTuple(MAX_READ_REQUESTS_PER_TX, makeEmptyReadRequestMembershipWitness),
finalData.newCommitments,
finalData.newNullifiers,
finalData.nullifiedCommitments,
Expand Down Expand Up @@ -464,7 +454,6 @@ export class CombinedAccumulatedData {
return new CombinedAccumulatedData(
AggregationObject.makeFake(),
makeTuple(MAX_READ_REQUESTS_PER_TX, Fr.zero),
makeTuple(MAX_READ_REQUESTS_PER_TX, () => ReadRequestMembershipWitness.empty(BigInt(0))),
makeTuple(MAX_NEW_COMMITMENTS_PER_TX, Fr.zero),
makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.zero),
makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.zero),
Expand Down
1 change: 0 additions & 1 deletion yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ export function makeAccumulatedData(seed = 1, full = false): CombinedAccumulated
return new CombinedAccumulatedData(
makeAggregationObject(seed),
tupleGenerator(MAX_READ_REQUESTS_PER_TX, fr, seed + 0x80),
tupleGenerator(MAX_READ_REQUESTS_PER_TX, i => makeReadRequestMembershipWitness(i * 123), seed + 0x90),
tupleGenerator(MAX_NEW_COMMITMENTS_PER_TX, fr, seed + 0x100),
tupleGenerator(MAX_NEW_NULLIFIERS_PER_TX, fr, seed + 0x200),
tupleGenerator(MAX_NEW_NULLIFIERS_PER_TX, fr, seed + 0x300),
Expand Down

0 comments on commit aa36af2

Please sign in to comment.