Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vc): remove viem signers from validator client #8517

Merged
merged 70 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
b51e908
feat: cleanup publisher
LHerskind Aug 22, 2024
da2eb7a
refactor: get rid of timetraveler from l1-publisher
LHerskind Aug 28, 2024
3388966
feat: revert if timestamp in future
LHerskind Aug 28, 2024
13a60a3
feat: including txhashes explicitly in the rollup attestations
Maddiaa0 Aug 29, 2024
86026f2
temp
Maddiaa0 Aug 30, 2024
f3eac5b
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Aug 30, 2024
fc7a04a
temp
Maddiaa0 Aug 30, 2024
9eed298
temp
Maddiaa0 Sep 2, 2024
cc09455
temp
Maddiaa0 Sep 2, 2024
06f950f
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 2, 2024
4727cd9
temp: get passing with txhash payloads
Maddiaa0 Sep 3, 2024
b4c2a46
fix: make sure transactions are available in the tx pool
Maddiaa0 Sep 5, 2024
4a8d178
chore: remove logs
Maddiaa0 Sep 5, 2024
b4324fc
fmt
Maddiaa0 Sep 5, 2024
052641a
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 5, 2024
a803a94
🪿
Maddiaa0 Sep 5, 2024
164c117
chore: validator tests
Maddiaa0 Sep 6, 2024
27da59d
Add timeouts to individual reqresp connections
Maddiaa0 Sep 6, 2024
9e7d2d8
fix
Maddiaa0 Sep 6, 2024
3c8e1b9
chore: include tests for specific error messages
Maddiaa0 Sep 6, 2024
9a738e5
fmt
Maddiaa0 Sep 6, 2024
c10260c
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 6, 2024
045af5a
clean
Maddiaa0 Sep 6, 2024
73d26ec
🧹
Maddiaa0 Sep 6, 2024
d358228
chore: fix sequencing tests
Maddiaa0 Sep 7, 2024
4b31953
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 7, 2024
2f82a8f
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 7, 2024
f673593
fmt
Maddiaa0 Sep 7, 2024
a15ab17
fmt
Maddiaa0 Sep 7, 2024
2e3f80b
fmt solidity
Maddiaa0 Sep 7, 2024
ae2a05e
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 7, 2024
5734006
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 7, 2024
1bde1fe
fix: test hash
Maddiaa0 Sep 8, 2024
c775b26
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 8, 2024
7a50a2b
exp: adjust test nodes
Maddiaa0 Sep 8, 2024
72f98bd
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 8, 2024
998f38c
chore: add reqresp configuration values to p2p config
Maddiaa0 Sep 8, 2024
1c2b151
fix: use abi.encode vs encodePacked
Maddiaa0 Sep 11, 2024
e6e7f6b
fix
Maddiaa0 Sep 11, 2024
6f417fc
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 11, 2024
cde6283
fix: merge fix
Maddiaa0 Sep 11, 2024
8290c99
fmt
Maddiaa0 Sep 11, 2024
b13ca93
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 11, 2024
1452017
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 11, 2024
120c9a3
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 11, 2024
b189270
feat: initial rate limiter impl
Maddiaa0 Sep 11, 2024
9b90fe1
Merge branch 'master' into md/09-06-add_timeouts_to_individual_reqres…
Maddiaa0 Sep 11, 2024
b7d815f
Merge branch 'md/09-06-add_timeouts_to_individual_reqresp_connections…
Maddiaa0 Sep 11, 2024
97a6a14
feat: tests + documentation
Maddiaa0 Sep 11, 2024
0e22558
test: add to reqresp.test.ts
Maddiaa0 Sep 11, 2024
b464dcf
Merge branch 'master' into md/add-rate-limits-to-reqresp-peers
Maddiaa0 Sep 11, 2024
d0da214
fix: add todo pr number
Maddiaa0 Sep 11, 2024
2b46268
feat: introduce new light signer
Maddiaa0 Sep 12, 2024
65d009a
chore: migrations
Maddiaa0 Sep 12, 2024
69aa4a0
chore: proliferate
Maddiaa0 Sep 12, 2024
d109853
chore: remove signature lib from leonidas
Maddiaa0 Sep 12, 2024
d3cf4b8
fmt
Maddiaa0 Sep 12, 2024
dc06395
Merge branch 'master' into md/replace-viem-in-validator
Maddiaa0 Sep 13, 2024
d762096
fmt + fix test
Maddiaa0 Sep 13, 2024
afb46ca
fmt
Maddiaa0 Sep 13, 2024
37929f5
document secp256 helpers
Maddiaa0 Sep 13, 2024
1cb6687
clean
Maddiaa0 Sep 13, 2024
62b7c72
clean
Maddiaa0 Sep 13, 2024
421470e
fix: validator pk validation
Maddiaa0 Sep 16, 2024
f0f87a4
fix: reinstante eip712
Maddiaa0 Sep 16, 2024
40303d0
Merge branch 'master' into md/replace-viem-in-validator
Maddiaa0 Sep 16, 2024
7ea196f
fix: attestation unit test
Maddiaa0 Sep 17, 2024
56b06ce
Merge branch 'master' into md/replace-viem-in-validator
Maddiaa0 Sep 17, 2024
5d1df99
Merge branch 'master' into md/replace-viem-in-validator
Maddiaa0 Sep 17, 2024
6b099f4
fmt
Maddiaa0 Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions l1-contracts/src/core/sequencer_selection/Leonidas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {Ownable} from "@oz/access/Ownable.sol";
import {SignatureLib} from "./SignatureLib.sol";
import {SampleLib} from "./SampleLib.sol";
import {Constants} from "../libraries/ConstantsGen.sol";
import {MessageHashUtils} from "@oz/utils/cryptography/MessageHashUtils.sol";
Maddiaa0 marked this conversation as resolved.
Show resolved Hide resolved

import {ILeonidas} from "./ILeonidas.sol";

Expand All @@ -30,7 +29,6 @@ import {ILeonidas} from "./ILeonidas.sol";
contract Leonidas is Ownable, ILeonidas {
using EnumerableSet for EnumerableSet.AddressSet;
using SignatureLib for SignatureLib.Signature;
using MessageHashUtils for bytes32;

/**
* @notice The data structure for an epoch
Expand Down Expand Up @@ -378,16 +376,14 @@ contract Leonidas is Ownable, ILeonidas {
// Validate the attestations
uint256 validAttestations = 0;

bytes32 ethSignedDigest = _digest.toEthSignedMessageHash();

for (uint256 i = 0; i < _signatures.length; i++) {
SignatureLib.Signature memory signature = _signatures[i];
if (signature.isEmpty) {
continue;
}

// The verification will throw if invalid
signature.verify(committee[i], ethSignedDigest);
signature.verify(committee[i], _digest);
validAttestations++;
}

Expand Down
6 changes: 1 addition & 5 deletions l1-contracts/test/sparta/Sparta.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {DecoderBase} from "../decoders/Base.sol";
import {DataStructures} from "../../src/core/libraries/DataStructures.sol";
import {Constants} from "../../src/core/libraries/ConstantsGen.sol";
import {SignatureLib} from "../../src/core/sequencer_selection/SignatureLib.sol";
import {MessageHashUtils} from "@oz/utils/cryptography/MessageHashUtils.sol";

import {Registry} from "../../src/core/messagebridge/Registry.sol";
import {Inbox} from "../../src/core/messagebridge/Inbox.sol";
Expand All @@ -26,8 +25,6 @@ import {IFeeJuicePortal} from "../../src/core/interfaces/IFeeJuicePortal.sol";
*/

contract SpartaTest is DecoderBase {
using MessageHashUtils for bytes32;

Registry internal registry;
Inbox internal inbox;
Outbox internal outbox;
Expand Down Expand Up @@ -280,8 +277,7 @@ contract SpartaTest is DecoderBase {
returns (SignatureLib.Signature memory)
{
uint256 privateKey = privateKeys[_signer];
bytes32 digestForSig = _digest.toEthSignedMessageHash();
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digestForSig);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, _digest);

return SignatureLib.Signature({isEmpty: false, v: v, r: r, s: s});
}
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/archiver/src/archiver/eth_log_handlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Body, InboxLeaf, L2Block, type ViemSignature } from '@aztec/circuit-types';
import { Body, InboxLeaf, L2Block } from '@aztec/circuit-types';
import { AppendOnlyTreeSnapshot, Header, Proof } from '@aztec/circuits.js';
import { type EthAddress } from '@aztec/foundation/eth-address';
import { type ViemSignature } from '@aztec/foundation/eth-signature';
import { Fr } from '@aztec/foundation/fields';
import { numToUInt32BE } from '@aztec/foundation/serialize';
import { InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/circuit-types/src/p2p/block_attestation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import { BlockAttestation } from './block_attestation.js';
import { makeBlockAttestation, randomSigner } from './mocks.js';

describe('Block Attestation serialization / deserialization', () => {
it('Should serialize / deserialize', async () => {
const attestation = await makeBlockAttestation();
it('Should serialize / deserialize', () => {
const attestation = makeBlockAttestation();

const serialized = attestation.toBuffer();
const deserialized = BlockAttestation.fromBuffer(serialized);

expect(deserialized).toEqual(attestation);
});

it('Should serialize / deserialize + recover sender', async () => {
it('Should serialize / deserialize + recover sender', () => {
const account = randomSigner();

const proposal = await makeBlockAttestation(account);
const proposal = makeBlockAttestation(account);
const serialized = proposal.toBuffer();
const deserialized = BlockAttestation.fromBuffer(serialized);

expect(deserialized).toEqual(proposal);

// Recover signature
const sender = await deserialized.getSender();
expect(sender.toChecksumString()).toEqual(account.address);
const sender = deserialized.getSender();
expect(sender).toEqual(account.address);
});
});
19 changes: 7 additions & 12 deletions yarn-project/circuit-types/src/p2p/block_attestation.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { EthAddress, Header } from '@aztec/circuits.js';
import { type EthAddress, Header } from '@aztec/circuits.js';
import { Buffer32 } from '@aztec/foundation/buffer';
import { recoverAddress } from '@aztec/foundation/crypto';
import { Signature } from '@aztec/foundation/eth-signature';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { recoverMessageAddress } from 'viem';

import { TxHash } from '../tx/tx_hash.js';
import { get0xStringHashedSignaturePayload, getSignaturePayload } from './block_utils.js';
import { getHashedSignaturePayload, getSignaturePayload } from './block_utils.js';
import { Gossipable } from './gossipable.js';
import { Signature } from './signature.js';
import { TopicType, createTopicString } from './topic_type.js';

export class BlockAttestationHash extends Buffer32 {
Expand Down Expand Up @@ -53,16 +52,12 @@ export class BlockAttestation extends Gossipable {
* Lazily evaluate and cache the sender of the attestation
* @returns The sender of the attestation
*/
async getSender() {
getSender() {
if (!this.sender) {
// Recover the sender from the attestation
const hashed = get0xStringHashedSignaturePayload(this.archive, this.txHashes);
const address = await recoverMessageAddress({
message: { raw: hashed },
signature: this.signature.to0xString(),
});
const hashed = getHashedSignaturePayload(this.archive, this.txHashes);
// Cache the sender for later use
this.sender = EthAddress.fromString(address);
this.sender = recoverAddress(hashed, this.signature);
}

return this.sender;
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/circuit-types/src/p2p/block_proposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import { BlockProposal } from './block_proposal.js';
import { makeBlockProposal, randomSigner } from './mocks.js';

describe('Block Proposal serialization / deserialization', () => {
it('Should serialize / deserialize', async () => {
const proposal = await makeBlockProposal();
it('Should serialize / deserialize', () => {
const proposal = makeBlockProposal();

const serialized = proposal.toBuffer();
const deserialized = BlockProposal.fromBuffer(serialized);

expect(deserialized).toEqual(proposal);
});

it('Should serialize / deserialize + recover sender', async () => {
it('Should serialize / deserialize + recover sender', () => {
const account = randomSigner();

const proposal = await makeBlockProposal(account);
const proposal = makeBlockProposal(account);
const serialized = proposal.toBuffer();
const deserialized = BlockProposal.fromBuffer(serialized);

expect(deserialized).toEqual(proposal);

// Recover signature
const sender = await deserialized.getSender();
expect(sender.toChecksumString()).toEqual(account.address);
const sender = deserialized.getSender();
expect(sender).toEqual(account.address);
});
});
22 changes: 8 additions & 14 deletions yarn-project/circuit-types/src/p2p/block_proposal.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { EthAddress, Header } from '@aztec/circuits.js';
import { type EthAddress, Header } from '@aztec/circuits.js';
import { Buffer32 } from '@aztec/foundation/buffer';
import { recoverAddress } from '@aztec/foundation/crypto';
import { Signature } from '@aztec/foundation/eth-signature';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { recoverMessageAddress } from 'viem';

import { TxHash } from '../tx/tx_hash.js';
import { get0xStringHashedSignaturePayload, getHashedSignaturePayload, getSignaturePayload } from './block_utils.js';
import { getHashedSignaturePayload, getSignaturePayload } from './block_utils.js';
import { Gossipable } from './gossipable.js';
import { Signature } from './signature.js';
import { TopicType, createTopicString } from './topic_type.js';

export class BlockProposalHash extends Buffer32 {
Expand Down Expand Up @@ -54,7 +53,7 @@ export class BlockProposal extends Gossipable {
header: Header,
archive: Fr,
txs: TxHash[],
payloadSigner: (payload: Buffer) => Promise<Signature>,
payloadSigner: (payload: Buffer32) => Promise<Signature>,
) {
const hashed = getHashedSignaturePayload(archive, txs);
const sig = await payloadSigner(hashed);
Expand All @@ -65,16 +64,11 @@ export class BlockProposal extends Gossipable {
/**Get Sender
* Lazily evaluate the sender of the proposal; result is cached
*/
async getSender() {
getSender() {
if (!this.sender) {
// performance note(): this signature method requires another hash behind the scenes
const hashed = get0xStringHashedSignaturePayload(this.archive, this.txs);
const address = await recoverMessageAddress({
message: { raw: hashed },
signature: this.signature.to0xString(),
});
const hashed = getHashedSignaturePayload(this.archive, this.txs);
// Cache the sender for later use
this.sender = EthAddress.fromString(address);
this.sender = recoverAddress(hashed, this.signature);
}

return this.sender;
Expand Down
13 changes: 5 additions & 8 deletions yarn-project/circuit-types/src/p2p/block_utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { keccak256 as keccak256Buffer } from '@aztec/foundation/crypto';
import { Buffer32 } from '@aztec/foundation/buffer';
import { keccak256 } from '@aztec/foundation/crypto';
import { type Fr } from '@aztec/foundation/fields';

import { encodeAbiParameters, keccak256 as keccak2560xString, parseAbiParameters } from 'viem';
import { encodeAbiParameters, parseAbiParameters } from 'viem';

import { type TxHash } from '../tx/tx_hash.js';

Expand All @@ -25,10 +26,6 @@ export function getSignaturePayload(archive: Fr, txs: TxHash[]) {
* @param txs - The transactions in the block
* @returns The hashed payload for the signature of the block proposal
*/
export function getHashedSignaturePayload(archive: Fr, txs: TxHash[]): Buffer {
return keccak256Buffer(getSignaturePayload(archive, txs));
}

export function get0xStringHashedSignaturePayload(archive: Fr, txs: TxHash[]): `0x${string}` {
return keccak2560xString(getSignaturePayload(archive, txs));
export function getHashedSignaturePayload(archive: Fr, txs: TxHash[]): Buffer32 {
return Buffer32.fromBuffer(keccak256(getSignaturePayload(archive, txs)));
}
1 change: 0 additions & 1 deletion yarn-project/circuit-types/src/p2p/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export * from './block_proposal.js';
export * from './interface.js';
export * from './gossipable.js';
export * from './topic_type.js';
export * from './signature.js';
export * from './block_utils.js';
26 changes: 12 additions & 14 deletions yarn-project/circuit-types/src/p2p/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
import { makeHeader } from '@aztec/circuits.js/testing';
import { Buffer32 } from '@aztec/foundation/buffer';
import { Secp256k1Signer } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';

import { type PrivateKeyAccount } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';

import { TxHash } from '../tx/tx_hash.js';
import { BlockAttestation } from './block_attestation.js';
import { BlockProposal } from './block_proposal.js';
import { get0xStringHashedSignaturePayload } from './block_utils.js';
import { Signature } from './signature.js';
import { getHashedSignaturePayload } from './block_utils.js';

export const makeBlockProposal = async (signer?: PrivateKeyAccount): Promise<BlockProposal> => {
export const makeBlockProposal = (signer?: Secp256k1Signer): BlockProposal => {
signer = signer || randomSigner();

const blockHeader = makeHeader(1);
const archive = Fr.random();
const txs = [0, 1, 2, 3, 4, 5].map(() => TxHash.random());
const hash = get0xStringHashedSignaturePayload(archive, txs);
const signature = Signature.from0xString(await signer.signMessage({ message: { raw: hash } }));
const hash = getHashedSignaturePayload(archive, txs);
const signature = signer.sign(hash);

return new BlockProposal(blockHeader, archive, txs, signature);
};

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8028)
export const makeBlockAttestation = async (signer?: PrivateKeyAccount): Promise<BlockAttestation> => {
export const makeBlockAttestation = (signer?: Secp256k1Signer): BlockAttestation => {
signer = signer || randomSigner();

const blockHeader = makeHeader(1);
const archive = Fr.random();
const txs = [0, 1, 2, 3, 4, 5].map(() => TxHash.random());
const hash = get0xStringHashedSignaturePayload(archive, txs);
const signature = Signature.from0xString(await signer.signMessage({ message: { raw: hash } }));
const hash = getHashedSignaturePayload(archive, txs);
const signature = signer.sign(hash);

return new BlockAttestation(blockHeader, archive, txs, signature);
};

export const randomSigner = (): PrivateKeyAccount => {
const privateKey = generatePrivateKey();
return privateKeyToAccount(privateKey);
export const randomSigner = (): Secp256k1Signer => {
const privateKey = Buffer32.random();
return new Secp256k1Signer(privateKey);
};
31 changes: 0 additions & 31 deletions yarn-project/circuit-types/src/p2p/signature.test.ts

This file was deleted.

4 changes: 3 additions & 1 deletion yarn-project/foundation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"./crypto": "./dest/crypto/index.js",
"./error": "./dest/error/index.js",
"./eth-address": "./dest/eth-address/index.js",
"./eth-signature": "./dest/eth-signature/index.js",
"./queue": "./dest/queue/index.js",
"./fs": "./dest/fs/index.js",
"./buffer": "./dest/buffer/index.js",
Expand Down Expand Up @@ -144,7 +145,8 @@
"prettier": "^2.7.1",
"supertest": "^6.3.3",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"typescript": "^5.0.4",
"viem": "^2.7.15"
},
"files": [
"dest",
Expand Down
18 changes: 18 additions & 0 deletions yarn-project/foundation/src/buffer/buffer32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,25 @@ export class Buffer32 {
* @param str - The TX hash in string format.
* @returns A new Buffer32 object.
*/
public static fromStringUnchecked(str: string): Buffer32 {
return new Buffer32(Buffer.from(str, 'hex'));
}

/**
* Converts a string into a Buffer32 object.
* NOTE: this method includes checks for the 0x prefix and the length of the string.
* if you dont need this checks, use fromStringUnchecked instead.
*
* @param str - The TX hash in string format.
* @returns A new Buffer32 object.
*/
public static fromString(str: string): Buffer32 {
if (str.startsWith('0x')) {
str = str.slice(2);
}
if (str.length !== 64) {
throw new Error(`Expected string to be 64 characters long, but was ${str.length}`);
}
return new Buffer32(Buffer.from(str, 'hex'));
}

Expand Down
1 change: 1 addition & 0 deletions yarn-project/foundation/src/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './sha256/index.js';
export * from './sha512/index.js';
export * from './pedersen/index.js';
export * from './poseidon/index.js';
export * from './secp256k1-signer/index.js';

/**
* Init the bb singleton. This constructs (if not already) the barretenberg sync api within bb.js itself.
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/foundation/src/crypto/secp256k1-signer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './secp256k1_signer.js';
export * from './utils.js';
Loading
Loading