Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion boxes/boxes/vanilla/app/embedded-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class EmbeddedWallet extends EmbeddedWalletBase {
if (!address) {
return null;
}
const parsed = AztecAddress.fromString(address);
const parsed = AztecAddress.fromStringUnsafe(address);
this.connectedAccount = parsed;
return this.connectedAccount;
}
Expand Down
8 changes: 4 additions & 4 deletions boxes/boxes/vanilla/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ document.addEventListener('DOMContentLoaded', async () => {
const instance = await getContractInstanceFromInstantiationParams(
PrivateVotingContract.artifact,
{
deployer: AztecAddress.fromString(deployerAddress),
deployer: AztecAddress.fromStringUnsafe(deployerAddress),
salt: Fr.fromString(deploymentSalt),
constructorArgs: [AztecAddress.fromString(deployerAddress)],
constructorArgs: [AztecAddress.fromStringUnsafe(deployerAddress)],
}
);
await wallet.registerContract(instance, PrivateVotingContract.artifact);
Expand Down Expand Up @@ -155,7 +155,7 @@ voteButton.addEventListener('click', async (e) => {

// Prepare contract interaction
const votingContract = PrivateVotingContract.at(
AztecAddress.fromString(contractAddress),
AztecAddress.fromStringUnsafe(contractAddress),
wallet
);

Expand Down Expand Up @@ -188,7 +188,7 @@ async function updateVoteTally(wallet: Wallet, from: AztecAddress) {

// Prepare contract interaction
const votingContract = PrivateVotingContract.at(
AztecAddress.fromString(contractAddress),
AztecAddress.fromStringUnsafe(contractAddress),
wallet
);

Expand Down
20 changes: 20 additions & 0 deletions docs/docs-developers/docs/resources/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ Aztec is in active development. Each version may introduce breaking changes that

## TBD

### [Aztec.js] Unchecked `AztecAddress` constructors renamed with an `Unsafe` suffix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant changes here


The synchronous `AztecAddress` constructors that build an address from a raw value do not verify that the value is a valid address (the x-coordinate of a point on the Grumpkin curve, which is what allows it to be encrypted to). An invalid value is accepted silently and only fails later, when a transaction is sent. To make this obvious at the call site, they now carry an `Unsafe` suffix:

| Before | After |
| --- | --- |
| `AztecAddress.fromField` | `AztecAddress.fromFieldUnsafe` |
| `AztecAddress.fromBigInt` | `AztecAddress.fromBigIntUnsafe` |
| `AztecAddress.fromNumber` | `AztecAddress.fromNumberUnsafe` |
| `AztecAddress.fromString` | `AztecAddress.fromStringUnsafe` |

**Migration:**

```diff
- const address = AztecAddress.fromBigInt(123n);
+ const address = AztecAddress.fromBigIntUnsafe(123n);
```

For a random, genuinely valid address in tests use `AztecAddress.random()`, and to check an untrusted value use `address.isValid()`. The serialization constructors `fromBuffer` and `fromFields` keep their names (they are part of the (de)serialization interface and read addresses from already-validated data), but their docs now note that they perform no validation either.

### Cross-contract utility calls now have a `msg_sender`

A utility function called by another contract (utility to utility, or private to utility) can read the calling contract's address via `self.msg_sender()`, mirroring private and public functions. A top-level utility call (e.g. invoked directly by a wallet or dapp) has no caller: `self.msg_sender()` panics, and `self.context.maybe_msg_sender()` returns `Option::none()`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ case 'sendTx': {

// 1. Deserialize the payload
const payload = deserializeExecutionPayload(executionPayload);
const fromAddress = AztecAddress.fromString(from || options.from);
const fromAddress = AztecAddress.fromStringUnsafe(from || options.from);

// 2. Call wallet.sendTx (inherited from BaseWallet)
const result = await wallet.sendTx(payload, {
Expand Down Expand Up @@ -297,7 +297,7 @@ For gas estimation or validation, dApps use `simulateTx`:
case 'simulateTx': {
const { executionPayload, options } = args;
const payload = deserializeExecutionPayload(executionPayload);
const fromAddress = AztecAddress.fromString(from || options.from);
const fromAddress = AztecAddress.fromStringUnsafe(from || options.from);

const result = await wallet.simulateTx(payload, {
...options,
Expand Down Expand Up @@ -342,7 +342,7 @@ For delegated actions (like approving token spending), the wallet creates auth w
```typescript
case 'createAuthWit': {
const { from: authFrom, messageHashOrIntent } = args;
const fromAddress = AztecAddress.fromString(authFrom);
const fromAddress = AztecAddress.fromStringUnsafe(authFrom);

const authWit = await wallet.createAuthWit(fromAddress, messageHashOrIntent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function GameLobby({ wallet, account, onGameJoined }: GameLobbyProps) {
return;
}

const contractAddr = AztecAddress.fromString(joinContractAddress);
const contractAddr = AztecAddress.fromStringUnsafe(joinContractAddress);
const contract = await attachToContract(
wallet,
contractAddr
Expand Down
6 changes: 3 additions & 3 deletions noir-projects/protocol-fuzzer/wallet-bridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const handlers = {
const w = await ensureWallet();
const { result: address, stdout } = await capturing(log =>
deploy(
w, node, AztecAddress.fromString(from), artifact,
w, node, AztecAddress.fromStringUnsafe(from), artifact,
false, /* json */
undefined, /* publicKeys */
Array.isArray(args) ? args : [], /* args */
Expand All @@ -106,8 +106,8 @@ const handlers = {

'/execute': async ({ verb, method, contract, from, args, artifact }) => {
const w = await ensureWallet();
const sender = AztecAddress.fromString(from);
const target = AztecAddress.fromString(contract);
const sender = AztecAddress.fromStringUnsafe(from);
const target = AztecAddress.fromStringUnsafe(contract);
const callArgs = args || [];
const { stdout } = await capturing(log =>
verb === 'send'
Expand Down
2 changes: 1 addition & 1 deletion playground/src/components/common/FnParameter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function FunctionParameter({ parameter, required, onParameterChange, defa
const contacts = await wallet.getAddressBook();

const contracts = (await playgroundDB.listAliases('contracts')).map(
({ alias, item }) => ({ alias, item: AztecAddress.fromString(item) }),
({ alias, item }) => ({ alias, item: AztecAddress.fromStringUnsafe(item) }),
);
setAliasedAddresses([...accounts, ...contacts, ...contracts]);
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function CreateAuthwitDialog({ open, contract, fnName, args, isPrivate, o
setCreating(true);
const call = await contract.methods[fnName](...args).getFunctionCall();
const intent = {
caller: AztecAddress.fromString(caller),
caller: AztecAddress.fromStringUnsafe(caller),
call,
};
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function CreateContractDialog({
const registerExistingContract = async () => {
setIsRegistering(true);
try {
const contract = await node.getContract(AztecAddress.fromString(address));
const contract = await node.getContract(AztecAddress.fromStringUnsafe(address));
if (!contract) {
throw new Error('Contract with this address was not found in node');
}
Expand Down
2 changes: 1 addition & 1 deletion playground/src/components/home/components/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export function Landing() {
const artifactAsString = await playgroundDB.retrieveAlias(`artifacts:${contract.item}`);
const contractArtifact = loadContractArtifact(parse(artifactAsString));
if (contractArtifact.name === contractArtifactJSON.name) {
deployedContractAddress = AztecAddress.fromString(contract.item);
deployedContractAddress = AztecAddress.fromStringUnsafe(contract.item);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function AccountSelector() {
onClose={() => setIsOpen(false)}
onChange={e => {
if (e.target.value !== '') {
handleAccountChange(AztecAddress.fromString(e.target.value));
handleAccountChange(AztecAddress.fromStringUnsafe(e.target.value));
}
}}
disabled={areAccountsLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function ContractSelector() {
} else {
const artifactAsString = await playgroundDB.retrieveAlias(`artifacts:${contractValue}`);
const contractArtifact = loadContractArtifact(parse(artifactAsString));
setCurrentContractAddress(AztecAddress.fromString(contractValue));
setCurrentContractAddress(AztecAddress.fromStringUnsafe(contractValue));
setCurrentContractArtifact(contractArtifact);
setSelectedPredefinedContract(undefined);
setShowContractInterface(true);
Expand Down
2 changes: 1 addition & 1 deletion playground/src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function filterDeployedAliasedContracts(
const deployed = (
await Promise.all(
aliasedContracts.map(async contract => {
const { isContractPublished } = await wallet.getContractMetadata(AztecAddress.fromString(contract.item));
const { isContractPublished } = await wallet.getContractMetadata(AztecAddress.fromStringUnsafe(contract.item));
return { ...contract, deployed: isContractPublished };
}),
)
Expand Down
2 changes: 1 addition & 1 deletion playground/src/wallet/components/AddSenderDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function AddSendersDialog({

const addSender = async () => {
try {
const parsed = AztecAddress.fromString(sender);
const parsed = AztecAddress.fromStringUnsafe(sender);
onClose(parsed, alias);
} catch (e) {
setError('Invalid Aztec address');
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/store/log_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function buildChainedCheckpointsWithLogs(
return checkpoints;
}

const CONTRACT = AztecAddress.fromNumber(543254);
const CONTRACT = AztecAddress.fromNumberUnsafe(543254);

describe('LogStore', () => {
let blockStore: BlockStore;
Expand Down Expand Up @@ -468,7 +468,7 @@ describe('LogStore', () => {
await logStore.addLogs([ckpt.checkpoint.blocks[0]]);

// Same tag, different contract → no hits.
const otherContract = AztecAddress.fromNumber(99);
const otherContract = AztecAddress.fromNumberUnsafe(99);
const [missing] = await logStore.getPublicLogsByTags({ contractAddress: otherContract, tags: [tag] });
expect(missing).toEqual([]);

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/archiver/src/store/log_store_codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('log_store_codec', () => {
});

it('strips 0x prefix for AztecAddress', () => {
const addr = AztecAddress.fromNumber(12345);
const addr = AztecAddress.fromNumberUnsafe(12345);
const hex = fieldHex(addr);
expect(hex).toHaveLength(64);
expect(hex).not.toMatch(/^0x/);
Expand All @@ -69,7 +69,7 @@ describe('log_store_codec', () => {
});

it('round-trips a public-style prefix (contract-tag)', () => {
const contractHex = fieldHex(AztecAddress.fromNumber(99));
const contractHex = fieldHex(AztecAddress.fromNumberUnsafe(99));
const tagHex = fieldHex(new Fr(0x5678n));
const prefix = encodePublicPrefix(contractHex, tagHex);
const key = encodeKey(prefix, 10, 0, 2);
Expand Down Expand Up @@ -242,7 +242,7 @@ describe('log_store_codec', () => {

describe('encodePublicPrefix', () => {
it('produces contractHex-tagHex', () => {
const contractHex = fieldHex(AztecAddress.fromNumber(1));
const contractHex = fieldHex(AztecAddress.fromNumberUnsafe(1));
const tagHex = fieldHex(new Fr(2n));
expect(encodePublicPrefix(contractHex, tagHex)).toBe(`${contractHex}-${tagHex}`);
});
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/archiver/src/test/mock_structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ export function makePublicLogTag(blockNumber: number, txIndex: number, logIndex:
}

/** Creates a PublicLog with fields derived from the tag. */
export function makePublicLog(tag: Tag, contractAddress: AztecAddress = AztecAddress.fromNumber(543254)): PublicLog {
export function makePublicLog(
tag: Tag,
contractAddress: AztecAddress = AztecAddress.fromNumberUnsafe(543254),
): PublicLog {
return PublicLog.from({
contractAddress,
fields: new Array(10).fill(null).map((_, i) => (!i ? tag.value : new Fr(tag.value.toBigInt() + BigInt(i)))),
Expand All @@ -281,7 +284,7 @@ export function makePublicLogs(
blockNumber: number,
txIndex: number,
numLogsPerTx: number,
contractAddress: AztecAddress = AztecAddress.fromNumber(543254),
contractAddress: AztecAddress = AztecAddress.fromNumberUnsafe(543254),
): PublicLog[] {
return times(numLogsPerTx, logIndex => {
const tag = makePublicLogTag(blockNumber, txIndex, logIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export class CallAuthorizationRequest {
const request = new CallAuthorizationRequest(
selector,
reader.readField(), // inner_hash
AztecAddress.fromField(reader.readField()), // on_behalf_of
AztecAddress.fromField(reader.readField()), // msg_sender
AztecAddress.fromFieldUnsafe(reader.readField()), // on_behalf_of
AztecAddress.fromFieldUnsafe(reader.readField()), // msg_sender
FunctionSelector.fromField(reader.readField()), // fn_selector
reader.readField(), // args_hash
reader.readFieldArray(reader.remainingFields()), // args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('extractOffchainOutput', () => {

const makeEffect = (data: Fr[], contractAddress?: AztecAddress): OffchainEffect => ({
data,
contractAddress: contractAddress ?? AztecAddress.fromField(Fr.random()),
contractAddress: contractAddress ?? AztecAddress.fromFieldUnsafe(Fr.random()),
});

const makeMessageEffect = async (recipient?: AztecAddress, payload?: Fr[], contractAddress?: AztecAddress) =>
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/contract/interaction_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function extractOffchainOutput(effects: OffchainEffect[], anchorBlockTime
for (const effect of effects) {
if (effect.data.length >= 2 && effect.data[0].equals(OFFCHAIN_MESSAGE_IDENTIFIER)) {
offchainMessages.push({
recipient: AztecAddress.fromField(effect.data[1]),
recipient: AztecAddress.fromFieldUnsafe(effect.data[1]),
payload: effect.data.slice(2),
contractAddress: effect.contractAddress,
anchorBlockTimestamp,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/standby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ROLLUP_POLL_INTERVAL_S = 60;
export async function computeExpectedGenesisRoot(config: GenesisStateConfig, userLog: LogFn) {
const testAccounts = config.testAccounts ? (await getInitialTestAccountsData()).map(a => a.address) : [];
const sponsoredFPCAccounts = config.sponsoredFPC ? [await getSponsoredFPCAddress()] : [];
const prefundAddresses = (config.prefundAddresses ?? []).map(a => AztecAddress.fromString(a));
const prefundAddresses = (config.prefundAddresses ?? []).map(a => AztecAddress.fromStringUnsafe(a));
const initialFundedAccounts = testAccounts.concat(sponsoredFPCAccounts).concat(prefundAddresses);

userLog(`Initial funded accounts: ${initialFundedAccounts.map(a => a.toString()).join(', ')}`);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/local-network/local-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {

const bananaFPC = await getBananaFPCAddress(initialAccounts);
const sponsoredFPC = await getSponsoredFPCAddress();
const prefundAddresses = (aztecNodeConfig.prefundAddresses ?? []).map(a => AztecAddress.fromString(a));
const prefundAddresses = (aztecNodeConfig.prefundAddresses ?? []).map(a => AztecAddress.fromStringUnsafe(a));
const fundedAddresses = [
...initialAccounts.map(a => a.address),
...(initialAccounts.length ? [bananaFPC, sponsoredFPC] : []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('AVM check-circuit – unhappy paths 1', () => {
tester = await AvmProvingTester.new(worldStateService, /*checkCircuitOnly*/ true);
avmTestContractInstance = await tester.registerAndDeployContract(
/*constructorArgs=*/ [],
/*deployer=*/ AztecAddress.fromNumber(420),
/*deployer=*/ AztecAddress.fromNumberUnsafe(420),
AvmTestContractArtifact,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AvmProvingTester } from './avm_proving_tester.js';
const TIMEOUT = 30_000;

describe('AVM check-circuit – unhappy paths 2', () => {
const sender = AztecAddress.fromNumber(42);
const sender = AztecAddress.fromNumberUnsafe(42);
let avmTestContractInstance: ContractInstanceWithAddress;
let tester: AvmProvingTester;
let worldStateService: NativeWorldStateService;
Expand All @@ -20,7 +20,7 @@ describe('AVM check-circuit – unhappy paths 2', () => {
tester = await AvmProvingTester.new(worldStateService, /*checkCircuitOnly*/ true);
avmTestContractInstance = await tester.registerAndDeployContract(
/*constructorArgs=*/ [],
/*deployer=*/ AztecAddress.fromNumber(420),
/*deployer=*/ AztecAddress.fromNumberUnsafe(420),
AvmTestContractArtifact,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AvmProvingTester } from './avm_proving_tester.js';
const TIMEOUT = 100_000;

describe('AVM check-circuit – unhappy paths 3', () => {
const sender = AztecAddress.fromNumber(42);
const sender = AztecAddress.fromNumberUnsafe(42);
let avmTestContractInstance: ContractInstanceWithAddress;
let tester: AvmProvingTester;
let worldStateService: NativeWorldStateService;
Expand All @@ -23,7 +23,7 @@ describe('AVM check-circuit – unhappy paths 3', () => {
tester = await AvmProvingTester.new(worldStateService, /*checkCircuitOnly*/ true);
avmTestContractInstance = await tester.registerAndDeployContract(
/*constructorArgs=*/ [],
/*deployer=*/ AztecAddress.fromNumber(420),
/*deployer=*/ AztecAddress.fromNumberUnsafe(420),
AvmTestContractArtifact,
);
});
Expand Down Expand Up @@ -137,15 +137,15 @@ describe('AVM check-circuit – unhappy paths 3', () => {
l2ToL1Msgs: [
new ScopedL2ToL1Message(
new L2ToL1Message(EthAddress.fromNumber(0x1111), new Fr(0xdddd)),
AztecAddress.fromNumber(0x1111),
AztecAddress.fromNumberUnsafe(0x1111),
),
new ScopedL2ToL1Message(
new L2ToL1Message(EthAddress.fromNumber(0x2222), new Fr(0xeeee)),
AztecAddress.fromNumber(0x2222),
AztecAddress.fromNumberUnsafe(0x2222),
),
new ScopedL2ToL1Message(
new L2ToL1Message(EthAddress.fromNumber(0x3333), new Fr(0xffff)),
AztecAddress.fromNumber(0x3333),
AztecAddress.fromNumberUnsafe(0x3333),
),
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AvmProvingTester } from './avm_proving_tester.js';
const TIMEOUT = 300_000;

describe('AVM check-circuit - contract class limits', () => {
const deployer = AztecAddress.fromNumber(42);
const deployer = AztecAddress.fromNumberUnsafe(42);
let instances: ContractInstanceWithAddress[];
let tester: AvmProvingTester;
let avmTestContractAddress: AztecAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AvmProvingTester } from './avm_proving_tester.js';
const TIMEOUT = 60_000;

describe('AVM check-circuit - contract updates', () => {
const sender = AztecAddress.fromNumber(42);
const sender = AztecAddress.fromNumberUnsafe(42);

const avmTestContractClassSeed = 0;
let avmTestContractInstance: ContractInstanceWithAddress;
Expand Down
Loading
Loading