Skip to content

refactor: drop artifact field from SimulationOverrides#22957

Merged
dbanks12 merged 3 commits into
merge-train/fairiesfrom
db/sim-overrides-drop-artifacts
May 8, 2026
Merged

refactor: drop artifact field from SimulationOverrides#22957
dbanks12 merged 3 commits into
merge-train/fairiesfrom
db/sim-overrides-drop-artifacts

Conversation

@dbanks12
Copy link
Copy Markdown
Contributor

@dbanks12 dbanks12 commented May 5, 2026

Drops the artifact field from SimulationOverrides.contracts entries. Simulation now resolves the override-instance's currentContractClassId through PXE's locally registered classes — callers register the target artifact via pxe.registerContractClass(...) once, then construct an instance with the desired currentContractClassId to drive dispatch.

In-tree account-stub flows (cli-wallet, embedded_wallet, test_wallet) migrate to the pre-register pattern: pre-register the stub class and bump currentContractClassId on the override instance.

proxied_contract_data_source drops its getFunctionArtifact* overrides — function lookup falls through to the regular ContractStore. The proxy now only overrides getContractInstance.

Test plan

  • All existing simulator unit tests pass against the refactored proxy.
  • E2E account-stub flows (kernelless-override simulation mode) continue to work via the pre-register pattern.

Copy link
Copy Markdown
Contributor Author

dbanks12 commented May 5, 2026

@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch 4 times, most recently from 683f4c5 to da4bd0d Compare May 5, 2026 16:46
@dbanks12 dbanks12 marked this pull request as ready for review May 5, 2026 17:44
@dbanks12 dbanks12 requested a review from Thunkar May 5, 2026 17:44
@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch from da4bd0d to 11e420f Compare May 5, 2026 18:05
salt: Fr.random(),
constructorArgs: stubConstructorArgs,
});
await this.pxe.registerContractClass(stubArtifact);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Love the approach, but I think you have to unfortunately reconstruct the instance in this particular case so it's given an address consistent with the new classId. This is failing in the bot test because we're simulating the deployment of the account contract itself, which calls the constructor that performs some checks related to the init_hash for the emission of the private initialization nullifier. Same for all account contract overrides (there's also a new test if you pull the merge-train that should verify we can simulate constructors properly during kernelless simulations)

Comment thread yarn-project/end-to-end/src/test-wallet/test_wallet.ts Outdated
Comment thread yarn-project/wallets/src/embedded/embedded_wallet.ts Outdated
@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch from 11e420f to 10e67ec Compare May 5, 2026 19:00
Comment on lines +25 to +39
const findFunctionInArtifact = async (
artifact: { name: string; functions: { name: string; parameters: any[] }[] },
selector: FunctionSelector,
contractAddress: AztecAddress,
) => {
for (const fn of artifact.functions) {
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
if (fnSelector.equals(selector)) {
return { ...fn, contractName: artifact.name } as any;
}
}
throw new Error(
`Function with selector ${selector} not found in stub artifact for overridden contract at ${contractAddress}.`,
);
};
Copy link
Copy Markdown
Contributor Author

@dbanks12 dbanks12 May 6, 2026

Choose a reason for hiding this comment

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

Claude pulled this out into a helper which made me think.... This logic ,which was previously inline in the switch statement below, is nearly identical to a helper in contract_store.ts. We can probably consolidate those implementations into a single helper (in stdlib abi?)

@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch 2 times, most recently from f0cb734 to c9c7a6c Compare May 6, 2026 02:39
Comment thread yarn-project/cli-wallet/src/utils/wallet.ts Outdated
@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch from c9c7a6c to eafdf07 Compare May 6, 2026 16:22
@dbanks12 dbanks12 added the ci-full Run all master checks. label May 6, 2026
@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch from 06fafc0 to a498f65 Compare May 6, 2026 18:56
}
return cached;
}

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.

Identical to cli-wallet's fn.... Could consider pulling into a helper somewhere, but not sure it's worth it.

Comment on lines -219 to -224
const stubConstructorArgs = type === 'schnorr' ? [Fr.ZERO, Fr.ZERO] : [Buffer.alloc(32), Buffer.alloc(32)];
const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
salt: Fr.random(),
constructorArgs: stubConstructorArgs,
});

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.

I know we've discussed twice already, but I need to be convinced that we actually need this....

Before this PR, we would derive the stub's instance+address here, but then we never actually use the stub's derived address anywhere as far as i can tell. In fact, in the proxied contract source, we overwrote it with the "real" address before ever using/returning it.

Same goes for initialization hash. And IIUC, we should be fine to use the real initialization hash anyway because the stub constructor has the same signature as the real one.....

Maybe i'm missing something about testing deployments as I remember discussing that briefly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If both the e2e_kernelless_simulation and e2e_bot tests pass, this is indeed not necessary anymore!

@dbanks12 dbanks12 requested a review from LeilaWang as a code owner May 6, 2026 19:39
@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch from cf88b94 to a72d30a Compare May 6, 2026 19:44
@dbanks12 dbanks12 removed the request for review from LeilaWang May 6, 2026 19:46
cached = (async () => {
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact(type);
const { id } = await getContractClassFromArtifact(stubArtifact);
await this.pxe.registerContractClass(stubArtifact);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd query PXE using getContractArtifact first. In case it's already registered, we can skip an extra round of hashing

Copy link
Copy Markdown
Contributor

@Thunkar Thunkar left a comment

Choose a reason for hiding this comment

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

LGTM, except the PXE query to avoid the extra hashing. With that, good to go, nice job!

@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch 2 times, most recently from 4d7ac18 to 386276c Compare May 7, 2026 14:44
@dbanks12 dbanks12 removed the ci-full Run all master checks. label May 7, 2026
@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch 2 times, most recently from dd377eb to d48dbfe Compare May 8, 2026 00:55
dbanks12 added 3 commits May 8, 2026 00:55
`SimulationOverrides.contracts` entries no longer carry a `ContractArtifact`. Simulation resolves the override-instance's `currentContractClassId` through PXE's locally registered classes, so callers register the target artifact via `pxe.registerContractClass(...)` once, then construct an instance with the desired `currentContractClassId` to drive dispatch.

Migrates the in-tree account-stub flows (`cli-wallet`, `embedded_wallet`, `test_wallet`) to pre-register the stub class and bump `currentContractClassId` on the override instance. `proxied_contract_data_source` drops its `getFunctionArtifact*` overrides — function lookup falls through to the regular `ContractStore`.
Match the embedded wallet's pattern: cache the stub class id and preimage
keyed on AccountType rather than on a 'schnorr' | 'ecdsa' flavor union, and
do the schnorr-vs-ecdsa artifact dispatch inline. The two ECDSA AccountType
values share a stub artifact, so on first miss for each variant we'll hash
and re-register the same artifact — a bounded one-time cost per type that's
worth the simpler shape.
Callers only ever consume the `id` field from `getContractClassFromArtifact`,
so cache `Map<AccountType, Promise<Fr>>` instead of the full
`ContractClassWithId & ContractClassIdPreimage`. Method renamed
`#getStubClass` → `#getStubClassId`, map renamed `#stubClasses` →
`#stubClassIds`, callers drop the destructure.

Drop the verbose Promise-as-value rationale comment — the idiom is
established in this codebase (see ContractSyncService) and the PXE
precedents document the cache contract briefly without explaining
the dedupe pattern.
@dbanks12 dbanks12 force-pushed the db/sim-overrides-drop-artifacts branch from d48dbfe to aec497a Compare May 8, 2026 00:55
@dbanks12 dbanks12 merged commit 5f305cc into merge-train/fairies May 8, 2026
15 checks passed
@dbanks12 dbanks12 deleted the db/sim-overrides-drop-artifacts branch May 8, 2026 01:19
dbanks12 added a commit that referenced this pull request May 8, 2026
## Summary

Addresses comment
#22957 (comment)

The same artifact-lookup loop was duplicated three times. Puts two
helper fns in `stdlib/abi`:

- `findFunctionArtifactBySelector(artifact, selector)` — searches
`artifact.functions`, returns `FunctionArtifact | undefined`.
- `findFunctionAbiBySelector(artifact, selector)` — searches
`artifact.functions ∪ nonDispatchPublicFunctions` via
`getAllFunctionAbis`, returns `FunctionAbi | undefined`.

Both `ContractStore` and `ProxiedContractStoreFactory` now call the same
stdlib primitive. The existing throwing `getFunctionArtifact` helper
also reuses `findFunctionArtifactBySelector`.

## Test plan

- [x] `yarn workspace @aztec/pxe test
src/storage/contract_store/contract_store.test.ts`
- [x] `yarn workspace @aztec/stdlib test src/abi/abi.test.ts`
- [x] `yarn lint pxe`, `yarn lint stdlib`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants