Skip to content

Commit f82c5e4

Browse files
authored
fix: enforce from check on all interactions (#16462)
Missed during the initial version
2 parents e624cb5 + 7b34b3e commit f82c5e4

File tree

9 files changed

+17
-20
lines changed

9 files changed

+17
-20
lines changed

yarn-project/aztec.js/src/contract/base_contract_interaction.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { FeeOptions, TxExecutionOptions, UserFeeOptions } from '@aztec/entr
22
import type { ExecutionPayload } from '@aztec/entrypoints/payload';
33
import { createLogger } from '@aztec/foundation/log';
44
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
5+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
56
import { GasSettings } from '@aztec/stdlib/gas';
67
import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
78

@@ -48,6 +49,11 @@ export abstract class BaseContractInteraction {
4849
* @returns The proving result.
4950
*/
5051
protected async proveInternal(options: SendMethodOptions): Promise<TxProvingResult> {
52+
if (options.from !== AztecAddress.ZERO && !options.from.equals(this.wallet.getAddress())) {
53+
throw new Error(
54+
`The address provided as from does not match the wallet address. Expected ${this.wallet.getAddress().toString()}, got ${options.from.toString()}.`,
55+
);
56+
}
5157
const txRequest = await this.create(options);
5258
return await this.wallet.proveTx(txRequest);
5359
}
@@ -60,11 +66,6 @@ export abstract class BaseContractInteraction {
6066
*/
6167
public async prove(options: SendMethodOptions): Promise<ProvenTx> {
6268
// docs:end:prove
63-
if (!options.from.equals(this.wallet.getAddress())) {
64-
throw new Error(
65-
`The address provided as from does not match the wallet address. Expected ${this.wallet.getAddress().toString()}, got ${options.from.toString()}.`,
66-
);
67-
}
6869
const txProvingResult = await this.proveInternal(options);
6970
return new ProvenTx(
7071
this.wallet,

yarn-project/aztec.js/src/contract/contract.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ describe('Contract Class', () => {
163163
};
164164

165165
wallet = mock<Wallet>();
166+
wallet.getAddress.mockReturnValue(account.address);
166167
wallet.simulateTx.mockResolvedValue(mockTxSimulationResult);
167168
wallet.createTxExecutionRequest.mockResolvedValue(mockTxRequest);
168169
wallet.getContractMetadata.mockResolvedValue({

yarn-project/aztec.js/src/contract/contract_function_interaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
189189
* @returns An object containing the function return value and profile result.
190190
*/
191191
public async profile(options: ProfileMethodOptions): Promise<TxProfileResult> {
192-
if (!options.from.equals(this.wallet.getAddress())) {
192+
if (options.from !== AztecAddress.ZERO && !options.from.equals(this.wallet.getAddress())) {
193193
throw new Error(
194194
`The address provided as from does not match the wallet address. Expected ${this.wallet.getAddress().toString()}, got ${options.from.toString()}.`,
195195
);

yarn-project/end-to-end/src/bench/client_flows/transfers.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ describe('Transfer benchmark', () => {
116116
caller: adminWallet.getAddress(),
117117
action: interaction,
118118
});
119-
await interaction
120-
.send({ from: benchysWallet.getAddress(), authWitnesses: [witness] })
121-
.wait({ timeout: 120 });
119+
await interaction.send({ from: adminAddress, authWitnesses: [witness] }).wait({ timeout: 120 });
122120
});
123121

124122
// Ensure we create a change note, by sending an amount that is not a multiple of the note amount

yarn-project/end-to-end/src/composed/docs_examples.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ describe('docs_examples', () => {
2929
await newAccount.deploy({ deployWallet: wallet }).wait();
3030
const newWallet = await newAccount.getWallet();
3131
const newAccountAddress = newWallet.getAddress();
32-
// docs:end:create_wallet
3332

3433
const defaultAccountAddress = wallet.getAddress();
34+
// docs:end:create_wallet
3535

3636
const deployedContract = await TokenContract.deploy(
3737
wallet, // wallet instance
@@ -49,16 +49,11 @@ describe('docs_examples', () => {
4949
// docs:end:full_deploy
5050

5151
// docs:start:send_transaction
52-
const _tx = await contract.methods
53-
.mint_to_public(newWallet.getAddress(), 1)
54-
.send({ from: newAccountAddress })
55-
.wait();
52+
await contract.methods.mint_to_public(newAccountAddress, 1).send({ from: defaultAccountAddress }).wait();
5653
// docs:end:send_transaction
5754

5855
// docs:start:simulate_function
59-
const balance = await contract.methods
60-
.balance_of_public(newWallet.getAddress())
61-
.simulate({ from: newAccountAddress });
56+
const balance = await contract.methods.balance_of_public(newAccountAddress).simulate({ from: newAccountAddress });
6257
expect(balance).toEqual(1n);
6358
// docs:end:simulate_function
6459
});

yarn-project/end-to-end/src/e2e_2_pxes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ describe('e2e_2_pxes', () => {
218218
const contractWithSharedWalletA = await TokenContract.at(token.address, sharedWalletOnA);
219219
await contractWithSharedWalletA.methods
220220
.transfer(accountBAddress, transferAmount2)
221-
.send({ from: accountAAddress })
221+
.send({ from: sharedAccountAddress })
222222
.wait();
223223

224224
// check balances from PXE-A's perspective

yarn-project/end-to-end/src/e2e_block_building.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ describe('e2e_block_building', () => {
289289

290290
beforeAll(async () => {
291291
({ teardown, pxe, logger, wallet: owner } = await setup(1));
292+
ownerAddress = owner.getAddress();
292293
contract = await TestContract.deploy(owner).send({ from: ownerAddress }).deployed();
293294
logger.info(`Test contract deployed at ${contract.address}`);
294295
});
@@ -515,6 +516,7 @@ describe('e2e_block_building', () => {
515516
skipProtocolContracts: true,
516517
ethereumSlotDuration: 6,
517518
}));
519+
ownerAddress = owner.getAddress();
518520

519521
logger.info('Deploying token contract');
520522
const token = await TokenContract.deploy(owner, owner.getCompleteAddress(), 'TokenName', 'TokenSymbol', 18)

yarn-project/end-to-end/src/e2e_card_game.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('e2e_card_game', () => {
141141
beforeEach(async () => {
142142
await Promise.all([
143143
contract.methods.buy_pack(seed).send({ from: firstPlayer }).wait(),
144-
contractAsSecondPlayer.methods.buy_pack(seed).send({ from: firstPlayer }).wait(),
144+
contractAsSecondPlayer.methods.buy_pack(seed).send({ from: secondPlayer }).wait(),
145145
]);
146146
firstPlayerCollection = boundedVecToArray(
147147
await contract.methods.view_collection_cards(firstPlayer, 0).simulate({ from: firstPlayer }),

yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ export const uniswapL1L2TestSuite = (
747747
nonceForSwap,
748748
);
749749
const validateActionInteraction = await ownerWallet.setPublicAuthWit({ caller: approvedUser, action }, true);
750-
await validateActionInteraction.send({ from: sponsorAddress }).wait();
750+
await validateActionInteraction.send({ from: ownerAddress }).wait();
751751

752752
await expect(action.simulate({ from: sponsorAddress })).rejects.toThrow(/unauthorized/);
753753
});

0 commit comments

Comments
 (0)