Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Aug 28, 2024
1 parent c006b33 commit ada167a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
15 changes: 11 additions & 4 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
LogType,
MerkleTreeId,
NullifierMembershipWitness,
type ProcessedTx,
type ProverConfig,
PublicDataWitness,
PublicSimulationOutput,
Expand All @@ -25,6 +26,7 @@ import {
type TxHash,
TxReceipt,
TxStatus,
type TxValidator,
partitionReverts,
} from '@aztec/circuit-types';
import {
Expand Down Expand Up @@ -762,7 +764,7 @@ export class AztecNodeService implements AztecNode {
);
}

public async isValidTx(tx: Tx): Promise<boolean> {
public async isValidTx(tx: Tx, isSimulation: boolean = false): Promise<boolean> {
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;

const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(
Expand All @@ -775,12 +777,17 @@ export class AztecNodeService implements AztecNode {
// These validators are taken from the sequencer, and should match.
// The reason why `phases` and `gas` tx validator is in the sequencer and not here is because
// those tx validators are customizable by the sequencer.
const txValidator = new AggregateTxValidator(
const txValidators: TxValidator<Tx | ProcessedTx>[] = [
new DataTxValidator(),
new MetadataTxValidator(newGlobalVariables),
new DoubleSpendTxValidator(new WorldStateDB(this.worldStateSynchronizer.getLatest())),
new TxProofValidator(this.proofVerifier),
);
];

if (!isSimulation) {
txValidators.push(new TxProofValidator(this.proofVerifier));
}

const txValidator = new AggregateTxValidator(...txValidators);

const [_, invalidTxs] = await txValidator.validateTxs([tx]);
if (invalidTxs.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/contract/batch_call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class BatchCall extends BaseContractInteraction {

const [unconstrainedResults, simulatedTx] = await Promise.all([
Promise.all(unconstrainedCalls),
this.wallet.simulateTx(txRequest, true, options?.from),
this.wallet.simulateTx(txRequest, true, options?.from, options?.skipTxValidation),
]);

const results: any[] = [];
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,9 @@ export interface AztecNode {
* made invalid by *other* transactions if e.g. they emit the same nullifiers, or come become invalid
* due to e.g. the max_block_number property.
* @param tx - The transaction to validate for correctness.
* @param isSimulation - True if the transaction is a simulated one without generated proofs. (Optional)
*/
isValidTx(tx: Tx): Promise<boolean>;
isValidTx(tx: Tx, isSimulation?: boolean): Promise<boolean>;

/**
* Updates the configuration of this node.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/package.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"test": "TIME_TRAVELER=${TIME_TRAVELER:-true} LOG_LEVEL=${LOG_LEVEL:-verbose} DEBUG_COLORS=1 NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --testTimeout=300000 --forceExit",
"test:unit": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest src/fixtures"
}
}
}
8 changes: 6 additions & 2 deletions yarn-project/end-to-end/src/e2e_prover/full.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('full_prover', () => {
});

afterEach(async () => {
await t.tokenSim.check();
// TODO: (#8187) Tx validation is skipped here because checking the simulation fails the proof validation
await t.tokenSim.check(true);
});

it(
Expand All @@ -41,7 +42,10 @@ describe('full_prover', () => {
expect(privateSendAmount).toBeGreaterThan(0n);
const privateInteraction = provenAssets[0].methods.transfer(accounts[1].address, privateSendAmount);

const publicBalance = await provenAssets[1].methods.balance_of_public(accounts[0].address).simulate();
// TODO: (#8187) This works with above private balance, but not public balance below.
const publicBalance = await provenAssets[1].methods.balance_of_public(accounts[0].address).simulate({
skipTxValidation: true,
});
const publicSendAmount = publicBalance / 2n;
expect(publicSendAmount).toBeGreaterThan(0n);
const publicInteraction = provenAssets[1].methods.transfer_public(
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/e2e_prover/with_padding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('full_prover_with_padding_tx', () => {
});

afterEach(async () => {
await t.tokenSim.check();
// TODO: (#8187) Tx validation is skipped here because checking the simulation fails the proof validation
await t.tokenSim.check(true);
});

it(
Expand Down
30 changes: 22 additions & 8 deletions yarn-project/end-to-end/src/simulators/token_simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,21 @@ export class TokenSimulator {
return this.balancesPrivate.get(address.toString()) || 0n;
}

async checkPublic() {
async checkPublic(skipTxValidation: boolean = false) {
// public calls
const calls = [this.token.methods.total_supply().request()];
for (const address of this.accounts) {
calls.push(this.token.methods.balance_of_public(address).request());
}

const results = (
await Promise.all(chunk(calls, 4).map(batch => new BatchCall(this.defaultWallet, batch).simulate()))
await Promise.all(
chunk(calls, 4).map(batch =>
new BatchCall(this.defaultWallet, batch).simulate({
skipTxValidation,
}),
),
)
).flat();
expect(results[0]).toEqual(this.totalSupply);

Expand All @@ -115,7 +121,7 @@ export class TokenSimulator {
}
}

async checkPrivate() {
async checkPrivate(skipTxValidation: boolean = false) {
// Private calls
const defaultLookups = [];
const nonDefaultLookups = [];
Expand All @@ -133,7 +139,13 @@ export class TokenSimulator {
defaultCalls.push(this.token.methods.balance_of_private(address).request());
}
const results = (
await Promise.all(chunk(defaultCalls, 4).map(batch => new BatchCall(this.defaultWallet, batch).simulate()))
await Promise.all(
chunk(defaultCalls, 4).map(batch =>
new BatchCall(this.defaultWallet, batch).simulate({
skipTxValidation,
}),
),
)
).flat();
for (let i = 0; i < defaultLookups.length; i++) {
expect(results[i]).toEqual(this.balanceOfPrivate(defaultLookups[i]));
Expand All @@ -145,13 +157,15 @@ export class TokenSimulator {
const wallet = this.lookupProvider.get(address.toString());
const asset = wallet ? this.token.withWallet(wallet) : this.token;

const actualPrivateBalance = await asset.methods.balance_of_private({ address }).simulate();
const actualPrivateBalance = await asset.methods.balance_of_private({ address }).simulate({
skipTxValidation,
});
expect(actualPrivateBalance).toEqual(this.balanceOfPrivate(address));
}
}

public async check() {
await this.checkPublic();
await this.checkPrivate();
public async check(skipTxValidation: boolean = false) {
await this.checkPublic(skipTxValidation);
await this.checkPrivate(skipTxValidation);
}
}
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export class PXEService implements PXE {
txRequest: TxExecutionRequest,
simulatePublic: boolean,
msgSender: AztecAddress | undefined = undefined,
skipTxValidation: boolean = true, // TODO(#7956): make the default be false
skipTxValidation: boolean = false,
scopes?: AztecAddress[],
): Promise<SimulatedTx> {
return await this.jobQueue.put(async () => {
Expand All @@ -542,7 +542,7 @@ export class PXEService implements PXE {
}

if (!skipTxValidation) {
if (!(await this.node.isValidTx(simulatedTx.tx))) {
if (!(await this.node.isValidTx(simulatedTx.tx, true))) {
throw new Error('The simulated transaction is unable to be added to state and is invalid.');
}
}
Expand Down

0 comments on commit ada167a

Please sign in to comment.