@aztec/stdlib 0.85.0-alpha-testnet.4 → 0.85.0-alpha-testnet.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/block/published_l2_block.d.ts +2 -1
- package/dest/block/published_l2_block.d.ts.map +1 -1
- package/dest/block/published_l2_block.js +5 -18
- package/dest/errors/simulation_error.d.ts.map +1 -1
- package/dest/errors/simulation_error.js +2 -2
- package/dest/p2p/block_proposal.d.ts +8 -3
- package/dest/p2p/block_proposal.d.ts.map +1 -1
- package/dest/p2p/block_proposal.js +23 -8
- package/dest/p2p/interface.d.ts +1 -1
- package/dest/tests/mocks.d.ts +5 -0
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +24 -1
- package/package.json +7 -7
- package/src/block/published_l2_block.ts +6 -16
- package/src/errors/simulation_error.ts +2 -2
- package/src/p2p/block_proposal.ts +29 -5
- package/src/tests/mocks.ts +31 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
2
2
|
import { L2Block } from '@aztec/stdlib/block';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { BlockAttestation } from '../p2p/block_attestation.js';
|
|
4
5
|
export type L1PublishedData = {
|
|
5
6
|
blockNumber: bigint;
|
|
6
7
|
timestamp: bigint;
|
|
@@ -85,5 +86,5 @@ export declare const PublishedL2BlockSchema: z.ZodObject<{
|
|
|
85
86
|
};
|
|
86
87
|
signatures: string[];
|
|
87
88
|
}>;
|
|
88
|
-
export declare function
|
|
89
|
+
export declare function getAttestationsFromPublishedL2Block(block: PublishedL2Block): BlockAttestation[];
|
|
89
90
|
//# sourceMappingURL=published_l2_block.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"published_l2_block.d.ts","sourceRoot":"","sources":["../../src/block/published_l2_block.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"published_l2_block.d.ts","sourceRoot":"","sources":["../../src/block/published_l2_block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAE5D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,EAAE,EAAE,eAAe,CAAC;IACpB,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQjC,CAAC;AAEH,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,gBAAgB,sBAG1E"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { times } from '@aztec/foundation/collection';
|
|
3
|
-
import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
4
1
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
5
2
|
import { schemas } from '@aztec/foundation/schemas';
|
|
6
3
|
import { L2Block } from '@aztec/stdlib/block';
|
|
7
4
|
import { z } from 'zod';
|
|
5
|
+
import { BlockAttestation } from '../p2p/block_attestation.js';
|
|
6
|
+
import { ConsensusPayload } from '../p2p/consensus_payload.js';
|
|
8
7
|
export const PublishedL2BlockSchema = z.object({
|
|
9
8
|
block: L2Block.schema,
|
|
10
9
|
l1: z.object({
|
|
@@ -14,19 +13,7 @@ export const PublishedL2BlockSchema = z.object({
|
|
|
14
13
|
}),
|
|
15
14
|
signatures: z.array(Signature.schema)
|
|
16
15
|
});
|
|
17
|
-
export
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
blockNumber: BigInt(block.number),
|
|
21
|
-
timestamp: block.header.globalVariables.timestamp.toBigInt(),
|
|
22
|
-
blockHash: Buffer32.random().toString()
|
|
23
|
-
};
|
|
24
|
-
// Create valid signatures
|
|
25
|
-
const signers = times(3, ()=>Secp256k1Signer.random());
|
|
26
|
-
const signatures = await Promise.all(times(3, async (i)=>signers[i].signMessage(Buffer32.fromField(await block.hash()))));
|
|
27
|
-
return {
|
|
28
|
-
block,
|
|
29
|
-
l1,
|
|
30
|
-
signatures
|
|
31
|
-
};
|
|
16
|
+
export function getAttestationsFromPublishedL2Block(block) {
|
|
17
|
+
const payload = ConsensusPayload.fromBlock(block.block);
|
|
18
|
+
return block.signatures.filter((sig)=>!sig.isEmpty).map((signature)=>new BlockAttestation(payload, signature));
|
|
32
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation_error.d.ts","sourceRoot":"","sources":["../../src/errors/simulation_error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAInD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"simulation_error.d.ts","sourceRoot":"","sources":["../../src/errors/simulation_error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAInD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,E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AAM;IAQ1E;;;;;OAKG;IACH,sBAAsB,CAAC,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM;IAY9G,QAAQ;IAqBR;;OAEG;IACH,YAAY,IAAI,eAAe,EAAE;IAIjC;;;OAGG;IACH,gBAAgB,IAAI,aAAa;IAIjC;;;OAGG;IACH,gBAAgB,CAAC,SAAS,EAAE,aAAa;IAIzC,eAAe,CAAC,OAAO,EAAE,MAAM;IAI/B,MAAM;;;;;;IASN,MAAM,KAAK,MAAM,IAAI,MAAM,CAAC,eAAe,CAAC,CAmB3C;WAEY,MAAM;CAKpB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { FunctionSelector } from '../abi/function_selector.js';
|
|
3
3
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
4
|
-
import { schemas } from '../schemas/index.js';
|
|
4
|
+
import { optional, schemas } from '../schemas/index.js';
|
|
5
5
|
const SourceCodeLocationSchema = z.object({
|
|
6
6
|
filePath: z.string(),
|
|
7
7
|
line: z.number().int().nonnegative(),
|
|
@@ -144,7 +144,7 @@ const NoirCallStackSchema = z.union([
|
|
|
144
144
|
functionErrorStack: z.array(z.object({
|
|
145
145
|
contractAddress: schemas.AztecAddress,
|
|
146
146
|
contractName: z.string().optional(),
|
|
147
|
-
functionSelector: schemas.FunctionSelector,
|
|
147
|
+
functionSelector: optional(schemas.FunctionSelector),
|
|
148
148
|
functionName: z.string().optional()
|
|
149
149
|
})),
|
|
150
150
|
noirErrorStack: NoirCallStackSchema.optional(),
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
4
4
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
5
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
6
|
-
import
|
|
6
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
7
7
|
import { BufferReader } from '@aztec/foundation/serialize';
|
|
8
|
+
import { Tx } from '../tx/tx.js';
|
|
8
9
|
import { ConsensusPayload } from './consensus_payload.js';
|
|
9
10
|
import { Gossipable } from './gossipable.js';
|
|
10
11
|
export declare class BlockProposalHash extends Buffer32 {
|
|
@@ -21,18 +22,22 @@ export declare class BlockProposal extends Gossipable {
|
|
|
21
22
|
readonly payload: ConsensusPayload;
|
|
22
23
|
/** The signer of the BlockProposal over the header of the new block*/
|
|
23
24
|
readonly signature: Signature;
|
|
25
|
+
/** The transactions in the block */
|
|
26
|
+
readonly txs?: Tx[] | undefined;
|
|
24
27
|
static p2pTopic: string;
|
|
25
28
|
private sender;
|
|
26
29
|
constructor(
|
|
27
30
|
/** The payload of the message, and what the signature is over */
|
|
28
31
|
payload: ConsensusPayload,
|
|
29
32
|
/** The signer of the BlockProposal over the header of the new block*/
|
|
30
|
-
signature: Signature
|
|
33
|
+
signature: Signature,
|
|
34
|
+
/** The transactions in the block */
|
|
35
|
+
txs?: Tx[] | undefined);
|
|
31
36
|
p2pMessageIdentifier(): Promise<Buffer32>;
|
|
32
37
|
get archive(): Fr;
|
|
33
38
|
get slotNumber(): Fr;
|
|
34
39
|
get blockNumber(): Fr;
|
|
35
|
-
static createProposalFromSigner(payload: ConsensusPayload, payloadSigner: (payload: Buffer32) => Promise<Signature>): Promise<BlockProposal>;
|
|
40
|
+
static createProposalFromSigner(payload: ConsensusPayload, txs: Tx[], payloadSigner: (payload: Buffer32) => Promise<Signature>): Promise<BlockProposal>;
|
|
36
41
|
/**Get Sender
|
|
37
42
|
* Lazily evaluate the sender of the proposal; result is cached
|
|
38
43
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_proposal.d.ts","sourceRoot":"","sources":["../../src/p2p/block_proposal.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OA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AC,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,SAAS,CAAC;IAQ1D;;OAEG;IACG,SAAS;IAaf,UAAU;IAIV,QAAQ,IAAI,MAAM;IASlB,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,aAAa;IAa5D,OAAO,IAAI,MAAM;CAOlB"}
|
|
@@ -2,6 +2,7 @@ import { Buffer32 } from '@aztec/foundation/buffer';
|
|
|
2
2
|
import { keccak256, recoverAddress } from '@aztec/foundation/crypto';
|
|
3
3
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
4
4
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
import { Tx } from '../tx/tx.js';
|
|
5
6
|
import { ConsensusPayload } from './consensus_payload.js';
|
|
6
7
|
import { Gossipable } from './gossipable.js';
|
|
7
8
|
import { SignatureDomainSeparator, getHashedSignaturePayload, getHashedSignaturePayloadEthSignedMessage } from './signature_utils.js';
|
|
@@ -19,10 +20,12 @@ export class BlockProposalHash extends Buffer32 {
|
|
|
19
20
|
*/ export class BlockProposal extends Gossipable {
|
|
20
21
|
payload;
|
|
21
22
|
signature;
|
|
23
|
+
txs;
|
|
22
24
|
static p2pTopic = createTopicString(TopicType.block_proposal);
|
|
23
25
|
sender;
|
|
24
|
-
constructor(/** The payload of the message, and what the signature is over */ payload, /** The signer of the BlockProposal over the header of the new block*/ signature)
|
|
25
|
-
|
|
26
|
+
constructor(/** The payload of the message, and what the signature is over */ payload, /** The signer of the BlockProposal over the header of the new block*/ signature, // Note(md): this is placed after the txs payload in order to be backwards compatible with previous versions
|
|
27
|
+
/** The transactions in the block */ txs){
|
|
28
|
+
super(), this.payload = payload, this.signature = signature, this.txs = txs;
|
|
26
29
|
}
|
|
27
30
|
p2pMessageIdentifier() {
|
|
28
31
|
return Promise.resolve(new BlockProposalHash(keccak256(this.signature.toBuffer())));
|
|
@@ -36,10 +39,11 @@ export class BlockProposalHash extends Buffer32 {
|
|
|
36
39
|
get blockNumber() {
|
|
37
40
|
return this.payload.header.globalVariables.blockNumber;
|
|
38
41
|
}
|
|
39
|
-
static async createProposalFromSigner(payload,
|
|
42
|
+
static async createProposalFromSigner(payload, // Note(md): Provided seperately to tx hashes such that this function can be optional
|
|
43
|
+
txs, payloadSigner) {
|
|
40
44
|
const hashed = await getHashedSignaturePayload(payload, SignatureDomainSeparator.blockProposal);
|
|
41
45
|
const sig = await payloadSigner(hashed);
|
|
42
|
-
return new BlockProposal(payload, sig);
|
|
46
|
+
return new BlockProposal(payload, sig, txs);
|
|
43
47
|
}
|
|
44
48
|
/**Get Sender
|
|
45
49
|
* Lazily evaluate the sender of the proposal; result is cached
|
|
@@ -55,16 +59,27 @@ export class BlockProposalHash extends Buffer32 {
|
|
|
55
59
|
return this.payload.getPayloadToSign(SignatureDomainSeparator.blockProposal);
|
|
56
60
|
}
|
|
57
61
|
toBuffer() {
|
|
58
|
-
|
|
62
|
+
const buffer = [
|
|
59
63
|
this.payload,
|
|
60
64
|
this.signature
|
|
61
|
-
]
|
|
65
|
+
];
|
|
66
|
+
if (this.txs) {
|
|
67
|
+
buffer.push(this.txs.length);
|
|
68
|
+
buffer.push(this.txs);
|
|
69
|
+
}
|
|
70
|
+
return serializeToBuffer(buffer);
|
|
62
71
|
}
|
|
63
72
|
static fromBuffer(buf) {
|
|
64
73
|
const reader = BufferReader.asReader(buf);
|
|
65
|
-
|
|
74
|
+
const payload = reader.readObject(ConsensusPayload);
|
|
75
|
+
const sig = reader.readObject(Signature);
|
|
76
|
+
if (!reader.isEmpty()) {
|
|
77
|
+
const txs = reader.readArray(reader.readNumber(), Tx);
|
|
78
|
+
return new BlockProposal(payload, sig, txs);
|
|
79
|
+
}
|
|
80
|
+
return new BlockProposal(payload, sig);
|
|
66
81
|
}
|
|
67
82
|
getSize() {
|
|
68
|
-
return this.payload.getSize() + this.signature.getSize();
|
|
83
|
+
return this.payload.getSize() + this.signature.getSize() + (this.txs ? this.txs.reduce((acc, tx)=>acc + tx.getSize(), 0) : 0);
|
|
69
84
|
}
|
|
70
85
|
}
|
package/dest/p2p/interface.d.ts
CHANGED
|
@@ -13,6 +13,6 @@ export declare const TopicTypeMap: Record<string, typeof Gossipable>;
|
|
|
13
13
|
* Used in msgIdFn libp2p to get the p2pMessageIdentifier from a message
|
|
14
14
|
*/
|
|
15
15
|
export declare const TopicToDeserializer: {
|
|
16
|
-
[x: string]: typeof
|
|
16
|
+
[x: string]: typeof Tx.fromBuffer | typeof BlockAttestation.fromBuffer | typeof BlockProposal.fromBuffer;
|
|
17
17
|
};
|
|
18
18
|
//# sourceMappingURL=interface.d.ts.map
|
package/dest/tests/mocks.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import type { ContractArtifact } from '../abi/abi.js';
|
|
4
4
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
5
|
+
import type { PublishedL2Block } from '../block/published_l2_block.js';
|
|
5
6
|
import type { ContractInstanceWithAddress } from '../contract/index.js';
|
|
6
7
|
import { GasFees } from '../gas/gas_fees.js';
|
|
7
8
|
import { ExtendedNote, UniqueNote } from '../note/extended_note.js';
|
|
@@ -43,7 +44,11 @@ export interface MakeConsensusPayloadOptions {
|
|
|
43
44
|
header?: BlockHeader;
|
|
44
45
|
archive?: Fr;
|
|
45
46
|
txHashes?: TxHash[];
|
|
47
|
+
txs?: Tx[];
|
|
46
48
|
}
|
|
47
49
|
export declare const makeBlockProposal: (options?: MakeConsensusPayloadOptions) => Promise<BlockProposal>;
|
|
48
50
|
export declare const makeBlockAttestation: (options?: MakeConsensusPayloadOptions) => Promise<BlockAttestation>;
|
|
51
|
+
export declare function randomPublishedL2Block(l2BlockNumber: number, opts?: {
|
|
52
|
+
signers?: Secp256k1Signer[];
|
|
53
|
+
}): Promise<PublishedL2Block>;
|
|
49
54
|
//# sourceMappingURL=mocks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAe,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAIvE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAS7C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAoE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEnH,OAAO,EAAE,kBAAkB,EAAiC,MAAM,uBAAuB,CAAC;AAE1F,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,eAAO,MAAM,YAAY,QAAO,MAAyB,CAAC;AAE1D,eAAO,MAAM,kBAAkB,gEAM5B,QAAQ,YAAY,CAAC,0BAQvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,uEAO1B,QAAQ,UAAU,CAAC,wBASrB,CAAC;AAEF,eAAO,MAAM,MAAM,gSAed;IACD,uCAAuC,CAAC,EAAE,MAAM,CAAC;IACjD,oCAAoC,CAAC,EA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;CAAO,GACzC,OAAO,CAAC,gBAAgB,CAAC,CAqB3B"}
|
package/dest/tests/mocks.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { MAX_ENQUEUED_CALLS_PER_TX } from '@aztec/constants';
|
|
2
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
3
|
import { times } from '@aztec/foundation/collection';
|
|
3
4
|
import { Secp256k1Signer, randomBytes } from '@aztec/foundation/crypto';
|
|
4
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
6
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
7
|
+
import { L2Block } from '../block/l2_block.js';
|
|
6
8
|
import { computeContractAddressFromInstance } from '../contract/contract_address.js';
|
|
7
9
|
import { getContractClassFromArtifact } from '../contract/contract_class.js';
|
|
8
10
|
import { SerializableContractInstance } from '../contract/contract_instance.js';
|
|
@@ -145,10 +147,31 @@ const makeAndSignConsensusPayload = async (domainSeparator, options)=>{
|
|
|
145
147
|
};
|
|
146
148
|
export const makeBlockProposal = async (options)=>{
|
|
147
149
|
const { payload, signature } = await makeAndSignConsensusPayload(SignatureDomainSeparator.blockProposal, options);
|
|
148
|
-
return new BlockProposal(payload, signature);
|
|
150
|
+
return new BlockProposal(payload, signature, options?.txs ?? []);
|
|
149
151
|
};
|
|
150
152
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8028)
|
|
151
153
|
export const makeBlockAttestation = async (options)=>{
|
|
152
154
|
const { payload, signature } = await makeAndSignConsensusPayload(SignatureDomainSeparator.blockAttestation, options);
|
|
153
155
|
return new BlockAttestation(payload, signature);
|
|
154
156
|
};
|
|
157
|
+
export async function randomPublishedL2Block(l2BlockNumber, opts = {}) {
|
|
158
|
+
const block = await L2Block.random(l2BlockNumber);
|
|
159
|
+
const l1 = {
|
|
160
|
+
blockNumber: BigInt(block.number),
|
|
161
|
+
timestamp: block.header.globalVariables.timestamp.toBigInt(),
|
|
162
|
+
blockHash: Buffer32.random().toString()
|
|
163
|
+
};
|
|
164
|
+
const signers = opts.signers ?? times(3, ()=>Secp256k1Signer.random());
|
|
165
|
+
const attestations = await Promise.all(signers.map((signer)=>makeBlockAttestation({
|
|
166
|
+
signer,
|
|
167
|
+
header: block.header,
|
|
168
|
+
archive: block.archive.root,
|
|
169
|
+
txHashes: block.body.txEffects.map((tx)=>tx.txHash)
|
|
170
|
+
})));
|
|
171
|
+
const signatures = attestations.map((attestation)=>attestation.signature);
|
|
172
|
+
return {
|
|
173
|
+
block,
|
|
174
|
+
l1,
|
|
175
|
+
signatures
|
|
176
|
+
};
|
|
177
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/stdlib",
|
|
3
|
-
"version": "0.85.0-alpha-testnet.
|
|
3
|
+
"version": "0.85.0-alpha-testnet.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"inherits": [
|
|
6
6
|
"../package.common.json",
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@aztec/bb.js": "0.85.0-alpha-testnet.
|
|
72
|
-
"@aztec/blob-lib": "0.85.0-alpha-testnet.
|
|
73
|
-
"@aztec/constants": "0.85.0-alpha-testnet.
|
|
74
|
-
"@aztec/ethereum": "0.85.0-alpha-testnet.
|
|
75
|
-
"@aztec/foundation": "0.85.0-alpha-testnet.
|
|
76
|
-
"@aztec/noir-noirc_abi": "0.85.0-alpha-testnet.
|
|
71
|
+
"@aztec/bb.js": "0.85.0-alpha-testnet.7",
|
|
72
|
+
"@aztec/blob-lib": "0.85.0-alpha-testnet.7",
|
|
73
|
+
"@aztec/constants": "0.85.0-alpha-testnet.7",
|
|
74
|
+
"@aztec/ethereum": "0.85.0-alpha-testnet.7",
|
|
75
|
+
"@aztec/foundation": "0.85.0-alpha-testnet.7",
|
|
76
|
+
"@aztec/noir-noirc_abi": "0.85.0-alpha-testnet.7",
|
|
77
77
|
"@google-cloud/storage": "^7.15.0",
|
|
78
78
|
"lodash.chunk": "^4.2.0",
|
|
79
79
|
"lodash.isequal": "^4.5.0",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { times } from '@aztec/foundation/collection';
|
|
3
|
-
import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
4
1
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
5
2
|
import { schemas } from '@aztec/foundation/schemas';
|
|
6
3
|
import { L2Block } from '@aztec/stdlib/block';
|
|
7
4
|
|
|
8
5
|
import { z } from 'zod';
|
|
9
6
|
|
|
7
|
+
import { BlockAttestation } from '../p2p/block_attestation.js';
|
|
8
|
+
import { ConsensusPayload } from '../p2p/consensus_payload.js';
|
|
9
|
+
|
|
10
10
|
export type L1PublishedData = {
|
|
11
11
|
blockNumber: bigint;
|
|
12
12
|
timestamp: bigint;
|
|
@@ -29,17 +29,7 @@ export const PublishedL2BlockSchema = z.object({
|
|
|
29
29
|
signatures: z.array(Signature.schema),
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
export
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
blockNumber: BigInt(block.number),
|
|
36
|
-
timestamp: block.header.globalVariables.timestamp.toBigInt(),
|
|
37
|
-
blockHash: Buffer32.random().toString(),
|
|
38
|
-
};
|
|
39
|
-
// Create valid signatures
|
|
40
|
-
const signers = times(3, () => Secp256k1Signer.random());
|
|
41
|
-
const signatures = await Promise.all(
|
|
42
|
-
times(3, async i => signers[i].signMessage(Buffer32.fromField(await block.hash()))),
|
|
43
|
-
);
|
|
44
|
-
return { block, l1, signatures };
|
|
32
|
+
export function getAttestationsFromPublishedL2Block(block: PublishedL2Block) {
|
|
33
|
+
const payload = ConsensusPayload.fromBlock(block.block);
|
|
34
|
+
return block.signatures.filter(sig => !sig.isEmpty).map(signature => new BlockAttestation(payload, signature));
|
|
45
35
|
}
|
|
@@ -5,7 +5,7 @@ import { z } from 'zod';
|
|
|
5
5
|
import type { OpcodeLocation } from '../abi/abi.js';
|
|
6
6
|
import { FunctionSelector } from '../abi/function_selector.js';
|
|
7
7
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
8
|
-
import { type ZodFor, schemas } from '../schemas/index.js';
|
|
8
|
+
import { type ZodFor, optional, schemas } from '../schemas/index.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Address and selector of a function that failed during simulation.
|
|
@@ -240,7 +240,7 @@ export class SimulationError extends Error {
|
|
|
240
240
|
z.object({
|
|
241
241
|
contractAddress: schemas.AztecAddress,
|
|
242
242
|
contractName: z.string().optional(),
|
|
243
|
-
functionSelector: schemas.FunctionSelector,
|
|
243
|
+
functionSelector: optional(schemas.FunctionSelector),
|
|
244
244
|
functionName: z.string().optional(),
|
|
245
245
|
}),
|
|
246
246
|
),
|
|
@@ -2,9 +2,10 @@ import { Buffer32 } from '@aztec/foundation/buffer';
|
|
|
2
2
|
import { keccak256, recoverAddress } from '@aztec/foundation/crypto';
|
|
3
3
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
5
|
-
import
|
|
5
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
7
7
|
|
|
8
|
+
import { Tx } from '../tx/tx.js';
|
|
8
9
|
import { ConsensusPayload } from './consensus_payload.js';
|
|
9
10
|
import { Gossipable } from './gossipable.js';
|
|
10
11
|
import {
|
|
@@ -37,6 +38,10 @@ export class BlockProposal extends Gossipable {
|
|
|
37
38
|
|
|
38
39
|
/** The signer of the BlockProposal over the header of the new block*/
|
|
39
40
|
public readonly signature: Signature,
|
|
41
|
+
|
|
42
|
+
// Note(md): this is placed after the txs payload in order to be backwards compatible with previous versions
|
|
43
|
+
/** The transactions in the block */
|
|
44
|
+
public readonly txs?: Tx[],
|
|
40
45
|
) {
|
|
41
46
|
super();
|
|
42
47
|
}
|
|
@@ -59,12 +64,14 @@ export class BlockProposal extends Gossipable {
|
|
|
59
64
|
|
|
60
65
|
static async createProposalFromSigner(
|
|
61
66
|
payload: ConsensusPayload,
|
|
67
|
+
// Note(md): Provided seperately to tx hashes such that this function can be optional
|
|
68
|
+
txs: Tx[],
|
|
62
69
|
payloadSigner: (payload: Buffer32) => Promise<Signature>,
|
|
63
70
|
) {
|
|
64
71
|
const hashed = await getHashedSignaturePayload(payload, SignatureDomainSeparator.blockProposal);
|
|
65
72
|
const sig = await payloadSigner(hashed);
|
|
66
73
|
|
|
67
|
-
return new BlockProposal(payload, sig);
|
|
74
|
+
return new BlockProposal(payload, sig, txs);
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
/**Get Sender
|
|
@@ -88,15 +95,32 @@ export class BlockProposal extends Gossipable {
|
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
toBuffer(): Buffer {
|
|
91
|
-
|
|
98
|
+
const buffer: any[] = [this.payload, this.signature];
|
|
99
|
+
if (this.txs) {
|
|
100
|
+
buffer.push(this.txs.length);
|
|
101
|
+
buffer.push(this.txs);
|
|
102
|
+
}
|
|
103
|
+
return serializeToBuffer(buffer);
|
|
92
104
|
}
|
|
93
105
|
|
|
94
106
|
static fromBuffer(buf: Buffer | BufferReader): BlockProposal {
|
|
95
107
|
const reader = BufferReader.asReader(buf);
|
|
96
|
-
|
|
108
|
+
const payload = reader.readObject(ConsensusPayload);
|
|
109
|
+
const sig = reader.readObject(Signature);
|
|
110
|
+
|
|
111
|
+
if (!reader.isEmpty()) {
|
|
112
|
+
const txs = reader.readArray(reader.readNumber(), Tx);
|
|
113
|
+
return new BlockProposal(payload, sig, txs);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return new BlockProposal(payload, sig);
|
|
97
117
|
}
|
|
98
118
|
|
|
99
119
|
getSize(): number {
|
|
100
|
-
return
|
|
120
|
+
return (
|
|
121
|
+
this.payload.getSize() +
|
|
122
|
+
this.signature.getSize() +
|
|
123
|
+
(this.txs ? this.txs.reduce((acc, tx) => acc + tx.getSize(), 0) : 0)
|
|
124
|
+
);
|
|
101
125
|
}
|
|
102
126
|
}
|
package/src/tests/mocks.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { MAX_ENQUEUED_CALLS_PER_TX } from '@aztec/constants';
|
|
2
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
3
|
import { times } from '@aztec/foundation/collection';
|
|
3
4
|
import { Secp256k1Signer, randomBytes } from '@aztec/foundation/crypto';
|
|
4
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
6
|
|
|
6
7
|
import type { ContractArtifact } from '../abi/abi.js';
|
|
7
8
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
9
|
+
import { L2Block } from '../block/l2_block.js';
|
|
10
|
+
import type { PublishedL2Block } from '../block/published_l2_block.js';
|
|
8
11
|
import { computeContractAddressFromInstance } from '../contract/contract_address.js';
|
|
9
12
|
import { getContractClassFromArtifact } from '../contract/contract_class.js';
|
|
10
13
|
import { SerializableContractInstance } from '../contract/contract_instance.js';
|
|
@@ -231,6 +234,7 @@ export interface MakeConsensusPayloadOptions {
|
|
|
231
234
|
header?: BlockHeader;
|
|
232
235
|
archive?: Fr;
|
|
233
236
|
txHashes?: TxHash[];
|
|
237
|
+
txs?: Tx[];
|
|
234
238
|
}
|
|
235
239
|
|
|
236
240
|
const makeAndSignConsensusPayload = async (
|
|
@@ -258,7 +262,7 @@ const makeAndSignConsensusPayload = async (
|
|
|
258
262
|
|
|
259
263
|
export const makeBlockProposal = async (options?: MakeConsensusPayloadOptions): Promise<BlockProposal> => {
|
|
260
264
|
const { payload, signature } = await makeAndSignConsensusPayload(SignatureDomainSeparator.blockProposal, options);
|
|
261
|
-
return new BlockProposal(payload, signature);
|
|
265
|
+
return new BlockProposal(payload, signature, options?.txs ?? []);
|
|
262
266
|
};
|
|
263
267
|
|
|
264
268
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8028)
|
|
@@ -266,3 +270,29 @@ export const makeBlockAttestation = async (options?: MakeConsensusPayloadOptions
|
|
|
266
270
|
const { payload, signature } = await makeAndSignConsensusPayload(SignatureDomainSeparator.blockAttestation, options);
|
|
267
271
|
return new BlockAttestation(payload, signature);
|
|
268
272
|
};
|
|
273
|
+
|
|
274
|
+
export async function randomPublishedL2Block(
|
|
275
|
+
l2BlockNumber: number,
|
|
276
|
+
opts: { signers?: Secp256k1Signer[] } = {},
|
|
277
|
+
): Promise<PublishedL2Block> {
|
|
278
|
+
const block = await L2Block.random(l2BlockNumber);
|
|
279
|
+
const l1 = {
|
|
280
|
+
blockNumber: BigInt(block.number),
|
|
281
|
+
timestamp: block.header.globalVariables.timestamp.toBigInt(),
|
|
282
|
+
blockHash: Buffer32.random().toString(),
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const signers = opts.signers ?? times(3, () => Secp256k1Signer.random());
|
|
286
|
+
const attestations = await Promise.all(
|
|
287
|
+
signers.map(signer =>
|
|
288
|
+
makeBlockAttestation({
|
|
289
|
+
signer,
|
|
290
|
+
header: block.header,
|
|
291
|
+
archive: block.archive.root,
|
|
292
|
+
txHashes: block.body.txEffects.map(tx => tx.txHash),
|
|
293
|
+
}),
|
|
294
|
+
),
|
|
295
|
+
);
|
|
296
|
+
const signatures = attestations.map(attestation => attestation.signature);
|
|
297
|
+
return { block, l1, signatures };
|
|
298
|
+
}
|