@aztec/stdlib 0.0.1-commit.0dc957cde → 0.0.1-commit.0ec55a70b
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/avm/avm.d.ts +300 -300
- package/dest/block/attestation_info.d.ts +3 -2
- package/dest/block/attestation_info.d.ts.map +1 -1
- package/dest/block/attestation_info.js +7 -5
- package/dest/block/block_data.d.ts +290 -1
- package/dest/block/block_data.d.ts.map +1 -1
- package/dest/block/block_data.js +14 -0
- package/dest/block/block_parameter.d.ts +30 -3
- package/dest/block/block_parameter.d.ts.map +1 -1
- package/dest/block/block_parameter.js +36 -2
- package/dest/block/l2_block_source.d.ts +39 -4
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/block/proposal/attestations_and_signers.d.ts +13 -6
- package/dest/block/proposal/attestations_and_signers.d.ts.map +1 -1
- package/dest/block/proposal/attestations_and_signers.js +26 -18
- package/dest/checkpoint/checkpoint_data.d.ts +7 -1
- package/dest/checkpoint/checkpoint_data.d.ts.map +1 -1
- package/dest/checkpoint/checkpoint_data.js +2 -0
- package/dest/config/chain-config.d.ts +2 -2
- package/dest/config/chain-config.d.ts.map +1 -1
- package/dest/config/chain-config.js +2 -2
- package/dest/config/sequencer-config.d.ts +5 -3
- package/dest/config/sequencer-config.d.ts.map +1 -1
- package/dest/config/sequencer-config.js +13 -6
- package/dest/ha-signing/local_config.d.ts +1 -1
- package/dest/ha-signing/local_config.d.ts.map +1 -1
- package/dest/ha-signing/local_config.js +2 -2
- package/dest/interfaces/archiver.d.ts +1 -1
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +7 -3
- package/dest/interfaces/aztec-node-admin.d.ts +14 -1
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-admin.js +2 -1
- package/dest/interfaces/aztec-node.d.ts +45 -55
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +18 -16
- package/dest/interfaces/block_response.d.ts +156 -0
- package/dest/interfaces/block_response.d.ts.map +1 -0
- package/dest/interfaces/block_response.js +24 -0
- package/dest/interfaces/chain_tips.d.ts +304 -0
- package/dest/interfaces/chain_tips.d.ts.map +1 -0
- package/dest/interfaces/chain_tips.js +11 -0
- package/dest/interfaces/checkpoint_parameter.d.ts +27 -0
- package/dest/interfaces/checkpoint_parameter.d.ts.map +1 -0
- package/dest/interfaces/checkpoint_parameter.js +20 -0
- package/dest/interfaces/checkpoint_response.d.ts +312 -0
- package/dest/interfaces/checkpoint_response.d.ts.map +1 -0
- package/dest/interfaces/checkpoint_response.js +26 -0
- package/dest/interfaces/client.d.ts +6 -1
- package/dest/interfaces/client.d.ts.map +1 -1
- package/dest/interfaces/client.js +5 -0
- package/dest/interfaces/configs.d.ts +12 -2
- package/dest/interfaces/configs.d.ts.map +1 -1
- package/dest/interfaces/configs.js +3 -1
- package/dest/interfaces/l1_publish_info.d.ts +43 -0
- package/dest/interfaces/l1_publish_info.d.ts.map +1 -0
- package/dest/interfaces/l1_publish_info.js +26 -0
- package/dest/interfaces/proving-job.d.ts +166 -166
- package/dest/interfaces/server.d.ts +6 -1
- package/dest/interfaces/server.d.ts.map +1 -1
- package/dest/interfaces/server.js +5 -0
- package/dest/interfaces/validator.d.ts +14 -2
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/interfaces/validator.js +2 -0
- package/dest/p2p/block_proposal.d.ts +19 -9
- package/dest/p2p/block_proposal.d.ts.map +1 -1
- package/dest/p2p/block_proposal.js +42 -32
- package/dest/p2p/checkpoint_attestation.d.ts +7 -3
- package/dest/p2p/checkpoint_attestation.d.ts.map +1 -1
- package/dest/p2p/checkpoint_attestation.js +15 -17
- package/dest/p2p/checkpoint_proposal.d.ts +15 -7
- package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
- package/dest/p2p/checkpoint_proposal.js +31 -29
- package/dest/p2p/consensus_payload.d.ts +18 -7
- package/dest/p2p/consensus_payload.d.ts.map +1 -1
- package/dest/p2p/consensus_payload.js +31 -19
- package/dest/p2p/signature_utils.d.ts +28 -19
- package/dest/p2p/signature_utils.d.ts.map +1 -1
- package/dest/p2p/signature_utils.js +118 -21
- package/dest/p2p/signed_txs.d.ts +15 -13
- package/dest/p2p/signed_txs.d.ts.map +1 -1
- package/dest/p2p/signed_txs.js +26 -24
- package/dest/parity/parity_base_private_inputs.d.ts +7 -3
- package/dest/parity/parity_base_private_inputs.d.ts.map +1 -1
- package/dest/parity/parity_base_private_inputs.js +7 -5
- package/dest/parity/parity_public_inputs.d.ts +7 -3
- package/dest/parity/parity_public_inputs.d.ts.map +1 -1
- package/dest/parity/parity_public_inputs.js +6 -3
- package/dest/tests/factories.d.ts +1 -1
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +2 -2
- package/dest/tests/mocks.d.ts +7 -1
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +28 -14
- package/dest/timetable/index.d.ts +1 -1
- package/dest/timetable/index.d.ts.map +1 -1
- package/dest/timetable/index.js +25 -11
- package/dest/tx/profiling.js +4 -4
- package/package.json +8 -8
- package/src/block/attestation_info.ts +11 -11
- package/src/block/block_data.ts +17 -0
- package/src/block/block_parameter.ts +35 -2
- package/src/block/l2_block_source.ts +43 -3
- package/src/block/proposal/attestations_and_signers.ts +32 -17
- package/src/checkpoint/checkpoint_data.ts +4 -0
- package/src/config/chain-config.ts +2 -3
- package/src/config/sequencer-config.ts +25 -7
- package/src/ha-signing/local_config.ts +2 -2
- package/src/interfaces/archiver.ts +13 -3
- package/src/interfaces/aztec-node-admin.ts +3 -1
- package/src/interfaces/aztec-node.ts +105 -95
- package/src/interfaces/block_response.ts +79 -0
- package/src/interfaces/chain_tips.ts +24 -0
- package/src/interfaces/checkpoint_parameter.ts +22 -0
- package/src/interfaces/checkpoint_response.ts +84 -0
- package/src/interfaces/client.ts +5 -0
- package/src/interfaces/configs.ts +8 -1
- package/src/interfaces/l1_publish_info.ts +40 -0
- package/src/interfaces/server.ts +5 -0
- package/src/interfaces/validator.ts +7 -1
- package/src/p2p/block_proposal.ts +84 -28
- package/src/p2p/checkpoint_attestation.ts +15 -20
- package/src/p2p/checkpoint_proposal.ts +69 -37
- package/src/p2p/consensus_payload.ts +50 -28
- package/src/p2p/signature_utils.ts +110 -25
- package/src/p2p/signed_txs.ts +46 -28
- package/src/parity/parity_base_private_inputs.ts +10 -4
- package/src/parity/parity_public_inputs.ts +9 -2
- package/src/tests/factories.ts +6 -1
- package/src/tests/mocks.ts +46 -26
- package/src/timetable/index.ts +26 -11
- package/src/tx/profiling.ts +4 -4
|
@@ -10,10 +10,21 @@ import { z } from 'zod';
|
|
|
10
10
|
import type { Checkpoint } from '../checkpoint/checkpoint.js';
|
|
11
11
|
import { CheckpointHeader } from '../rollup/checkpoint_header.js';
|
|
12
12
|
import type { CheckpointProposal, CheckpointProposalCore } from './checkpoint_proposal.js';
|
|
13
|
-
import
|
|
13
|
+
import {
|
|
14
|
+
type CoordinationSignatureContext,
|
|
15
|
+
type CoordinationSignatureType,
|
|
16
|
+
EMPTY_COORDINATION_SIGNATURE_CONTEXT,
|
|
17
|
+
type Signable,
|
|
18
|
+
coordinationSignatureContextEquals,
|
|
19
|
+
coordinationSignatureContextSchema,
|
|
20
|
+
readCoordinationSignatureContext,
|
|
21
|
+
serializeCoordinationSignatureContext,
|
|
22
|
+
} from './signature_utils.js';
|
|
14
23
|
|
|
15
24
|
/** Checkpoint consensus payload as signed by validators and verified on L1. */
|
|
16
25
|
export class ConsensusPayload implements Signable {
|
|
26
|
+
readonly primaryType: CoordinationSignatureType = 'CheckpointAttestation';
|
|
27
|
+
|
|
17
28
|
private size: number | undefined;
|
|
18
29
|
|
|
19
30
|
constructor(
|
|
@@ -22,7 +33,9 @@ export class ConsensusPayload implements Signable {
|
|
|
22
33
|
/** The archive root after the block is added */
|
|
23
34
|
public readonly archive: Fr,
|
|
24
35
|
/** The fee asset price modifier in basis points (from oracle) */
|
|
25
|
-
public readonly feeAssetPriceModifier: bigint
|
|
36
|
+
public readonly feeAssetPriceModifier: bigint,
|
|
37
|
+
/** The signing domain (chainId + rollupAddress) the signature is bound to */
|
|
38
|
+
public readonly signatureContext: CoordinationSignatureContext,
|
|
26
39
|
) {}
|
|
27
40
|
|
|
28
41
|
static get schema() {
|
|
@@ -31,36 +44,38 @@ export class ConsensusPayload implements Signable {
|
|
|
31
44
|
header: CheckpointHeader.schema,
|
|
32
45
|
archive: schemas.Fr,
|
|
33
46
|
feeAssetPriceModifier: schemas.BigInt,
|
|
47
|
+
signatureContext: coordinationSignatureContextSchema,
|
|
34
48
|
})
|
|
35
|
-
.transform(obj => new ConsensusPayload(obj.header, obj.archive, obj.feeAssetPriceModifier));
|
|
49
|
+
.transform(obj => new ConsensusPayload(obj.header, obj.archive, obj.feeAssetPriceModifier, obj.signatureContext));
|
|
36
50
|
}
|
|
37
51
|
|
|
38
|
-
static getFields(fields: FieldsOf<ConsensusPayload>) {
|
|
39
|
-
return [fields.header, fields.archive, fields.feeAssetPriceModifier] as const;
|
|
52
|
+
static getFields(fields: Omit<FieldsOf<ConsensusPayload>, 'primaryType'>) {
|
|
53
|
+
return [fields.header, fields.archive, fields.feeAssetPriceModifier, fields.signatureContext] as const;
|
|
40
54
|
}
|
|
41
55
|
|
|
42
|
-
getPayloadToSign(
|
|
56
|
+
getPayloadToSign(): Buffer {
|
|
57
|
+
// Matches the L1 ProposePayload struct in ProposeLib.sol.
|
|
43
58
|
const abi = parseAbiParameters(
|
|
44
|
-
'
|
|
45
|
-
'(' +
|
|
59
|
+
'(' +
|
|
46
60
|
'bytes32, ' + // archive
|
|
47
61
|
'(int256), ' + // oracleInput
|
|
48
62
|
'bytes32' + // headerHash
|
|
49
63
|
')',
|
|
50
64
|
);
|
|
51
65
|
const archiveRoot = this.archive.toString();
|
|
52
|
-
|
|
53
66
|
const headerHash = this.header.hash().toString();
|
|
54
|
-
const encodedData = encodeAbiParameters(abi, [
|
|
55
|
-
domainSeparator,
|
|
56
|
-
[archiveRoot, [this.feeAssetPriceModifier], headerHash],
|
|
57
|
-
] as const);
|
|
67
|
+
const encodedData = encodeAbiParameters(abi, [[archiveRoot, [this.feeAssetPriceModifier], headerHash]] as const);
|
|
58
68
|
|
|
59
69
|
return hexToBuffer(encodedData);
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
toBuffer(): Buffer {
|
|
63
|
-
return serializeToBuffer([
|
|
73
|
+
return serializeToBuffer([
|
|
74
|
+
this.header,
|
|
75
|
+
this.archive,
|
|
76
|
+
serializeSignedBigInt(this.feeAssetPriceModifier),
|
|
77
|
+
serializeCoordinationSignatureContext(this.signatureContext),
|
|
78
|
+
]);
|
|
64
79
|
}
|
|
65
80
|
|
|
66
81
|
public equals(other: ConsensusPayload | CheckpointProposal | CheckpointProposalCore): boolean {
|
|
@@ -69,34 +84,39 @@ export class ConsensusPayload implements Signable {
|
|
|
69
84
|
return (
|
|
70
85
|
this.header.equals(otherHeader) &&
|
|
71
86
|
this.archive.equals(other.archive) &&
|
|
72
|
-
this.feeAssetPriceModifier === otherModifier
|
|
87
|
+
this.feeAssetPriceModifier === otherModifier &&
|
|
88
|
+
coordinationSignatureContextEquals(this.signatureContext, other.signatureContext)
|
|
73
89
|
);
|
|
74
90
|
}
|
|
75
91
|
|
|
76
92
|
static fromBuffer(buf: Buffer | BufferReader): ConsensusPayload {
|
|
77
93
|
const reader = BufferReader.asReader(buf);
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
return payload;
|
|
94
|
+
const header = reader.readObject(CheckpointHeader);
|
|
95
|
+
const archive = reader.readObject(Fr);
|
|
96
|
+
const feeAssetPriceModifier = reader.readInt256();
|
|
97
|
+
const signatureContext = readCoordinationSignatureContext(reader);
|
|
98
|
+
return new ConsensusPayload(header, archive, feeAssetPriceModifier, signatureContext);
|
|
84
99
|
}
|
|
85
100
|
|
|
86
|
-
static fromFields(fields: FieldsOf<ConsensusPayload>): ConsensusPayload {
|
|
87
|
-
return new ConsensusPayload(fields.header, fields.archive, fields.feeAssetPriceModifier);
|
|
101
|
+
static fromFields(fields: Omit<FieldsOf<ConsensusPayload>, 'primaryType'>): ConsensusPayload {
|
|
102
|
+
return new ConsensusPayload(fields.header, fields.archive, fields.feeAssetPriceModifier, fields.signatureContext);
|
|
88
103
|
}
|
|
89
104
|
|
|
90
|
-
static fromCheckpoint(checkpoint: Checkpoint): ConsensusPayload {
|
|
91
|
-
return new ConsensusPayload(
|
|
105
|
+
static fromCheckpoint(checkpoint: Checkpoint, signatureContext: CoordinationSignatureContext): ConsensusPayload {
|
|
106
|
+
return new ConsensusPayload(
|
|
107
|
+
checkpoint.header,
|
|
108
|
+
checkpoint.archive.root,
|
|
109
|
+
checkpoint.feeAssetPriceModifier,
|
|
110
|
+
signatureContext,
|
|
111
|
+
);
|
|
92
112
|
}
|
|
93
113
|
|
|
94
114
|
static empty(): ConsensusPayload {
|
|
95
|
-
return new ConsensusPayload(CheckpointHeader.empty(), Fr.ZERO, 0n);
|
|
115
|
+
return new ConsensusPayload(CheckpointHeader.empty(), Fr.ZERO, 0n, EMPTY_COORDINATION_SIGNATURE_CONTEXT);
|
|
96
116
|
}
|
|
97
117
|
|
|
98
118
|
static random(): ConsensusPayload {
|
|
99
|
-
return new ConsensusPayload(CheckpointHeader.random(), Fr.random(), 0n);
|
|
119
|
+
return new ConsensusPayload(CheckpointHeader.random(), Fr.random(), 0n, EMPTY_COORDINATION_SIGNATURE_CONTEXT);
|
|
100
120
|
}
|
|
101
121
|
|
|
102
122
|
/**
|
|
@@ -117,10 +137,12 @@ export class ConsensusPayload implements Signable {
|
|
|
117
137
|
header: this.header.toInspect(),
|
|
118
138
|
archive: this.archive.toString(),
|
|
119
139
|
feeAssetPriceModifier: this.feeAssetPriceModifier.toString(),
|
|
140
|
+
chainId: this.signatureContext.chainId,
|
|
141
|
+
rollupAddress: this.signatureContext.rollupAddress.toString(),
|
|
120
142
|
};
|
|
121
143
|
}
|
|
122
144
|
|
|
123
145
|
toString() {
|
|
124
|
-
return `header: ${this.header.toString()}, archive: ${this.archive.toString()}, feeAssetPriceModifier: ${this.feeAssetPriceModifier}}`;
|
|
146
|
+
return `header: ${this.header.toString()}, archive: ${this.archive.toString()}, feeAssetPriceModifier: ${this.feeAssetPriceModifier}, chainId: ${this.signatureContext.chainId}, rollupAddress: ${this.signatureContext.rollupAddress.toString()}`;
|
|
125
147
|
}
|
|
126
148
|
}
|
|
@@ -1,37 +1,122 @@
|
|
|
1
1
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
2
|
import { keccak256 } from '@aztec/foundation/crypto/keccak';
|
|
3
|
-
import {
|
|
3
|
+
import { tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
4
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
+
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
6
|
+
import { type BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import { type TypedDataDefinition, hashTypedData } from 'viem';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
|
|
11
|
+
import type { ZodFor } from '../schemas/index.js';
|
|
12
|
+
|
|
13
|
+
export type CoordinationSignatureType =
|
|
14
|
+
| 'BlockProposal'
|
|
15
|
+
| 'CheckpointProposal'
|
|
16
|
+
| 'CheckpointAttestation'
|
|
17
|
+
| 'AttestationsAndSigners'
|
|
18
|
+
| 'SignedTxs';
|
|
19
|
+
|
|
20
|
+
export type CoordinationSignatureContext = {
|
|
21
|
+
chainId: number;
|
|
22
|
+
rollupAddress: EthAddress;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const EMPTY_COORDINATION_SIGNATURE_CONTEXT: CoordinationSignatureContext = {
|
|
26
|
+
chainId: 0,
|
|
27
|
+
rollupAddress: EthAddress.ZERO,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const coordinationSignatureContextSchema: ZodFor<CoordinationSignatureContext> = z.object({
|
|
31
|
+
chainId: z.number(),
|
|
32
|
+
rollupAddress: EthAddress.schema,
|
|
33
|
+
});
|
|
12
34
|
|
|
13
35
|
export interface Signable {
|
|
14
|
-
|
|
36
|
+
readonly primaryType: CoordinationSignatureType;
|
|
37
|
+
readonly signatureContext: CoordinationSignatureContext;
|
|
38
|
+
getPayloadToSign(): Buffer;
|
|
15
39
|
}
|
|
16
40
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
41
|
+
export function coordinationSignatureContextEquals(
|
|
42
|
+
a: CoordinationSignatureContext,
|
|
43
|
+
b: CoordinationSignatureContext,
|
|
44
|
+
): boolean {
|
|
45
|
+
return a.chainId === b.chainId && a.rollupAddress.equals(b.rollupAddress);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function serializeCoordinationSignatureContext(ctx: CoordinationSignatureContext): Buffer {
|
|
49
|
+
return serializeToBuffer([ctx.chainId, ctx.rollupAddress]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function readCoordinationSignatureContext(reader: BufferReader): CoordinationSignatureContext {
|
|
53
|
+
const chainId = reader.readNumber();
|
|
54
|
+
const rollupAddress = reader.readObject(EthAddress);
|
|
55
|
+
return { chainId, rollupAddress };
|
|
24
56
|
}
|
|
25
57
|
|
|
26
58
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
59
|
+
* Returns true if the signable carries a context matching the node's expected context.
|
|
60
|
+
* Use this at the P2P ingress boundary to reject foreign-chain messages cheaply before
|
|
61
|
+
* performing any signature recovery.
|
|
30
62
|
*/
|
|
31
|
-
export function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
63
|
+
export function hasValidSignatureContext(signable: Signable, expected: CoordinationSignatureContext): boolean {
|
|
64
|
+
return coordinationSignatureContextEquals(signable.signatureContext, expected);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const COORDINATION_SIGNATURE_NAME = 'Aztec Rollup';
|
|
68
|
+
const COORDINATION_SIGNATURE_VERSION = '1';
|
|
69
|
+
|
|
70
|
+
const EIP712_DOMAIN_FIELDS = [
|
|
71
|
+
{ name: 'name', type: 'string' },
|
|
72
|
+
{ name: 'version', type: 'string' },
|
|
73
|
+
{ name: 'chainId', type: 'uint256' },
|
|
74
|
+
{ name: 'verifyingContract', type: 'address' },
|
|
75
|
+
] as const;
|
|
76
|
+
|
|
77
|
+
const COORDINATION_SIGNATURE_TYPES = {
|
|
78
|
+
EIP712Domain: EIP712_DOMAIN_FIELDS,
|
|
79
|
+
BlockProposal: [{ name: 'payloadHash', type: 'bytes32' }],
|
|
80
|
+
CheckpointProposal: [{ name: 'payloadHash', type: 'bytes32' }],
|
|
81
|
+
CheckpointAttestation: [{ name: 'payloadHash', type: 'bytes32' }],
|
|
82
|
+
AttestationsAndSigners: [{ name: 'payloadHash', type: 'bytes32' }],
|
|
83
|
+
SignedTxs: [{ name: 'payloadHash', type: 'bytes32' }],
|
|
84
|
+
} as const;
|
|
85
|
+
|
|
86
|
+
export function getCoordinationSignatureTypedDataForPayloadHash(
|
|
87
|
+
payloadHash: Buffer32,
|
|
88
|
+
type: CoordinationSignatureType,
|
|
89
|
+
context: CoordinationSignatureContext,
|
|
90
|
+
): TypedDataDefinition {
|
|
91
|
+
return {
|
|
92
|
+
domain: {
|
|
93
|
+
name: COORDINATION_SIGNATURE_NAME,
|
|
94
|
+
version: COORDINATION_SIGNATURE_VERSION,
|
|
95
|
+
chainId: context.chainId,
|
|
96
|
+
verifyingContract: context.rollupAddress.toString() as `0x${string}`,
|
|
97
|
+
},
|
|
98
|
+
types: COORDINATION_SIGNATURE_TYPES,
|
|
99
|
+
primaryType: type,
|
|
100
|
+
message: {
|
|
101
|
+
payloadHash: payloadHash.toString() as `0x${string}`,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function getCoordinationSignatureTypedData(signable: Signable): TypedDataDefinition {
|
|
107
|
+
const payloadHash = getHashedSignaturePayload(signable);
|
|
108
|
+
return getCoordinationSignatureTypedDataForPayloadHash(payloadHash, signable.primaryType, signable.signatureContext);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function getHashedSignaturePayloadTypedData(signable: Signable): Buffer32 {
|
|
112
|
+
return Buffer32.fromString(hashTypedData(getCoordinationSignatureTypedData(signable)));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function recoverCoordinationSigner(signable: Signable, signature: Signature): EthAddress | undefined {
|
|
116
|
+
const digest = getHashedSignaturePayloadTypedData(signable);
|
|
117
|
+
return tryRecoverAddress(digest, signature, { allowYParityAsV: true });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function getHashedSignaturePayload(s: Signable): Buffer32 {
|
|
121
|
+
return Buffer32.fromBuffer(keccak256(s.getPayloadToSign()));
|
|
37
122
|
}
|
package/src/p2p/signed_txs.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
3
1
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
2
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
5
3
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
6
4
|
|
|
5
|
+
import type { TypedDataDefinition } from 'viem';
|
|
6
|
+
|
|
7
7
|
import { MAX_TXS_PER_BLOCK } from '../deserialization/index.js';
|
|
8
8
|
import { Tx } from '../tx/tx.js';
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
type CoordinationSignatureContext,
|
|
11
|
+
type CoordinationSignatureType,
|
|
12
|
+
EMPTY_COORDINATION_SIGNATURE_CONTEXT,
|
|
13
|
+
type Signable,
|
|
14
|
+
getCoordinationSignatureTypedData,
|
|
15
|
+
readCoordinationSignatureContext,
|
|
16
|
+
recoverCoordinationSigner,
|
|
17
|
+
serializeCoordinationSignatureContext,
|
|
13
18
|
} from './signature_utils.js';
|
|
14
19
|
|
|
15
20
|
/**
|
|
@@ -17,50 +22,56 @@ import {
|
|
|
17
22
|
* The signature is over the transaction objects themselves, providing
|
|
18
23
|
* data availability guarantees beyond just the transaction hashes.
|
|
19
24
|
*/
|
|
20
|
-
export class SignedTxs {
|
|
21
|
-
|
|
25
|
+
export class SignedTxs implements Signable {
|
|
26
|
+
readonly primaryType: CoordinationSignatureType = 'SignedTxs';
|
|
27
|
+
|
|
28
|
+
private cachedSender: EthAddress | undefined | null = undefined;
|
|
22
29
|
|
|
23
30
|
constructor(
|
|
24
31
|
/** The transactions */
|
|
25
32
|
public readonly txs: Tx[],
|
|
26
33
|
/** The proposer's signature over the transactions */
|
|
27
34
|
public readonly signature: Signature,
|
|
35
|
+
/** The signing domain (chainId + rollupAddress) the signature is bound to */
|
|
36
|
+
public readonly signatureContext: CoordinationSignatureContext,
|
|
28
37
|
) {}
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
getPayloadToSign(domainSeparator: SignatureDomainSeparator): Buffer {
|
|
34
|
-
return serializeToBuffer([domainSeparator, this.txs.length, this.txs]);
|
|
39
|
+
getPayloadToSign(): Buffer {
|
|
40
|
+
return serializeToBuffer([this.txs.length, this.txs]);
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
/**
|
|
38
|
-
* Lazily evaluate the sender of the signed txs; result is cached
|
|
44
|
+
* Lazily evaluate the sender of the signed txs; result is cached.
|
|
39
45
|
* @returns The sender address, or undefined if signature recovery fails
|
|
40
46
|
*/
|
|
41
47
|
getSender(): EthAddress | undefined {
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
this.sender = tryRecoverAddress(hashed, this.signature);
|
|
48
|
+
if (this.cachedSender === undefined) {
|
|
49
|
+
this.cachedSender = recoverCoordinationSigner(this, this.signature) ?? null;
|
|
45
50
|
}
|
|
46
|
-
return this.
|
|
51
|
+
return this.cachedSender ?? undefined;
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
/**
|
|
50
|
-
* Create SignedTxs from a signer function
|
|
55
|
+
* Create SignedTxs from a typed-data signer function
|
|
51
56
|
*/
|
|
52
57
|
static async createFromSigner(
|
|
53
58
|
txs: Tx[],
|
|
54
|
-
|
|
59
|
+
signatureContext: CoordinationSignatureContext,
|
|
60
|
+
typedDataSigner: (typedData: TypedDataDefinition) => Promise<Signature>,
|
|
55
61
|
): Promise<SignedTxs> {
|
|
56
|
-
const tempSignedTxs = new SignedTxs(txs, Signature.empty());
|
|
57
|
-
const
|
|
58
|
-
const signature = await
|
|
59
|
-
return new SignedTxs(txs, signature);
|
|
62
|
+
const tempSignedTxs = new SignedTxs(txs, Signature.empty(), signatureContext);
|
|
63
|
+
const typedData = getCoordinationSignatureTypedData(tempSignedTxs);
|
|
64
|
+
const signature = await typedDataSigner(typedData);
|
|
65
|
+
return new SignedTxs(txs, signature, signatureContext);
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
toBuffer(): Buffer {
|
|
63
|
-
return serializeToBuffer([
|
|
69
|
+
return serializeToBuffer([
|
|
70
|
+
this.txs.length,
|
|
71
|
+
this.txs,
|
|
72
|
+
this.signature,
|
|
73
|
+
serializeCoordinationSignatureContext(this.signatureContext),
|
|
74
|
+
]);
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
static fromBuffer(buf: Buffer | BufferReader): SignedTxs {
|
|
@@ -71,18 +82,25 @@ export class SignedTxs {
|
|
|
71
82
|
}
|
|
72
83
|
const txs = reader.readArray(txCount, Tx);
|
|
73
84
|
const signature = reader.readObject(Signature);
|
|
74
|
-
|
|
85
|
+
const signatureContext = readCoordinationSignatureContext(reader);
|
|
86
|
+
return new SignedTxs(txs, signature, signatureContext);
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
getSize(): number {
|
|
78
|
-
return
|
|
90
|
+
return (
|
|
91
|
+
4 /* txs.length */ +
|
|
92
|
+
this.txs.reduce((acc, tx) => acc + tx.getSize(), 0) +
|
|
93
|
+
this.signature.getSize() +
|
|
94
|
+
4 /* chainId */ +
|
|
95
|
+
20 /* rollupAddress */
|
|
96
|
+
);
|
|
79
97
|
}
|
|
80
98
|
|
|
81
99
|
static empty(): SignedTxs {
|
|
82
|
-
return new SignedTxs([], Signature.empty());
|
|
100
|
+
return new SignedTxs([], Signature.empty(), EMPTY_COORDINATION_SIGNATURE_CONTEXT);
|
|
83
101
|
}
|
|
84
102
|
|
|
85
103
|
static random(): SignedTxs {
|
|
86
|
-
return new SignedTxs([Tx.random(), Tx.random()], Signature.random());
|
|
104
|
+
return new SignedTxs([Tx.random(), Tx.random()], Signature.random(), EMPTY_COORDINATION_SIGNATURE_CONTEXT);
|
|
87
105
|
}
|
|
88
106
|
}
|
|
@@ -10,9 +10,11 @@ export class ParityBasePrivateInputs {
|
|
|
10
10
|
public readonly msgs: Tuple<Fr, typeof NUM_MSGS_PER_BASE_PARITY>,
|
|
11
11
|
/** Root of the VK tree */
|
|
12
12
|
public readonly vkTreeRoot: Fr,
|
|
13
|
+
/** Prover identity committed to by the circuit, for sybil protection. */
|
|
14
|
+
public readonly proverId: Fr,
|
|
13
15
|
) {}
|
|
14
16
|
|
|
15
|
-
public static fromSlice(array: Fr[], index: number, vkTreeRoot: Fr): ParityBasePrivateInputs {
|
|
17
|
+
public static fromSlice(array: Fr[], index: number, vkTreeRoot: Fr, proverId: Fr): ParityBasePrivateInputs {
|
|
16
18
|
// Can't use Tuple<Fr, typeof NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP> due to length
|
|
17
19
|
if (array.length !== NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) {
|
|
18
20
|
throw new Error(
|
|
@@ -22,12 +24,12 @@ export class ParityBasePrivateInputs {
|
|
|
22
24
|
const start = index * NUM_MSGS_PER_BASE_PARITY;
|
|
23
25
|
const end = start + NUM_MSGS_PER_BASE_PARITY;
|
|
24
26
|
const msgs = array.slice(start, end);
|
|
25
|
-
return new ParityBasePrivateInputs(msgs as Tuple<Fr, typeof NUM_MSGS_PER_BASE_PARITY>, vkTreeRoot);
|
|
27
|
+
return new ParityBasePrivateInputs(msgs as Tuple<Fr, typeof NUM_MSGS_PER_BASE_PARITY>, vkTreeRoot, proverId);
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
/** Serializes the inputs to a buffer. */
|
|
29
31
|
toBuffer() {
|
|
30
|
-
return serializeToBuffer(this.msgs, this.vkTreeRoot);
|
|
32
|
+
return serializeToBuffer(this.msgs, this.vkTreeRoot, this.proverId);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/** Serializes the inputs to a hex string. */
|
|
@@ -41,7 +43,11 @@ export class ParityBasePrivateInputs {
|
|
|
41
43
|
*/
|
|
42
44
|
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
43
45
|
const reader = BufferReader.asReader(buffer);
|
|
44
|
-
return new ParityBasePrivateInputs(
|
|
46
|
+
return new ParityBasePrivateInputs(
|
|
47
|
+
reader.readArray(NUM_MSGS_PER_BASE_PARITY, Fr),
|
|
48
|
+
Fr.fromBuffer(reader),
|
|
49
|
+
Fr.fromBuffer(reader),
|
|
50
|
+
);
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|
|
@@ -12,6 +12,8 @@ export class ParityPublicInputs {
|
|
|
12
12
|
public convertedRoot: Fr,
|
|
13
13
|
/** Root of the VK tree */
|
|
14
14
|
public vkTreeRoot: Fr,
|
|
15
|
+
/** Prover identity committed to by the circuit, for sybil protection. */
|
|
16
|
+
public proverId: Fr,
|
|
15
17
|
) {
|
|
16
18
|
if (shaRoot.toBuffer()[0] != 0) {
|
|
17
19
|
throw new Error(`shaRoot buffer must be 31 bytes. Got 32 bytes`);
|
|
@@ -54,7 +56,7 @@ export class ParityPublicInputs {
|
|
|
54
56
|
* @returns The instance fields.
|
|
55
57
|
*/
|
|
56
58
|
static getFields(fields: FieldsOf<ParityPublicInputs>) {
|
|
57
|
-
return [fields.shaRoot, fields.convertedRoot, fields.vkTreeRoot] as const;
|
|
59
|
+
return [fields.shaRoot, fields.convertedRoot, fields.vkTreeRoot, fields.proverId] as const;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
/**
|
|
@@ -64,7 +66,12 @@ export class ParityPublicInputs {
|
|
|
64
66
|
*/
|
|
65
67
|
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
66
68
|
const reader = BufferReader.asReader(buffer);
|
|
67
|
-
return new ParityPublicInputs(
|
|
69
|
+
return new ParityPublicInputs(
|
|
70
|
+
reader.readObject(Fr),
|
|
71
|
+
reader.readObject(Fr),
|
|
72
|
+
Fr.fromBuffer(reader),
|
|
73
|
+
Fr.fromBuffer(reader),
|
|
74
|
+
);
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
/**
|
package/src/tests/factories.ts
CHANGED
|
@@ -854,11 +854,16 @@ export function makeParityPublicInputs(seed = 0): ParityPublicInputs {
|
|
|
854
854
|
new Fr(BigInt(seed + 0x200)),
|
|
855
855
|
new Fr(BigInt(seed + 0x300)),
|
|
856
856
|
new Fr(BigInt(seed + 0x400)),
|
|
857
|
+
new Fr(BigInt(seed + 0x500)),
|
|
857
858
|
);
|
|
858
859
|
}
|
|
859
860
|
|
|
860
861
|
export function makeParityBasePrivateInputs(seed = 0): ParityBasePrivateInputs {
|
|
861
|
-
return new ParityBasePrivateInputs(
|
|
862
|
+
return new ParityBasePrivateInputs(
|
|
863
|
+
makeTuple(NUM_MSGS_PER_BASE_PARITY, fr, seed + 0x3000),
|
|
864
|
+
new Fr(seed + 0x4000),
|
|
865
|
+
new Fr(seed + 0x5000),
|
|
866
|
+
);
|
|
862
867
|
}
|
|
863
868
|
|
|
864
869
|
export function makeParityRootPrivateInputs(seed = 0) {
|