-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
336 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
yarn-project/aztec-node/src/aztec-node/tx_validator/tx_metadata_validator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { mockTx, mockTxForRollup } from '@aztec/circuit-types'; | ||
import { Fr } from '@aztec/circuits.js'; | ||
|
||
import { MetadataTxValidator } from './tx_metadata_validator.js'; | ||
|
||
describe('MetadataTxValidator', () => { | ||
let chainId: Fr; | ||
let validator: MetadataTxValidator; | ||
|
||
beforeEach(() => { | ||
chainId = Fr.random(); | ||
validator = new MetadataTxValidator(chainId); | ||
}); | ||
|
||
it('allows only transactions for the right chain', async () => { | ||
const goodTxs = [mockTx(1), mockTxForRollup(2)]; | ||
const badTxs = [mockTx(3), mockTxForRollup(4)]; | ||
|
||
goodTxs.forEach(tx => { | ||
tx.data.constants.txContext.chainId = chainId; | ||
}); | ||
|
||
badTxs.forEach(tx => { | ||
tx.data.constants.txContext.chainId = chainId.add(new Fr(1)); | ||
}); | ||
|
||
await expect(validator.validateTxs([...goodTxs, ...badTxs])).resolves.toEqual([goodTxs, badTxs]); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
yarn-project/aztec-node/src/aztec-node/tx_validator/tx_metadata_validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Tx, type TxValidator } from '@aztec/circuit-types'; | ||
import { Fr } from '@aztec/circuits.js'; | ||
import { createDebugLogger } from '@aztec/foundation/log'; | ||
|
||
export class MetadataTxValidator implements TxValidator<Tx> { | ||
#log = createDebugLogger('aztec:sequencer:tx_validator:tx_metadata'); | ||
#chainId: Fr; | ||
|
||
constructor(chainId: number | Fr) { | ||
this.#chainId = new Fr(chainId); | ||
} | ||
|
||
validateTxs(txs: Tx[]): Promise<[validTxs: Tx[], invalidTxs: Tx[]]> { | ||
const validTxs: Tx[] = []; | ||
const invalidTxs: Tx[] = []; | ||
for (const tx of txs) { | ||
if (!this.#hasCorrectChainId(tx)) { | ||
invalidTxs.push(tx); | ||
continue; | ||
} | ||
|
||
validTxs.push(tx); | ||
} | ||
|
||
return Promise.resolve([validTxs, invalidTxs]); | ||
} | ||
|
||
#hasCorrectChainId(tx: Tx): boolean { | ||
if (!tx.data.constants.txContext.chainId.equals(this.#chainId)) { | ||
this.#log.warn( | ||
`Rejecting tx ${Tx.getHash( | ||
tx, | ||
)} because of incorrect chain ${tx.data.constants.txContext.chainId.toNumber()} != ${this.#chainId.toNumber()}`, | ||
); | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
yarn-project/aztec-node/src/aztec-node/tx_validator/tx_proof_validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { type ClientProtocolCircuitVerifier, Tx, type TxValidator } from '@aztec/circuit-types'; | ||
import { createDebugLogger } from '@aztec/foundation/log'; | ||
|
||
export class TxProofValidator implements TxValidator<Tx> { | ||
#log = createDebugLogger('aztec:sequencer:tx_validator:private_proof'); | ||
|
||
constructor(private verifier: ClientProtocolCircuitVerifier) {} | ||
|
||
async validateTxs(txs: Tx[]): Promise<[validTxs: Tx[], invalidTxs: Tx[]]> { | ||
const validTxs: Tx[] = []; | ||
const invalidTxs: Tx[] = []; | ||
|
||
for (const tx of txs) { | ||
if (await this.verifier.verifyProof(tx)) { | ||
validTxs.push(tx); | ||
} else { | ||
this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} for invalid proof`); | ||
invalidTxs.push(tx); | ||
} | ||
} | ||
|
||
return [validTxs, invalidTxs]; | ||
} | ||
|
||
validateTx(tx: Tx): Promise<boolean> { | ||
return this.verifier.verifyProof(tx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
{ | ||
"path": "../archiver" | ||
}, | ||
{ | ||
"path": "../bb-prover" | ||
}, | ||
{ | ||
"path": "../circuit-types" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './test_circuit_prover.js'; | ||
export * from './test_verifier.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type ClientProtocolCircuitVerifier, type Tx } from '@aztec/circuit-types'; | ||
import { type VerificationKeys, getMockVerificationKeys } from '@aztec/circuits.js'; | ||
|
||
export class TestCircuitVerifier implements ClientProtocolCircuitVerifier { | ||
verifyProof(_tx: Tx): Promise<boolean> { | ||
return Promise.resolve(true); | ||
} | ||
|
||
getVerificationKeys(): Promise<VerificationKeys> { | ||
return Promise.resolve(getMockVerificationKeys()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.