Skip to content

Commit 8be7360

Browse files
committed
refactor: using ExtendedContractData in tx
1 parent a161564 commit 8be7360

File tree

8 files changed

+47
-122
lines changed

8 files changed

+47
-122
lines changed

yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import {
88
AztecAddress,
99
CompleteAddress,
10+
EthAddress,
1011
FunctionData,
1112
KernelCircuitPublicInputs,
1213
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
@@ -395,23 +396,20 @@ export class AztecRPCServer implements AztecRPC {
395396
const encryptedLogs = new TxL2Logs(collectEncryptedLogs(executionResult));
396397
const unencryptedLogs = new TxL2Logs(collectUnencryptedLogs(executionResult));
397398
const enqueuedPublicFunctions = collectEnqueuedPublicFunctionCalls(executionResult);
398-
const partialAddress = newContract?.completeAddress.partialAddress ?? Fr.ZERO;
399-
const publicKey = newContract?.completeAddress.publicKey ?? Point.ZERO;
399+
400+
const contractData = new ContractData(newContract?.completeAddress.address ?? AztecAddress.ZERO, EthAddress.ZERO);
401+
const extendedContractData = new ExtendedContractData(
402+
contractData,
403+
newContractPublicFunctions,
404+
newContract?.completeAddress.partialAddress ?? Fr.ZERO,
405+
newContract?.completeAddress.publicKey ?? Point.ZERO,
406+
);
400407

401408
// HACK(#1639): Manually patches the ordering of the public call stack
402409
// TODO(#757): Enforce proper ordering of enqueued public calls
403410
await this.patchPublicCallStackOrdering(publicInputs, enqueuedPublicFunctions);
404411

405-
return new Tx(
406-
publicInputs,
407-
proof,
408-
encryptedLogs,
409-
unencryptedLogs,
410-
newContractPublicFunctions,
411-
enqueuedPublicFunctions,
412-
[partialAddress],
413-
[publicKey],
414-
);
412+
return new Tx(publicInputs, proof, encryptedLogs, unencryptedLogs, enqueuedPublicFunctions, [extendedContractData]);
415413
}
416414

417415
// HACK(#1639): this is a hack to fix ordering of public calls enqueued in the call stack. Since the private kernel

yarn-project/p2p/src/service/tx_messages.test.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ const verifyTx = (actual: Tx, expected: Tx) => {
2525
expect(actual.data!.toBuffer()).toEqual(expected.data?.toBuffer());
2626
expect(actual.proof!.toBuffer()).toEqual(expected.proof!.toBuffer());
2727
expect(actual.encryptedLogs!.toBuffer()).toEqual(expected.encryptedLogs?.toBuffer());
28-
expect(actual.newContractPublicFunctions!.length).toEqual(expected.newContractPublicFunctions!.length);
29-
for (let i = 0; i < actual.newContractPublicFunctions!.length; i++) {
30-
expect(actual.newContractPublicFunctions![i].toBuffer()).toEqual(
31-
expected.newContractPublicFunctions![i].toBuffer(),
32-
);
28+
expect(actual.newContracts!.length).toEqual(expected.newContracts!.length);
29+
for (let i = 0; i < actual.newContracts!.length; i++) {
30+
expect(actual.newContracts![i].toBuffer()).toEqual(expected.newContracts![i].toBuffer());
3331
}
3432
};
3533

yarn-project/p2p/src/service/tx_messages.ts

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
import {
2-
Fr,
3-
KernelCircuitPublicInputs,
4-
MAX_NEW_CONTRACTS_PER_TX,
5-
PartialAddress,
6-
Point,
7-
Proof,
8-
PublicCallRequest,
9-
PublicKey,
10-
} from '@aztec/circuits.js';
1+
import { KernelCircuitPublicInputs, MAX_NEW_CONTRACTS_PER_TX, Proof, PublicCallRequest } from '@aztec/circuits.js';
112
import { Tuple, numToUInt32BE } from '@aztec/foundation/serialize';
12-
import { EncodedContractFunction, Tx, TxHash, TxL2Logs } from '@aztec/types';
3+
import { ExtendedContractData, Tx, TxHash, TxL2Logs } from '@aztec/types';
134

145
/**
156
* Enumeration of P2P message types.
@@ -154,10 +145,8 @@ export function toTxMessage(tx: Tx): Buffer {
154145
createMessageComponent(tx.proof),
155146
createMessageComponent(tx.encryptedLogs),
156147
createMessageComponent(tx.unencryptedLogs),
157-
createMessageComponents(tx.newContractPublicFunctions),
158148
createMessageComponents(tx.enqueuedPublicFunctionCalls),
159-
createMessageComponents(tx.partialAddresses),
160-
createMessageComponents(tx.publicKeys),
149+
createMessageComponents(tx.newContracts),
161150
]);
162151
const messageLength = numToUInt32BE(messageBuffer.length);
163152
return Buffer.concat([messageLength, messageBuffer]);
@@ -209,18 +198,14 @@ export function fromTxMessage(buffer: Buffer): Tx {
209198
unencryptedLogs.obj = new TxL2Logs([]);
210199
}
211200

212-
const functions = toObjectArray(unencryptedLogs.remainingData, EncodedContractFunction);
213-
const publicCalls = toObjectArray(functions.remainingData, PublicCallRequest);
214-
const partialAddresses = toObjectArray(publicCalls.remainingData, Fr);
215-
const publicKeys = toObjectArray(partialAddresses.remainingData, Point);
201+
const publicCalls = toObjectArray(unencryptedLogs.remainingData, PublicCallRequest);
202+
const newContracts = toObjectArray(publicCalls.remainingData, ExtendedContractData);
216203
return new Tx(
217204
publicInputs.obj!,
218205
proof.obj!,
219206
encryptedLogs.obj,
220207
unencryptedLogs.obj,
221-
functions.objects,
222208
publicCalls.objects,
223-
partialAddresses.objects as Tuple<PartialAddress, typeof MAX_NEW_CONTRACTS_PER_TX>,
224-
publicKeys.objects as Tuple<PublicKey, typeof MAX_NEW_CONTRACTS_PER_TX>,
209+
newContracts.objects as Tuple<ExtendedContractData, typeof MAX_NEW_CONTRACTS_PER_TX>,
225210
);
226211
}

yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { toBufferBE } from '@aztec/foundation/bigint-buffer';
3333
import { to2Fields } from '@aztec/foundation/serialize';
3434
import {
3535
ContractData,
36+
ExtendedContractData,
3637
L2Block,
3738
L2BlockL2Logs,
3839
MerkleTreeId,
@@ -178,10 +179,8 @@ describe('sequencer/solo_block_builder', () => {
178179
emptyProof,
179180
makeEmptyLogs(),
180181
makeEmptyLogs(),
181-
[],
182182
times(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makePublicCallRequest),
183-
[new Fr(0)],
184-
[Point.ZERO],
183+
[ExtendedContractData.random()],
185184
),
186185
);
187186

yarn-project/sequencer-client/src/sequencer/public_processor.test.ts

+5-15
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import {
1212
MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX,
1313
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
1414
PUBLIC_DATA_TREE_HEIGHT,
15-
Point,
1615
Proof,
1716
PublicCallRequest,
1817
makeEmptyProof,
19-
makeTuple,
18+
makeTuple
2019
} from '@aztec/circuits.js';
2120
import { computeCallStackItemHash } from '@aztec/circuits.js/abis';
2221
import {
@@ -156,16 +155,9 @@ describe('public_processor', () => {
156155
kernelOutput.end.publicCallStack = padArrayEnd(callStackHashes, Fr.ZERO, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX);
157156
kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX);
158157

159-
const tx = new Tx(
160-
kernelOutput,
161-
proof,
162-
TxL2Logs.random(2, 3),
163-
TxL2Logs.random(3, 2),
164-
[],
165-
callRequests,
166-
[Fr.random()],
167-
[Point.random()],
168-
);
158+
const tx = new Tx(kernelOutput, proof, TxL2Logs.random(2, 3), TxL2Logs.random(3, 2), callRequests, [
159+
ExtendedContractData.random(),
160+
]);
169161

170162
publicExecutor.execute.mockImplementation(execution => {
171163
for (const request of callRequests) {
@@ -198,10 +190,8 @@ describe('public_processor', () => {
198190
proof,
199191
TxL2Logs.random(2, 3),
200192
TxL2Logs.random(3, 2),
201-
[],
202193
[callRequest],
203-
[Fr.random()],
204-
[Point.random()],
194+
[ExtendedContractData.random()],
205195
);
206196

207197
const publicExecutionResult = makePublicExecutionResultFromRequest(callRequest);

yarn-project/sequencer-client/src/sequencer/sequencer.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,7 @@ export class Sequencer {
194194
// Currently can only have 1 new contract per tx
195195
const newContract = tx.data?.end.newContracts[0];
196196
if (newContract) {
197-
return new ExtendedContractData(
198-
new ContractData(newContract.contractAddress, newContract.portalContractAddress),
199-
tx.newContractPublicFunctions,
200-
tx.partialAddresses[0],
201-
tx.publicKeys[0],
202-
);
197+
return tx.newContracts[0];
203198
}
204199
})
205200
.filter((cd): cd is Exclude<typeof cd, undefined> => cd !== undefined);

yarn-project/types/src/mocks.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import {
22
CompleteAddress,
33
EthAddress,
4-
Fr,
54
MAX_NEW_CONTRACTS_PER_TX,
65
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
7-
PartialAddress,
8-
Point,
96
Proof,
10-
PublicKey,
117
} from '@aztec/circuits.js';
128
import { makeKernelPublicInputs, makePublicCallRequest } from '@aztec/circuits.js/factories';
139
import { ContractAbi } from '@aztec/foundation/abi';
@@ -16,7 +12,7 @@ import { Tuple } from '@aztec/foundation/serialize';
1612

1713
import times from 'lodash.times';
1814

19-
import { DeployedContract, EncodedContractFunction, FunctionL2Logs, TxL2Logs } from './index.js';
15+
import { DeployedContract, ExtendedContractData, FunctionL2Logs, TxL2Logs } from './index.js';
2016
import { Tx } from './tx/index.js';
2117

2218
/**
@@ -33,10 +29,11 @@ export const mockTx = (seed = 1) => {
3329
new Proof(Buffer.alloc(0)),
3430
TxL2Logs.random(8, 3), // 8 priv function invocations creating 3 encrypted logs each
3531
TxL2Logs.random(11, 2), // 8 priv + 3 pub function invocations creating 2 unencrypted logs each
36-
times(3, EncodedContractFunction.random),
3732
times(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makePublicCallRequest),
38-
times(MAX_NEW_CONTRACTS_PER_TX, Fr.random) as Tuple<PartialAddress, typeof MAX_NEW_CONTRACTS_PER_TX>,
39-
times(MAX_NEW_CONTRACTS_PER_TX, Point.random) as Tuple<PublicKey, typeof MAX_NEW_CONTRACTS_PER_TX>,
33+
times(MAX_NEW_CONTRACTS_PER_TX, ExtendedContractData.random) as Tuple<
34+
ExtendedContractData,
35+
typeof MAX_NEW_CONTRACTS_PER_TX
36+
>,
4037
);
4138
};
4239

yarn-project/types/src/tx/tx.ts

+15-52
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import {
2-
Fr,
32
KernelCircuitPublicInputs,
43
MAX_NEW_CONTRACTS_PER_TX,
54
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
6-
PartialAddress,
7-
Point,
85
Proof,
96
PublicCallRequest,
10-
PublicKey,
117
} from '@aztec/circuits.js';
128
import { serializeToBuffer } from '@aztec/circuits.js/utils';
139
import { arrayNonEmptyLength } from '@aztec/foundation/collection';
14-
import { BufferReader, Tuple, numToUInt32BE } from '@aztec/foundation/serialize';
10+
import { BufferReader, Tuple } from '@aztec/foundation/serialize';
1511

16-
import { EncodedContractFunction } from '../contract_data.js';
12+
import { ExtendedContractData } from '../contract_data.js';
1713
import { TxL2Logs } from '../logs/tx_l2_logs.js';
1814
import { TxHash } from './tx_hash.js';
1915

@@ -38,19 +34,16 @@ export class Tx {
3834
* Unencrypted logs generated by the tx.
3935
*/
4036
public readonly unencryptedLogs: TxL2Logs,
41-
/**
42-
* New public functions made available by this tx.
43-
*/
44-
public readonly newContractPublicFunctions: EncodedContractFunction[],
4537
/**
4638
* Enqueued public functions from the private circuit to be run by the sequencer.
4739
* Preimages of the public call stack entries from the private kernel circuit output.
4840
*/
4941
public readonly enqueuedPublicFunctionCalls: PublicCallRequest[],
50-
/** Partial addresses of new contracts. */
51-
public readonly partialAddresses: Tuple<PartialAddress, typeof MAX_NEW_CONTRACTS_PER_TX>,
52-
/** Public keys of new contracts. */
53-
public readonly publicKeys: Tuple<PublicKey, typeof MAX_NEW_CONTRACTS_PER_TX>,
42+
/**
43+
* Contracts deployed in this tx.
44+
* Note: Portal address is always set to zero in the tx's new contracts.
45+
*/
46+
public readonly newContracts: Tuple<ExtendedContractData, typeof MAX_NEW_CONTRACTS_PER_TX>,
5447
) {
5548
if (this.unencryptedLogs.functionLogs.length < this.encryptedLogs.functionLogs.length) {
5649
// This check is present because each private function invocation creates encrypted FunctionL2Logs object and
@@ -84,10 +77,8 @@ export class Tx {
8477
reader.readObject(Proof),
8578
reader.readObject(TxL2Logs),
8679
reader.readObject(TxL2Logs),
87-
reader.readArray(reader.readNumber(), EncodedContractFunction),
8880
reader.readArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, PublicCallRequest),
89-
reader.readArray(MAX_NEW_CONTRACTS_PER_TX, Fr),
90-
reader.readArray(MAX_NEW_CONTRACTS_PER_TX, Point),
81+
reader.readArray(MAX_NEW_CONTRACTS_PER_TX, ExtendedContractData),
9182
);
9283
}
9384

@@ -101,12 +92,8 @@ export class Tx {
10192
this.proof,
10293
this.encryptedLogs,
10394
this.unencryptedLogs,
104-
// number of new contract public functions is not constant so we need to include it in the serialization
105-
numToUInt32BE(this.newContractPublicFunctions.length),
106-
this.newContractPublicFunctions,
10795
this.enqueuedPublicFunctionCalls,
108-
this.partialAddresses,
109-
this.publicKeys,
96+
this.newContracts,
11097
]);
11198
}
11299

@@ -120,10 +107,8 @@ export class Tx {
120107
encryptedLogs: this.encryptedLogs.toBuffer().toString('hex'),
121108
unencryptedLogs: this.unencryptedLogs.toBuffer().toString('hex'),
122109
proof: this.proof.toBuffer().toString('hex'),
123-
newContractPublicFunctions: this.newContractPublicFunctions.map(f => f.toBuffer().toString('hex')) ?? [],
124110
enqueuedPublicFunctions: this.enqueuedPublicFunctionCalls.map(f => f.toBuffer().toString('hex')) ?? [],
125-
partialAddresses: this.partialAddresses.map(f => f.toBuffer().toString('hex')),
126-
publicKeys: this.publicKeys.map(f => f.toBuffer().toString('hex')),
111+
newContracts: this.newContracts.map(c => c.toBuffer().toString('hex')),
127112
};
128113
}
129114

@@ -137,23 +122,17 @@ export class Tx {
137122
const encryptedLogs = TxL2Logs.fromBuffer(Buffer.from(obj.encryptedLogs, 'hex'));
138123
const unencryptedLogs = TxL2Logs.fromBuffer(Buffer.from(obj.unencryptedLogs, 'hex'));
139124
const proof = Buffer.from(obj.proof, 'hex');
140-
const newContractPublicFunctions = obj.newContractPublicFunctions
141-
? obj.newContractPublicFunctions.map((x: string) => EncodedContractFunction.fromBuffer(Buffer.from(x, 'hex')))
142-
: [];
143125
const enqueuedPublicFunctions = obj.enqueuedPublicFunctions
144126
? obj.enqueuedPublicFunctions.map((x: string) => PublicCallRequest.fromBuffer(Buffer.from(x, 'hex')))
145127
: [];
146-
const partialAddresses = obj.partialAddresses.map((x: string) => Fr.fromBuffer(Buffer.from(x, 'hex')));
147-
const publicKeys = obj.publicKeys.map((x: string) => Point.fromBuffer(Buffer.from(x, 'hex')));
128+
const newContracts = obj.newContracts.map((x: string) => ExtendedContractData.fromBuffer(Buffer.from(x, 'hex')));
148129
return new Tx(
149130
publicInputs,
150131
Proof.fromBuffer(proof),
151132
encryptedLogs,
152133
unencryptedLogs,
153-
newContractPublicFunctions,
154134
enqueuedPublicFunctions,
155-
partialAddresses,
156-
publicKeys,
135+
newContracts,
157136
);
158137
}
159138

@@ -187,29 +166,13 @@ export class Tx {
187166
const proof = Proof.fromBuffer(tx.proof.toBuffer());
188167
const encryptedLogs = TxL2Logs.fromBuffer(tx.encryptedLogs.toBuffer());
189168
const unencryptedLogs = TxL2Logs.fromBuffer(tx.unencryptedLogs.toBuffer());
190-
const publicFunctions = tx.newContractPublicFunctions.map(x => {
191-
return EncodedContractFunction.fromBuffer(x.toBuffer());
192-
});
193169
const enqueuedPublicFunctions = tx.enqueuedPublicFunctionCalls.map(x => {
194170
return PublicCallRequest.fromBuffer(x.toBuffer());
195171
});
196-
const partialAddresses = tx.partialAddresses.map(x => Fr.fromBuffer(x.toBuffer())) as Tuple<
197-
PartialAddress,
198-
typeof MAX_NEW_CONTRACTS_PER_TX
199-
>;
200-
const publicKeys = tx.publicKeys.map(x => Point.fromBuffer(x.toBuffer())) as Tuple<
201-
PublicKey,
172+
const newContracts = tx.newContracts.map(c => ExtendedContractData.fromBuffer(c.toBuffer())) as Tuple<
173+
ExtendedContractData,
202174
typeof MAX_NEW_CONTRACTS_PER_TX
203175
>;
204-
return new Tx(
205-
publicInputs,
206-
proof,
207-
encryptedLogs,
208-
unencryptedLogs,
209-
publicFunctions,
210-
enqueuedPublicFunctions,
211-
partialAddresses,
212-
publicKeys,
213-
);
176+
return new Tx(publicInputs, proof, encryptedLogs, unencryptedLogs, enqueuedPublicFunctions, newContracts);
214177
}
215178
}

0 commit comments

Comments
 (0)