From c2ef10c3b6096f24197b83895722b3133a76ff35 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 7 Mar 2025 07:13:34 +0000 Subject: [PATCH 01/48] remove unnecessary code from aztec.js --- .../aztec.js/src/api/ethereum/anvil_test_watcher.ts | 2 +- yarn-project/aztec.js/src/api/ethereum/cheat_codes.ts | 2 +- yarn-project/aztec.js/src/api/ethereum/index.ts | 6 ------ yarn-project/aztec.js/src/api/ethereum/portal_manager.ts | 5 ++++- .../src/composed/integration_proof_verification.test.ts | 4 ++-- .../src/e2e_epochs/epochs_empty_blocks.test.ts | 2 +- .../end-to-end/src/e2e_epochs/epochs_proof_fails.test.ts | 2 +- yarn-project/end-to-end/src/e2e_epochs/epochs_test.ts | 2 +- yarn-project/end-to-end/src/e2e_fees/fees_test.ts | 2 +- yarn-project/end-to-end/src/e2e_lending_contract.test.ts | 9 ++------- yarn-project/end-to-end/src/e2e_outbox.test.ts | 2 +- yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts | 2 +- .../src/e2e_p2p/upgrade_governance_proposer.test.ts | 3 ++- .../end-to-end/src/e2e_prover/e2e_prover_test.ts | 3 +-- .../end-to-end/src/fixtures/setup_l1_contracts.ts | 4 ++-- yarn-project/end-to-end/src/fixtures/snapshot_manager.ts | 9 +++++++-- yarn-project/end-to-end/src/fixtures/utils.ts | 4 ++-- .../end-to-end/src/shared/cross_chain_test_harness.ts | 8 ++++++-- yarn-project/ethereum/src/contracts/fee_juice.ts | 2 +- yarn-project/ethereum/src/contracts/forwarder.ts | 3 ++- yarn-project/ethereum/src/contracts/governance.ts | 2 +- .../ethereum/src/contracts/governance_proposer.ts | 2 +- yarn-project/ethereum/src/contracts/rollup.ts | 4 +++- yarn-project/ethereum/src/contracts/slashing_proposer.ts | 2 +- .../api/ethereum => ethereum/src/test}/chain_monitor.ts | 0 yarn-project/ethereum/src/test/index.ts | 1 + yarn-project/ethereum/src/test/upgrade_utils.ts | 2 +- yarn-project/ethereum/src/utils.ts | 2 +- 28 files changed, 48 insertions(+), 43 deletions(-) rename yarn-project/{aztec.js/src/api/ethereum => ethereum/src/test}/chain_monitor.ts (100%) diff --git a/yarn-project/aztec.js/src/api/ethereum/anvil_test_watcher.ts b/yarn-project/aztec.js/src/api/ethereum/anvil_test_watcher.ts index 5b06b45c1cff..35fbbd7d3291 100644 --- a/yarn-project/aztec.js/src/api/ethereum/anvil_test_watcher.ts +++ b/yarn-project/aztec.js/src/api/ethereum/anvil_test_watcher.ts @@ -4,7 +4,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { RunningPromise } from '@aztec/foundation/running-promise'; import type { TestDateProvider } from '@aztec/foundation/timer'; -import { RollupAbi } from '@aztec/l1-artifacts'; +import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi'; import { type GetContractReturnType, getAddress, getContract } from 'viem'; diff --git a/yarn-project/aztec.js/src/api/ethereum/cheat_codes.ts b/yarn-project/aztec.js/src/api/ethereum/cheat_codes.ts index ce646c4a6de8..2b5be7c29396 100644 --- a/yarn-project/aztec.js/src/api/ethereum/cheat_codes.ts +++ b/yarn-project/aztec.js/src/api/ethereum/cheat_codes.ts @@ -3,7 +3,7 @@ import { EthCheatCodes } from '@aztec/ethereum/eth-cheatcodes'; import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses'; import { EthAddress } from '@aztec/foundation/eth-address'; import { createLogger } from '@aztec/foundation/log'; -import { RollupAbi } from '@aztec/l1-artifacts'; +import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi'; import { type GetContractReturnType, type Hex, createPublicClient, fallback, getContract, http, keccak256 } from 'viem'; import { foundry } from 'viem/chains'; diff --git a/yarn-project/aztec.js/src/api/ethereum/index.ts b/yarn-project/aztec.js/src/api/ethereum/index.ts index f99e90e89197..0bc7b775c243 100644 --- a/yarn-project/aztec.js/src/api/ethereum/index.ts +++ b/yarn-project/aztec.js/src/api/ethereum/index.ts @@ -10,10 +10,4 @@ export { } from './portal_manager.js'; export { getL1ContractAddresses } from './l1_contracts.js'; export { RollupCheatCodes, EthCheatCodes } from './cheat_codes.js'; -export { ChainMonitor } from './chain_monitor.js'; export { AnvilTestWatcher } from './anvil_test_watcher.js'; -export { - deployL1Contract, - deployL1Contracts, - type DeployL1ContractsReturnType, -} from '@aztec/ethereum/deploy-l1-contracts'; diff --git a/yarn-project/aztec.js/src/api/ethereum/portal_manager.ts b/yarn-project/aztec.js/src/api/ethereum/portal_manager.ts index 368c7411165e..37ce8c50428a 100644 --- a/yarn-project/aztec.js/src/api/ethereum/portal_manager.ts +++ b/yarn-project/aztec.js/src/api/ethereum/portal_manager.ts @@ -5,7 +5,10 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import type { Logger } from '@aztec/foundation/log'; import type { SiblingPath } from '@aztec/foundation/trees'; -import { FeeJuicePortalAbi, OutboxAbi, TestERC20Abi, TokenPortalAbi } from '@aztec/l1-artifacts'; +import { FeeJuicePortalAbi } from '@aztec/l1-artifacts/FeeJuicePortalAbi'; +import { OutboxAbi } from '@aztec/l1-artifacts/OutboxAbi'; +import { TestERC20Abi } from '@aztec/l1-artifacts/TestERC20Abi'; +import { TokenPortalAbi } from '@aztec/l1-artifacts/TokenPortalAbi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { computeSecretHash } from '@aztec/stdlib/hash'; import type { PXE } from '@aztec/stdlib/interfaces/client'; diff --git a/yarn-project/end-to-end/src/composed/integration_proof_verification.test.ts b/yarn-project/end-to-end/src/composed/integration_proof_verification.test.ts index 0459b9a660bf..dd686e466254 100644 --- a/yarn-project/end-to-end/src/composed/integration_proof_verification.test.ts +++ b/yarn-project/end-to-end/src/composed/integration_proof_verification.test.ts @@ -1,6 +1,6 @@ -import { deployL1Contract, fileURLToPath } from '@aztec/aztec.js'; +import { fileURLToPath } from '@aztec/aztec.js'; import { BBCircuitVerifier } from '@aztec/bb-prover'; -import { type ViemPublicClient, type ViemWalletClient, createL1Clients } from '@aztec/ethereum'; +import { type ViemPublicClient, type ViemWalletClient, createL1Clients, deployL1Contract } from '@aztec/ethereum'; import type { Logger } from '@aztec/foundation/log'; import { HonkVerifierAbi, HonkVerifierBytecode, IVerifierAbi } from '@aztec/l1-artifacts'; import { Proof } from '@aztec/stdlib/proofs'; diff --git a/yarn-project/end-to-end/src/e2e_epochs/epochs_empty_blocks.test.ts b/yarn-project/end-to-end/src/e2e_epochs/epochs_empty_blocks.test.ts index d9ff11859110..bf62fd820fc6 100644 --- a/yarn-project/end-to-end/src/e2e_epochs/epochs_empty_blocks.test.ts +++ b/yarn-project/end-to-end/src/e2e_epochs/epochs_empty_blocks.test.ts @@ -1,7 +1,7 @@ import { type Logger, sleep } from '@aztec/aztec.js'; -import { ChainMonitor } from '@aztec/aztec.js/ethereum'; // eslint-disable-next-line no-restricted-imports import { RollupContract } from '@aztec/ethereum/contracts'; +import { ChainMonitor } from '@aztec/ethereum/test'; import { jest } from '@jest/globals'; diff --git a/yarn-project/end-to-end/src/e2e_epochs/epochs_proof_fails.test.ts b/yarn-project/end-to-end/src/e2e_epochs/epochs_proof_fails.test.ts index a6ed4aa86543..9b407aee9cc2 100644 --- a/yarn-project/end-to-end/src/e2e_epochs/epochs_proof_fails.test.ts +++ b/yarn-project/end-to-end/src/e2e_epochs/epochs_proof_fails.test.ts @@ -1,6 +1,6 @@ import { type Logger, getTimestampRangeForEpoch, sleep } from '@aztec/aztec.js'; -import { ChainMonitor } from '@aztec/aztec.js/ethereum'; import { RollupContract } from '@aztec/ethereum/contracts'; +import { ChainMonitor } from '@aztec/ethereum/test'; import { type Delayer, waitUntilL1Timestamp } from '@aztec/ethereum/test'; import { promiseWithResolvers } from '@aztec/foundation/promise'; import type { TestProverNode } from '@aztec/prover-node/test'; diff --git a/yarn-project/end-to-end/src/e2e_epochs/epochs_test.ts b/yarn-project/end-to-end/src/e2e_epochs/epochs_test.ts index 94ac185c9774..de75e0c097f1 100644 --- a/yarn-project/end-to-end/src/e2e_epochs/epochs_test.ts +++ b/yarn-project/end-to-end/src/e2e_epochs/epochs_test.ts @@ -1,7 +1,7 @@ import { AztecNodeService } from '@aztec/aztec-node'; import { Fr, type Logger, getTimestampRangeForEpoch, retryUntil, sleep } from '@aztec/aztec.js'; -import { ChainMonitor } from '@aztec/aztec.js/ethereum'; import { RollupContract } from '@aztec/ethereum/contracts'; +import { ChainMonitor } from '@aztec/ethereum/test'; import { DelayedTxUtils, type Delayer, waitUntilL1Timestamp } from '@aztec/ethereum/test'; import { randomBytes } from '@aztec/foundation/crypto'; import { withLogNameSuffix } from '@aztec/foundation/log'; diff --git a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts index e5a4880f3bab..16c54e865c12 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts @@ -3,7 +3,6 @@ import { type AccountWallet, type AztecAddress, type AztecNode, - ChainMonitor, CheatCodes, type Logger, type PXE, @@ -12,6 +11,7 @@ import { } from '@aztec/aztec.js'; import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants'; import { type DeployL1ContractsArgs, RollupContract, createL1Clients } from '@aztec/ethereum'; +import { ChainMonitor } from '@aztec/ethereum/test'; import { EthAddress } from '@aztec/foundation/eth-address'; import { RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts'; import { AppSubscriptionContract } from '@aztec/noir-contracts.js/AppSubscription'; diff --git a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts index 9c5fdffbc31b..03149b538162 100644 --- a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts @@ -1,10 +1,5 @@ -import { - type AccountWallet, - type CheatCodes, - type DeployL1ContractsReturnType, - Fr, - type Logger, -} from '@aztec/aztec.js'; +import { type AccountWallet, type CheatCodes, Fr, type Logger } from '@aztec/aztec.js'; +import type { DeployL1ContractsReturnType } from '@aztec/ethereum'; import type { TestDateProvider } from '@aztec/foundation/timer'; import { RollupAbi } from '@aztec/l1-artifacts'; import { LendingContract } from '@aztec/noir-contracts.js/Lending'; diff --git a/yarn-project/end-to-end/src/e2e_outbox.test.ts b/yarn-project/end-to-end/src/e2e_outbox.test.ts index e08004df4765..780a479b465a 100644 --- a/yarn-project/end-to-end/src/e2e_outbox.test.ts +++ b/yarn-project/end-to-end/src/e2e_outbox.test.ts @@ -3,11 +3,11 @@ import { type AztecNode, BatchCall, type CheatCodes, - type DeployL1ContractsReturnType, EthAddress, Fr, type SiblingPath, } from '@aztec/aztec.js'; +import type { DeployL1ContractsReturnType } from '@aztec/ethereum'; import { sha256ToField } from '@aztec/foundation/crypto'; import { truncateAndPad } from '@aztec/foundation/serialize'; import { OutboxAbi } from '@aztec/l1-artifacts'; diff --git a/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts b/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts index 0b1c7579f13f..c8b9cd9aa296 100644 --- a/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts +++ b/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts @@ -2,9 +2,9 @@ import { getSchnorrWalletWithSecretKey } from '@aztec/accounts/schnorr'; import type { InitialAccountData } from '@aztec/accounts/testing'; import type { AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node'; import type { AccountWalletWithSecretKey } from '@aztec/aztec.js'; -import { ChainMonitor } from '@aztec/aztec.js/ethereum'; import { RollupContract, getExpectedAddress, getL1ContractsConfigEnvVars } from '@aztec/ethereum'; import { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs'; +import { ChainMonitor } from '@aztec/ethereum/test'; import { EthCheatCodesWithState } from '@aztec/ethereum/test'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { ForwarderAbi, ForwarderBytecode, RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts'; diff --git a/yarn-project/end-to-end/src/e2e_p2p/upgrade_governance_proposer.test.ts b/yarn-project/end-to-end/src/e2e_p2p/upgrade_governance_proposer.test.ts index 922c37bb807a..0a53dd1fa529 100644 --- a/yarn-project/end-to-end/src/e2e_p2p/upgrade_governance_proposer.test.ts +++ b/yarn-project/end-to-end/src/e2e_p2p/upgrade_governance_proposer.test.ts @@ -1,5 +1,6 @@ import type { AztecNodeService } from '@aztec/aztec-node'; -import { deployL1Contract, sleep } from '@aztec/aztec.js'; +import { sleep } from '@aztec/aztec.js'; +import { deployL1Contract } from '@aztec/ethereum'; import { TestERC20Abi as FeeJuiceAbi, GovernanceAbi, diff --git a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts index 2dd3dcaf6e5a..f6167e7a9739 100644 --- a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts @@ -10,16 +10,15 @@ import { type AztecNode, type CheatCodes, type CompleteAddress, - type DeployL1ContractsReturnType, EthAddress, type Logger, type PXE, createLogger, - deployL1Contract, } from '@aztec/aztec.js'; import { BBCircuitVerifier, type ClientProtocolCircuitVerifier, TestCircuitVerifier } from '@aztec/bb-prover'; import { createBlobSinkClient } from '@aztec/blob-sink/client'; import type { BlobSinkServer } from '@aztec/blob-sink/server'; +import { type DeployL1ContractsReturnType, deployL1Contract } from '@aztec/ethereum'; import { Buffer32 } from '@aztec/foundation/buffer'; import { HonkVerifierAbi, HonkVerifierBytecode, RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; diff --git a/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts b/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts index e4489960ca48..dcf716d6fccd 100644 --- a/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts +++ b/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts @@ -1,5 +1,5 @@ -import { type Logger, deployL1Contracts } from '@aztec/aztec.js'; -import type { DeployL1ContractsArgs, L1ContractsConfig } from '@aztec/ethereum'; +import { type Logger } from '@aztec/aztec.js'; +import { type DeployL1ContractsArgs, type L1ContractsConfig, deployL1Contracts } from '@aztec/ethereum'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts'; diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index d9ea3e2b42a2..b6131344cbe9 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -9,7 +9,6 @@ import { CheatCodes, type CompleteAddress, type ContractFunctionInteraction, - type DeployL1ContractsReturnType, type FunctionCall, type Logger, type PXE, @@ -18,7 +17,13 @@ import { } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; import { type BlobSinkServer, createBlobSinkServer } from '@aztec/blob-sink/server'; -import { type DeployL1ContractsArgs, createL1Clients, getL1ContractsConfigEnvVars, l1Artifacts } from '@aztec/ethereum'; +import { + type DeployL1ContractsArgs, + type DeployL1ContractsReturnType, + createL1Clients, + getL1ContractsConfigEnvVars, + l1Artifacts, +} from '@aztec/ethereum'; import { EthCheatCodesWithState, startAnvil } from '@aztec/ethereum/test'; import { asyncMap } from '@aztec/foundation/async-map'; import { randomBytes } from '@aztec/foundation/crypto'; diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 18edbcce1aac..abec582e2f09 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -16,7 +16,6 @@ import { BatchCall, CheatCodes, type ContractMethod, - type DeployL1ContractsReturnType, FeeJuicePaymentMethod, type Logger, type PXE, @@ -25,7 +24,6 @@ import { createAztecNodeClient, createLogger, createPXEClient, - deployL1Contracts, makeFetch, waitForPXE, } from '@aztec/aztec.js'; @@ -36,9 +34,11 @@ import { type BlobSinkServer, createBlobSinkServer } from '@aztec/blob-sink/serv import { FEE_JUICE_INITIAL_MINT, GENESIS_ARCHIVE_ROOT, GENESIS_BLOCK_HASH } from '@aztec/constants'; import { type DeployL1ContractsArgs, + type DeployL1ContractsReturnType, ForwarderContract, NULL_KEY, createL1Clients, + deployL1Contracts, getL1ContractsConfigEnvVars, isAnvilTestChain, l1Artifacts, diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index e6cb8c017e86..d21b28d1efca 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -15,10 +15,14 @@ import { type SiblingPath, type TxReceipt, type Wallet, - deployL1Contract, retryUntil, } from '@aztec/aztec.js'; -import type { L1ContractAddresses, ViemPublicClient, ViemWalletClient } from '@aztec/ethereum'; +import { + type L1ContractAddresses, + type ViemPublicClient, + type ViemWalletClient, + deployL1Contract, +} from '@aztec/ethereum'; import { TestERC20Abi, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge'; diff --git a/yarn-project/ethereum/src/contracts/fee_juice.ts b/yarn-project/ethereum/src/contracts/fee_juice.ts index 388adb66278b..da6820f2883a 100644 --- a/yarn-project/ethereum/src/contracts/fee_juice.ts +++ b/yarn-project/ethereum/src/contracts/fee_juice.ts @@ -1,5 +1,5 @@ import { EthAddress } from '@aztec/foundation/eth-address'; -import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts'; +import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts/TestERC20Abi'; import { type GetContractReturnType, type Hex, getContract } from 'viem'; diff --git a/yarn-project/ethereum/src/contracts/forwarder.ts b/yarn-project/ethereum/src/contracts/forwarder.ts index ff7e300e5520..f988a0e7147c 100644 --- a/yarn-project/ethereum/src/contracts/forwarder.ts +++ b/yarn-project/ethereum/src/contracts/forwarder.ts @@ -1,6 +1,7 @@ import { toHex } from '@aztec/foundation/bigint-buffer'; import type { Logger } from '@aztec/foundation/log'; -import { ForwarderAbi, ForwarderBytecode } from '@aztec/l1-artifacts'; +import { ForwarderAbi } from '@aztec/l1-artifacts/ForwarderAbi'; +import { ForwarderBytecode } from '@aztec/l1-artifacts/ForwarderBytecode'; import { type EncodeFunctionDataParameters, diff --git a/yarn-project/ethereum/src/contracts/governance.ts b/yarn-project/ethereum/src/contracts/governance.ts index 2f4d3789aaf9..09d079b6dd4d 100644 --- a/yarn-project/ethereum/src/contracts/governance.ts +++ b/yarn-project/ethereum/src/contracts/governance.ts @@ -1,7 +1,7 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import type { Logger } from '@aztec/foundation/log'; import { sleep } from '@aztec/foundation/sleep'; -import { GovernanceAbi } from '@aztec/l1-artifacts'; +import { GovernanceAbi } from '@aztec/l1-artifacts/GovernanceAbi'; import { type EncodeFunctionDataParameters, diff --git a/yarn-project/ethereum/src/contracts/governance_proposer.ts b/yarn-project/ethereum/src/contracts/governance_proposer.ts index 83d7578365c0..75985931815f 100644 --- a/yarn-project/ethereum/src/contracts/governance_proposer.ts +++ b/yarn-project/ethereum/src/contracts/governance_proposer.ts @@ -1,6 +1,6 @@ import { memoize } from '@aztec/foundation/decorators'; import { EthAddress } from '@aztec/foundation/eth-address'; -import { GovernanceProposerAbi } from '@aztec/l1-artifacts'; +import { GovernanceProposerAbi } from '@aztec/l1-artifacts/GovernanceProposerAbi'; import { type GetContractReturnType, type Hex, type TransactionReceipt, encodeFunctionData, getContract } from 'viem'; diff --git a/yarn-project/ethereum/src/contracts/rollup.ts b/yarn-project/ethereum/src/contracts/rollup.ts index 8c33ca146d41..be5062bf7080 100644 --- a/yarn-project/ethereum/src/contracts/rollup.ts +++ b/yarn-project/ethereum/src/contracts/rollup.ts @@ -1,7 +1,9 @@ import { memoize } from '@aztec/foundation/decorators'; import { EthAddress } from '@aztec/foundation/eth-address'; import type { ViemSignature } from '@aztec/foundation/eth-signature'; -import { RollupAbi, RollupStorage, SlasherAbi } from '@aztec/l1-artifacts'; +import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi'; +import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage'; +import { SlasherAbi } from '@aztec/l1-artifacts/SlasherAbi'; import { type Account, type GetContractReturnType, type Hex, getAddress, getContract } from 'viem'; diff --git a/yarn-project/ethereum/src/contracts/slashing_proposer.ts b/yarn-project/ethereum/src/contracts/slashing_proposer.ts index 47d36efd84aa..fcef89a031a3 100644 --- a/yarn-project/ethereum/src/contracts/slashing_proposer.ts +++ b/yarn-project/ethereum/src/contracts/slashing_proposer.ts @@ -1,5 +1,5 @@ import { EthAddress } from '@aztec/foundation/eth-address'; -import { SlashingProposerAbi } from '@aztec/l1-artifacts'; +import { SlashingProposerAbi } from '@aztec/l1-artifacts/SlashingProposerAbi'; import { type GetContractReturnType, type Hex, getContract } from 'viem'; diff --git a/yarn-project/aztec.js/src/api/ethereum/chain_monitor.ts b/yarn-project/ethereum/src/test/chain_monitor.ts similarity index 100% rename from yarn-project/aztec.js/src/api/ethereum/chain_monitor.ts rename to yarn-project/ethereum/src/test/chain_monitor.ts diff --git a/yarn-project/ethereum/src/test/index.ts b/yarn-project/ethereum/src/test/index.ts index 345924d3695c..6b6e5807b512 100644 --- a/yarn-project/ethereum/src/test/index.ts +++ b/yarn-project/ethereum/src/test/index.ts @@ -3,3 +3,4 @@ export * from './eth_cheat_codes_with_state.js'; export * from './start_anvil.js'; export * from './tx_delayer.js'; export * from './upgrade_utils.js'; +export * from './chain_monitor.js'; diff --git a/yarn-project/ethereum/src/test/upgrade_utils.ts b/yarn-project/ethereum/src/test/upgrade_utils.ts index 652fd5bf00c4..3d84ed28afc2 100644 --- a/yarn-project/ethereum/src/test/upgrade_utils.ts +++ b/yarn-project/ethereum/src/test/upgrade_utils.ts @@ -1,6 +1,6 @@ import type { Logger } from '@aztec/foundation/log'; -import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts'; import { GovernanceAbi } from '@aztec/l1-artifacts/GovernanceAbi'; +import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts/TestERC20Abi'; import { type GetContractReturnType, type PrivateKeyAccount, getContract } from 'viem'; diff --git a/yarn-project/ethereum/src/utils.ts b/yarn-project/ethereum/src/utils.ts index 5f028d65ce1a..243f41ae9825 100644 --- a/yarn-project/ethereum/src/utils.ts +++ b/yarn-project/ethereum/src/utils.ts @@ -1,6 +1,6 @@ import type { Fr } from '@aztec/foundation/fields'; import type { Logger } from '@aztec/foundation/log'; -import { ErrorsAbi } from '@aztec/l1-artifacts'; +import { ErrorsAbi } from '@aztec/l1-artifacts/ErrorsAbi'; import { type Abi, From e1601722d24cdf215ce2309154de520cbd23a00a Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 7 Mar 2025 08:33:22 +0000 Subject: [PATCH 02/48] more refactoring --- yarn-project/aztec.js/package.json | 5 +++-- yarn-project/aztec.js/src/account/wallet.ts | 2 +- .../aztec.js/src/account_manager/deploy_account_method.ts | 4 ++-- .../src/account_manager/deploy_account_sent_tx.ts | 2 +- yarn-project/aztec.js/src/account_manager/index.ts | 6 +++--- .../src/{ => api}/contract/base_contract_interaction.ts | 8 ++++---- .../aztec.js/src/{ => api}/contract/batch_call.ts | 2 +- .../aztec.js/src/{ => api}/contract/checker.test.ts | 0 yarn-project/aztec.js/src/{ => api}/contract/checker.ts | 0 .../aztec.js/src/{ => api}/contract/contract.test.ts | 2 +- yarn-project/aztec.js/src/{ => api}/contract/contract.ts | 2 +- .../aztec.js/src/{ => api}/contract/contract_base.ts | 2 +- .../{ => api}/contract/contract_function_interaction.ts | 4 ++-- .../aztec.js/src/{ => api}/contract/deploy_method.ts | 8 ++++---- .../aztec.js/src/{ => api}/contract/deploy_proven_tx.ts | 2 +- .../aztec.js/src/{ => api}/contract/deploy_sent_tx.ts | 2 +- .../src/{ => api}/contract/get_gas_limits.test.ts | 0 .../aztec.js/src/{ => api}/contract/get_gas_limits.ts | 0 yarn-project/aztec.js/src/{ => api}/contract/index.ts | 0 .../aztec.js/src/{ => api}/contract/protocol_contracts.ts | 2 +- yarn-project/aztec.js/src/{ => api}/contract/proven_tx.ts | 2 +- .../aztec.js/src/{ => api}/contract/sent_tx.test.ts | 0 yarn-project/aztec.js/src/{ => api}/contract/sent_tx.ts | 0 .../aztec.js/src/{ => api}/contract/unsafe_contract.ts | 2 +- yarn-project/aztec.js/src/api/ethereum/index.ts | 2 -- .../src/api/{ethereum => test}/anvil_test_watcher.ts | 2 +- .../aztec_cheatcodes.ts => api/test/aztec_cheat_codes.ts} | 0 yarn-project/aztec.js/src/api/{ => test}/cheat_codes.ts | 4 ++-- yarn-project/aztec.js/src/api/test/index.ts | 5 +++++ .../cheat_codes.ts => test/rollup_cheat_codes.ts} | 2 -- yarn-project/aztec.js/src/{ => api}/utils/abi_types.ts | 0 yarn-project/aztec.js/src/{ => api}/utils/authwit.ts | 0 yarn-project/aztec.js/src/{ => api}/utils/fee_juice.ts | 2 +- .../src/{ => api}/utils/field_compressed_string.ts | 0 yarn-project/aztec.js/src/{ => api}/utils/index.ts | 0 yarn-project/aztec.js/src/{ => api}/utils/node.ts | 0 yarn-project/aztec.js/src/{ => api}/utils/pub_key.ts | 0 yarn-project/aztec.js/src/{ => api}/utils/pxe.ts | 0 .../aztec.js/src/deployment/broadcast_function.ts | 4 ++-- yarn-project/aztec.js/src/deployment/contract_deployer.ts | 4 ++-- yarn-project/aztec.js/src/deployment/deploy_instance.ts | 4 ++-- yarn-project/aztec.js/src/deployment/register_class.ts | 4 ++-- .../src/fee/fee_juice_payment_method_with_claim.ts | 2 +- .../aztec.js/src/fee/private_fee_payment_method.ts | 2 +- .../aztec.js/src/fee/public_fee_payment_method.ts | 2 +- yarn-project/aztec.js/src/index.ts | 6 ++---- yarn-project/aztec.js/src/wallet/account_wallet.ts | 6 +++--- yarn-project/aztec.js/src/wallet/base_wallet.ts | 2 +- yarn-project/aztec.js/src/wallet/signerless_wallet.ts | 2 +- yarn-project/aztec/src/sandbox/sandbox.ts | 3 ++- yarn-project/cli/src/cmds/l1/advance_epoch.ts | 3 ++- yarn-project/cli/src/cmds/l1/assume_proven_through.ts | 3 ++- yarn-project/end-to-end/src/e2e_block_building.test.ts | 3 +-- yarn-project/end-to-end/src/e2e_cheat_codes.test.ts | 3 ++- .../cross_chain_messaging_test.ts | 2 +- .../token_bridge_private.test.ts | 3 ++- .../end-to-end/src/e2e_crowdfunding_and_claim.test.ts | 2 +- yarn-project/end-to-end/src/e2e_fees/fee_settings.test.ts | 2 +- yarn-project/end-to-end/src/e2e_fees/fees_test.ts | 2 +- yarn-project/end-to-end/src/e2e_lending_contract.test.ts | 3 ++- yarn-project/end-to-end/src/e2e_outbox.test.ts | 2 +- yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts | 3 +-- yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts | 2 +- yarn-project/end-to-end/src/e2e_pruned_blocks.test.ts | 2 +- .../end-to-end/src/e2e_sequencer/gov_proposal.test.ts | 3 ++- yarn-project/end-to-end/src/e2e_synching.test.ts | 2 +- .../end-to-end/src/fixtures/setup_l1_contracts.ts | 2 +- yarn-project/end-to-end/src/fixtures/snapshot_manager.ts | 3 +-- yarn-project/end-to-end/src/fixtures/utils.ts | 3 +-- yarn-project/end-to-end/src/guides/dapp_testing.test.ts | 3 ++- yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts | 2 +- .../end-to-end/src/simulators/lending_simulator.ts | 3 ++- yarn-project/end-to-end/src/spartan/4epochs.test.ts | 2 +- .../end-to-end/src/spartan/gating-passive.test.ts | 2 +- yarn-project/end-to-end/src/spartan/reorg.test.ts | 2 +- yarn-project/end-to-end/src/spartan/utils.ts | 2 +- 76 files changed, 92 insertions(+), 87 deletions(-) rename yarn-project/aztec.js/src/{ => api}/contract/base_contract_interaction.ts (96%) rename yarn-project/aztec.js/src/{ => api}/contract/batch_call.ts (98%) rename yarn-project/aztec.js/src/{ => api}/contract/checker.test.ts (100%) rename yarn-project/aztec.js/src/{ => api}/contract/checker.ts (100%) rename yarn-project/aztec.js/src/{ => api}/contract/contract.test.ts (99%) rename yarn-project/aztec.js/src/{ => api}/contract/contract.ts (98%) rename yarn-project/aztec.js/src/{ => api}/contract/contract_base.ts (98%) rename yarn-project/aztec.js/src/{ => api}/contract/contract_function_interaction.ts (98%) rename yarn-project/aztec.js/src/{ => api}/contract/deploy_method.ts (97%) rename yarn-project/aztec.js/src/{ => api}/contract/deploy_proven_tx.ts (95%) rename yarn-project/aztec.js/src/{ => api}/contract/deploy_sent_tx.ts (98%) rename yarn-project/aztec.js/src/{ => api}/contract/get_gas_limits.test.ts (100%) rename yarn-project/aztec.js/src/{ => api}/contract/get_gas_limits.ts (100%) rename yarn-project/aztec.js/src/{ => api}/contract/index.ts (100%) rename yarn-project/aztec.js/src/{ => api}/contract/protocol_contracts.ts (96%) rename yarn-project/aztec.js/src/{ => api}/contract/proven_tx.ts (95%) rename yarn-project/aztec.js/src/{ => api}/contract/sent_tx.test.ts (100%) rename yarn-project/aztec.js/src/{ => api}/contract/sent_tx.ts (100%) rename yarn-project/aztec.js/src/{ => api}/contract/unsafe_contract.ts (92%) rename yarn-project/aztec.js/src/api/{ethereum => test}/anvil_test_watcher.ts (98%) rename yarn-project/aztec.js/src/{utils/aztec_cheatcodes.ts => api/test/aztec_cheat_codes.ts} (100%) rename yarn-project/aztec.js/src/api/{ => test}/cheat_codes.ts (90%) create mode 100644 yarn-project/aztec.js/src/api/test/index.ts rename yarn-project/aztec.js/src/api/{ethereum/cheat_codes.ts => test/rollup_cheat_codes.ts} (99%) rename yarn-project/aztec.js/src/{ => api}/utils/abi_types.ts (100%) rename yarn-project/aztec.js/src/{ => api}/utils/authwit.ts (100%) rename yarn-project/aztec.js/src/{ => api}/utils/fee_juice.ts (90%) rename yarn-project/aztec.js/src/{ => api}/utils/field_compressed_string.ts (100%) rename yarn-project/aztec.js/src/{ => api}/utils/index.ts (100%) rename yarn-project/aztec.js/src/{ => api}/utils/node.ts (100%) rename yarn-project/aztec.js/src/{ => api}/utils/pub_key.ts (100%) rename yarn-project/aztec.js/src/{ => api}/utils/pxe.ts (100%) diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index 89429fc99387..0d044991ecbd 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -10,7 +10,7 @@ "./account": "./dest/api/account.js", "./addresses": "./dest/api/addresses.js", "./cheatcodes": "./dest/api/cheatcodes.js", - "./contracts": "./dest/contract/index.js", + "./contracts": "./dest/api/contract/index.js", "./deployment": "./dest/api/deployment.js", "./entrypoint": "./dest/api/entrypoint.js", "./eth_address": "./dest/api/eth_address.js", @@ -22,7 +22,8 @@ "./rpc": "./dest/rpc_clients/index.js", "./tx_hash": "./dest/api/tx_hash.js", "./wallet": "./dest/api/wallet.js", - "./utils": "./dest/utils/index.js" + "./utils": "./dest/api/utils/index.js", + "./testing": "./dest/api/test/index.js" }, "typedocOptions": { "entryPoints": [ diff --git a/yarn-project/aztec.js/src/account/wallet.ts b/yarn-project/aztec.js/src/account/wallet.ts index baf7f6231962..9624871bf5d6 100644 --- a/yarn-project/aztec.js/src/account/wallet.ts +++ b/yarn-project/aztec.js/src/account/wallet.ts @@ -1,7 +1,7 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { PXE } from '@aztec/stdlib/interfaces/client'; -import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; +import type { IntentAction, IntentInnerHash } from '../api/utils/authwit.js'; import type { AccountInterface } from './interface.js'; /** diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 76fb1701ce31..dbc9e8d77170 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -9,9 +9,9 @@ import type { PublicKeys } from '@aztec/stdlib/keys'; import type { AuthWitnessProvider } from '../account/interface.js'; import type { Wallet } from '../account/wallet.js'; +import { Contract } from '../api/contract/contract.js'; +import { DeployMethod, type DeployOptions } from '../api/contract/deploy_method.js'; import type { ExecutionRequestInit } from '../api/entrypoint.js'; -import { Contract } from '../contract/contract.js'; -import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; import { EntrypointPayload, computeCombinedPayloadHash } from '../entrypoint/payload.js'; /** diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts index 57a23ef929bf..606d89324245 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts @@ -3,7 +3,7 @@ import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { TxHash, TxReceipt } from '@aztec/stdlib/tx'; import type { Wallet } from '../account/index.js'; -import { DefaultWaitOpts, SentTx, type WaitOpts } from '../contract/sent_tx.js'; +import { DefaultWaitOpts, SentTx, type WaitOpts } from '../api/contract/sent_tx.js'; /** Extends a transaction receipt with a wallet instance for the newly deployed contract. */ export type DeployAccountTxReceipt = FieldsOf & { diff --git a/yarn-project/aztec.js/src/account_manager/index.ts b/yarn-project/aztec.js/src/account_manager/index.ts index 5f52856fc10f..2c526776c612 100644 --- a/yarn-project/aztec.js/src/account_manager/index.ts +++ b/yarn-project/aztec.js/src/account_manager/index.ts @@ -7,9 +7,9 @@ import { deriveKeys } from '@aztec/stdlib/keys'; import type { AccountContract } from '../account/contract.js'; import type { Salt, Wallet } from '../account/index.js'; import type { AccountInterface } from '../account/interface.js'; -import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; -import { Contract } from '../contract/index.js'; -import { DefaultWaitOpts, type WaitOpts } from '../contract/sent_tx.js'; +import { Contract } from '../api/contract/contract.js'; +import { DeployMethod, type DeployOptions } from '../api/contract/deploy_method.js'; +import { DefaultWaitOpts, type WaitOpts } from '../api/contract/sent_tx.js'; import { DefaultMultiCallEntrypoint } from '../entrypoint/default_multi_call_entrypoint.js'; import { AccountWalletWithSecretKey, SignerlessWallet } from '../wallet/index.js'; import { DeployAccountMethod } from './deploy_account_method.js'; diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/api/contract/base_contract_interaction.ts similarity index 96% rename from yarn-project/aztec.js/src/contract/base_contract_interaction.ts rename to yarn-project/aztec.js/src/api/contract/base_contract_interaction.ts index 1340329666b1..65e76e0055b3 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/api/contract/base_contract_interaction.ts @@ -3,10 +3,10 @@ import { createLogger } from '@aztec/foundation/log'; import { GasSettings } from '@aztec/stdlib/gas'; import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; -import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; -import type { FeeOptions, UserFeeOptions } from '../entrypoint/payload.js'; -import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; +import type { Wallet } from '../../account/wallet.js'; +import type { ExecutionRequestInit } from '../../entrypoint/entrypoint.js'; +import type { FeeOptions, UserFeeOptions } from '../../entrypoint/payload.js'; +import { FeeJuicePaymentMethod } from '../../fee/fee_juice_payment_method.js'; import { getGasLimits } from './get_gas_limits.js'; import { ProvenTx } from './proven_tx.js'; import { SentTx } from './sent_tx.js'; diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/api/contract/batch_call.ts similarity index 98% rename from yarn-project/aztec.js/src/contract/batch_call.ts rename to yarn-project/aztec.js/src/api/contract/batch_call.ts index e432418ab2e9..0e13666e23ce 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/api/contract/batch_call.ts @@ -1,7 +1,7 @@ import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/index.js'; +import type { Wallet } from '../../account/index.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; import type { SimulateMethodOptions } from './contract_function_interaction.js'; diff --git a/yarn-project/aztec.js/src/contract/checker.test.ts b/yarn-project/aztec.js/src/api/contract/checker.test.ts similarity index 100% rename from yarn-project/aztec.js/src/contract/checker.test.ts rename to yarn-project/aztec.js/src/api/contract/checker.test.ts diff --git a/yarn-project/aztec.js/src/contract/checker.ts b/yarn-project/aztec.js/src/api/contract/checker.ts similarity index 100% rename from yarn-project/aztec.js/src/contract/checker.ts rename to yarn-project/aztec.js/src/api/contract/checker.ts diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/api/contract/contract.test.ts similarity index 99% rename from yarn-project/aztec.js/src/contract/contract.test.ts rename to yarn-project/aztec.js/src/api/contract/contract.test.ts index 48d50f2b07f0..9d4c2021c260 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/api/contract/contract.test.ts @@ -13,7 +13,7 @@ import type { Tx, TxExecutionRequest, TxHash, TxProvingResult, TxReceipt, TxSimu import { type MockProxy, mock } from 'jest-mock-extended'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../../account/wallet.js'; import { Contract } from './contract.js'; describe('Contract Class', () => { diff --git a/yarn-project/aztec.js/src/contract/contract.ts b/yarn-project/aztec.js/src/api/contract/contract.ts similarity index 98% rename from yarn-project/aztec.js/src/contract/contract.ts rename to yarn-project/aztec.js/src/api/contract/contract.ts index db1d2175d079..2e2804cb4238 100644 --- a/yarn-project/aztec.js/src/contract/contract.ts +++ b/yarn-project/aztec.js/src/api/contract/contract.ts @@ -3,7 +3,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { getContractClassFromArtifact } from '@aztec/stdlib/contract'; import { PublicKeys } from '@aztec/stdlib/keys'; -import type { Wallet } from '../account/index.js'; +import type { Wallet } from '../../account/index.js'; import { ContractBase } from './contract_base.js'; import { DeployMethod } from './deploy_method.js'; diff --git a/yarn-project/aztec.js/src/contract/contract_base.ts b/yarn-project/aztec.js/src/api/contract/contract_base.ts similarity index 98% rename from yarn-project/aztec.js/src/contract/contract_base.ts rename to yarn-project/aztec.js/src/api/contract/contract_base.ts index bc28318afba7..ba9bea299322 100644 --- a/yarn-project/aztec.js/src/contract/contract_base.ts +++ b/yarn-project/aztec.js/src/api/contract/contract_base.ts @@ -7,7 +7,7 @@ import { } from '@aztec/stdlib/abi'; import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract'; -import type { Wallet } from '../account/index.js'; +import type { Wallet } from '../../account/index.js'; import { ContractFunctionInteraction } from './contract_function_interaction.js'; /** diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/api/contract/contract_function_interaction.ts similarity index 98% rename from yarn-project/aztec.js/src/contract/contract_function_interaction.ts rename to yarn-project/aztec.js/src/api/contract/contract_function_interaction.ts index a3404e20f88b..d449eb9904c9 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/api/contract/contract_function_interaction.ts @@ -10,8 +10,8 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PrivateKernelProverProfileResult } from '@aztec/stdlib/kernel'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; -import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; +import type { Wallet } from '../../account/wallet.js'; +import { FeeJuicePaymentMethod } from '../../fee/fee_juice_payment_method.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; export type { SendMethodOptions }; diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/api/contract/deploy_method.ts similarity index 97% rename from yarn-project/aztec.js/src/contract/deploy_method.ts rename to yarn-project/aztec.js/src/api/contract/deploy_method.ts index 271dfdec819e..b72b36eeb895 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/api/contract/deploy_method.ts @@ -11,10 +11,10 @@ import type { GasSettings } from '@aztec/stdlib/gas'; import type { PublicKeys } from '@aztec/stdlib/keys'; import type { Capsule, TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/index.js'; -import { deployInstance } from '../deployment/deploy_instance.js'; -import { registerContractClass } from '../deployment/register_class.js'; -import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; +import type { Wallet } from '../../account/index.js'; +import { deployInstance } from '../../deployment/deploy_instance.js'; +import { registerContractClass } from '../../deployment/register_class.js'; +import type { ExecutionRequestInit } from '../../entrypoint/entrypoint.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; import type { Contract } from './contract.js'; import type { ContractBase } from './contract_base.js'; diff --git a/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts b/yarn-project/aztec.js/src/api/contract/deploy_proven_tx.ts similarity index 95% rename from yarn-project/aztec.js/src/contract/deploy_proven_tx.ts rename to yarn-project/aztec.js/src/api/contract/deploy_proven_tx.ts index 13d61a308cfa..659ab8cc82b3 100644 --- a/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts +++ b/yarn-project/aztec.js/src/api/contract/deploy_proven_tx.ts @@ -3,7 +3,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { Tx } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/index.js'; +import type { Wallet } from '../../account/index.js'; import type { Contract } from './contract.js'; import { DeploySentTx } from './deploy_sent_tx.js'; import { ProvenTx } from './proven_tx.js'; diff --git a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts b/yarn-project/aztec.js/src/api/contract/deploy_sent_tx.ts similarity index 98% rename from yarn-project/aztec.js/src/contract/deploy_sent_tx.ts rename to yarn-project/aztec.js/src/api/contract/deploy_sent_tx.ts index e5992e06da53..1c092b72bbfc 100644 --- a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/api/contract/deploy_sent_tx.ts @@ -5,7 +5,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client'; import type { TxHash, TxReceipt } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/index.js'; +import type { Wallet } from '../../account/index.js'; import type { Contract } from './contract.js'; import type { ContractBase } from './contract_base.js'; import { SentTx, type WaitOpts } from './sent_tx.js'; diff --git a/yarn-project/aztec.js/src/contract/get_gas_limits.test.ts b/yarn-project/aztec.js/src/api/contract/get_gas_limits.test.ts similarity index 100% rename from yarn-project/aztec.js/src/contract/get_gas_limits.test.ts rename to yarn-project/aztec.js/src/api/contract/get_gas_limits.test.ts diff --git a/yarn-project/aztec.js/src/contract/get_gas_limits.ts b/yarn-project/aztec.js/src/api/contract/get_gas_limits.ts similarity index 100% rename from yarn-project/aztec.js/src/contract/get_gas_limits.ts rename to yarn-project/aztec.js/src/api/contract/get_gas_limits.ts diff --git a/yarn-project/aztec.js/src/contract/index.ts b/yarn-project/aztec.js/src/api/contract/index.ts similarity index 100% rename from yarn-project/aztec.js/src/contract/index.ts rename to yarn-project/aztec.js/src/api/contract/index.ts diff --git a/yarn-project/aztec.js/src/contract/protocol_contracts.ts b/yarn-project/aztec.js/src/api/contract/protocol_contracts.ts similarity index 96% rename from yarn-project/aztec.js/src/contract/protocol_contracts.ts rename to yarn-project/aztec.js/src/api/contract/protocol_contracts.ts index 0166d5e3f3c7..55fbadaf4e44 100644 --- a/yarn-project/aztec.js/src/contract/protocol_contracts.ts +++ b/yarn-project/aztec.js/src/api/contract/protocol_contracts.ts @@ -1,6 +1,6 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import type { Wallet } from '../wallet/index.js'; +import type { Wallet } from '../../wallet/index.js'; import { UnsafeContract } from './unsafe_contract.js'; /** Returns a Contract wrapper for the class registerer. */ diff --git a/yarn-project/aztec.js/src/contract/proven_tx.ts b/yarn-project/aztec.js/src/api/contract/proven_tx.ts similarity index 95% rename from yarn-project/aztec.js/src/contract/proven_tx.ts rename to yarn-project/aztec.js/src/api/contract/proven_tx.ts index cbe0a4c87a69..e6ea78f4f983 100644 --- a/yarn-project/aztec.js/src/contract/proven_tx.ts +++ b/yarn-project/aztec.js/src/api/contract/proven_tx.ts @@ -1,7 +1,7 @@ import type { PXE } from '@aztec/stdlib/interfaces/client'; import { Tx } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/index.js'; +import type { Wallet } from '../../account/index.js'; import { SentTx } from './sent_tx.js'; /** diff --git a/yarn-project/aztec.js/src/contract/sent_tx.test.ts b/yarn-project/aztec.js/src/api/contract/sent_tx.test.ts similarity index 100% rename from yarn-project/aztec.js/src/contract/sent_tx.test.ts rename to yarn-project/aztec.js/src/api/contract/sent_tx.test.ts diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/api/contract/sent_tx.ts similarity index 100% rename from yarn-project/aztec.js/src/contract/sent_tx.ts rename to yarn-project/aztec.js/src/api/contract/sent_tx.ts diff --git a/yarn-project/aztec.js/src/contract/unsafe_contract.ts b/yarn-project/aztec.js/src/api/contract/unsafe_contract.ts similarity index 92% rename from yarn-project/aztec.js/src/contract/unsafe_contract.ts rename to yarn-project/aztec.js/src/api/contract/unsafe_contract.ts index f45b7eb9ba30..7194a9544f73 100644 --- a/yarn-project/aztec.js/src/contract/unsafe_contract.ts +++ b/yarn-project/aztec.js/src/api/contract/unsafe_contract.ts @@ -1,7 +1,7 @@ import type { ContractArtifact } from '@aztec/stdlib/abi'; import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; -import type { Wallet } from '../wallet/index.js'; +import type { Wallet } from '../../wallet/index.js'; import { ContractBase } from './contract_base.js'; /** Unsafe constructor for ContractBase that bypasses the check that the instance is registered in the wallet. */ diff --git a/yarn-project/aztec.js/src/api/ethereum/index.ts b/yarn-project/aztec.js/src/api/ethereum/index.ts index 0bc7b775c243..20790abb1685 100644 --- a/yarn-project/aztec.js/src/api/ethereum/index.ts +++ b/yarn-project/aztec.js/src/api/ethereum/index.ts @@ -9,5 +9,3 @@ export { generateClaimSecret, } from './portal_manager.js'; export { getL1ContractAddresses } from './l1_contracts.js'; -export { RollupCheatCodes, EthCheatCodes } from './cheat_codes.js'; -export { AnvilTestWatcher } from './anvil_test_watcher.js'; diff --git a/yarn-project/aztec.js/src/api/ethereum/anvil_test_watcher.ts b/yarn-project/aztec.js/src/api/test/anvil_test_watcher.ts similarity index 98% rename from yarn-project/aztec.js/src/api/ethereum/anvil_test_watcher.ts rename to yarn-project/aztec.js/src/api/test/anvil_test_watcher.ts index 35fbbd7d3291..f4f7aa4b3fb1 100644 --- a/yarn-project/aztec.js/src/api/ethereum/anvil_test_watcher.ts +++ b/yarn-project/aztec.js/src/api/test/anvil_test_watcher.ts @@ -8,7 +8,7 @@ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi'; import { type GetContractReturnType, getAddress, getContract } from 'viem'; -import { RollupCheatCodes } from './cheat_codes.js'; +import { RollupCheatCodes } from './rollup_cheat_codes.js'; /** * Represents a watcher for a rollup contract. diff --git a/yarn-project/aztec.js/src/utils/aztec_cheatcodes.ts b/yarn-project/aztec.js/src/api/test/aztec_cheat_codes.ts similarity index 100% rename from yarn-project/aztec.js/src/utils/aztec_cheatcodes.ts rename to yarn-project/aztec.js/src/api/test/aztec_cheat_codes.ts diff --git a/yarn-project/aztec.js/src/api/cheat_codes.ts b/yarn-project/aztec.js/src/api/test/cheat_codes.ts similarity index 90% rename from yarn-project/aztec.js/src/api/cheat_codes.ts rename to yarn-project/aztec.js/src/api/test/cheat_codes.ts index eecb51dfba42..e4068d1a79e0 100644 --- a/yarn-project/aztec.js/src/api/cheat_codes.ts +++ b/yarn-project/aztec.js/src/api/test/cheat_codes.ts @@ -2,8 +2,8 @@ import { EthCheatCodes } from '@aztec/ethereum/eth-cheatcodes'; import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses'; import type { PXE } from '@aztec/stdlib/interfaces/client'; -import { AztecCheatCodes } from '../utils/aztec_cheatcodes.js'; -import { RollupCheatCodes } from './ethereum/cheat_codes.js'; +import { AztecCheatCodes } from './aztec_cheat_codes.js'; +import { RollupCheatCodes } from './rollup_cheat_codes.js'; /** * A class that provides utility functions for interacting with the chain. diff --git a/yarn-project/aztec.js/src/api/test/index.ts b/yarn-project/aztec.js/src/api/test/index.ts new file mode 100644 index 000000000000..1b4028228fd1 --- /dev/null +++ b/yarn-project/aztec.js/src/api/test/index.ts @@ -0,0 +1,5 @@ +export { AnvilTestWatcher } from './anvil_test_watcher.js'; +export { RollupCheatCodes } from './rollup_cheat_codes.js'; +export { AztecCheatCodes } from './aztec_cheat_codes.js'; +export { EthCheatCodes } from '@aztec/ethereum/eth-cheatcodes'; +export { CheatCodes } from './cheat_codes.js'; diff --git a/yarn-project/aztec.js/src/api/ethereum/cheat_codes.ts b/yarn-project/aztec.js/src/api/test/rollup_cheat_codes.ts similarity index 99% rename from yarn-project/aztec.js/src/api/ethereum/cheat_codes.ts rename to yarn-project/aztec.js/src/api/test/rollup_cheat_codes.ts index 2b5be7c29396..e098165dfd66 100644 --- a/yarn-project/aztec.js/src/api/ethereum/cheat_codes.ts +++ b/yarn-project/aztec.js/src/api/test/rollup_cheat_codes.ts @@ -8,8 +8,6 @@ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi'; import { type GetContractReturnType, type Hex, createPublicClient, fallback, getContract, http, keccak256 } from 'viem'; import { foundry } from 'viem/chains'; -export { EthCheatCodes }; - /** Cheat codes for the L1 rollup contract. */ export class RollupCheatCodes { private client: ViemPublicClient; diff --git a/yarn-project/aztec.js/src/utils/abi_types.ts b/yarn-project/aztec.js/src/api/utils/abi_types.ts similarity index 100% rename from yarn-project/aztec.js/src/utils/abi_types.ts rename to yarn-project/aztec.js/src/api/utils/abi_types.ts diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/api/utils/authwit.ts similarity index 100% rename from yarn-project/aztec.js/src/utils/authwit.ts rename to yarn-project/aztec.js/src/api/utils/authwit.ts diff --git a/yarn-project/aztec.js/src/utils/fee_juice.ts b/yarn-project/aztec.js/src/api/utils/fee_juice.ts similarity index 90% rename from yarn-project/aztec.js/src/utils/fee_juice.ts rename to yarn-project/aztec.js/src/api/utils/fee_juice.ts index e9fd51fb52ab..603beabe822a 100644 --- a/yarn-project/aztec.js/src/utils/fee_juice.ts +++ b/yarn-project/aztec.js/src/api/utils/fee_juice.ts @@ -3,7 +3,7 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { deriveStorageSlotInMap } from '@aztec/stdlib/hash'; -import type { PXE } from '../api/interfaces/pxe.js'; +import type { PXE } from '../../api/interfaces/pxe.js'; /** * Returns the owner's fee juice balance. diff --git a/yarn-project/aztec.js/src/utils/field_compressed_string.ts b/yarn-project/aztec.js/src/api/utils/field_compressed_string.ts similarity index 100% rename from yarn-project/aztec.js/src/utils/field_compressed_string.ts rename to yarn-project/aztec.js/src/api/utils/field_compressed_string.ts diff --git a/yarn-project/aztec.js/src/utils/index.ts b/yarn-project/aztec.js/src/api/utils/index.ts similarity index 100% rename from yarn-project/aztec.js/src/utils/index.ts rename to yarn-project/aztec.js/src/api/utils/index.ts diff --git a/yarn-project/aztec.js/src/utils/node.ts b/yarn-project/aztec.js/src/api/utils/node.ts similarity index 100% rename from yarn-project/aztec.js/src/utils/node.ts rename to yarn-project/aztec.js/src/api/utils/node.ts diff --git a/yarn-project/aztec.js/src/utils/pub_key.ts b/yarn-project/aztec.js/src/api/utils/pub_key.ts similarity index 100% rename from yarn-project/aztec.js/src/utils/pub_key.ts rename to yarn-project/aztec.js/src/api/utils/pub_key.ts diff --git a/yarn-project/aztec.js/src/utils/pxe.ts b/yarn-project/aztec.js/src/api/utils/pxe.ts similarity index 100% rename from yarn-project/aztec.js/src/utils/pxe.ts rename to yarn-project/aztec.js/src/api/utils/pxe.ts diff --git a/yarn-project/aztec.js/src/deployment/broadcast_function.ts b/yarn-project/aztec.js/src/deployment/broadcast_function.ts index 5cf1cdf39b99..ab422e25804c 100644 --- a/yarn-project/aztec.js/src/deployment/broadcast_function.ts +++ b/yarn-project/aztec.js/src/deployment/broadcast_function.ts @@ -15,8 +15,8 @@ import { } from '@aztec/stdlib/contract'; import { Capsule } from '@aztec/stdlib/tx'; -import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; -import { getRegistererContract } from '../contract/protocol_contracts.js'; +import type { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; +import { getRegistererContract } from '../api/contract/protocol_contracts.js'; import type { Wallet } from '../wallet/index.js'; /** diff --git a/yarn-project/aztec.js/src/deployment/contract_deployer.ts b/yarn-project/aztec.js/src/deployment/contract_deployer.ts index 10567f04f0fc..88e1acd9c659 100644 --- a/yarn-project/aztec.js/src/deployment/contract_deployer.ts +++ b/yarn-project/aztec.js/src/deployment/contract_deployer.ts @@ -3,8 +3,8 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { PublicKeys } from '@aztec/stdlib/keys'; import type { Wallet } from '../account/wallet.js'; -import { Contract } from '../contract/contract.js'; -import { DeployMethod } from '../contract/deploy_method.js'; +import { Contract } from '../api/contract/contract.js'; +import { DeployMethod } from '../api/contract/deploy_method.js'; /** * A class for deploying contract. diff --git a/yarn-project/aztec.js/src/deployment/deploy_instance.ts b/yarn-project/aztec.js/src/deployment/deploy_instance.ts index e24fc43dc4b7..5f9d11cf9678 100644 --- a/yarn-project/aztec.js/src/deployment/deploy_instance.ts +++ b/yarn-project/aztec.js/src/deployment/deploy_instance.ts @@ -1,7 +1,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; -import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; -import { getDeployerContract } from '../contract/protocol_contracts.js'; +import type { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; +import { getDeployerContract } from '../api/contract/protocol_contracts.js'; import type { Wallet } from '../wallet/index.js'; /** diff --git a/yarn-project/aztec.js/src/deployment/register_class.ts b/yarn-project/aztec.js/src/deployment/register_class.ts index 4cd770c00a1c..e9a07df25463 100644 --- a/yarn-project/aztec.js/src/deployment/register_class.ts +++ b/yarn-project/aztec.js/src/deployment/register_class.ts @@ -5,8 +5,8 @@ import { type ContractArtifact, bufferAsFields } from '@aztec/stdlib/abi'; import { getContractClassFromArtifact } from '@aztec/stdlib/contract'; import { Capsule } from '@aztec/stdlib/tx'; -import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; -import { getRegistererContract } from '../contract/protocol_contracts.js'; +import type { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; +import { getRegistererContract } from '../api/contract/protocol_contracts.js'; import type { Wallet } from '../wallet/index.js'; const defaultEmitPublicBytecode = diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts index 89eae417ea06..ac3d3a808944 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts @@ -3,8 +3,8 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { FunctionCall } from '@aztec/stdlib/abi'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; +import { getFeeJuice } from '../api/contract/protocol_contracts.js'; import type { L2AmountClaim } from '../api/ethereum/portal_manager.js'; -import { getFeeJuice } from '../contract/protocol_contracts.js'; import type { Wallet } from '../wallet/index.js'; import { FeeJuicePaymentMethod } from './fee_juice_payment_method.js'; diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index a4d0d6752f2b..4d78cd97e91d 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -4,7 +4,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; import type { Wallet } from '../account/wallet.js'; -import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; +import { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; import { SignerlessWallet } from '../wallet/signerless_wallet.js'; import type { FeePaymentMethod } from './fee_payment_method.js'; diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index 8acae43925ac..a900e2b488cf 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -4,7 +4,7 @@ import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; -import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; +import { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; import type { AccountWallet } from '../wallet/account_wallet.js'; import { SignerlessWallet } from '../wallet/signerless_wallet.js'; import type { FeePaymentMethod } from './fee_payment_method.js'; diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index db7b56ea4a15..2774a4238f65 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -97,10 +97,8 @@ export { fileURLToPath } from '@aztec/foundation/url'; export * from './api/abi.js'; export * from './api/account.js'; export * from './api/addresses.js'; -export * from './api/cheat_codes.js'; export * from './api/ethereum/index.js'; export * from './api/fee.js'; export * from './api/log.js'; -// Granular export, even if not in the api folder -export * from './contract/index.js'; -export * from './utils/index.js'; +export * from './api/contract/index.js'; +export * from './api/utils/index.js'; diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 55983f9322ea..307358909379 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -7,14 +7,14 @@ import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; import type { AccountInterface } from '../account/interface.js'; -import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; -import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; +import { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; import { type IntentAction, type IntentInnerHash, computeAuthWitMessageHash, computeInnerAuthWitHashFromAction, -} from '../utils/authwit.js'; +} from '../api/utils/authwit.js'; +import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; import { BaseWallet } from './base_wallet.js'; /** diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index c6ef5b918609..ed9ec93bd99a 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -29,8 +29,8 @@ import type { } from '@aztec/stdlib/tx'; import type { Wallet } from '../account/wallet.js'; +import type { IntentAction, IntentInnerHash } from '../api/utils/authwit.js'; import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; -import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; /** * A base class for Wallet implementations diff --git a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts index 022d2052604f..79bc47716438 100644 --- a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts @@ -4,9 +4,9 @@ import type { CompleteAddress } from '@aztec/stdlib/contract'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; +import type { IntentAction, IntentInnerHash } from '../api/utils/authwit.js'; import { DefaultEntrypoint } from '../entrypoint/default_entrypoint.js'; import type { EntrypointInterface, ExecutionRequestInit } from '../entrypoint/entrypoint.js'; -import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; import { BaseWallet } from './base_wallet.js'; /** diff --git a/yarn-project/aztec/src/sandbox/sandbox.ts b/yarn-project/aztec/src/sandbox/sandbox.ts index b5b4990b2d04..9c7ae1cde522 100644 --- a/yarn-project/aztec/src/sandbox/sandbox.ts +++ b/yarn-project/aztec/src/sandbox/sandbox.ts @@ -2,7 +2,8 @@ import { getSchnorrWallet } from '@aztec/accounts/schnorr'; import { deployFundedSchnorrAccounts, getInitialTestAccounts } from '@aztec/accounts/testing'; import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; -import { AnvilTestWatcher, EthCheatCodes, SignerlessWallet } from '@aztec/aztec.js'; +import { SignerlessWallet } from '@aztec/aztec.js'; +import { AnvilTestWatcher, EthCheatCodes } from '@aztec/aztec.js/testing'; import { type BlobSinkClientInterface, createBlobSinkClient } from '@aztec/blob-sink/client'; import { setupCanonicalL2FeeJuice } from '@aztec/cli/setup-contracts'; import { GENESIS_ARCHIVE_ROOT, GENESIS_BLOCK_HASH } from '@aztec/constants'; diff --git a/yarn-project/cli/src/cmds/l1/advance_epoch.ts b/yarn-project/cli/src/cmds/l1/advance_epoch.ts index 4fc5fbbc9c2f..a4003f922318 100644 --- a/yarn-project/cli/src/cmds/l1/advance_epoch.ts +++ b/yarn-project/cli/src/cmds/l1/advance_epoch.ts @@ -1,4 +1,5 @@ -import { CheatCodes, createPXEClient, makeFetch } from '@aztec/aztec.js'; +import { createPXEClient, makeFetch } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import type { LogFn } from '@aztec/foundation/log'; export async function advanceEpoch(l1RpcUrls: string[], rpcUrl: string, log: LogFn) { diff --git a/yarn-project/cli/src/cmds/l1/assume_proven_through.ts b/yarn-project/cli/src/cmds/l1/assume_proven_through.ts index 6217b05179ab..2d5aa03f664e 100644 --- a/yarn-project/cli/src/cmds/l1/assume_proven_through.ts +++ b/yarn-project/cli/src/cmds/l1/assume_proven_through.ts @@ -1,4 +1,5 @@ -import { EthCheatCodes, RollupCheatCodes, createPXEClient, makeFetch } from '@aztec/aztec.js'; +import { createPXEClient, makeFetch } from '@aztec/aztec.js'; +import { EthCheatCodes, RollupCheatCodes } from '@aztec/aztec.js/testing'; import type { LogFn } from '@aztec/foundation/log'; export async function assumeProvenThrough( diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 2746bc74bd7f..82aa203dcf3b 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -3,10 +3,8 @@ import type { AztecNodeService } from '@aztec/aztec-node'; import { type AccountWallet, AccountWalletWithSecretKey, - AnvilTestWatcher, type AztecAddress, type AztecNode, - type CheatCodes, ContractDeployer, ContractFunctionInteraction, Fr, @@ -20,6 +18,7 @@ import { retryUntil, sleep, } from '@aztec/aztec.js'; +import { AnvilTestWatcher, CheatCodes } from '@aztec/aztec.js/testing'; import { getL1ContractsConfigEnvVars } from '@aztec/ethereum'; import { asyncMap } from '@aztec/foundation/async-map'; import { times, unique } from '@aztec/foundation/collection'; diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index 807d35d7287b..ebdec0d7dabb 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -1,4 +1,5 @@ -import { AnvilTestWatcher, type AztecAddress, type CheatCodes, EthAddress, Fr, type Wallet } from '@aztec/aztec.js'; +import { type AztecAddress, EthAddress, Fr, type Wallet } from '@aztec/aztec.js'; +import { AnvilTestWatcher, CheatCodes } from '@aztec/aztec.js/testing'; import { EthCheatCodes, type ViemPublicClient, type ViemWalletClient, createL1Clients } from '@aztec/ethereum'; import { RollupContract } from '@aztec/ethereum/contracts'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts index ada71b14e577..83952263927a 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts @@ -4,13 +4,13 @@ import { type AccountWallet, AztecAddress, type AztecNode, - CheatCodes, type CompleteAddress, EthAddress, type Logger, type PXE, createLogger, } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { type ViemPublicClient, createL1Clients, deployL1Contract } from '@aztec/ethereum'; import { InboxAbi, OutboxAbi, RollupAbi, TestERC20Abi, TestERC20Bytecode } from '@aztec/l1-artifacts'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts index db03704e637f..6c4158db185b 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts @@ -1,4 +1,5 @@ -import { CheatCodes, Fr } from '@aztec/aztec.js'; +import { Fr } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { RollupAbi } from '@aztec/l1-artifacts'; import { getContract } from 'viem'; diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index 442a4baa0abb..ab46a9f6ae57 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -1,6 +1,5 @@ import { type AccountWallet, - type CheatCodes, Fr, HashedValues, type Logger, @@ -9,6 +8,7 @@ import { type UniqueNote, deriveKeys, } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { ClaimContract } from '@aztec/noir-contracts.js/Claim'; import { CrowdfundingContract } from '@aztec/noir-contracts.js/Crowdfunding'; import { TestContract } from '@aztec/noir-contracts.js/Test'; diff --git a/yarn-project/end-to-end/src/e2e_fees/fee_settings.test.ts b/yarn-project/end-to-end/src/e2e_fees/fee_settings.test.ts index b9c5b6f6a3a1..a3ca4d1407cb 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fee_settings.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fee_settings.test.ts @@ -2,10 +2,10 @@ import { type AccountWallet, type AztecAddress, type AztecNode, - type CheatCodes, FeeJuicePaymentMethod, retryUntil, } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { Fr } from '@aztec/foundation/fields'; import { TestContract } from '@aztec/noir-contracts.js/Test'; import type { GasSettings } from '@aztec/stdlib/gas'; diff --git a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts index 16c54e865c12..e66dab0362f2 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts @@ -3,12 +3,12 @@ import { type AccountWallet, type AztecAddress, type AztecNode, - CheatCodes, type Logger, type PXE, createLogger, sleep, } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants'; import { type DeployL1ContractsArgs, RollupContract, createL1Clients } from '@aztec/ethereum'; import { ChainMonitor } from '@aztec/ethereum/test'; diff --git a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts index 03149b538162..d7740f51b5fa 100644 --- a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts @@ -1,4 +1,5 @@ -import { type AccountWallet, type CheatCodes, Fr, type Logger } from '@aztec/aztec.js'; +import { type AccountWallet, Fr, type Logger } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import type { DeployL1ContractsReturnType } from '@aztec/ethereum'; import type { TestDateProvider } from '@aztec/foundation/timer'; import { RollupAbi } from '@aztec/l1-artifacts'; diff --git a/yarn-project/end-to-end/src/e2e_outbox.test.ts b/yarn-project/end-to-end/src/e2e_outbox.test.ts index 780a479b465a..c68895de639d 100644 --- a/yarn-project/end-to-end/src/e2e_outbox.test.ts +++ b/yarn-project/end-to-end/src/e2e_outbox.test.ts @@ -2,11 +2,11 @@ import { type AccountWalletWithSecretKey, type AztecNode, BatchCall, - type CheatCodes, EthAddress, Fr, type SiblingPath, } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import type { DeployL1ContractsReturnType } from '@aztec/ethereum'; import { sha256ToField } from '@aztec/foundation/crypto'; import { truncateAndPad } from '@aztec/foundation/serialize'; diff --git a/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts b/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts index c8b9cd9aa296..e871b9eba2cc 100644 --- a/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts +++ b/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts @@ -4,8 +4,7 @@ import type { AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node'; import type { AccountWalletWithSecretKey } from '@aztec/aztec.js'; import { RollupContract, getExpectedAddress, getL1ContractsConfigEnvVars } from '@aztec/ethereum'; import { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs'; -import { ChainMonitor } from '@aztec/ethereum/test'; -import { EthCheatCodesWithState } from '@aztec/ethereum/test'; +import { ChainMonitor, EthCheatCodesWithState } from '@aztec/ethereum/test'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { ForwarderAbi, ForwarderBytecode, RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts'; import { SpamContract } from '@aztec/noir-contracts.js/Spam'; diff --git a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts index f6167e7a9739..9bea56c2639a 100644 --- a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts @@ -8,13 +8,13 @@ import { type Archiver, createArchiver } from '@aztec/archiver'; import { type AccountWalletWithSecretKey, type AztecNode, - type CheatCodes, type CompleteAddress, EthAddress, type Logger, type PXE, createLogger, } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { BBCircuitVerifier, type ClientProtocolCircuitVerifier, TestCircuitVerifier } from '@aztec/bb-prover'; import { createBlobSinkClient } from '@aztec/blob-sink/client'; import type { BlobSinkServer } from '@aztec/blob-sink/server'; diff --git a/yarn-project/end-to-end/src/e2e_pruned_blocks.test.ts b/yarn-project/end-to-end/src/e2e_pruned_blocks.test.ts index 66f67cfb19c6..51c174e18512 100644 --- a/yarn-project/end-to-end/src/e2e_pruned_blocks.test.ts +++ b/yarn-project/end-to-end/src/e2e_pruned_blocks.test.ts @@ -2,12 +2,12 @@ import { type AccountWallet, type AztecAddress, type AztecNode, - type CheatCodes, type Logger, MerkleTreeId, type Wallet, retryUntil, } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; import { setup } from './fixtures/utils.js'; diff --git a/yarn-project/end-to-end/src/e2e_sequencer/gov_proposal.test.ts b/yarn-project/end-to-end/src/e2e_sequencer/gov_proposal.test.ts index 5979422dfb4c..5c3e5096fd8c 100644 --- a/yarn-project/end-to-end/src/e2e_sequencer/gov_proposal.test.ts +++ b/yarn-project/end-to-end/src/e2e_sequencer/gov_proposal.test.ts @@ -1,4 +1,5 @@ -import type { AztecNode, CheatCodes, Logger, PXE, Wallet } from '@aztec/aztec.js'; +import type { AztecNode, Logger, PXE, Wallet } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { type DeployL1ContractsReturnType, GovernanceProposerContract, diff --git a/yarn-project/end-to-end/src/e2e_synching.test.ts b/yarn-project/end-to-end/src/e2e_synching.test.ts index 89c4a858e582..4b40f5babdca 100644 --- a/yarn-project/end-to-end/src/e2e_synching.test.ts +++ b/yarn-project/end-to-end/src/e2e_synching.test.ts @@ -37,7 +37,6 @@ import { createArchiver } from '@aztec/archiver'; import { AztecNodeService } from '@aztec/aztec-node'; import { type AccountWalletWithSecretKey, - AnvilTestWatcher, BatchCall, type Contract, Fr, @@ -46,6 +45,7 @@ import { createLogger, sleep, } from '@aztec/aztec.js'; +import { AnvilTestWatcher } from '@aztec/aztec.js/testing'; import { createBlobSinkClient } from '@aztec/blob-sink/client'; import { EpochCache } from '@aztec/epoch-cache'; import { diff --git a/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts b/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts index dcf716d6fccd..a99e00069e95 100644 --- a/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts +++ b/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts @@ -1,4 +1,4 @@ -import { type Logger } from '@aztec/aztec.js'; +import type { Logger } from '@aztec/aztec.js'; import { type DeployL1ContractsArgs, type L1ContractsConfig, deployL1Contracts } from '@aztec/ethereum'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts'; diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index b6131344cbe9..6875c947cec4 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -2,11 +2,9 @@ import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr'; import { type InitialAccountData, deployFundedSchnorrAccounts, generateSchnorrAccounts } from '@aztec/accounts/testing'; import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { - AnvilTestWatcher, type AztecAddress, BatchCall, type Capsule, - CheatCodes, type CompleteAddress, type ContractFunctionInteraction, type FunctionCall, @@ -16,6 +14,7 @@ import { getContractClassFromArtifact, } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; +import { AnvilTestWatcher, CheatCodes } from '@aztec/aztec.js/testing'; import { type BlobSinkServer, createBlobSinkServer } from '@aztec/blob-sink/server'; import { type DeployL1ContractsArgs, diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index abec582e2f09..981037dacbca 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -10,11 +10,9 @@ import { type Archiver, createArchiver } from '@aztec/archiver'; import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { type AccountWalletWithSecretKey, - AnvilTestWatcher, type AztecAddress, type AztecNode, BatchCall, - CheatCodes, type ContractMethod, FeeJuicePaymentMethod, type Logger, @@ -28,6 +26,7 @@ import { waitForPXE, } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; +import { AnvilTestWatcher, CheatCodes } from '@aztec/aztec.js/testing'; import type { BBNativePrivateKernelProver } from '@aztec/bb-prover'; import { createBlobSinkClient } from '@aztec/blob-sink/client'; import { type BlobSinkServer, createBlobSinkServer } from '@aztec/blob-sink/server'; diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index 039fa607b46d..ccf87c7208c7 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -1,6 +1,7 @@ // docs:start:imports import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing'; -import { type AccountWallet, CheatCodes, Fr, type PXE, TxStatus, createPXEClient, waitForPXE } from '@aztec/aztec.js'; +import { type AccountWallet, Fr, type PXE, TxStatus, createPXEClient, waitForPXE } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; // docs:end:imports // docs:start:import_contract import { TestContract } from '@aztec/noir-contracts.js/Test'; diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index e9019a2dedf1..708516525dc2 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -2,7 +2,6 @@ import { type AccountWallet, AztecAddress, type AztecNode, - type CheatCodes, EthAddress, Fr, type Logger, @@ -10,6 +9,7 @@ import { computeAuthWitMessageHash, generateClaimSecret, } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { type DeployL1ContractsReturnType, type ViemPublicClient, diff --git a/yarn-project/end-to-end/src/simulators/lending_simulator.ts b/yarn-project/end-to-end/src/simulators/lending_simulator.ts index c88f16a64b86..9d0723859a73 100644 --- a/yarn-project/end-to-end/src/simulators/lending_simulator.ts +++ b/yarn-project/end-to-end/src/simulators/lending_simulator.ts @@ -1,5 +1,6 @@ // Convenience struct to hold an account's address and secret that can easily be passed around. -import { AztecAddress, type CheatCodes, Fr } from '@aztec/aztec.js'; +import { AztecAddress, Fr } from '@aztec/aztec.js'; +import { CheatCodes } from '@aztec/aztec.js/testing'; import { pedersenHash } from '@aztec/foundation/crypto'; import type { TestDateProvider } from '@aztec/foundation/timer'; import type { RollupAbi } from '@aztec/l1-artifacts'; diff --git a/yarn-project/end-to-end/src/spartan/4epochs.test.ts b/yarn-project/end-to-end/src/spartan/4epochs.test.ts index 8a59b9e36861..557c07d8c880 100644 --- a/yarn-project/end-to-end/src/spartan/4epochs.test.ts +++ b/yarn-project/end-to-end/src/spartan/4epochs.test.ts @@ -1,5 +1,5 @@ import { readFieldCompressedString } from '@aztec/aztec.js'; -import { RollupCheatCodes } from '@aztec/aztec.js/ethereum'; +import { RollupCheatCodes } from '@aztec/aztec.js/testing'; import { getL1ContractsConfigEnvVars } from '@aztec/ethereum'; import { EthCheatCodesWithState } from '@aztec/ethereum/test'; import { createLogger } from '@aztec/foundation/log'; diff --git a/yarn-project/end-to-end/src/spartan/gating-passive.test.ts b/yarn-project/end-to-end/src/spartan/gating-passive.test.ts index d9789d3512e9..1d141f36ab97 100644 --- a/yarn-project/end-to-end/src/spartan/gating-passive.test.ts +++ b/yarn-project/end-to-end/src/spartan/gating-passive.test.ts @@ -1,5 +1,5 @@ import { createCompatibleClient, sleep } from '@aztec/aztec.js'; -import { RollupCheatCodes } from '@aztec/aztec.js/ethereum'; +import { RollupCheatCodes } from '@aztec/aztec.js/testing'; import { EthCheatCodesWithState } from '@aztec/ethereum/test'; import { createLogger } from '@aztec/foundation/log'; diff --git a/yarn-project/end-to-end/src/spartan/reorg.test.ts b/yarn-project/end-to-end/src/spartan/reorg.test.ts index 074f1d8bd68c..0802a875f52c 100644 --- a/yarn-project/end-to-end/src/spartan/reorg.test.ts +++ b/yarn-project/end-to-end/src/spartan/reorg.test.ts @@ -1,5 +1,5 @@ import { sleep } from '@aztec/aztec.js'; -import { RollupCheatCodes } from '@aztec/aztec.js/ethereum'; +import { RollupCheatCodes } from '@aztec/aztec.js/testing'; import { EthCheatCodesWithState } from '@aztec/ethereum/test'; import { createLogger } from '@aztec/foundation/log'; diff --git a/yarn-project/end-to-end/src/spartan/utils.ts b/yarn-project/end-to-end/src/spartan/utils.ts index 021e46ccb89b..cebf8c7e932b 100644 --- a/yarn-project/end-to-end/src/spartan/utils.ts +++ b/yarn-project/end-to-end/src/spartan/utils.ts @@ -1,5 +1,5 @@ import { createAztecNodeClient, createLogger, sleep } from '@aztec/aztec.js'; -import type { RollupCheatCodes } from '@aztec/aztec.js/ethereum'; +import type { RollupCheatCodes } from '@aztec/aztec.js/testing'; import type { Logger } from '@aztec/foundation/log'; import type { SequencerConfig } from '@aztec/sequencer-client'; From 36c3d2e817862a5dc18e096dfd3968153b2936dd Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 7 Mar 2025 09:24:00 +0000 Subject: [PATCH 03/48] reorg aztec.js --- yarn-project/aztec.js/package.json | 12 ++++++------ yarn-project/aztec.js/src/account/wallet.ts | 2 +- .../account_manager/deploy_account_method.ts | 4 ++-- .../account_manager/deploy_account_sent_tx.ts | 2 +- .../aztec.js/src/account_manager/index.ts | 6 +++--- yarn-project/aztec.js/src/api/account.ts | 2 +- .../api/{contract/index.ts => contract.ts} | 19 ++++++++++++------- yarn-project/aztec.js/src/api/deployment.ts | 1 + .../api/{ethereum/index.ts => ethereum.ts} | 4 ++-- .../api/{interfaces/pxe.ts => interfaces.ts} | 0 yarn-project/aztec.js/src/api/rpc.ts | 2 ++ yarn-project/aztec.js/src/api/test/index.ts | 5 ----- yarn-project/aztec.js/src/api/testing.ts | 5 +++++ .../src/api/{utils/index.ts => utils.ts} | 14 +++++++------- .../contract/base_contract_interaction.ts | 8 ++++---- .../src/{api => }/contract/batch_call.ts | 2 +- .../src/{api => }/contract/checker.test.ts | 0 .../src/{api => }/contract/checker.ts | 0 .../src/{api => }/contract/contract.test.ts | 2 +- .../src/{api => }/contract/contract.ts | 2 +- .../src/{api => }/contract/contract_base.ts | 2 +- .../contract/contract_function_interaction.ts | 4 ++-- .../src/{api => }/contract/deploy_method.ts | 8 ++++---- .../{api => }/contract/deploy_proven_tx.ts | 2 +- .../src/{api => }/contract/deploy_sent_tx.ts | 2 +- .../{api => }/contract/get_gas_limits.test.ts | 0 .../src/{api => }/contract/get_gas_limits.ts | 0 .../{api => }/contract/protocol_contracts.ts | 2 +- .../src/{api => }/contract/proven_tx.ts | 2 +- .../src/{api => }/contract/sent_tx.test.ts | 0 .../src/{api => }/contract/sent_tx.ts | 0 .../src/{api => }/contract/unsafe_contract.ts | 2 +- .../src/deployment/broadcast_function.ts | 4 ++-- .../src/deployment/contract_deployer.ts | 4 ++-- .../src/deployment/deploy_instance.ts | 4 ++-- yarn-project/aztec.js/src/deployment/index.ts | 1 - .../aztec.js/src/deployment/register_class.ts | 4 ++-- .../src/{api => }/ethereum/l1_contracts.ts | 2 +- .../src/{api => }/ethereum/portal_manager.ts | 0 .../fee_juice_payment_method_with_claim.ts | 4 ++-- .../src/fee/private_fee_payment_method.ts | 2 +- .../src/fee/public_fee_payment_method.ts | 2 +- yarn-project/aztec.js/src/index.ts | 17 ++++++----------- .../aztec.js/src/rpc_clients/index.ts | 2 -- .../src/{api => }/test/anvil_test_watcher.ts | 0 .../src/{api => }/test/aztec_cheat_codes.ts | 0 .../src/{api => }/test/cheat_codes.ts | 0 .../src/{api => }/test/rollup_cheat_codes.ts | 0 .../aztec.js/src/{api => }/utils/abi_types.ts | 0 .../aztec.js/src/{api => }/utils/authwit.ts | 0 .../aztec.js/src/{api => }/utils/fee_juice.ts | 3 +-- .../utils/field_compressed_string.ts | 0 .../aztec.js/src/{api => }/utils/node.ts | 0 .../aztec.js/src/{api => }/utils/pub_key.ts | 0 .../aztec.js/src/{api => }/utils/pxe.ts | 0 .../aztec.js/src/wallet/account_wallet.ts | 6 +++--- .../aztec.js/src/wallet/base_wallet.ts | 2 +- .../aztec.js/src/wallet/signerless_wallet.ts | 2 +- 58 files changed, 87 insertions(+), 88 deletions(-) rename yarn-project/aztec.js/src/api/{contract/index.ts => contract.ts} (81%) rename yarn-project/aztec.js/src/api/{ethereum/index.ts => ethereum.ts} (64%) rename yarn-project/aztec.js/src/api/{interfaces/pxe.ts => interfaces.ts} (100%) create mode 100644 yarn-project/aztec.js/src/api/rpc.ts delete mode 100644 yarn-project/aztec.js/src/api/test/index.ts create mode 100644 yarn-project/aztec.js/src/api/testing.ts rename yarn-project/aztec.js/src/api/{utils/index.ts => utils.ts} (53%) rename yarn-project/aztec.js/src/{api => }/contract/base_contract_interaction.ts (96%) rename yarn-project/aztec.js/src/{api => }/contract/batch_call.ts (98%) rename yarn-project/aztec.js/src/{api => }/contract/checker.test.ts (100%) rename yarn-project/aztec.js/src/{api => }/contract/checker.ts (100%) rename yarn-project/aztec.js/src/{api => }/contract/contract.test.ts (99%) rename yarn-project/aztec.js/src/{api => }/contract/contract.ts (98%) rename yarn-project/aztec.js/src/{api => }/contract/contract_base.ts (98%) rename yarn-project/aztec.js/src/{api => }/contract/contract_function_interaction.ts (98%) rename yarn-project/aztec.js/src/{api => }/contract/deploy_method.ts (97%) rename yarn-project/aztec.js/src/{api => }/contract/deploy_proven_tx.ts (95%) rename yarn-project/aztec.js/src/{api => }/contract/deploy_sent_tx.ts (98%) rename yarn-project/aztec.js/src/{api => }/contract/get_gas_limits.test.ts (100%) rename yarn-project/aztec.js/src/{api => }/contract/get_gas_limits.ts (100%) rename yarn-project/aztec.js/src/{api => }/contract/protocol_contracts.ts (96%) rename yarn-project/aztec.js/src/{api => }/contract/proven_tx.ts (95%) rename yarn-project/aztec.js/src/{api => }/contract/sent_tx.test.ts (100%) rename yarn-project/aztec.js/src/{api => }/contract/sent_tx.ts (100%) rename yarn-project/aztec.js/src/{api => }/contract/unsafe_contract.ts (92%) delete mode 100644 yarn-project/aztec.js/src/deployment/index.ts rename yarn-project/aztec.js/src/{api => }/ethereum/l1_contracts.ts (89%) rename yarn-project/aztec.js/src/{api => }/ethereum/portal_manager.ts (100%) delete mode 100644 yarn-project/aztec.js/src/rpc_clients/index.ts rename yarn-project/aztec.js/src/{api => }/test/anvil_test_watcher.ts (100%) rename yarn-project/aztec.js/src/{api => }/test/aztec_cheat_codes.ts (100%) rename yarn-project/aztec.js/src/{api => }/test/cheat_codes.ts (100%) rename yarn-project/aztec.js/src/{api => }/test/rollup_cheat_codes.ts (100%) rename yarn-project/aztec.js/src/{api => }/utils/abi_types.ts (100%) rename yarn-project/aztec.js/src/{api => }/utils/authwit.ts (100%) rename yarn-project/aztec.js/src/{api => }/utils/fee_juice.ts (90%) rename yarn-project/aztec.js/src/{api => }/utils/field_compressed_string.ts (100%) rename yarn-project/aztec.js/src/{api => }/utils/node.ts (100%) rename yarn-project/aztec.js/src/{api => }/utils/pub_key.ts (100%) rename yarn-project/aztec.js/src/{api => }/utils/pxe.ts (100%) diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index 0d044991ecbd..8dc1143853ac 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -5,25 +5,25 @@ "type": "module", "exports": { ".": "./dest/index.js", - "./interfaces/pxe": "./dest/api/interfaces/pxe.js", + "./interfaces": "./dest/api/interfaces.js", "./abi": "./dest/api/abi.js", "./account": "./dest/api/account.js", "./addresses": "./dest/api/addresses.js", "./cheatcodes": "./dest/api/cheatcodes.js", - "./contracts": "./dest/api/contract/index.js", + "./contracts": "./dest/api/contract.js", "./deployment": "./dest/api/deployment.js", "./entrypoint": "./dest/api/entrypoint.js", "./eth_address": "./dest/api/eth_address.js", - "./ethereum": "./dest/api/ethereum/index.js", + "./ethereum": "./dest/api/ethereum.js", "./fee": "./dest/api/fee.js", "./fields": "./dest/api/fields.js", "./log": "./dest/api/log.js", "./log_id": "./dest/api/log_id.js", - "./rpc": "./dest/rpc_clients/index.js", + "./rpc": "./dest/api/rpc.js", "./tx_hash": "./dest/api/tx_hash.js", "./wallet": "./dest/api/wallet.js", - "./utils": "./dest/api/utils/index.js", - "./testing": "./dest/api/test/index.js" + "./utils": "./dest/api/utils.js", + "./testing": "./dest/api/testing.js" }, "typedocOptions": { "entryPoints": [ diff --git a/yarn-project/aztec.js/src/account/wallet.ts b/yarn-project/aztec.js/src/account/wallet.ts index 9624871bf5d6..baf7f6231962 100644 --- a/yarn-project/aztec.js/src/account/wallet.ts +++ b/yarn-project/aztec.js/src/account/wallet.ts @@ -1,7 +1,7 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { PXE } from '@aztec/stdlib/interfaces/client'; -import type { IntentAction, IntentInnerHash } from '../api/utils/authwit.js'; +import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; import type { AccountInterface } from './interface.js'; /** diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index dbc9e8d77170..76fb1701ce31 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -9,9 +9,9 @@ import type { PublicKeys } from '@aztec/stdlib/keys'; import type { AuthWitnessProvider } from '../account/interface.js'; import type { Wallet } from '../account/wallet.js'; -import { Contract } from '../api/contract/contract.js'; -import { DeployMethod, type DeployOptions } from '../api/contract/deploy_method.js'; import type { ExecutionRequestInit } from '../api/entrypoint.js'; +import { Contract } from '../contract/contract.js'; +import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; import { EntrypointPayload, computeCombinedPayloadHash } from '../entrypoint/payload.js'; /** diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts index 606d89324245..57a23ef929bf 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts @@ -3,7 +3,7 @@ import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { TxHash, TxReceipt } from '@aztec/stdlib/tx'; import type { Wallet } from '../account/index.js'; -import { DefaultWaitOpts, SentTx, type WaitOpts } from '../api/contract/sent_tx.js'; +import { DefaultWaitOpts, SentTx, type WaitOpts } from '../contract/sent_tx.js'; /** Extends a transaction receipt with a wallet instance for the newly deployed contract. */ export type DeployAccountTxReceipt = FieldsOf & { diff --git a/yarn-project/aztec.js/src/account_manager/index.ts b/yarn-project/aztec.js/src/account_manager/index.ts index 2c526776c612..f642ea5d2264 100644 --- a/yarn-project/aztec.js/src/account_manager/index.ts +++ b/yarn-project/aztec.js/src/account_manager/index.ts @@ -7,9 +7,9 @@ import { deriveKeys } from '@aztec/stdlib/keys'; import type { AccountContract } from '../account/contract.js'; import type { Salt, Wallet } from '../account/index.js'; import type { AccountInterface } from '../account/interface.js'; -import { Contract } from '../api/contract/contract.js'; -import { DeployMethod, type DeployOptions } from '../api/contract/deploy_method.js'; -import { DefaultWaitOpts, type WaitOpts } from '../api/contract/sent_tx.js'; +import { Contract } from '../contract/contract.js'; +import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; +import { DefaultWaitOpts, type WaitOpts } from '../contract/sent_tx.js'; import { DefaultMultiCallEntrypoint } from '../entrypoint/default_multi_call_entrypoint.js'; import { AccountWalletWithSecretKey, SignerlessWallet } from '../wallet/index.js'; import { DeployAccountMethod } from './deploy_account_method.js'; diff --git a/yarn-project/aztec.js/src/api/account.ts b/yarn-project/aztec.js/src/api/account.ts index 9e745d3e9379..d064159f05b9 100644 --- a/yarn-project/aztec.js/src/api/account.ts +++ b/yarn-project/aztec.js/src/api/account.ts @@ -7,4 +7,4 @@ export { getAccountContractAddress, } from '../account/index.js'; -export { AccountManager } from '../account_manager/index.js'; +export { AccountManager, type DeployAccountOptions } from '../account_manager/index.js'; diff --git a/yarn-project/aztec.js/src/api/contract/index.ts b/yarn-project/aztec.js/src/api/contract.ts similarity index 81% rename from yarn-project/aztec.js/src/api/contract/index.ts rename to yarn-project/aztec.js/src/api/contract.ts index 265886aea9cc..f9c41522a263 100644 --- a/yarn-project/aztec.js/src/api/contract/index.ts +++ b/yarn-project/aztec.js/src/api/contract.ts @@ -35,14 +35,19 @@ * * @packageDocumentation */ -export { Contract } from './contract.js'; +export { Contract } from '../contract/contract.js'; export { ContractFunctionInteraction, type ProfileResult, type SendMethodOptions, -} from './contract_function_interaction.js'; -export { DefaultWaitOpts, SentTx, type WaitOpts } from './sent_tx.js'; -export { ContractBase, type ContractMethod, type ContractNotes, type ContractStorageLayout } from './contract_base.js'; -export { BatchCall } from './batch_call.js'; -export { type DeployOptions, DeployMethod } from './deploy_method.js'; -export { DeploySentTx } from './deploy_sent_tx.js'; +} from '../contract/contract_function_interaction.js'; +export { DefaultWaitOpts, SentTx, type WaitOpts } from '../contract/sent_tx.js'; +export { + ContractBase, + type ContractMethod, + type ContractNotes, + type ContractStorageLayout, +} from '../contract/contract_base.js'; +export { BatchCall } from '../contract/batch_call.js'; +export { type DeployOptions, DeployMethod } from '../contract/deploy_method.js'; +export { DeploySentTx } from '../contract/deploy_sent_tx.js'; diff --git a/yarn-project/aztec.js/src/api/deployment.ts b/yarn-project/aztec.js/src/api/deployment.ts index e6e2ad245211..ed89873c5aa6 100644 --- a/yarn-project/aztec.js/src/api/deployment.ts +++ b/yarn-project/aztec.js/src/api/deployment.ts @@ -1,3 +1,4 @@ export { registerContractClass } from '../deployment/register_class.js'; export { broadcastPrivateFunction, broadcastUnconstrainedFunction } from '../deployment/broadcast_function.js'; export { deployInstance } from '../deployment/deploy_instance.js'; +export { ContractDeployer } from '../deployment/contract_deployer.js'; diff --git a/yarn-project/aztec.js/src/api/ethereum/index.ts b/yarn-project/aztec.js/src/api/ethereum.ts similarity index 64% rename from yarn-project/aztec.js/src/api/ethereum/index.ts rename to yarn-project/aztec.js/src/api/ethereum.ts index 20790abb1685..6c6a7d2058ed 100644 --- a/yarn-project/aztec.js/src/api/ethereum/index.ts +++ b/yarn-project/aztec.js/src/api/ethereum.ts @@ -7,5 +7,5 @@ export { type L2AmountClaimWithRecipient, type L2Claim, generateClaimSecret, -} from './portal_manager.js'; -export { getL1ContractAddresses } from './l1_contracts.js'; +} from '../ethereum/portal_manager.js'; +export { getL1ContractAddresses } from '../ethereum/l1_contracts.js'; diff --git a/yarn-project/aztec.js/src/api/interfaces/pxe.ts b/yarn-project/aztec.js/src/api/interfaces.ts similarity index 100% rename from yarn-project/aztec.js/src/api/interfaces/pxe.ts rename to yarn-project/aztec.js/src/api/interfaces.ts diff --git a/yarn-project/aztec.js/src/api/rpc.ts b/yarn-project/aztec.js/src/api/rpc.ts new file mode 100644 index 000000000000..7f12bc9cba0f --- /dev/null +++ b/yarn-project/aztec.js/src/api/rpc.ts @@ -0,0 +1,2 @@ +export { createPXEClient } from '../rpc_clients/pxe_client.js'; +export { createCompatibleClient } from '../rpc_clients/node/index.js'; diff --git a/yarn-project/aztec.js/src/api/test/index.ts b/yarn-project/aztec.js/src/api/test/index.ts deleted file mode 100644 index 1b4028228fd1..000000000000 --- a/yarn-project/aztec.js/src/api/test/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export { AnvilTestWatcher } from './anvil_test_watcher.js'; -export { RollupCheatCodes } from './rollup_cheat_codes.js'; -export { AztecCheatCodes } from './aztec_cheat_codes.js'; -export { EthCheatCodes } from '@aztec/ethereum/eth-cheatcodes'; -export { CheatCodes } from './cheat_codes.js'; diff --git a/yarn-project/aztec.js/src/api/testing.ts b/yarn-project/aztec.js/src/api/testing.ts new file mode 100644 index 000000000000..c17d63bc0f70 --- /dev/null +++ b/yarn-project/aztec.js/src/api/testing.ts @@ -0,0 +1,5 @@ +export { AnvilTestWatcher } from '../test/anvil_test_watcher.js'; +export { RollupCheatCodes } from '../test/rollup_cheat_codes.js'; +export { AztecCheatCodes } from '../test/aztec_cheat_codes.js'; +export { EthCheatCodes } from '@aztec/ethereum/eth-cheatcodes'; +export { CheatCodes } from '../test/cheat_codes.js'; diff --git a/yarn-project/aztec.js/src/api/utils/index.ts b/yarn-project/aztec.js/src/api/utils.ts similarity index 53% rename from yarn-project/aztec.js/src/api/utils/index.ts rename to yarn-project/aztec.js/src/api/utils.ts index bd52ec8ea9c3..acc098ae5bee 100644 --- a/yarn-project/aztec.js/src/api/utils/index.ts +++ b/yarn-project/aztec.js/src/api/utils.ts @@ -1,4 +1,4 @@ -export { generatePublicKey } from './pub_key.js'; +export { generatePublicKey } from '../utils/pub_key.js'; export { type AztecAddressLike, type EthAddressLike, @@ -7,15 +7,15 @@ export { type FunctionSelectorLike, type U128Like, type WrappedFieldLike, -} from './abi_types.js'; +} from '../utils/abi_types.js'; export { computeAuthWitMessageHash, computeInnerAuthWitHash, computeInnerAuthWitHashFromAction, type IntentAction, type IntentInnerHash, -} from './authwit.js'; -export { waitForPXE } from './pxe.js'; -export { waitForNode, createAztecNodeClient, type AztecNode } from './node.js'; -export { getFeeJuiceBalance } from './fee_juice.js'; -export { readFieldCompressedString } from './field_compressed_string.js'; +} from '../utils/authwit.js'; +export { waitForPXE } from '../utils/pxe.js'; +export { waitForNode, createAztecNodeClient, type AztecNode } from '../utils/node.js'; +export { getFeeJuiceBalance } from '../utils/fee_juice.js'; +export { readFieldCompressedString } from '../utils/field_compressed_string.js'; diff --git a/yarn-project/aztec.js/src/api/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts similarity index 96% rename from yarn-project/aztec.js/src/api/contract/base_contract_interaction.ts rename to yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 65e76e0055b3..1340329666b1 100644 --- a/yarn-project/aztec.js/src/api/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -3,10 +3,10 @@ import { createLogger } from '@aztec/foundation/log'; import { GasSettings } from '@aztec/stdlib/gas'; import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx'; -import type { Wallet } from '../../account/wallet.js'; -import type { ExecutionRequestInit } from '../../entrypoint/entrypoint.js'; -import type { FeeOptions, UserFeeOptions } from '../../entrypoint/payload.js'; -import { FeeJuicePaymentMethod } from '../../fee/fee_juice_payment_method.js'; +import type { Wallet } from '../account/wallet.js'; +import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; +import type { FeeOptions, UserFeeOptions } from '../entrypoint/payload.js'; +import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; import { getGasLimits } from './get_gas_limits.js'; import { ProvenTx } from './proven_tx.js'; import { SentTx } from './sent_tx.js'; diff --git a/yarn-project/aztec.js/src/api/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts similarity index 98% rename from yarn-project/aztec.js/src/api/contract/batch_call.ts rename to yarn-project/aztec.js/src/contract/batch_call.ts index 0e13666e23ce..5cc860556e0b 100644 --- a/yarn-project/aztec.js/src/api/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -1,7 +1,7 @@ import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { Wallet } from '../../account/index.js'; +import type { Wallet } from '../account/wallet.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; import type { SimulateMethodOptions } from './contract_function_interaction.js'; diff --git a/yarn-project/aztec.js/src/api/contract/checker.test.ts b/yarn-project/aztec.js/src/contract/checker.test.ts similarity index 100% rename from yarn-project/aztec.js/src/api/contract/checker.test.ts rename to yarn-project/aztec.js/src/contract/checker.test.ts diff --git a/yarn-project/aztec.js/src/api/contract/checker.ts b/yarn-project/aztec.js/src/contract/checker.ts similarity index 100% rename from yarn-project/aztec.js/src/api/contract/checker.ts rename to yarn-project/aztec.js/src/contract/checker.ts diff --git a/yarn-project/aztec.js/src/api/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts similarity index 99% rename from yarn-project/aztec.js/src/api/contract/contract.test.ts rename to yarn-project/aztec.js/src/contract/contract.test.ts index 9d4c2021c260..48d50f2b07f0 100644 --- a/yarn-project/aztec.js/src/api/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -13,7 +13,7 @@ import type { Tx, TxExecutionRequest, TxHash, TxProvingResult, TxReceipt, TxSimu import { type MockProxy, mock } from 'jest-mock-extended'; -import type { Wallet } from '../../account/wallet.js'; +import type { Wallet } from '../account/wallet.js'; import { Contract } from './contract.js'; describe('Contract Class', () => { diff --git a/yarn-project/aztec.js/src/api/contract/contract.ts b/yarn-project/aztec.js/src/contract/contract.ts similarity index 98% rename from yarn-project/aztec.js/src/api/contract/contract.ts rename to yarn-project/aztec.js/src/contract/contract.ts index 2e2804cb4238..61caeae78aa2 100644 --- a/yarn-project/aztec.js/src/api/contract/contract.ts +++ b/yarn-project/aztec.js/src/contract/contract.ts @@ -3,7 +3,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { getContractClassFromArtifact } from '@aztec/stdlib/contract'; import { PublicKeys } from '@aztec/stdlib/keys'; -import type { Wallet } from '../../account/index.js'; +import type { Wallet } from '../account/wallet.js'; import { ContractBase } from './contract_base.js'; import { DeployMethod } from './deploy_method.js'; diff --git a/yarn-project/aztec.js/src/api/contract/contract_base.ts b/yarn-project/aztec.js/src/contract/contract_base.ts similarity index 98% rename from yarn-project/aztec.js/src/api/contract/contract_base.ts rename to yarn-project/aztec.js/src/contract/contract_base.ts index ba9bea299322..84fd3ba018f2 100644 --- a/yarn-project/aztec.js/src/api/contract/contract_base.ts +++ b/yarn-project/aztec.js/src/contract/contract_base.ts @@ -7,7 +7,7 @@ import { } from '@aztec/stdlib/abi'; import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract'; -import type { Wallet } from '../../account/index.js'; +import type { Wallet } from '../account/wallet.js'; import { ContractFunctionInteraction } from './contract_function_interaction.js'; /** diff --git a/yarn-project/aztec.js/src/api/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts similarity index 98% rename from yarn-project/aztec.js/src/api/contract/contract_function_interaction.ts rename to yarn-project/aztec.js/src/contract/contract_function_interaction.ts index d449eb9904c9..a3404e20f88b 100644 --- a/yarn-project/aztec.js/src/api/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -10,8 +10,8 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PrivateKernelProverProfileResult } from '@aztec/stdlib/kernel'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { Wallet } from '../../account/wallet.js'; -import { FeeJuicePaymentMethod } from '../../fee/fee_juice_payment_method.js'; +import type { Wallet } from '../account/wallet.js'; +import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; export type { SendMethodOptions }; diff --git a/yarn-project/aztec.js/src/api/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts similarity index 97% rename from yarn-project/aztec.js/src/api/contract/deploy_method.ts rename to yarn-project/aztec.js/src/contract/deploy_method.ts index b72b36eeb895..0ecf3a7419fb 100644 --- a/yarn-project/aztec.js/src/api/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -11,10 +11,10 @@ import type { GasSettings } from '@aztec/stdlib/gas'; import type { PublicKeys } from '@aztec/stdlib/keys'; import type { Capsule, TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { Wallet } from '../../account/index.js'; -import { deployInstance } from '../../deployment/deploy_instance.js'; -import { registerContractClass } from '../../deployment/register_class.js'; -import type { ExecutionRequestInit } from '../../entrypoint/entrypoint.js'; +import type { Wallet } from '../account/wallet.js'; +import { deployInstance } from '../deployment/deploy_instance.js'; +import { registerContractClass } from '../deployment/register_class.js'; +import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; import type { Contract } from './contract.js'; import type { ContractBase } from './contract_base.js'; diff --git a/yarn-project/aztec.js/src/api/contract/deploy_proven_tx.ts b/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts similarity index 95% rename from yarn-project/aztec.js/src/api/contract/deploy_proven_tx.ts rename to yarn-project/aztec.js/src/contract/deploy_proven_tx.ts index 659ab8cc82b3..cf7151091524 100644 --- a/yarn-project/aztec.js/src/api/contract/deploy_proven_tx.ts +++ b/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts @@ -3,7 +3,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { Tx } from '@aztec/stdlib/tx'; -import type { Wallet } from '../../account/index.js'; +import type { Wallet } from '../account/wallet.js'; import type { Contract } from './contract.js'; import { DeploySentTx } from './deploy_sent_tx.js'; import { ProvenTx } from './proven_tx.js'; diff --git a/yarn-project/aztec.js/src/api/contract/deploy_sent_tx.ts b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts similarity index 98% rename from yarn-project/aztec.js/src/api/contract/deploy_sent_tx.ts rename to yarn-project/aztec.js/src/contract/deploy_sent_tx.ts index 1c092b72bbfc..6ff89c1fb776 100644 --- a/yarn-project/aztec.js/src/api/contract/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts @@ -5,7 +5,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client'; import type { TxHash, TxReceipt } from '@aztec/stdlib/tx'; -import type { Wallet } from '../../account/index.js'; +import type { Wallet } from '../account/wallet.js'; import type { Contract } from './contract.js'; import type { ContractBase } from './contract_base.js'; import { SentTx, type WaitOpts } from './sent_tx.js'; diff --git a/yarn-project/aztec.js/src/api/contract/get_gas_limits.test.ts b/yarn-project/aztec.js/src/contract/get_gas_limits.test.ts similarity index 100% rename from yarn-project/aztec.js/src/api/contract/get_gas_limits.test.ts rename to yarn-project/aztec.js/src/contract/get_gas_limits.test.ts diff --git a/yarn-project/aztec.js/src/api/contract/get_gas_limits.ts b/yarn-project/aztec.js/src/contract/get_gas_limits.ts similarity index 100% rename from yarn-project/aztec.js/src/api/contract/get_gas_limits.ts rename to yarn-project/aztec.js/src/contract/get_gas_limits.ts diff --git a/yarn-project/aztec.js/src/api/contract/protocol_contracts.ts b/yarn-project/aztec.js/src/contract/protocol_contracts.ts similarity index 96% rename from yarn-project/aztec.js/src/api/contract/protocol_contracts.ts rename to yarn-project/aztec.js/src/contract/protocol_contracts.ts index 55fbadaf4e44..a72d22c45d41 100644 --- a/yarn-project/aztec.js/src/api/contract/protocol_contracts.ts +++ b/yarn-project/aztec.js/src/contract/protocol_contracts.ts @@ -1,6 +1,6 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import type { Wallet } from '../../wallet/index.js'; +import type { Wallet } from '../account/wallet.js'; import { UnsafeContract } from './unsafe_contract.js'; /** Returns a Contract wrapper for the class registerer. */ diff --git a/yarn-project/aztec.js/src/api/contract/proven_tx.ts b/yarn-project/aztec.js/src/contract/proven_tx.ts similarity index 95% rename from yarn-project/aztec.js/src/api/contract/proven_tx.ts rename to yarn-project/aztec.js/src/contract/proven_tx.ts index e6ea78f4f983..dd30bb060060 100644 --- a/yarn-project/aztec.js/src/api/contract/proven_tx.ts +++ b/yarn-project/aztec.js/src/contract/proven_tx.ts @@ -1,7 +1,7 @@ import type { PXE } from '@aztec/stdlib/interfaces/client'; import { Tx } from '@aztec/stdlib/tx'; -import type { Wallet } from '../../account/index.js'; +import type { Wallet } from '../account/wallet.js'; import { SentTx } from './sent_tx.js'; /** diff --git a/yarn-project/aztec.js/src/api/contract/sent_tx.test.ts b/yarn-project/aztec.js/src/contract/sent_tx.test.ts similarity index 100% rename from yarn-project/aztec.js/src/api/contract/sent_tx.test.ts rename to yarn-project/aztec.js/src/contract/sent_tx.test.ts diff --git a/yarn-project/aztec.js/src/api/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts similarity index 100% rename from yarn-project/aztec.js/src/api/contract/sent_tx.ts rename to yarn-project/aztec.js/src/contract/sent_tx.ts diff --git a/yarn-project/aztec.js/src/api/contract/unsafe_contract.ts b/yarn-project/aztec.js/src/contract/unsafe_contract.ts similarity index 92% rename from yarn-project/aztec.js/src/api/contract/unsafe_contract.ts rename to yarn-project/aztec.js/src/contract/unsafe_contract.ts index 7194a9544f73..05174da334d1 100644 --- a/yarn-project/aztec.js/src/api/contract/unsafe_contract.ts +++ b/yarn-project/aztec.js/src/contract/unsafe_contract.ts @@ -1,7 +1,7 @@ import type { ContractArtifact } from '@aztec/stdlib/abi'; import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; -import type { Wallet } from '../../wallet/index.js'; +import type { Wallet } from '../account/wallet.js'; import { ContractBase } from './contract_base.js'; /** Unsafe constructor for ContractBase that bypasses the check that the instance is registered in the wallet. */ diff --git a/yarn-project/aztec.js/src/deployment/broadcast_function.ts b/yarn-project/aztec.js/src/deployment/broadcast_function.ts index ab422e25804c..5cf1cdf39b99 100644 --- a/yarn-project/aztec.js/src/deployment/broadcast_function.ts +++ b/yarn-project/aztec.js/src/deployment/broadcast_function.ts @@ -15,8 +15,8 @@ import { } from '@aztec/stdlib/contract'; import { Capsule } from '@aztec/stdlib/tx'; -import type { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; -import { getRegistererContract } from '../api/contract/protocol_contracts.js'; +import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; +import { getRegistererContract } from '../contract/protocol_contracts.js'; import type { Wallet } from '../wallet/index.js'; /** diff --git a/yarn-project/aztec.js/src/deployment/contract_deployer.ts b/yarn-project/aztec.js/src/deployment/contract_deployer.ts index 88e1acd9c659..10567f04f0fc 100644 --- a/yarn-project/aztec.js/src/deployment/contract_deployer.ts +++ b/yarn-project/aztec.js/src/deployment/contract_deployer.ts @@ -3,8 +3,8 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { PublicKeys } from '@aztec/stdlib/keys'; import type { Wallet } from '../account/wallet.js'; -import { Contract } from '../api/contract/contract.js'; -import { DeployMethod } from '../api/contract/deploy_method.js'; +import { Contract } from '../contract/contract.js'; +import { DeployMethod } from '../contract/deploy_method.js'; /** * A class for deploying contract. diff --git a/yarn-project/aztec.js/src/deployment/deploy_instance.ts b/yarn-project/aztec.js/src/deployment/deploy_instance.ts index 5f9d11cf9678..e24fc43dc4b7 100644 --- a/yarn-project/aztec.js/src/deployment/deploy_instance.ts +++ b/yarn-project/aztec.js/src/deployment/deploy_instance.ts @@ -1,7 +1,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; -import type { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; -import { getDeployerContract } from '../api/contract/protocol_contracts.js'; +import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; +import { getDeployerContract } from '../contract/protocol_contracts.js'; import type { Wallet } from '../wallet/index.js'; /** diff --git a/yarn-project/aztec.js/src/deployment/index.ts b/yarn-project/aztec.js/src/deployment/index.ts deleted file mode 100644 index 587eeb108ce7..000000000000 --- a/yarn-project/aztec.js/src/deployment/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './contract_deployer.js'; diff --git a/yarn-project/aztec.js/src/deployment/register_class.ts b/yarn-project/aztec.js/src/deployment/register_class.ts index e9a07df25463..4cd770c00a1c 100644 --- a/yarn-project/aztec.js/src/deployment/register_class.ts +++ b/yarn-project/aztec.js/src/deployment/register_class.ts @@ -5,8 +5,8 @@ import { type ContractArtifact, bufferAsFields } from '@aztec/stdlib/abi'; import { getContractClassFromArtifact } from '@aztec/stdlib/contract'; import { Capsule } from '@aztec/stdlib/tx'; -import type { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; -import { getRegistererContract } from '../api/contract/protocol_contracts.js'; +import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; +import { getRegistererContract } from '../contract/protocol_contracts.js'; import type { Wallet } from '../wallet/index.js'; const defaultEmitPublicBytecode = diff --git a/yarn-project/aztec.js/src/api/ethereum/l1_contracts.ts b/yarn-project/aztec.js/src/ethereum/l1_contracts.ts similarity index 89% rename from yarn-project/aztec.js/src/api/ethereum/l1_contracts.ts rename to yarn-project/aztec.js/src/ethereum/l1_contracts.ts index 7796ec1b5652..645f2ad49b6f 100644 --- a/yarn-project/aztec.js/src/api/ethereum/l1_contracts.ts +++ b/yarn-project/aztec.js/src/ethereum/l1_contracts.ts @@ -1,7 +1,7 @@ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses'; import { retryUntil } from '@aztec/foundation/retry'; -import { createPXEClient } from '../../rpc_clients/index.js'; +import { createPXEClient } from '../rpc_clients/pxe_client.js'; export const getL1ContractAddresses = async (url: string): Promise => { const pxeClient = createPXEClient(url, {}); diff --git a/yarn-project/aztec.js/src/api/ethereum/portal_manager.ts b/yarn-project/aztec.js/src/ethereum/portal_manager.ts similarity index 100% rename from yarn-project/aztec.js/src/api/ethereum/portal_manager.ts rename to yarn-project/aztec.js/src/ethereum/portal_manager.ts diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts index ac3d3a808944..28efae594188 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts @@ -3,8 +3,8 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { FunctionCall } from '@aztec/stdlib/abi'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; -import { getFeeJuice } from '../api/contract/protocol_contracts.js'; -import type { L2AmountClaim } from '../api/ethereum/portal_manager.js'; +import { getFeeJuice } from '../contract/protocol_contracts.js'; +import type { L2AmountClaim } from '../ethereum/portal_manager.js'; import type { Wallet } from '../wallet/index.js'; import { FeeJuicePaymentMethod } from './fee_juice_payment_method.js'; diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index 4d78cd97e91d..a4d0d6752f2b 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -4,7 +4,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; import type { Wallet } from '../account/wallet.js'; -import { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; +import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { SignerlessWallet } from '../wallet/signerless_wallet.js'; import type { FeePaymentMethod } from './fee_payment_method.js'; diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index a900e2b488cf..8acae43925ac 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -4,7 +4,7 @@ import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; -import { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; +import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import type { AccountWallet } from '../wallet/account_wallet.js'; import { SignerlessWallet } from '../wallet/signerless_wallet.js'; import type { FeePaymentMethod } from './fee_payment_method.js'; diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 2774a4238f65..2da0faf02abf 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -20,16 +20,8 @@ * TODO: Ultimately reimplement this mega exporter by mega exporting a granular api (then deprecate it). */ -export { ContractDeployer } from './deployment/index.js'; - export { NoteSelector } from '@aztec/stdlib/abi'; -export { createCompatibleClient, createPXEClient } from './rpc_clients/index.js'; - -export { type DeployAccountOptions } from './account_manager/index.js'; - -export { AccountWallet, AccountWalletWithSecretKey, SignerlessWallet } from './wallet/index.js'; - export { EthAddress } from '@aztec/foundation/eth-address'; export { Fq, Fr, Point, GrumpkinScalar } from '@aztec/foundation/fields'; @@ -97,8 +89,11 @@ export { fileURLToPath } from '@aztec/foundation/url'; export * from './api/abi.js'; export * from './api/account.js'; export * from './api/addresses.js'; -export * from './api/ethereum/index.js'; +export * from './api/deployment.js'; +export * from './api/ethereum.js'; export * from './api/fee.js'; export * from './api/log.js'; -export * from './api/contract/index.js'; -export * from './api/utils/index.js'; +export * from './api/contract.js'; +export * from './api/utils.js'; +export * from './api/rpc.js'; +export * from './api/wallet.js'; diff --git a/yarn-project/aztec.js/src/rpc_clients/index.ts b/yarn-project/aztec.js/src/rpc_clients/index.ts deleted file mode 100644 index 194614b56eeb..000000000000 --- a/yarn-project/aztec.js/src/rpc_clients/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './pxe_client.js'; -export * from './node/index.js'; diff --git a/yarn-project/aztec.js/src/api/test/anvil_test_watcher.ts b/yarn-project/aztec.js/src/test/anvil_test_watcher.ts similarity index 100% rename from yarn-project/aztec.js/src/api/test/anvil_test_watcher.ts rename to yarn-project/aztec.js/src/test/anvil_test_watcher.ts diff --git a/yarn-project/aztec.js/src/api/test/aztec_cheat_codes.ts b/yarn-project/aztec.js/src/test/aztec_cheat_codes.ts similarity index 100% rename from yarn-project/aztec.js/src/api/test/aztec_cheat_codes.ts rename to yarn-project/aztec.js/src/test/aztec_cheat_codes.ts diff --git a/yarn-project/aztec.js/src/api/test/cheat_codes.ts b/yarn-project/aztec.js/src/test/cheat_codes.ts similarity index 100% rename from yarn-project/aztec.js/src/api/test/cheat_codes.ts rename to yarn-project/aztec.js/src/test/cheat_codes.ts diff --git a/yarn-project/aztec.js/src/api/test/rollup_cheat_codes.ts b/yarn-project/aztec.js/src/test/rollup_cheat_codes.ts similarity index 100% rename from yarn-project/aztec.js/src/api/test/rollup_cheat_codes.ts rename to yarn-project/aztec.js/src/test/rollup_cheat_codes.ts diff --git a/yarn-project/aztec.js/src/api/utils/abi_types.ts b/yarn-project/aztec.js/src/utils/abi_types.ts similarity index 100% rename from yarn-project/aztec.js/src/api/utils/abi_types.ts rename to yarn-project/aztec.js/src/utils/abi_types.ts diff --git a/yarn-project/aztec.js/src/api/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts similarity index 100% rename from yarn-project/aztec.js/src/api/utils/authwit.ts rename to yarn-project/aztec.js/src/utils/authwit.ts diff --git a/yarn-project/aztec.js/src/api/utils/fee_juice.ts b/yarn-project/aztec.js/src/utils/fee_juice.ts similarity index 90% rename from yarn-project/aztec.js/src/api/utils/fee_juice.ts rename to yarn-project/aztec.js/src/utils/fee_juice.ts index 603beabe822a..81ddb58844a7 100644 --- a/yarn-project/aztec.js/src/api/utils/fee_juice.ts +++ b/yarn-project/aztec.js/src/utils/fee_juice.ts @@ -2,8 +2,7 @@ import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { deriveStorageSlotInMap } from '@aztec/stdlib/hash'; - -import type { PXE } from '../../api/interfaces/pxe.js'; +import type { PXE } from '@aztec/stdlib/interfaces/client'; /** * Returns the owner's fee juice balance. diff --git a/yarn-project/aztec.js/src/api/utils/field_compressed_string.ts b/yarn-project/aztec.js/src/utils/field_compressed_string.ts similarity index 100% rename from yarn-project/aztec.js/src/api/utils/field_compressed_string.ts rename to yarn-project/aztec.js/src/utils/field_compressed_string.ts diff --git a/yarn-project/aztec.js/src/api/utils/node.ts b/yarn-project/aztec.js/src/utils/node.ts similarity index 100% rename from yarn-project/aztec.js/src/api/utils/node.ts rename to yarn-project/aztec.js/src/utils/node.ts diff --git a/yarn-project/aztec.js/src/api/utils/pub_key.ts b/yarn-project/aztec.js/src/utils/pub_key.ts similarity index 100% rename from yarn-project/aztec.js/src/api/utils/pub_key.ts rename to yarn-project/aztec.js/src/utils/pub_key.ts diff --git a/yarn-project/aztec.js/src/api/utils/pxe.ts b/yarn-project/aztec.js/src/utils/pxe.ts similarity index 100% rename from yarn-project/aztec.js/src/api/utils/pxe.ts rename to yarn-project/aztec.js/src/utils/pxe.ts diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 307358909379..55983f9322ea 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -7,14 +7,14 @@ import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; import type { AccountInterface } from '../account/interface.js'; -import { ContractFunctionInteraction } from '../api/contract/contract_function_interaction.js'; +import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; +import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; import { type IntentAction, type IntentInnerHash, computeAuthWitMessageHash, computeInnerAuthWitHashFromAction, -} from '../api/utils/authwit.js'; -import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; +} from '../utils/authwit.js'; import { BaseWallet } from './base_wallet.js'; /** diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index ed9ec93bd99a..c6ef5b918609 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -29,8 +29,8 @@ import type { } from '@aztec/stdlib/tx'; import type { Wallet } from '../account/wallet.js'; -import type { IntentAction, IntentInnerHash } from '../api/utils/authwit.js'; import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; +import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; /** * A base class for Wallet implementations diff --git a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts index 79bc47716438..022d2052604f 100644 --- a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts @@ -4,9 +4,9 @@ import type { CompleteAddress } from '@aztec/stdlib/contract'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { IntentAction, IntentInnerHash } from '../api/utils/authwit.js'; import { DefaultEntrypoint } from '../entrypoint/default_entrypoint.js'; import type { EntrypointInterface, ExecutionRequestInit } from '../entrypoint/entrypoint.js'; +import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; import { BaseWallet } from './base_wallet.js'; /** From 53912cbc12e5d298decc4a622445ec1ebdd54e11 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 7 Mar 2025 09:56:16 +0000 Subject: [PATCH 04/48] more cleanup --- playground/src/aztecEnv.ts | 18 +++++---- .../src/components/common/fnParameter.tsx | 2 +- playground/vite.config.ts | 39 +++++++++---------- yarn-project/aztec.js/src/api/abi.ts | 7 ++++ yarn-project/aztec.js/src/api/wallet.ts | 8 +--- yarn-project/aztec.js/src/index.ts | 5 +-- 6 files changed, 39 insertions(+), 40 deletions(-) diff --git a/playground/src/aztecEnv.ts b/playground/src/aztecEnv.ts index 5aceaff7e5a9..715220205ee5 100644 --- a/playground/src/aztecEnv.ts +++ b/playground/src/aztecEnv.ts @@ -1,15 +1,19 @@ -import { createAztecNodeClient, type AztecNode } from '@aztec/aztec.js/utils'; +import { + createAztecNodeClient, + type AztecNode, + AztecAddress, + AccountWalletWithSecretKey, + Contract, + type PXE, + type Logger, + createLogger, +} from '@aztec/aztec.js'; -import { AztecAddress } from '@aztec/aztec.js/addresses'; -import { AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet'; -import { Contract } from '@aztec/aztec.js/contracts'; -import { type PXE } from '@aztec/aztec.js/interfaces/pxe'; import { createPXEService, type PXEServiceConfig, getPXEServiceConfig } from '@aztec/pxe/client/lazy'; import { createStore } from '@aztec/kv-store/indexeddb'; import { createContext } from 'react'; import { NetworkDB, WalletDB } from './utils/storage'; import { type ContractFunctionInteractionTx } from './utils/txs'; -import { type Logger, createLogger } from '@aztec/aztec.js/log'; const logLevel = ['silent', 'fatal', 'error', 'warn', 'info', 'verbose', 'debug', 'trace'] as const; @@ -155,7 +159,7 @@ export class AztecEnv { store: WebLogger.getInstance().createLogger('pxe:data:indexeddb'), pxe: WebLogger.getInstance().createLogger('pxe:service'), prover: WebLogger.getInstance().createLogger('bb:wasm:lazy'), - } + }, }); return pxe; } diff --git a/playground/src/components/common/fnParameter.tsx b/playground/src/components/common/fnParameter.tsx index 30fb78571e08..3b0927df4d06 100644 --- a/playground/src/components/common/fnParameter.tsx +++ b/playground/src/components/common/fnParameter.tsx @@ -1,4 +1,4 @@ -import { type ABIParameter, type AbiType, isAddressStruct } from '@aztec/stdlib/abi'; +import { type ABIParameter, type AbiType, isAddressStruct } from '@aztec/aztec.js'; import { formatFrAsString, parseAliasedBuffersAsString } from '../../utils/conversion'; import { useContext, useState } from 'react'; import EditIcon from '@mui/icons-material/Edit'; diff --git a/playground/vite.config.ts b/playground/vite.config.ts index a497d614a445..25906edaeb52 100644 --- a/playground/vite.config.ts +++ b/playground/vite.config.ts @@ -1,7 +1,7 @@ -import { defineConfig, loadEnv, searchForWorkspaceRoot } from "vite"; -import react from "@vitejs/plugin-react-swc"; -import { PolyfillOptions, nodePolyfills } from "vite-plugin-node-polyfills"; -import bundlesize from "vite-plugin-bundlesize"; +import { defineConfig, loadEnv, searchForWorkspaceRoot } from 'vite'; +import react from '@vitejs/plugin-react-swc'; +import { PolyfillOptions, nodePolyfills } from 'vite-plugin-node-polyfills'; +import bundlesize from 'vite-plugin-bundlesize'; // Only required for alternative bb wasm file, left as reference // import { viteStaticCopy } from "vite-plugin-static-copy"; @@ -13,10 +13,7 @@ const nodePolyfillsFix = (options?: PolyfillOptions | undefined): Plugin => { ...nodePolyfills(options), /* @ts-ignore */ resolveId(source: string) { - const m = - /^vite-plugin-node-polyfills\/shims\/(buffer|global|process)$/.exec( - source - ); + const m = /^vite-plugin-node-polyfills\/shims\/(buffer|global|process)$/.exec(source); if (m) { return `./node_modules/vite-plugin-node-polyfills/shims/${m[1]}/dist/index.cjs`; } @@ -26,30 +23,30 @@ const nodePolyfillsFix = (options?: PolyfillOptions | undefined): Plugin => { // https://vite.dev/config/ export default defineConfig(({ mode }) => { - const env = loadEnv(mode, process.cwd(), ""); + const env = loadEnv(mode, process.cwd(), ''); return { - logLevel: "error", + logLevel: 'error', server: { // Headers needed for bb WASM to work in multithreaded mode headers: { - "Cross-Origin-Opener-Policy": "same-origin", - "Cross-Origin-Embedder-Policy": "require-corp", + 'Cross-Origin-Opener-Policy': 'same-origin', + 'Cross-Origin-Embedder-Policy': 'require-corp', }, // Allow vite to serve files from these directories, since they are symlinked // These are the protocol circuit artifacts, noir WASMs and bb WASMs. fs: { allow: [ searchForWorkspaceRoot(process.cwd()), - "../yarn-project/noir-protocol-circuits-types/artifacts", - "../noir/packages/noirc_abi/web", - "../noir/packages/acvm_js/web", - "../barretenberg/ts/dest/browser", + '../yarn-project/noir-protocol-circuits-types/artifacts', + '../noir/packages/noirc_abi/web', + '../noir/packages/acvm_js/web', + '../barretenberg/ts/dest/browser', ], }, }, plugins: [ - react({ jsxImportSource: "@emotion/react" }), - nodePolyfillsFix({ include: ["buffer", "path"] }), + react({ jsxImportSource: '@emotion/react' }), + nodePolyfillsFix({ include: ['buffer', 'path'] }), // This is unnecessary unless BB_WASM_PATH is defined (default would be /assets/barretenberg.wasm.gz) // Left as an example of how to use a different bb wasm file than the default lazily loaded one // viteStaticCopy({ @@ -61,11 +58,11 @@ export default defineConfig(({ mode }) => { // ], // }), bundlesize({ - limits: [{ name: "assets/index-*", limit: "1900kB" }], + limits: [{ name: 'assets/index-*', limit: '1600kB' }], }), ], define: { - "process.env": JSON.stringify({ + 'process.env': JSON.stringify({ LOG_LEVEL: env.LOG_LEVEL, // The path to a custom WASM file for bb.js. // Only the single-threaded file name is needed, the multithreaded file name will be inferred @@ -76,7 +73,7 @@ export default defineConfig(({ mode }) => { }, build: { // Required by vite-plugin-bundle-size - sourcemap: "hidden", + sourcemap: 'hidden', }, }; }); diff --git a/yarn-project/aztec.js/src/api/abi.ts b/yarn-project/aztec.js/src/api/abi.ts index 8291aabae1ea..ecbab2520815 100644 --- a/yarn-project/aztec.js/src/api/abi.ts +++ b/yarn-project/aztec.js/src/api/abi.ts @@ -3,6 +3,13 @@ export { type FunctionArtifact, EventSelector, FunctionSelector, + NoteSelector, + type ABIParameter, + isAddressStruct, + isAztecAddressStruct, + isEthAddressStruct, + isWrappedFieldStruct, + isFunctionSelectorStruct, loadContractArtifact, contractArtifactToBuffer, contractArtifactFromBuffer, diff --git a/yarn-project/aztec.js/src/api/wallet.ts b/yarn-project/aztec.js/src/api/wallet.ts index edcf1b0f6e15..e43a5bddb55d 100644 --- a/yarn-project/aztec.js/src/api/wallet.ts +++ b/yarn-project/aztec.js/src/api/wallet.ts @@ -1,7 +1 @@ -export { - AccountWallet, - AccountWalletWithSecretKey as AccountWalletWithSecretKey, - SignerlessWallet, - type Wallet, - getWallet, -} from '../wallet/index.js'; +export { AccountWallet, AccountWalletWithSecretKey, SignerlessWallet, getWallet } from '../wallet/index.js'; diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 2da0faf02abf..05c13053691a 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -20,10 +20,6 @@ * TODO: Ultimately reimplement this mega exporter by mega exporting a granular api (then deprecate it). */ -export { NoteSelector } from '@aztec/stdlib/abi'; - -export { EthAddress } from '@aztec/foundation/eth-address'; - export { Fq, Fr, Point, GrumpkinScalar } from '@aztec/foundation/fields'; export { SiblingPath } from '@aztec/foundation/trees'; @@ -91,6 +87,7 @@ export * from './api/account.js'; export * from './api/addresses.js'; export * from './api/deployment.js'; export * from './api/ethereum.js'; +export * from './api/eth_address.js'; export * from './api/fee.js'; export * from './api/log.js'; export * from './api/contract.js'; From 5ed100d1b69729c4c50523fc04e32c7537dd3b15 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 7 Mar 2025 10:12:40 +0000 Subject: [PATCH 05/48] fixed docs, renaming --- docs/docs/developers/guides/js_apps/pay_fees.md | 2 +- yarn-project/pxe/src/entrypoints/client/bundle/index.ts | 2 +- yarn-project/pxe/src/entrypoints/client/lazy/index.ts | 2 +- yarn-project/pxe/src/entrypoints/server/index.ts | 2 +- .../pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts | 2 +- .../pxe_oracle_interface/{index.ts => pxe_oracle_interface.ts} | 0 yarn-project/pxe/src/pxe_service/pxe_service.ts | 2 +- 7 files changed, 6 insertions(+), 6 deletions(-) rename yarn-project/pxe/src/pxe_oracle_interface/{index.ts => pxe_oracle_interface.ts} (100%) diff --git a/docs/docs/developers/guides/js_apps/pay_fees.md b/docs/docs/developers/guides/js_apps/pay_fees.md index 53b846734ae7..920485bff762 100644 --- a/docs/docs/developers/guides/js_apps/pay_fees.md +++ b/docs/docs/developers/guides/js_apps/pay_fees.md @@ -79,7 +79,7 @@ After a user has sent fee juice from L1 to be bridged to L2, a transaction can b The claim object: -#include_code claim_type_amount yarn-project/aztec.js/src/api/ethereum/portal_manager.ts javascript +#include_code claim_type_amount yarn-project/aztec.js/src/ethereum/portal_manager.ts javascript Calling a function on an object (in this case checking the balance of the fee juice contract) diff --git a/yarn-project/pxe/src/entrypoints/client/bundle/index.ts b/yarn-project/pxe/src/entrypoints/client/bundle/index.ts index 3f4a339f0e71..46e26b7bd029 100644 --- a/yarn-project/pxe/src/entrypoints/client/bundle/index.ts +++ b/yarn-project/pxe/src/entrypoints/client/bundle/index.ts @@ -2,4 +2,4 @@ export * from '../../../pxe_service/index.js'; export * from '../../../config/index.js'; export * from '../../../storage/index.js'; export * from './utils.js'; -export { PXEOracleInterface } from '../../../pxe_oracle_interface/index.js'; +export { PXEOracleInterface } from '../../../pxe_oracle_interface/pxe_oracle_interface.js'; diff --git a/yarn-project/pxe/src/entrypoints/client/lazy/index.ts b/yarn-project/pxe/src/entrypoints/client/lazy/index.ts index 3f4a339f0e71..46e26b7bd029 100644 --- a/yarn-project/pxe/src/entrypoints/client/lazy/index.ts +++ b/yarn-project/pxe/src/entrypoints/client/lazy/index.ts @@ -2,4 +2,4 @@ export * from '../../../pxe_service/index.js'; export * from '../../../config/index.js'; export * from '../../../storage/index.js'; export * from './utils.js'; -export { PXEOracleInterface } from '../../../pxe_oracle_interface/index.js'; +export { PXEOracleInterface } from '../../../pxe_oracle_interface/pxe_oracle_interface.js'; diff --git a/yarn-project/pxe/src/entrypoints/server/index.ts b/yarn-project/pxe/src/entrypoints/server/index.ts index 05cc5088853b..aa939b193464 100644 --- a/yarn-project/pxe/src/entrypoints/server/index.ts +++ b/yarn-project/pxe/src/entrypoints/server/index.ts @@ -3,4 +3,4 @@ export * from '../../pxe_http/index.js'; export * from '../../config/index.js'; export * from '../../storage/index.js'; export * from './utils.js'; -export { PXEOracleInterface } from '../../pxe_oracle_interface/index.js'; +export { PXEOracleInterface } from '../../pxe_oracle_interface/pxe_oracle_interface.js'; diff --git a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts index a1e5e180c0d1..75c70306eadb 100644 --- a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts +++ b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts @@ -26,7 +26,7 @@ import { ContractDataProvider } from '../storage/contract_data_provider/contract import { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js'; import { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js'; import { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js'; -import { PXEOracleInterface } from './index.js'; +import { PXEOracleInterface } from './pxe_oracle_interface.js'; import { WINDOW_HALF_SIZE } from './tagging_utils.js'; const TXS_PER_BLOCK = 4; diff --git a/yarn-project/pxe/src/pxe_oracle_interface/index.ts b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts similarity index 100% rename from yarn-project/pxe/src/pxe_oracle_interface/index.ts rename to yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index f10fb2300e1e..ad6b30382118 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -71,7 +71,7 @@ import type { PXEServiceConfig } from '../config/index.js'; import { getPackageInfo } from '../config/package_info.js'; import { KernelOracle } from '../kernel_oracle/index.js'; import { KernelProver, type ProvingConfig } from '../kernel_prover/kernel_prover.js'; -import { PXEOracleInterface } from '../pxe_oracle_interface/index.js'; +import { PXEOracleInterface } from '../pxe_oracle_interface/pxe_oracle_interface.js'; import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js'; import { AuthWitnessDataProvider } from '../storage/auth_witness_data_provider/auth_witness_data_provider.js'; import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js'; From b11999fc39b0aff09fa191e8bae225b4632ecec1 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 7 Mar 2025 10:49:40 +0000 Subject: [PATCH 06/48] updated CODEOWNERS --- CODEOWNERS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CODEOWNERS b/CODEOWNERS index d0a03ed6eb87..fcdff07a0f8d 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -37,3 +37,6 @@ # on changes to the AVM transpiler /avm-transpiler/src @fcarreiro @dbanks12 ##################################################### + +# Notify fairies of changes to playground bundler config +/playground/vite.config.ts @Thunkar From a2b69dd01329daa8d990d0f4963da2cc2ca0ab59 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 7 Mar 2025 13:58:35 +0000 Subject: [PATCH 07/48] cleaner --- yarn-project/aztec.js/src/api/abi.ts | 4 ++++ yarn-project/aztec.js/src/api/contract.ts | 9 +++++++++ yarn-project/aztec.js/src/index.ts | 2 -- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/yarn-project/aztec.js/src/api/abi.ts b/yarn-project/aztec.js/src/api/abi.ts index ecbab2520815..202228406304 100644 --- a/yarn-project/aztec.js/src/api/abi.ts +++ b/yarn-project/aztec.js/src/api/abi.ts @@ -3,8 +3,12 @@ export { type FunctionArtifact, EventSelector, FunctionSelector, + FunctionCall, NoteSelector, type ABIParameter, + decodeFromAbi, + encodeArguments, + type AbiType, isAddressStruct, isAztecAddressStruct, isEthAddressStruct, diff --git a/yarn-project/aztec.js/src/api/contract.ts b/yarn-project/aztec.js/src/api/contract.ts index f9c41522a263..e128adf0e465 100644 --- a/yarn-project/aztec.js/src/api/contract.ts +++ b/yarn-project/aztec.js/src/api/contract.ts @@ -51,3 +51,12 @@ export { export { BatchCall } from '../contract/batch_call.js'; export { type DeployOptions, DeployMethod } from '../contract/deploy_method.js'; export { DeploySentTx } from '../contract/deploy_sent_tx.js'; + +export { + type PartialAddress, + type ContractClassWithId, + type ContractInstanceWithAddress, + getContractClassFromArtifact, + getContractInstanceFromDeployParams, + type NodeInfo, +} from '@aztec/stdlib/contract'; diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 05c13053691a..1b83e91b36b6 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -45,7 +45,6 @@ export { } from '@aztec/stdlib/keys'; export { AuthWitness } from '@aztec/stdlib/auth-witness'; export { getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers'; -export { FunctionCall } from '@aztec/stdlib/abi'; export { Tx, TxExecutionRequest, @@ -68,7 +67,6 @@ export { ProtocolContractAddress } from '@aztec/protocol-contracts'; // TODO: These kinds of things have no place on our public api. // External devs will almost certainly have their own methods of doing these things. // If we want to use them in our own "aztec.js consuming code", import them from foundation as needed. -export { decodeFromAbi, encodeArguments, type AbiType } from '@aztec/stdlib/abi'; export { toBigIntBE } from '@aztec/foundation/bigint-buffer'; export { sha256, Grumpkin, Schnorr } from '@aztec/foundation/crypto'; export { makeFetch } from '@aztec/foundation/json-rpc/client'; From 189439a9ce15221a9cbd846bbe172f99e7727a6d Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 7 Mar 2025 14:16:39 +0000 Subject: [PATCH 08/48] save file --- yarn-project/aztec.js/src/index.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 1b83e91b36b6..6f51e88a49c3 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -26,14 +26,6 @@ export { SiblingPath } from '@aztec/foundation/trees'; export { INITIAL_L2_BLOCK_NUM } from '@aztec/constants'; -export { - type PartialAddress, - type ContractClassWithId, - type ContractInstanceWithAddress, - getContractClassFromArtifact, - getContractInstanceFromDeployParams, - type NodeInfo, -} from '@aztec/stdlib/contract'; export { MerkleTreeId, merkleTreeIds } from '@aztec/stdlib/trees'; export { type PublicKey, PublicKeys } from '@aztec/stdlib/keys'; export { computeSecretHash } from '@aztec/stdlib/hash'; From 2d5bcf8432342e8551d4f660effaf5174578b174 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 10 Mar 2025 11:49:04 +0000 Subject: [PATCH 09/48] cleaner interfaces --- .../contract_tutorials/write_accounts_contract.md | 2 +- .../src/account/{contract.ts => account_contract.ts} | 0 yarn-project/aztec.js/src/account/index.ts | 3 +-- .../aztec.js/src/account_manager/deploy_account_method.ts | 2 +- .../src/account_manager/deploy_account_sent_tx.ts | 2 +- yarn-project/aztec.js/src/account_manager/index.ts | 6 +++--- yarn-project/aztec.js/src/api/account.ts | 1 - yarn-project/aztec.js/src/api/wallet.ts | 8 +++++++- .../aztec.js/src/contract/base_contract_interaction.ts | 2 +- yarn-project/aztec.js/src/contract/batch_call.ts | 2 +- yarn-project/aztec.js/src/contract/contract.test.ts | 2 +- yarn-project/aztec.js/src/contract/contract.ts | 2 +- yarn-project/aztec.js/src/contract/contract_base.ts | 2 +- .../src/contract/contract_function_interaction.ts | 2 +- yarn-project/aztec.js/src/contract/deploy_method.ts | 2 +- yarn-project/aztec.js/src/contract/deploy_proven_tx.ts | 2 +- yarn-project/aztec.js/src/contract/deploy_sent_tx.ts | 2 +- yarn-project/aztec.js/src/contract/protocol_contracts.ts | 2 +- yarn-project/aztec.js/src/contract/proven_tx.ts | 2 +- yarn-project/aztec.js/src/contract/unsafe_contract.ts | 2 +- yarn-project/aztec.js/src/deployment/contract_deployer.ts | 2 +- .../aztec.js/src/fee/private_fee_payment_method.ts | 2 +- yarn-project/aztec.js/src/wallet/base_wallet.ts | 2 +- yarn-project/aztec.js/src/wallet/index.ts | 4 ++-- yarn-project/aztec.js/src/{account => wallet}/wallet.ts | 2 +- 25 files changed, 32 insertions(+), 28 deletions(-) rename yarn-project/aztec.js/src/account/{contract.ts => account_contract.ts} (100%) rename yarn-project/aztec.js/src/{account => wallet}/wallet.ts (84%) diff --git a/docs/docs/developers/tutorials/codealong/contract_tutorials/write_accounts_contract.md b/docs/docs/developers/tutorials/codealong/contract_tutorials/write_accounts_contract.md index e6ce84af88f7..d283662446c2 100644 --- a/docs/docs/developers/tutorials/codealong/contract_tutorials/write_accounts_contract.md +++ b/docs/docs/developers/tutorials/codealong/contract_tutorials/write_accounts_contract.md @@ -69,7 +69,7 @@ A side-effect of not having nonces at the protocol level is that it is not possi Now that we have a valid account contract, we need to write the typescript glue code that will take care of formatting and authenticating transactions so they can be processed by our contract, as well as deploying the contract during account setup. This takes the form of implementing the `AccountContract` interface from `@aztec/aztec.js`: -#include_code account-contract-interface yarn-project/aztec.js/src/account/contract.ts typescript +#include_code account-contract-interface yarn-project/aztec.js/src/account/account_contract.ts typescript However, if you are using the default `AccountActions` module, then you can leverage the `DefaultAccountContract` class from `@aztec/accounts` and just implement the logic for generating an auth witness that matches the one you wrote in Noir: diff --git a/yarn-project/aztec.js/src/account/contract.ts b/yarn-project/aztec.js/src/account/account_contract.ts similarity index 100% rename from yarn-project/aztec.js/src/account/contract.ts rename to yarn-project/aztec.js/src/account/account_contract.ts diff --git a/yarn-project/aztec.js/src/account/index.ts b/yarn-project/aztec.js/src/account/index.ts index 8be941cdab46..cbb7bb572722 100644 --- a/yarn-project/aztec.js/src/account/index.ts +++ b/yarn-project/aztec.js/src/account/index.ts @@ -8,9 +8,8 @@ */ import type { Fr } from '@aztec/foundation/fields'; -export { type AccountContract, getAccountContractAddress } from './contract.js'; +export { type AccountContract, getAccountContractAddress } from './account_contract.js'; export { type AccountInterface, type AuthWitnessProvider } from './interface.js'; -export * from './wallet.js'; /** A contract deployment salt. */ export type Salt = Fr | number | bigint; diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 76fb1701ce31..820accc0941e 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -8,11 +8,11 @@ import { import type { PublicKeys } from '@aztec/stdlib/keys'; import type { AuthWitnessProvider } from '../account/interface.js'; -import type { Wallet } from '../account/wallet.js'; import type { ExecutionRequestInit } from '../api/entrypoint.js'; import { Contract } from '../contract/contract.js'; import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; import { EntrypointPayload, computeCombinedPayloadHash } from '../entrypoint/payload.js'; +import type { Wallet } from '../wallet/wallet.js'; /** * Contract interaction for deploying an account contract. Handles fee preparation and contract initialization. diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts index 57a23ef929bf..dbd6350d8976 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts @@ -2,8 +2,8 @@ import type { FieldsOf } from '@aztec/foundation/types'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { TxHash, TxReceipt } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/index.js'; import { DefaultWaitOpts, SentTx, type WaitOpts } from '../contract/sent_tx.js'; +import type { Wallet } from '../wallet/wallet.js'; /** Extends a transaction receipt with a wallet instance for the newly deployed contract. */ export type DeployAccountTxReceipt = FieldsOf & { diff --git a/yarn-project/aztec.js/src/account_manager/index.ts b/yarn-project/aztec.js/src/account_manager/index.ts index f642ea5d2264..fe1beeb44d73 100644 --- a/yarn-project/aztec.js/src/account_manager/index.ts +++ b/yarn-project/aztec.js/src/account_manager/index.ts @@ -4,14 +4,14 @@ import { getContractInstanceFromDeployParams } from '@aztec/stdlib/contract'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import { deriveKeys } from '@aztec/stdlib/keys'; -import type { AccountContract } from '../account/contract.js'; -import type { Salt, Wallet } from '../account/index.js'; +import type { AccountContract } from '../account/account_contract.js'; +import type { Salt } from '../account/index.js'; import type { AccountInterface } from '../account/interface.js'; import { Contract } from '../contract/contract.js'; import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; import { DefaultWaitOpts, type WaitOpts } from '../contract/sent_tx.js'; import { DefaultMultiCallEntrypoint } from '../entrypoint/default_multi_call_entrypoint.js'; -import { AccountWalletWithSecretKey, SignerlessWallet } from '../wallet/index.js'; +import { AccountWalletWithSecretKey, SignerlessWallet, type Wallet } from '../wallet/index.js'; import { DeployAccountMethod } from './deploy_account_method.js'; import { DeployAccountSentTx } from './deploy_account_sent_tx.js'; diff --git a/yarn-project/aztec.js/src/api/account.ts b/yarn-project/aztec.js/src/api/account.ts index d064159f05b9..f54471ad82b8 100644 --- a/yarn-project/aztec.js/src/api/account.ts +++ b/yarn-project/aztec.js/src/api/account.ts @@ -3,7 +3,6 @@ export { type AccountInterface, type AuthWitnessProvider, type Salt, - type Wallet, getAccountContractAddress, } from '../account/index.js'; diff --git a/yarn-project/aztec.js/src/api/wallet.ts b/yarn-project/aztec.js/src/api/wallet.ts index e43a5bddb55d..036591122943 100644 --- a/yarn-project/aztec.js/src/api/wallet.ts +++ b/yarn-project/aztec.js/src/api/wallet.ts @@ -1 +1,7 @@ -export { AccountWallet, AccountWalletWithSecretKey, SignerlessWallet, getWallet } from '../wallet/index.js'; +export { + AccountWallet, + AccountWalletWithSecretKey, + SignerlessWallet, + getWallet, + type Wallet, +} from '../wallet/index.js'; diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 1340329666b1..3a13dcd52235 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -3,10 +3,10 @@ import { createLogger } from '@aztec/foundation/log'; import { GasSettings } from '@aztec/stdlib/gas'; import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; import type { FeeOptions, UserFeeOptions } from '../entrypoint/payload.js'; import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; +import type { Wallet } from '../wallet/wallet.js'; import { getGasLimits } from './get_gas_limits.js'; import { ProvenTx } from './proven_tx.js'; import { SentTx } from './sent_tx.js'; diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 5cc860556e0b..3e53420729ee 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -1,7 +1,7 @@ import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; import type { SimulateMethodOptions } from './contract_function_interaction.js'; diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 48d50f2b07f0..8f96a12d7204 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -13,7 +13,7 @@ import type { Tx, TxExecutionRequest, TxHash, TxProvingResult, TxReceipt, TxSimu import { type MockProxy, mock } from 'jest-mock-extended'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import { Contract } from './contract.js'; describe('Contract Class', () => { diff --git a/yarn-project/aztec.js/src/contract/contract.ts b/yarn-project/aztec.js/src/contract/contract.ts index 61caeae78aa2..8cde44d81348 100644 --- a/yarn-project/aztec.js/src/contract/contract.ts +++ b/yarn-project/aztec.js/src/contract/contract.ts @@ -3,7 +3,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { getContractClassFromArtifact } from '@aztec/stdlib/contract'; import { PublicKeys } from '@aztec/stdlib/keys'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import { ContractBase } from './contract_base.js'; import { DeployMethod } from './deploy_method.js'; diff --git a/yarn-project/aztec.js/src/contract/contract_base.ts b/yarn-project/aztec.js/src/contract/contract_base.ts index 84fd3ba018f2..760c4c271d0c 100644 --- a/yarn-project/aztec.js/src/contract/contract_base.ts +++ b/yarn-project/aztec.js/src/contract/contract_base.ts @@ -7,7 +7,7 @@ import { } from '@aztec/stdlib/abi'; import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import { ContractFunctionInteraction } from './contract_function_interaction.js'; /** diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index a3404e20f88b..ef99d2eb734f 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -10,8 +10,8 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PrivateKernelProverProfileResult } from '@aztec/stdlib/kernel'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; +import type { Wallet } from '../wallet/wallet.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; export type { SendMethodOptions }; diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 0ecf3a7419fb..98f7230a7c6c 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -11,10 +11,10 @@ import type { GasSettings } from '@aztec/stdlib/gas'; import type { PublicKeys } from '@aztec/stdlib/keys'; import type { Capsule, TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; import { deployInstance } from '../deployment/deploy_instance.js'; import { registerContractClass } from '../deployment/register_class.js'; import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; +import type { Wallet } from '../wallet/wallet.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; import type { Contract } from './contract.js'; import type { ContractBase } from './contract_base.js'; diff --git a/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts b/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts index cf7151091524..9dee7d6e0bb8 100644 --- a/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts +++ b/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts @@ -3,7 +3,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { Tx } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import type { Contract } from './contract.js'; import { DeploySentTx } from './deploy_sent_tx.js'; import { ProvenTx } from './proven_tx.js'; diff --git a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts index 6ff89c1fb776..88834b0fe479 100644 --- a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts @@ -5,7 +5,7 @@ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client'; import type { TxHash, TxReceipt } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import type { Contract } from './contract.js'; import type { ContractBase } from './contract_base.js'; import { SentTx, type WaitOpts } from './sent_tx.js'; diff --git a/yarn-project/aztec.js/src/contract/protocol_contracts.ts b/yarn-project/aztec.js/src/contract/protocol_contracts.ts index a72d22c45d41..fb055ca879c1 100644 --- a/yarn-project/aztec.js/src/contract/protocol_contracts.ts +++ b/yarn-project/aztec.js/src/contract/protocol_contracts.ts @@ -1,6 +1,6 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import { UnsafeContract } from './unsafe_contract.js'; /** Returns a Contract wrapper for the class registerer. */ diff --git a/yarn-project/aztec.js/src/contract/proven_tx.ts b/yarn-project/aztec.js/src/contract/proven_tx.ts index dd30bb060060..1a73e59547ca 100644 --- a/yarn-project/aztec.js/src/contract/proven_tx.ts +++ b/yarn-project/aztec.js/src/contract/proven_tx.ts @@ -1,7 +1,7 @@ import type { PXE } from '@aztec/stdlib/interfaces/client'; import { Tx } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import { SentTx } from './sent_tx.js'; /** diff --git a/yarn-project/aztec.js/src/contract/unsafe_contract.ts b/yarn-project/aztec.js/src/contract/unsafe_contract.ts index 05174da334d1..1e127e23eb18 100644 --- a/yarn-project/aztec.js/src/contract/unsafe_contract.ts +++ b/yarn-project/aztec.js/src/contract/unsafe_contract.ts @@ -1,7 +1,7 @@ import type { ContractArtifact } from '@aztec/stdlib/abi'; import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; -import type { Wallet } from '../account/wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import { ContractBase } from './contract_base.js'; /** Unsafe constructor for ContractBase that bypasses the check that the instance is registered in the wallet. */ diff --git a/yarn-project/aztec.js/src/deployment/contract_deployer.ts b/yarn-project/aztec.js/src/deployment/contract_deployer.ts index 10567f04f0fc..6027516dc840 100644 --- a/yarn-project/aztec.js/src/deployment/contract_deployer.ts +++ b/yarn-project/aztec.js/src/deployment/contract_deployer.ts @@ -2,9 +2,9 @@ import type { ContractArtifact } from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { PublicKeys } from '@aztec/stdlib/keys'; -import type { Wallet } from '../account/wallet.js'; import { Contract } from '../contract/contract.js'; import { DeployMethod } from '../contract/deploy_method.js'; +import type { Wallet } from '../wallet/wallet.js'; /** * A class for deploying contract. diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index a4d0d6752f2b..3b59e59c8f6d 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -3,9 +3,9 @@ import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; -import type { Wallet } from '../account/wallet.js'; import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { SignerlessWallet } from '../wallet/signerless_wallet.js'; +import type { Wallet } from '../wallet/wallet.js'; import type { FeePaymentMethod } from './fee_payment_method.js'; /** diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index c6ef5b918609..bad227718d45 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -28,9 +28,9 @@ import type { TxSimulationResult, } from '@aztec/stdlib/tx'; -import type { Wallet } from '../account/wallet.js'; import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; +import type { Wallet } from './wallet.js'; /** * A base class for Wallet implementations diff --git a/yarn-project/aztec.js/src/wallet/index.ts b/yarn-project/aztec.js/src/wallet/index.ts index 367281979af9..78d5430d5b14 100644 --- a/yarn-project/aztec.js/src/wallet/index.ts +++ b/yarn-project/aztec.js/src/wallet/index.ts @@ -1,10 +1,10 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PXE } from '@aztec/stdlib/interfaces/client'; -import type { AccountContract } from '../account/contract.js'; +import type { AccountContract } from '../account/account_contract.js'; import { AccountWallet } from './account_wallet.js'; -export * from '../account/wallet.js'; +export * from './wallet.js'; export * from './account_wallet.js'; export * from './account_wallet_with_private_key.js'; export * from './signerless_wallet.js'; diff --git a/yarn-project/aztec.js/src/account/wallet.ts b/yarn-project/aztec.js/src/wallet/wallet.ts similarity index 84% rename from yarn-project/aztec.js/src/account/wallet.ts rename to yarn-project/aztec.js/src/wallet/wallet.ts index baf7f6231962..2da7130423dd 100644 --- a/yarn-project/aztec.js/src/account/wallet.ts +++ b/yarn-project/aztec.js/src/wallet/wallet.ts @@ -1,8 +1,8 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { PXE } from '@aztec/stdlib/interfaces/client'; +import type { AccountInterface } from '../account/interface.js'; import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; -import type { AccountInterface } from './interface.js'; /** * The wallet interface. From df29417c494a9c1d2e7b3d7ffd52dbd6ef72ea7d Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 11 Mar 2025 09:13:01 +0000 Subject: [PATCH 10/48] entrypoint cleanup --- .../aztec.js/src/account/interface.ts | 13 +-- .../account_manager/deploy_account_method.ts | 2 +- .../account_manager/deploy_account_sent_tx.ts | 6 +- yarn-project/aztec.js/src/api/entrypoint.ts | 2 +- yarn-project/aztec.js/src/api/fee.ts | 2 +- .../src/contract/base_contract_interaction.ts | 4 +- .../aztec.js/src/contract/deploy_method.ts | 2 +- .../aztec.js/src/contract/deploy_sent_tx.ts | 8 +- .../aztec.js/src/contract/proven_tx.ts | 3 +- yarn-project/aztec.js/src/contract/sent_tx.ts | 51 ++---------- .../default_multi_call_entrypoint.ts | 3 +- .../src/fee/fee_juice_payment_method.ts | 2 +- .../aztec.js/src/fee/fee_payment_method.ts | 22 ----- .../src/fee/private_fee_payment_method.ts | 2 +- .../src/fee/public_fee_payment_method.ts | 2 +- yarn-project/aztec.js/src/utils/authwit.ts | 31 +------ .../aztec.js/src/wallet/account_wallet.ts | 8 +- .../aztec.js/src/wallet/base_wallet.ts | 81 ++----------------- .../aztec.js/src/wallet/signerless_wallet.ts | 8 +- yarn-project/aztec.js/src/wallet/wallet.ts | 20 ++++- yarn-project/entrypoints/package.json | 5 +- .../entrypoints/src/account_entrypoint.ts | 14 ++-- .../entrypoints/src/dapp_entrypoint.ts | 19 +++-- .../src}/default_entrypoint.ts | 2 +- yarn-project/entrypoints/src/index.ts | 2 + .../src/interfaces.ts} | 34 +++++++- .../entrypoint => entrypoints/src}/payload.ts | 2 +- yarn-project/entrypoints/tsconfig.json | 3 - .../stdlib/src/auth_witness/auth_witness.ts | 29 +++++++ yarn-project/yarn.lock | 1 - 30 files changed, 141 insertions(+), 242 deletions(-) delete mode 100644 yarn-project/aztec.js/src/fee/fee_payment_method.ts rename yarn-project/{aztec.js/src/entrypoint => entrypoints/src}/default_entrypoint.ts (98%) rename yarn-project/{aztec.js/src/entrypoint/entrypoint.ts => entrypoints/src/interfaces.ts} (60%) rename yarn-project/{aztec.js/src/entrypoint => entrypoints/src}/payload.ts (99%) diff --git a/yarn-project/aztec.js/src/account/interface.ts b/yarn-project/aztec.js/src/account/interface.ts index 7d203d77ae81..74165393726a 100644 --- a/yarn-project/aztec.js/src/account/interface.ts +++ b/yarn-project/aztec.js/src/account/interface.ts @@ -1,20 +1,9 @@ +import type { AuthWitnessProvider, EntrypointInterface } from '@aztec/entrypoints/interfaces'; import type { Fr } from '@aztec/foundation/fields'; -import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { CompleteAddress } from '@aztec/stdlib/contract'; -import type { EntrypointInterface } from '../entrypoint/entrypoint.js'; - // docs:start:account-interface -/** Creates authorization witnesses. */ -export interface AuthWitnessProvider { - /** - * Computes an authentication witness from either a message hash - * @param messageHash - The message hash to approve - * @returns The authentication witness - */ - createAuthWit(messageHash: Fr | Buffer): Promise; -} /** * Handler for interfacing with an account. Knows how to create transaction execution diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 820accc0941e..ec8832b2fefd 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -7,11 +7,11 @@ import { } from '@aztec/stdlib/abi'; import type { PublicKeys } from '@aztec/stdlib/keys'; +import { EntrypointPayload, computeCombinedPayloadHash } from '../../../entrypoints/src/payload.js'; import type { AuthWitnessProvider } from '../account/interface.js'; import type { ExecutionRequestInit } from '../api/entrypoint.js'; import { Contract } from '../contract/contract.js'; import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; -import { EntrypointPayload, computeCombinedPayloadHash } from '../entrypoint/payload.js'; import type { Wallet } from '../wallet/wallet.js'; /** diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts index dbd6350d8976..a5dd7ddcd470 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts @@ -1,5 +1,5 @@ import type { FieldsOf } from '@aztec/foundation/types'; -import type { PXE } from '@aztec/stdlib/interfaces/client'; +import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client'; import type { TxHash, TxReceipt } from '@aztec/stdlib/tx'; import { DefaultWaitOpts, SentTx, type WaitOpts } from '../contract/sent_tx.js'; @@ -15,8 +15,8 @@ export type DeployAccountTxReceipt = FieldsOf & { * A deployment transaction for an account contract sent to the network, extending SentTx with methods to get the resulting wallet. */ export class DeployAccountSentTx extends SentTx { - constructor(pxe: PXE, txHashPromise: Promise, private getWalletPromise: Promise) { - super(pxe, txHashPromise); + constructor(node: AztecNode, txHashPromise: Promise, private getWalletPromise: Promise) { + super(node, txHashPromise); } /** diff --git a/yarn-project/aztec.js/src/api/entrypoint.ts b/yarn-project/aztec.js/src/api/entrypoint.ts index dbe8196c6ef5..53723125a4b8 100644 --- a/yarn-project/aztec.js/src/api/entrypoint.ts +++ b/yarn-project/aztec.js/src/api/entrypoint.ts @@ -1 +1 @@ -export * from '../entrypoint/entrypoint.js'; +export * from '../../../entrypoints/src/interfaces.js'; diff --git a/yarn-project/aztec.js/src/api/fee.ts b/yarn-project/aztec.js/src/api/fee.ts index 4bbb7bfa3960..fc3fa7894e95 100644 --- a/yarn-project/aztec.js/src/api/fee.ts +++ b/yarn-project/aztec.js/src/api/fee.ts @@ -1,4 +1,4 @@ -export type { FeePaymentMethod } from '../fee/fee_payment_method.js'; +export type { FeePaymentMethod } from '../../../entrypoints/src/fee_payment_method.js'; export { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; export { PrivateFeePaymentMethod } from '../fee/private_fee_payment_method.js'; export { PublicFeePaymentMethod } from '../fee/public_fee_payment_method.js'; diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 3a13dcd52235..281a1f44b8ec 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -3,8 +3,8 @@ import { createLogger } from '@aztec/foundation/log'; import { GasSettings } from '@aztec/stdlib/gas'; import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx'; -import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; -import type { FeeOptions, UserFeeOptions } from '../entrypoint/payload.js'; +import type { ExecutionRequestInit } from '../../../entrypoints/src/interfaces.js'; +import type { FeeOptions, UserFeeOptions } from '../../../entrypoints/src/payload.js'; import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; import type { Wallet } from '../wallet/wallet.js'; import { getGasLimits } from './get_gas_limits.js'; diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 98f7230a7c6c..253c67457d39 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -11,9 +11,9 @@ import type { GasSettings } from '@aztec/stdlib/gas'; import type { PublicKeys } from '@aztec/stdlib/keys'; import type { Capsule, TxExecutionRequest } from '@aztec/stdlib/tx'; +import type { ExecutionRequestInit } from '../../../entrypoints/src/interfaces.js'; import { deployInstance } from '../deployment/deploy_instance.js'; import { registerContractClass } from '../deployment/register_class.js'; -import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; import type { Wallet } from '../wallet/wallet.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; import type { Contract } from './contract.js'; diff --git a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts index 88834b0fe479..29f49644b56b 100644 --- a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts @@ -29,7 +29,7 @@ export class DeploySentTx extends SentTx private log = createLogger('aztecjs:deploy_sent_tx'); constructor( - pxeOrWallet: PXE | Wallet, + pxeOrWallet: Wallet, txHashPromise: Promise, private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise, /** A getter for the deployed contract instance */ @@ -62,9 +62,9 @@ export class DeploySentTx extends SentTx } protected async getContractObject(wallet?: Wallet): Promise { - const isWallet = (pxeOrWallet: PXE | Wallet | AztecNode): pxeOrWallet is Wallet => - !!(pxeOrWallet as Wallet).createTxExecutionRequest; - const contractWallet = wallet ?? (isWallet(this.pxeOrNode) && this.pxeOrNode); + const isWallet = (walletOrNode: Wallet | AztecNode): walletOrNode is Wallet => + !!(walletOrNode as Wallet).createTxExecutionRequest; + const contractWallet = wallet ?? (isWallet(this.walletOrNode) && this.walletOrNode); if (!contractWallet) { throw new Error(`A wallet is required for creating a contract instance`); } diff --git a/yarn-project/aztec.js/src/contract/proven_tx.ts b/yarn-project/aztec.js/src/contract/proven_tx.ts index 1a73e59547ca..b31baaa47953 100644 --- a/yarn-project/aztec.js/src/contract/proven_tx.ts +++ b/yarn-project/aztec.js/src/contract/proven_tx.ts @@ -1,4 +1,3 @@ -import type { PXE } from '@aztec/stdlib/interfaces/client'; import { Tx } from '@aztec/stdlib/tx'; import type { Wallet } from '../wallet/wallet.js'; @@ -8,7 +7,7 @@ import { SentTx } from './sent_tx.js'; * A proven transaction that can be sent to the network. Returned by the `prove` method of a contract interaction. */ export class ProvenTx extends Tx { - constructor(protected wallet: PXE | Wallet, tx: Tx) { + constructor(protected wallet: Wallet, tx: Tx) { super( tx.data, tx.clientIvcProof, diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 86e21b48f530..5e3f01f163ee 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -1,8 +1,10 @@ import { retryUntil } from '@aztec/foundation/retry'; import type { FieldsOf } from '@aztec/foundation/types'; -import type { AztecNode, GetPublicLogsResponse, PXE } from '@aztec/stdlib/interfaces/client'; +import type { AztecNode } from '@aztec/stdlib/interfaces/client'; import { type TxHash, type TxReceipt, TxStatus } from '@aztec/stdlib/tx'; +import type { Wallet } from '../wallet/wallet.js'; + /** Options related to waiting for a tx. */ export type WaitOpts = { /** The amount of time to ignore TxStatus.DROPPED receipts (in seconds) due to the presumption that it is being propagated by the p2p network. Defaults to 5. */ @@ -13,10 +15,6 @@ export type WaitOpts = { provenTimeout?: number; /** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */ interval?: number; - /** Whether to wait for the tx to be proven. */ - proven?: boolean; - /** Whether to include information useful for debugging/testing in the receipt. */ - debug?: boolean; /** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */ dontThrowOnRevert?: boolean; }; @@ -24,9 +22,7 @@ export type WaitOpts = { export const DefaultWaitOpts: WaitOpts = { ignoreDroppedReceiptsFor: 5, timeout: 60, - provenTimeout: 600, interval: 1, - debug: false, }; /** @@ -34,7 +30,7 @@ export const DefaultWaitOpts: WaitOpts = { * its hash, receipt, and mining status. */ export class SentTx { - constructor(protected pxeOrNode: PXE | AztecNode, protected txHashPromise: Promise) {} + constructor(protected walletOrNode: Wallet | AztecNode, protected txHashPromise: Promise) {} /** * Retrieves the transaction hash of the SentTx instance. @@ -56,7 +52,7 @@ export class SentTx { */ public async getReceipt(): Promise { const txHash = await this.getTxHash(); - return await this.pxeOrNode.getTxReceipt(txHash); + return await this.walletOrNode.getTxReceipt(txHash); } /** @@ -71,32 +67,9 @@ export class SentTx { `Transaction ${await this.getTxHash()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`, ); } - if (opts?.proven && receipt.blockNumber !== undefined) { - await this.waitForProven(receipt.blockNumber, opts); - } - if (opts?.debug) { - const txHash = await this.getTxHash(); - const { data: tx } = (await this.pxeOrNode.getTxEffect(txHash))!; - receipt.debugInfo = { - noteHashes: tx.noteHashes, - nullifiers: tx.nullifiers, - publicDataWrites: tx.publicDataWrites, - l2ToL1Msgs: tx.l2ToL1Msgs, - }; - } return receipt; } - /** - * Gets public logs emitted by this tx. - * @remarks This function will wait for the tx to be mined if it hasn't been already. - * @returns The requested logs. - */ - public async getPublicLogs(): Promise { - await this.wait(); - return this.pxeOrNode.getPublicLogs({ txHash: await this.getTxHash() }); - } - protected async waitForReceipt(opts?: WaitOpts): Promise { const txHash = await this.getTxHash(); const startTime = Date.now(); @@ -104,7 +77,7 @@ export class SentTx { return await retryUntil( async () => { - const txReceipt = await this.pxeOrNode.getTxReceipt(txHash); + const txReceipt = await this.walletOrNode.getTxReceipt(txHash); // If receipt is not yet available, try again if (txReceipt.status === TxStatus.PENDING) { return undefined; @@ -126,16 +99,4 @@ export class SentTx { opts?.interval ?? DefaultWaitOpts.interval, ); } - - protected async waitForProven(minedBlock: number, opts?: WaitOpts) { - return await retryUntil( - async () => { - const provenBlock = await this.pxeOrNode.getProvenBlockNumber(); - return provenBlock >= minedBlock ? provenBlock : undefined; - }, - 'isProven', - opts?.provenTimeout ?? DefaultWaitOpts.provenTimeout, - opts?.interval ?? DefaultWaitOpts.interval, - ); - } } diff --git a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts index 27a57eff38f4..963974560184 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts @@ -1,10 +1,9 @@ +import { type EntrypointInterface, EntrypointPayload, type ExecutionRequestInit } from '@aztec/entrypoints'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; -import { type EntrypointInterface, EntrypointPayload, type ExecutionRequestInit } from './entrypoint.js'; - /** * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction */ diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts index 1dc32d1bda51..a64876891fef 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts @@ -2,7 +2,7 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { FunctionCall } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; -import type { FeePaymentMethod } from './fee_payment_method.js'; +import type { FeePaymentMethod } from '../../../entrypoints/src/fee_payment_method.js'; // docs:start:fee_juice_method /** diff --git a/yarn-project/aztec.js/src/fee/fee_payment_method.ts b/yarn-project/aztec.js/src/fee/fee_payment_method.ts deleted file mode 100644 index a2d89370a51b..000000000000 --- a/yarn-project/aztec.js/src/fee/fee_payment_method.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { FunctionCall } from '@aztec/stdlib/abi'; -import type { AztecAddress } from '@aztec/stdlib/aztec-address'; -import type { GasSettings } from '@aztec/stdlib/gas'; - -/** - * Holds information about how the fee for a transaction is to be paid. - */ -export interface FeePaymentMethod { - /** The asset used to pay the fee. */ - getAsset(): Promise; - /** - * Creates a function call to pay the fee in the given asset. - * @param gasSettings - The gas limits and max fees. - * @returns The function call to pay the fee. - */ - getFunctionCalls(gasSettings: GasSettings): Promise; - /** - * The expected fee payer for this tx. - * @param gasSettings - The gas limits and max fees. - */ - getFeePayer(gasSettings: GasSettings): Promise; -} diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index 3b59e59c8f6d..5aa1ea299fb0 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -3,10 +3,10 @@ import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; +import type { FeePaymentMethod } from '../../../entrypoints/src/fee_payment_method.js'; import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { SignerlessWallet } from '../wallet/signerless_wallet.js'; import type { Wallet } from '../wallet/wallet.js'; -import type { FeePaymentMethod } from './fee_payment_method.js'; /** * Holds information about how the fee for a transaction is to be paid. diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index 8acae43925ac..2d74af9cd4c0 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -4,10 +4,10 @@ import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; +import type { FeePaymentMethod } from '../../../entrypoints/src/fee_payment_method.js'; import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import type { AccountWallet } from '../wallet/account_wallet.js'; import { SignerlessWallet } from '../wallet/signerless_wallet.js'; -import type { FeePaymentMethod } from './fee_payment_method.js'; /** * Holds information about how the fee for a transaction is to be paid. diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index bc695f642e6a..850445bcc996 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -2,6 +2,7 @@ import { GeneratorIndex } from '@aztec/constants'; import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import type { FunctionCall } from '@aztec/stdlib/abi'; +import { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues } from '@aztec/stdlib/tx'; @@ -78,33 +79,3 @@ export const computeInnerAuthWitHashFromAction = async (caller: AztecAddress, ac action.selector.toField(), (await HashedValues.fromValues(action.args)).hash, ]); - -/** - * Compute the inner hash for an authentication witness. - * This is the "intent" of the message, before siloed with the consumer. - * It is used as part of the `computeAuthWitMessageHash` but can also be used - * in case the message is not a "call" to a function, but arbitrary data. - * @param args - The arguments to hash - * @returns The inner hash for the witness - */ -export const computeInnerAuthWitHash = (args: Fr[]) => { - return poseidon2HashWithSeparator(args, GeneratorIndex.AUTHWIT_INNER); -}; - -/** - * Compute the outer hash for an authentication witness. - * This is the value siloed with its "consumer" and what the `on_behalf_of` - * should be signing. - * The consumer is who will be consuming the message, for token approvals it - * is the token contract itself (because the token makes the call to check the approval). - * It is used as part of the `computeAuthWitMessageHash` but can also be used - * in case the message is not a "call" to a function, but arbitrary data. - * @param consumer - The address that can "consume" the authwit - * @param chainId - The chain id that can "consume" the authwit - * @param version - The version that can "consume" the authwit - * @param innerHash - The inner hash for the witness - * @returns The outer hash for the witness - */ -const computeOuterAuthWitHash = (consumer: AztecAddress, chainId: Fr, version: Fr, innerHash: Fr) => { - return poseidon2HashWithSeparator([consumer.toField(), chainId, version, innerHash], GeneratorIndex.AUTHWIT_OUTER); -}; diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 55983f9322ea..75be40509e16 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -8,7 +8,7 @@ import type { TxExecutionRequest } from '@aztec/stdlib/tx'; import type { AccountInterface } from '../account/interface.js'; import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; -import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; +import type { ExecutionRequestInit } from '../entrypoint/interfaces.js'; import { type IntentAction, type IntentInnerHash, @@ -37,10 +37,6 @@ export class AccountWallet extends BaseWallet { return this.account.getVersion(); } - override isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise { - return this.pxe.isL1ToL2MessageSynced(l1ToL2Message); - } - /** * Computes an authentication witness from either a message hash or an intent. * @@ -150,7 +146,7 @@ export class AccountWallet extends BaseWallet { const results = { isValidInPrivate: false, isValidInPublic: false }; // Check private - const witness = await this.getAuthWitness(messageHash); + const witness = await this.pxe.getAuthWitness(messageHash); if (witness !== undefined) { results.isValidInPrivate = (await new ContractFunctionInteraction(this, onBehalfOf, this.getLookupValidityAbi(), [ consumer, diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index bad227718d45..e25272834d15 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -28,7 +28,7 @@ import type { TxSimulationResult, } from '@aztec/stdlib/tx'; -import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js'; +import type { ExecutionRequestInit } from '../../../entrypoints/src/interfaces.js'; import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; import type { Wallet } from './wallet.js'; @@ -38,8 +38,6 @@ import type { Wallet } from './wallet.js'; export abstract class BaseWallet implements Wallet { constructor(protected readonly pxe: PXE, private scopes?: AztecAddress[]) {} - abstract isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise; - abstract getCompleteAddress(): CompleteAddress; abstract getChainId(): Fr; @@ -50,26 +48,10 @@ export abstract class BaseWallet implements Wallet { abstract createAuthWit(intent: Fr | Buffer | IntentInnerHash | IntentAction): Promise; - setScopes(scopes: AztecAddress[]) { - this.scopes = scopes; - } - - getScopes() { - return this.scopes; - } - getAddress() { return this.getCompleteAddress().address; } - storeCapsule(contract: AztecAddress, storageSlot: Fr, capsule: Fr[]): Promise { - return this.pxe.storeCapsule(contract, storageSlot, capsule); - } - registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise { - return this.pxe.registerAccount(secretKey, partialAddress); - } - getRegisteredAccounts(): Promise { - return this.pxe.getRegisteredAccounts(); - } + registerSender(address: AztecAddress): Promise { return this.pxe.registerSender(address); } @@ -91,9 +73,6 @@ export abstract class BaseWallet implements Wallet { updateContract(contractAddress: AztecAddress, artifact: ContractArtifact): Promise { return this.pxe.updateContract(contractAddress, artifact); } - getContracts(): Promise { - return this.pxe.getContracts(); - } proveTx(txRequest: TxExecutionRequest, privateExecutionResult: PrivateExecutionResult): Promise { return this.pxe.proveTx(txRequest, privateExecutionResult); } @@ -118,21 +97,6 @@ export abstract class BaseWallet implements Wallet { sendTx(tx: Tx): Promise { return this.pxe.sendTx(tx); } - getTxEffect(txHash: TxHash) { - return this.pxe.getTxEffect(txHash); - } - getTxReceipt(txHash: TxHash): Promise { - return this.pxe.getTxReceipt(txHash); - } - getNotes(filter: NotesFilter): Promise { - return this.pxe.getNotes(filter); - } - getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise { - return this.pxe.getPublicStorageAt(contract, storageSlot); - } - getBlock(number: number): Promise { - return this.pxe.getBlock(number); - } getCurrentBaseFees(): Promise { return this.pxe.getCurrentBaseFees(); } @@ -144,27 +108,9 @@ export abstract class BaseWallet implements Wallet { ): Promise { return this.pxe.simulateUnconstrained(functionName, args, to, from); } - getPublicLogs(filter: LogFilter): Promise { - return this.pxe.getPublicLogs(filter); - } - getContractClassLogs(filter: LogFilter): Promise { - return this.pxe.getContractClassLogs(filter); - } - getBlockNumber(): Promise { - return this.pxe.getBlockNumber(); - } - getProvenBlockNumber(): Promise { - return this.pxe.getProvenBlockNumber(); - } getNodeInfo(): Promise { return this.pxe.getNodeInfo(); } - addAuthWitness(authWitness: AuthWitness) { - return this.pxe.addAuthWitness(authWitness); - } - getAuthWitness(messageHash: Fr) { - return this.pxe.getAuthWitness(messageHash); - } getPXEInfo(): Promise { return this.pxe.getPXEInfo(); } @@ -174,25 +120,8 @@ export abstract class BaseWallet implements Wallet { getContractMetadata(address: AztecAddress): Promise { return this.pxe.getContractMetadata(address); } - getPrivateEvents( - event: EventMetadataDefinition, - from: number, - limit: number, - vpks: Point[] = [this.getCompleteAddress().publicKeys.masterIncomingViewingPublicKey], - ): Promise { - return this.pxe.getPrivateEvents(event, from, limit, vpks); - } - getPublicEvents(event: EventMetadataDefinition, from: number, limit: number): Promise { - return this.pxe.getPublicEvents(event, from, limit); - } - public getL1ToL2MembershipWitness( - contractAddress: AztecAddress, - messageHash: Fr, - secret: Fr, - ): Promise<[bigint, SiblingPath]> { - return this.pxe.getL1ToL2MembershipWitness(contractAddress, messageHash, secret); - } - getL2ToL1MembershipWitness(blockNumber: number, l2Tol1Message: Fr): Promise<[bigint, SiblingPath]> { - return this.pxe.getL2ToL1MembershipWitness(blockNumber, l2Tol1Message); + + getTxReceipt(txHash: TxHash): Promise { + return this.pxe.getTxReceipt(txHash); } } diff --git a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts index 022d2052604f..b3d9fbf8370a 100644 --- a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts @@ -1,11 +1,11 @@ +import { DefaultEntrypoint } from '@aztec/entrypoints'; +import type { EntrypointInterface, ExecutionRequestInit } from '@aztec/entrypoints'; import type { Fr } from '@aztec/foundation/fields'; import { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { CompleteAddress } from '@aztec/stdlib/contract'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; -import { DefaultEntrypoint } from '../entrypoint/default_entrypoint.js'; -import type { EntrypointInterface, ExecutionRequestInit } from '../entrypoint/entrypoint.js'; import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; import { BaseWallet } from './base_wallet.js'; @@ -45,8 +45,4 @@ export class SignerlessWallet extends BaseWallet { createAuthWit(_intent: Fr | Buffer | IntentInnerHash | IntentAction): Promise { throw new Error('SignerlessWallet: Method createAuthWit not implemented.'); } - - override isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise { - return this.pxe.isL1ToL2MessageSynced(l1ToL2Message); - } } diff --git a/yarn-project/aztec.js/src/wallet/wallet.ts b/yarn-project/aztec.js/src/wallet/wallet.ts index 2da7130423dd..431b6817f499 100644 --- a/yarn-project/aztec.js/src/wallet/wallet.ts +++ b/yarn-project/aztec.js/src/wallet/wallet.ts @@ -8,6 +8,24 @@ import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; * The wallet interface. */ export type Wallet = AccountInterface & - PXE & { + Pick< + PXE, + | 'simulateTx' + | 'simulateUnconstrained' + | 'sendTx' + | 'getContractClassMetadata' + | 'getContractMetadata' + | 'registerContract' + | 'registerContractClass' + | 'proveTx' + | 'getNodeInfo' + | 'getPXEInfo' + | 'getCurrentBaseFees' + | 'updateContract' + | 'registerSender' + | 'getSenders' + | 'removeSender' + | 'getTxReceipt' + > & { createAuthWit(intent: IntentInnerHash | IntentAction): Promise; }; diff --git a/yarn-project/entrypoints/package.json b/yarn-project/entrypoints/package.json index df2c974f785f..8ebf31356ac2 100644 --- a/yarn-project/entrypoints/package.json +++ b/yarn-project/entrypoints/package.json @@ -6,7 +6,9 @@ "type": "module", "exports": { "./dapp": "./dest/dapp_entrypoint.js", - "./account": "./dest/account_entrypoint.js" + "./account": "./dest/account_entrypoint.js", + "./default": "./dest/default_entrypoint.js", + "./interfaces": "./dest/interfaces.js" }, "typedocOptions": { "entryPoints": [ @@ -61,7 +63,6 @@ ] }, "dependencies": { - "@aztec/aztec.js": "workspace:^", "@aztec/foundation": "workspace:^", "@aztec/protocol-contracts": "workspace:^", "@aztec/stdlib": "workspace:^", diff --git a/yarn-project/entrypoints/src/account_entrypoint.ts b/yarn-project/entrypoints/src/account_entrypoint.ts index 8759ee73cff4..70c15d350f31 100644 --- a/yarn-project/entrypoints/src/account_entrypoint.ts +++ b/yarn-project/entrypoints/src/account_entrypoint.ts @@ -1,15 +1,15 @@ -import type { AuthWitnessProvider } from '@aztec/aztec.js/account'; -import { - type EntrypointInterface, - EntrypointPayload, - type ExecutionRequestInit, - computeCombinedPayloadHash, -} from '@aztec/aztec.js/entrypoint'; import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; +import { + type AuthWitnessProvider, + type EntrypointInterface, + EntrypointPayload, + type ExecutionRequestInit, + computeCombinedPayloadHash, +} from './interfaces.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index 4864f50fcc84..61821524ecc6 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -1,11 +1,16 @@ -import { Fr, computeAuthWitMessageHash, computeInnerAuthWitHash } from '@aztec/aztec.js'; -import type { AuthWitnessProvider } from '@aztec/aztec.js/account'; -import { type EntrypointInterface, EntrypointPayload, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint'; +import { Fr } from '@aztec/foundation/fields'; import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi'; +import { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; +import { + type AuthWitnessProvider, + type EntrypointInterface, + EntrypointPayload, + type ExecutionRequestInit, +} from './interfaces.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature @@ -37,9 +42,11 @@ export class DefaultDappEntrypoint implements EntrypointInterface { functionSelector.toField(), entrypointHashedArgs.hash, ]); - const outerHash = await computeAuthWitMessageHash( - { consumer: this.dappEntrypointAddress, innerHash }, - { chainId: new Fr(this.chainId), version: new Fr(this.version) }, + const outerHash = await computeOuterAuthWitHash( + this.dappEntrypointAddress, + new Fr(this.chainId), + new Fr(this.version), + innerHash, ); const authWitness = await this.userAuthWitnessProvider.createAuthWit(outerHash); diff --git a/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts b/yarn-project/entrypoints/src/default_entrypoint.ts similarity index 98% rename from yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts rename to yarn-project/entrypoints/src/default_entrypoint.ts index 8523a385790c..87dfe77221e9 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts +++ b/yarn-project/entrypoints/src/default_entrypoint.ts @@ -1,7 +1,7 @@ import { FunctionType } from '@aztec/stdlib/abi'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { EntrypointInterface, ExecutionRequestInit } from './entrypoint.js'; +import type { EntrypointInterface, ExecutionRequestInit } from './interfaces.js'; /** * Default implementation of the entrypoint interface. It calls a function on a contract directly diff --git a/yarn-project/entrypoints/src/index.ts b/yarn-project/entrypoints/src/index.ts index fb1c0fedaba8..77c4e3706b8d 100644 --- a/yarn-project/entrypoints/src/index.ts +++ b/yarn-project/entrypoints/src/index.ts @@ -8,3 +8,5 @@ export * from './account_entrypoint.js'; export * from './dapp_entrypoint.js'; +export * from './interfaces.js'; +export * from './default_entrypoint.js'; diff --git a/yarn-project/aztec.js/src/entrypoint/entrypoint.ts b/yarn-project/entrypoints/src/interfaces.ts similarity index 60% rename from yarn-project/aztec.js/src/entrypoint/entrypoint.ts rename to yarn-project/entrypoints/src/interfaces.ts index a43caf342e0a..4a44c0412aa1 100644 --- a/yarn-project/aztec.js/src/entrypoint/entrypoint.ts +++ b/yarn-project/entrypoints/src/interfaces.ts @@ -1,15 +1,14 @@ import type { Fr } from '@aztec/foundation/fields'; import type { FunctionCall } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; +import type { AztecAddress } from '@aztec/stdlib/aztec-address'; +import type { GasSettings } from '@aztec/stdlib/gas'; import type { Capsule, HashedValues, TxExecutionRequest } from '@aztec/stdlib/tx'; import { EntrypointPayload, type FeeOptions, computeCombinedPayloadHash } from './payload.js'; export { EntrypointPayload, type FeeOptions, computeCombinedPayloadHash }; -export { DefaultEntrypoint } from './default_entrypoint.js'; -export { DefaultMultiCallEntrypoint } from './default_multi_call_entrypoint.js'; - /** Encodes the calls to be done in a transaction. */ export type ExecutionRequestInit = { /** The function calls to be executed. */ @@ -37,3 +36,32 @@ export interface EntrypointInterface { */ createTxExecutionRequest(execution: ExecutionRequestInit): Promise; } + +/** Creates authorization witnesses. */ +export interface AuthWitnessProvider { + /** + * Computes an authentication witness from either a message hash + * @param messageHash - The message hash to approve + * @returns The authentication witness + */ + createAuthWit(messageHash: Fr | Buffer): Promise; +} + +/** + * Holds information about how the fee for a transaction is to be paid. + */ +export interface FeePaymentMethod { + /** The asset used to pay the fee. */ + getAsset(): Promise; + /** + * Creates a function call to pay the fee in the given asset. + * @param gasSettings - The gas limits and max fees. + * @returns The function call to pay the fee. + */ + getFunctionCalls(gasSettings: GasSettings): Promise; + /** + * The expected fee payer for this tx. + * @param gasSettings - The gas limits and max fees. + */ + getFeePayer(gasSettings: GasSettings): Promise; +} diff --git a/yarn-project/aztec.js/src/entrypoint/payload.ts b/yarn-project/entrypoints/src/payload.ts similarity index 99% rename from yarn-project/aztec.js/src/entrypoint/payload.ts rename to yarn-project/entrypoints/src/payload.ts index 8e75d7e7aa9b..31de8175321e 100644 --- a/yarn-project/aztec.js/src/entrypoint/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -9,7 +9,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; import { HashedValues } from '@aztec/stdlib/tx'; -import type { FeePaymentMethod } from '../fee/fee_payment_method.js'; +import type { FeePaymentMethod } from './interfaces.js'; /** * Fee payment options for a transaction. diff --git a/yarn-project/entrypoints/tsconfig.json b/yarn-project/entrypoints/tsconfig.json index 4f123bda041a..f95bf43c8387 100644 --- a/yarn-project/entrypoints/tsconfig.json +++ b/yarn-project/entrypoints/tsconfig.json @@ -6,9 +6,6 @@ "tsBuildInfoFile": ".tsbuildinfo" }, "references": [ - { - "path": "../aztec.js" - }, { "path": "../foundation" }, diff --git a/yarn-project/stdlib/src/auth_witness/auth_witness.ts b/yarn-project/stdlib/src/auth_witness/auth_witness.ts index b834228eb7ba..7fcce7c274d8 100644 --- a/yarn-project/stdlib/src/auth_witness/auth_witness.ts +++ b/yarn-project/stdlib/src/auth_witness/auth_witness.ts @@ -1,7 +1,10 @@ +import { GeneratorIndex } from '@aztec/constants'; +import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; +import type { AztecAddress } from '../aztec-address/index.js'; import { hexSchemaFor } from '../schemas/schemas.js'; import { Vector } from '../types/shared.js'; @@ -50,3 +53,29 @@ export class AuthWitness { return new AuthWitness(Fr.random(), [Fr.random(), Fr.random(), Fr.random()]); } } + +/** + * Compute the inner hash for an authentication witness. + * This is the "intent" of the message, before siloed with the consumer. + * @param args - The arguments to hash + * @returns The inner hash for the witness + */ +export const computeInnerAuthWitHash = (args: Fr[]) => { + return poseidon2HashWithSeparator(args, GeneratorIndex.AUTHWIT_INNER); +}; + +/** + * Compute the outer hash for an authentication witness. + * This is the value siloed with its "consumer" and what the `on_behalf_of` + * should be signing. + * The consumer is who will be consuming the message, for token approvals it + * is the token contract itself (because the token makes the call to check the approval). + * @param consumer - The address that can "consume" the authwit + * @param chainId - The chain id that can "consume" the authwit + * @param version - The version that can "consume" the authwit + * @param innerHash - The inner hash for the witness + * @returns The outer hash for the witness + */ +export const computeOuterAuthWitHash = (consumer: AztecAddress, chainId: Fr, version: Fr, innerHash: Fr) => { + return poseidon2HashWithSeparator([consumer.toField(), chainId, version, innerHash], GeneratorIndex.AUTHWIT_OUTER); +}; diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 9be881a44307..2484096246a5 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -645,7 +645,6 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/entrypoints@workspace:entrypoints" dependencies: - "@aztec/aztec.js": "workspace:^" "@aztec/foundation": "workspace:^" "@aztec/protocol-contracts": "workspace:^" "@aztec/stdlib": "workspace:^" From f8164872fab9bd67667932a3b1d8a963e3a78d63 Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 11 Mar 2025 14:06:54 +0000 Subject: [PATCH 11/48] wip --- .../aztec.js/src/account/account_contract.ts | 3 +- yarn-project/aztec.js/src/account/index.ts | 2 +- .../account_manager/deploy_account_method.ts | 4 +- .../account_manager/deploy_account_sent_tx.ts | 4 +- yarn-project/aztec.js/src/api/account.ts | 9 +-- yarn-project/aztec.js/src/api/entrypoint.ts | 1 - yarn-project/aztec.js/src/api/fee.ts | 2 +- yarn-project/aztec.js/src/api/utils.ts | 2 +- .../src/contract/base_contract_interaction.ts | 3 +- .../aztec.js/src/contract/batch_call.ts | 3 +- .../aztec.js/src/contract/contract.test.ts | 1 - .../aztec.js/src/contract/deploy_method.ts | 3 +- .../aztec.js/src/contract/deploy_sent_tx.ts | 6 +- yarn-project/aztec.js/src/contract/sent_tx.ts | 8 +-- .../default_multi_call_entrypoint.ts | 3 +- .../src/fee/fee_juice_payment_method.ts | 3 +- .../src/fee/private_fee_payment_method.ts | 56 +++++++--------- .../src/fee/public_fee_payment_method.ts | 66 ++++++++----------- yarn-project/aztec.js/src/fee/utils.ts | 26 ++++++++ yarn-project/aztec.js/src/utils/authwit.ts | 2 - .../aztec.js/src/wallet/account_wallet.ts | 2 +- .../aztec.js/src/wallet/base_wallet.ts | 21 ++---- .../aztec.js/src/wallet/signerless_wallet.ts | 4 +- yarn-project/entrypoints/package.json | 4 +- .../entrypoints/src/account_entrypoint.ts | 10 +-- .../entrypoints/src/dapp_entrypoint.ts | 8 +-- yarn-project/entrypoints/src/index.ts | 1 + yarn-project/entrypoints/src/interfaces.ts | 52 ++++++++------- yarn-project/entrypoints/src/payload.ts | 50 +------------- yarn-project/entrypoints/src/utils.ts | 43 ++++++++++++ 30 files changed, 194 insertions(+), 208 deletions(-) delete mode 100644 yarn-project/aztec.js/src/api/entrypoint.ts create mode 100644 yarn-project/aztec.js/src/fee/utils.ts create mode 100644 yarn-project/entrypoints/src/utils.ts diff --git a/yarn-project/aztec.js/src/account/account_contract.ts b/yarn-project/aztec.js/src/account/account_contract.ts index 63df16c3746d..ad30e82481f5 100644 --- a/yarn-project/aztec.js/src/account/account_contract.ts +++ b/yarn-project/aztec.js/src/account/account_contract.ts @@ -1,10 +1,11 @@ +import type { AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import type { ContractArtifact } from '@aztec/stdlib/abi'; import type { CompleteAddress, NodeInfo } from '@aztec/stdlib/contract'; import { getContractInstanceFromDeployParams } from '@aztec/stdlib/contract'; import { deriveKeys } from '@aztec/stdlib/keys'; -import type { AccountInterface, AuthWitnessProvider } from './interface.js'; +import type { AccountInterface } from './interface.js'; // docs:start:account-contract-interface /** diff --git a/yarn-project/aztec.js/src/account/index.ts b/yarn-project/aztec.js/src/account/index.ts index cbb7bb572722..65c503f3c965 100644 --- a/yarn-project/aztec.js/src/account/index.ts +++ b/yarn-project/aztec.js/src/account/index.ts @@ -9,7 +9,7 @@ import type { Fr } from '@aztec/foundation/fields'; export { type AccountContract, getAccountContractAddress } from './account_contract.js'; -export { type AccountInterface, type AuthWitnessProvider } from './interface.js'; +export { type AccountInterface } from './interface.js'; /** A contract deployment salt. */ export type Salt = Fr | number | bigint; diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 2545242c80a8..bd5f52c1fb5a 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -1,4 +1,6 @@ -import type { AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; +import { type AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; +import { EntrypointPayload } from '@aztec/entrypoints/payload'; +import { computeCombinedPayloadHash } from '@aztec/entrypoints/utils'; import { type ContractArtifact, type FunctionArtifact, getFunctionArtifactByName } from '@aztec/stdlib/abi'; import type { PublicKeys } from '@aztec/stdlib/keys'; diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts index a5dd7ddcd470..1f1023e2f006 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_sent_tx.ts @@ -15,8 +15,8 @@ export type DeployAccountTxReceipt = FieldsOf & { * A deployment transaction for an account contract sent to the network, extending SentTx with methods to get the resulting wallet. */ export class DeployAccountSentTx extends SentTx { - constructor(node: AztecNode, txHashPromise: Promise, private getWalletPromise: Promise) { - super(node, txHashPromise); + constructor(pxeOrNode: AztecNode | PXE, txHashPromise: Promise, private getWalletPromise: Promise) { + super(pxeOrNode, txHashPromise); } /** diff --git a/yarn-project/aztec.js/src/api/account.ts b/yarn-project/aztec.js/src/api/account.ts index f54471ad82b8..d46078d1562f 100644 --- a/yarn-project/aztec.js/src/api/account.ts +++ b/yarn-project/aztec.js/src/api/account.ts @@ -1,9 +1,4 @@ -export { - type AccountContract, - type AccountInterface, - type AuthWitnessProvider, - type Salt, - getAccountContractAddress, -} from '../account/index.js'; +export { type AccountContract, type AccountInterface, type Salt, getAccountContractAddress } from '../account/index.js'; +export type { AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; export { AccountManager, type DeployAccountOptions } from '../account_manager/index.js'; diff --git a/yarn-project/aztec.js/src/api/entrypoint.ts b/yarn-project/aztec.js/src/api/entrypoint.ts deleted file mode 100644 index 53723125a4b8..000000000000 --- a/yarn-project/aztec.js/src/api/entrypoint.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '../../../entrypoints/src/interfaces.js'; diff --git a/yarn-project/aztec.js/src/api/fee.ts b/yarn-project/aztec.js/src/api/fee.ts index fc3fa7894e95..ec3e7762646a 100644 --- a/yarn-project/aztec.js/src/api/fee.ts +++ b/yarn-project/aztec.js/src/api/fee.ts @@ -1,4 +1,4 @@ -export type { FeePaymentMethod } from '../../../entrypoints/src/fee_payment_method.js'; +export type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; export { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; export { PrivateFeePaymentMethod } from '../fee/private_fee_payment_method.js'; export { PublicFeePaymentMethod } from '../fee/public_fee_payment_method.js'; diff --git a/yarn-project/aztec.js/src/api/utils.ts b/yarn-project/aztec.js/src/api/utils.ts index acc098ae5bee..6fd68b85741a 100644 --- a/yarn-project/aztec.js/src/api/utils.ts +++ b/yarn-project/aztec.js/src/api/utils.ts @@ -10,11 +10,11 @@ export { } from '../utils/abi_types.js'; export { computeAuthWitMessageHash, - computeInnerAuthWitHash, computeInnerAuthWitHashFromAction, type IntentAction, type IntentInnerHash, } from '../utils/authwit.js'; +export { computeInnerAuthWitHash } from '@aztec/stdlib/auth-witness'; export { waitForPXE } from '../utils/pxe.js'; export { waitForNode, createAztecNodeClient, type AztecNode } from '../utils/node.js'; export { getFeeJuiceBalance } from '../utils/fee_juice.js'; diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index a9c14114df45..bbf7e9bb62a2 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -1,11 +1,10 @@ +import type { ExecutionRequestInit, FeeOptions, UserFeeOptions } from '@aztec/entrypoints/interfaces'; import type { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { GasSettings } from '@aztec/stdlib/gas'; import type { Capsule, HashedValues, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx'; -import type { ExecutionRequestInit } from '../../../entrypoints/src/interfaces.js'; -import type { FeeOptions, UserFeeOptions } from '../../../entrypoints/src/payload.js'; import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; import type { Wallet } from '../wallet/wallet.js'; import { getGasLimits } from './get_gas_limits.js'; diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index a6e3852965b2..4434f49c2200 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -1,4 +1,5 @@ -import { type ExecutionRequestInit, mergeExecutionRequestInits } from '@aztec/entrypoints/interfaces'; +import { type ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import { mergeExecutionRequestInits } from '@aztec/entrypoints/utils'; import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 8f96a12d7204..2d694a3b81cc 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -167,7 +167,6 @@ describe('Contract Class', () => { wallet.getTxReceipt.mockResolvedValue(mockTxReceipt); wallet.getNodeInfo.mockResolvedValue(mockNodeInfo); wallet.proveTx.mockResolvedValue(mockTxProvingResult); - wallet.getRegisteredAccounts.mockResolvedValue([account]); wallet.getCurrentBaseFees.mockResolvedValue(new GasFees(100, 100)); }); diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 755523c31035..20d0365862e2 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -1,4 +1,5 @@ -import { type ExecutionRequestInit, mergeExecutionRequestInits } from '@aztec/entrypoints/interfaces'; +import { type ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import { mergeExecutionRequestInits } from '@aztec/entrypoints/utils'; import type { Fr } from '@aztec/foundation/fields'; import { type ContractArtifact, type FunctionArtifact, getInitializer } from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; diff --git a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts index 29f49644b56b..f0d647a44b79 100644 --- a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts @@ -62,9 +62,9 @@ export class DeploySentTx extends SentTx } protected async getContractObject(wallet?: Wallet): Promise { - const isWallet = (walletOrNode: Wallet | AztecNode): walletOrNode is Wallet => - !!(walletOrNode as Wallet).createTxExecutionRequest; - const contractWallet = wallet ?? (isWallet(this.walletOrNode) && this.walletOrNode); + const isWallet = (pxeWalletOrNode: Wallet | AztecNode | PXE): pxeWalletOrNode is Wallet => + !!(pxeWalletOrNode as Wallet).createTxExecutionRequest; + const contractWallet = wallet ?? (isWallet(this.pxeWalletOrNode) && this.pxeWalletOrNode); if (!contractWallet) { throw new Error(`A wallet is required for creating a contract instance`); } diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 5e3f01f163ee..99c7dd4fbb58 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -1,6 +1,6 @@ import { retryUntil } from '@aztec/foundation/retry'; import type { FieldsOf } from '@aztec/foundation/types'; -import type { AztecNode } from '@aztec/stdlib/interfaces/client'; +import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client'; import { type TxHash, type TxReceipt, TxStatus } from '@aztec/stdlib/tx'; import type { Wallet } from '../wallet/wallet.js'; @@ -30,7 +30,7 @@ export const DefaultWaitOpts: WaitOpts = { * its hash, receipt, and mining status. */ export class SentTx { - constructor(protected walletOrNode: Wallet | AztecNode, protected txHashPromise: Promise) {} + constructor(protected pxeWalletOrNode: Wallet | AztecNode | PXE, protected txHashPromise: Promise) {} /** * Retrieves the transaction hash of the SentTx instance. @@ -52,7 +52,7 @@ export class SentTx { */ public async getReceipt(): Promise { const txHash = await this.getTxHash(); - return await this.walletOrNode.getTxReceipt(txHash); + return await this.pxeWalletOrNode.getTxReceipt(txHash); } /** @@ -77,7 +77,7 @@ export class SentTx { return await retryUntil( async () => { - const txReceipt = await this.walletOrNode.getTxReceipt(txHash); + const txReceipt = await this.pxeWalletOrNode.getTxReceipt(txHash); // If receipt is not yet available, try again if (txReceipt.status === TxStatus.PENDING) { return undefined; diff --git a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts index 963974560184..de826e90076a 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts @@ -1,4 +1,5 @@ -import { type EntrypointInterface, EntrypointPayload, type ExecutionRequestInit } from '@aztec/entrypoints'; +import { type EntrypointInterface, type ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import { EntrypointPayload } from '@aztec/entrypoints/payload'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts index a64876891fef..e700a293cbf5 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts @@ -1,9 +1,8 @@ +import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { FunctionCall } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; -import type { FeePaymentMethod } from '../../../entrypoints/src/fee_payment_method.js'; - // docs:start:fee_juice_method /** * Pay fee directly in the Fee Juice. diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index 5aa1ea299fb0..95231547cc26 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -1,12 +1,13 @@ +import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; -import type { FeePaymentMethod } from '../../../entrypoints/src/fee_payment_method.js'; import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { SignerlessWallet } from '../wallet/signerless_wallet.js'; import type { Wallet } from '../wallet/wallet.js'; +import { simulateWithoutSignature } from './utils.js'; /** * Holds information about how the fee for a transaction is to be paid. @@ -39,38 +40,29 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { getAsset(): Promise { if (!this.assetPromise) { // We use signer-less wallet because this function could be triggered before the associated account is deployed. - const signerlessWallet = new SignerlessWallet(this.wallet); - - const interaction = new ContractFunctionInteraction( - signerlessWallet, - this.paymentContract, - { - name: 'get_accepted_asset', - functionType: FunctionType.PRIVATE, - isInternal: false, - isStatic: false, - parameters: [], - returnTypes: [ - { - kind: 'struct', - path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress', - fields: [ - { - name: 'inner', - type: { - kind: 'field', - }, + this.assetPromise = simulateWithoutSignature(this.wallet, this.paymentContract, { + name: 'get_accepted_asset', + functionType: FunctionType.PRIVATE, + isInternal: false, + isStatic: false, + parameters: [], + returnTypes: [ + { + kind: 'struct', + path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress', + fields: [ + { + name: 'inner', + type: { + kind: 'field', }, - ], - }, - ], - errorTypes: {}, - isInitializer: false, - }, - [], - ); - - this.assetPromise = interaction.simulate(); + }, + ], + }, + ], + errorTypes: {}, + isInitializer: false, + }) as Promise; } return this.assetPromise!; } diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index 2d115cd4dbc2..f54a29e6d1d8 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -1,13 +1,12 @@ +import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import type { FunctionCall } from '@aztec/stdlib/abi'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; -import type { AztecAddress } from '@aztec/stdlib/aztec-address'; -import type { GasSettings } from '@aztec/stdlib/gas'; +import { AztecAddress } from '@aztec/stdlib/aztec-address'; +import { GasSettings } from '@aztec/stdlib/gas'; -import type { FeePaymentMethod } from '../../../entrypoints/src/fee_payment_method.js'; -import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import type { AccountWallet } from '../wallet/account_wallet.js'; -import { SignerlessWallet } from '../wallet/signerless_wallet.js'; +import { simulateWithoutSignature } from './utils.js'; /** * Holds information about how the fee for a transaction is to be paid. @@ -30,41 +29,32 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { * The asset used to pay the fee. * @returns The asset used to pay the fee. */ - getAsset(): Promise { + async getAsset(): Promise { if (!this.assetPromise) { - // We use signer-less wallet because this function could be triggered before the associated account is deployed. - const signerlessWallet = new SignerlessWallet(this.wallet); - - const interaction = new ContractFunctionInteraction( - signerlessWallet, - this.paymentContract, - { - name: 'get_accepted_asset', - functionType: FunctionType.PRIVATE, - isInternal: false, - isStatic: false, - parameters: [], - returnTypes: [ - { - kind: 'struct', - path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress', - fields: [ - { - name: 'inner', - type: { - kind: 'field', - }, + // We use the utility method to avoid a signature because this function could be triggered before the associated account is deployed. + this.assetPromise = simulateWithoutSignature(this.wallet, this.paymentContract, { + name: 'get_accepted_asset', + functionType: FunctionType.PRIVATE, + isInternal: false, + isStatic: false, + parameters: [], + returnTypes: [ + { + kind: 'struct', + path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress', + fields: [ + { + name: 'inner', + type: { + kind: 'field', }, - ], - }, - ], - errorTypes: {}, - isInitializer: false, - }, - [], - ); - - this.assetPromise = interaction.simulate(); + }, + ], + }, + ], + errorTypes: {}, + isInitializer: false, + }) as Promise; } return this.assetPromise!; } diff --git a/yarn-project/aztec.js/src/fee/utils.ts b/yarn-project/aztec.js/src/fee/utils.ts new file mode 100644 index 000000000000..07eb9050244a --- /dev/null +++ b/yarn-project/aztec.js/src/fee/utils.ts @@ -0,0 +1,26 @@ +import { DefaultEntrypoint } from '@aztec/entrypoints/default'; +import { type FunctionAbi, decodeFromAbi } from '@aztec/stdlib/abi'; +import { AztecAddress } from '@aztec/stdlib/aztec-address'; +import { GasSettings } from '@aztec/stdlib/gas'; + +import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; +import type { Wallet } from '../wallet/wallet.js'; +import { FeeJuicePaymentMethod } from './fee_juice_payment_method.js'; + +export async function simulateWithoutSignature(wallet: Wallet, contractAddress: AztecAddress, abi: FunctionAbi) { + const interaction = new ContractFunctionInteraction(wallet, contractAddress, abi, []); + + const request = await interaction.request(); + const maxFeesPerGas = (await wallet.getCurrentBaseFees()).mul(1.5); + const paymentMethod = new FeeJuicePaymentMethod(AztecAddress.ZERO); + const gasSettings = GasSettings.default({ maxFeesPerGas }); + const fee = { gasSettings, paymentMethod }; + + const { l1ChainId: chainId, protocolVersion } = await wallet.getNodeInfo(); + const entrypoint = new DefaultEntrypoint(chainId, protocolVersion); + const signerlessTxExecutionRequest = await entrypoint.createTxExecutionRequest({ ...request, fee }); + + const simulationResult = await wallet.simulateTx(signerlessTxExecutionRequest, false, undefined, undefined, true); + const rawReturnValues = simulationResult.getPrivateReturnValues().values; + return decodeFromAbi(abi.returnTypes, rawReturnValues!); +} diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index e5aaf9a37521..49fdb900ddeb 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -1,5 +1,3 @@ -import { GeneratorIndex } from '@aztec/constants'; -import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import type { FunctionCall } from '@aztec/stdlib/abi'; import { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness'; diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index bb3871007bcc..2fa96ab32c85 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -1,3 +1,4 @@ +import type { ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type ABIParameterVisibility, type FunctionAbi, FunctionType } from '@aztec/stdlib/abi'; @@ -8,7 +9,6 @@ import type { TxExecutionRequest } from '@aztec/stdlib/tx'; import type { AccountInterface } from '../account/interface.js'; import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; -import type { ExecutionRequestInit } from '../entrypoint/interfaces.js'; import { type IntentAction, type IntentInnerHash, diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index e25272834d15..c6a7d2d02db8 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -1,23 +1,11 @@ -import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants'; -import type { Fr, Point } from '@aztec/foundation/fields'; -import type { SiblingPath } from '@aztec/foundation/trees'; +import type { ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import type { Fr } from '@aztec/foundation/fields'; import type { AbiDecoded, ContractArtifact } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; -import type { L2Block } from '@aztec/stdlib/block'; -import type { CompleteAddress, ContractInstanceWithAddress, NodeInfo, PartialAddress } from '@aztec/stdlib/contract'; +import type { CompleteAddress, ContractInstanceWithAddress, NodeInfo } from '@aztec/stdlib/contract'; import type { GasFees } from '@aztec/stdlib/gas'; -import type { - ContractClassMetadata, - ContractMetadata, - EventMetadataDefinition, - GetContractClassLogsResponse, - GetPublicLogsResponse, - PXE, - PXEInfo, -} from '@aztec/stdlib/interfaces/client'; -import type { LogFilter } from '@aztec/stdlib/logs'; -import type { NotesFilter, UniqueNote } from '@aztec/stdlib/note'; +import type { ContractClassMetadata, ContractMetadata, PXE, PXEInfo } from '@aztec/stdlib/interfaces/client'; import type { PrivateExecutionResult, Tx, @@ -28,7 +16,6 @@ import type { TxSimulationResult, } from '@aztec/stdlib/tx'; -import type { ExecutionRequestInit } from '../../../entrypoints/src/interfaces.js'; import type { IntentAction, IntentInnerHash } from '../utils/authwit.js'; import type { Wallet } from './wallet.js'; diff --git a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts index b3d9fbf8370a..6d4505474baf 100644 --- a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts @@ -1,5 +1,5 @@ -import { DefaultEntrypoint } from '@aztec/entrypoints'; -import type { EntrypointInterface, ExecutionRequestInit } from '@aztec/entrypoints'; +import { DefaultEntrypoint } from '@aztec/entrypoints/default'; +import type { EntrypointInterface, ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; import type { Fr } from '@aztec/foundation/fields'; import { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { CompleteAddress } from '@aztec/stdlib/contract'; diff --git a/yarn-project/entrypoints/package.json b/yarn-project/entrypoints/package.json index 8ebf31356ac2..4be02217c0a3 100644 --- a/yarn-project/entrypoints/package.json +++ b/yarn-project/entrypoints/package.json @@ -8,7 +8,9 @@ "./dapp": "./dest/dapp_entrypoint.js", "./account": "./dest/account_entrypoint.js", "./default": "./dest/default_entrypoint.js", - "./interfaces": "./dest/interfaces.js" + "./interfaces": "./dest/interfaces.js", + "./payload": "./dest/payload.js", + "./utils": "./dest/utils.js" }, "typedocOptions": { "entryPoints": [ diff --git a/yarn-project/entrypoints/src/account_entrypoint.ts b/yarn-project/entrypoints/src/account_entrypoint.ts index 2219795d72fd..54b4ac1349f5 100644 --- a/yarn-project/entrypoints/src/account_entrypoint.ts +++ b/yarn-project/entrypoints/src/account_entrypoint.ts @@ -3,13 +3,9 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; -import { - type AuthWitnessProvider, - type EntrypointInterface, - EntrypointPayload, - type ExecutionRequestInit, - computeCombinedPayloadHash, -} from './interfaces.js'; +import { type AuthWitnessProvider, type EntrypointInterface, type ExecutionRequestInit } from './interfaces.js'; +import { EntrypointPayload } from './payload.js'; +import { computeCombinedPayloadHash } from './utils.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index 217683e6bca6..bf9e583efe1d 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -5,12 +5,8 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; -import { - type AuthWitnessProvider, - type EntrypointInterface, - EntrypointPayload, - type ExecutionRequestInit, -} from './interfaces.js'; +import { type AuthWitnessProvider, type EntrypointInterface, type ExecutionRequestInit } from './interfaces.js'; +import { EntrypointPayload } from './payload.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature diff --git a/yarn-project/entrypoints/src/index.ts b/yarn-project/entrypoints/src/index.ts index 77c4e3706b8d..da04efb9b608 100644 --- a/yarn-project/entrypoints/src/index.ts +++ b/yarn-project/entrypoints/src/index.ts @@ -10,3 +10,4 @@ export * from './account_entrypoint.js'; export * from './dapp_entrypoint.js'; export * from './interfaces.js'; export * from './default_entrypoint.js'; +export * from './utils.js'; diff --git a/yarn-project/entrypoints/src/interfaces.ts b/yarn-project/entrypoints/src/interfaces.ts index 78d66b27d7a9..1b5e326d42bf 100644 --- a/yarn-project/entrypoints/src/interfaces.ts +++ b/yarn-project/entrypoints/src/interfaces.ts @@ -1,14 +1,11 @@ import type { Fr } from '@aztec/foundation/fields'; +import type { FieldsOf } from '@aztec/foundation/types'; import type { FunctionCall } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; import type { Capsule, HashedValues, TxExecutionRequest } from '@aztec/stdlib/tx'; -import { EntrypointPayload, type FeeOptions, computeCombinedPayloadHash } from './payload.js'; - -export { EntrypointPayload, type FeeOptions, computeCombinedPayloadHash }; - /** Encodes the calls to be done in a transaction. */ export type ExecutionRequestInit = { /** The function calls to be executed. */ @@ -27,27 +24,6 @@ export type ExecutionRequestInit = { cancellable?: boolean; }; -/** - * Merges an array of ExecutionRequestInits. - */ -export function mergeExecutionRequestInits( - requests: Pick[], - { nonce, cancellable }: Pick = {}, -): Omit { - const calls = requests.map(r => r.calls).flat(); - const authWitnesses = requests.map(r => r.authWitnesses ?? []).flat(); - const hashedArguments = requests.map(r => r.hashedArguments ?? []).flat(); - const capsules = requests.map(r => r.capsules ?? []).flat(); - return { - calls, - authWitnesses, - hashedArguments, - capsules, - nonce, - cancellable, - }; -} - /** Creates transaction execution requests out of a set of function calls. */ export interface EntrypointInterface { /** @@ -86,3 +62,29 @@ export interface FeePaymentMethod { */ getFeePayer(gasSettings: GasSettings): Promise; } + +/** + * Fee payment options for a transaction. + */ +export type FeeOptions = { + /** The fee payment method to use */ + paymentMethod: FeePaymentMethod; + /** The gas settings */ + gasSettings: GasSettings; +}; + +// docs:start:user_fee_options +/** Fee options as set by a user. */ +export type UserFeeOptions = { + /** The fee payment method to use */ + paymentMethod?: FeePaymentMethod; + /** The gas settings */ + gasSettings?: Partial>; + /** Percentage to pad the base fee by, if empty, defaults to 0.5 */ + baseFeePadding?: number; + /** Whether to run an initial simulation of the tx with high gas limit to figure out actual gas settings. */ + estimateGas?: boolean; + /** Percentage to pad the estimated gas limits by, if empty, defaults to 0.1. Only relevant if estimateGas is set. */ + estimatedGasPadding?: number; +}; +// docs:end:user_fee_options diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index 31de8175321e..ce99e134b72d 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -3,39 +3,11 @@ import { padArrayEnd } from '@aztec/foundation/collection'; import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import type { Tuple } from '@aztec/foundation/serialize'; -import type { FieldsOf } from '@aztec/foundation/types'; import { FunctionCall, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; -import type { GasSettings } from '@aztec/stdlib/gas'; import { HashedValues } from '@aztec/stdlib/tx'; -import type { FeePaymentMethod } from './interfaces.js'; - -/** - * Fee payment options for a transaction. - */ -export type FeeOptions = { - /** The fee payment method to use */ - paymentMethod: FeePaymentMethod; - /** The gas settings */ - gasSettings: GasSettings; -}; - -// docs:start:user_fee_options -/** Fee options as set by a user. */ -export type UserFeeOptions = { - /** The fee payment method to use */ - paymentMethod?: FeePaymentMethod; - /** The gas settings */ - gasSettings?: Partial>; - /** Percentage to pad the base fee by, if empty, defaults to 0.5 */ - baseFeePadding?: number; - /** Whether to run an initial simulation of the tx with high gas limit to figure out actual gas settings. */ - estimateGas?: boolean; - /** Percentage to pad the estimated gas limits by, if empty, defaults to 0.1. Only relevant if estimateGas is set. */ - estimatedGasPadding?: number; -}; -// docs:end:user_fee_options +import type { FeeOptions } from './interfaces.js'; // These must match the values defined in: // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr @@ -188,14 +160,14 @@ export abstract class EntrypointPayload { } /** Entrypoint payload for app phase execution. */ -class AppEntrypointPayload extends EntrypointPayload { +export class AppEntrypointPayload extends EntrypointPayload { override toFields(): Fr[] { return [...this.functionCallsToFields(), this.nonce]; } } /** Entrypoint payload for fee payment to be run during setup phase. */ -class FeeEntrypointPayload extends EntrypointPayload { +export class FeeEntrypointPayload extends EntrypointPayload { #isFeePayer: boolean; constructor( @@ -220,19 +192,3 @@ class FeeEntrypointPayload extends EntrypointPayload { } /* eslint-enable camelcase */ } - -/** - * Computes a hash of a combined payload. - * @param appPayload - An app payload. - * @param feePayload - A fee payload. - * @returns A hash of a combined payload. - */ -export async function computeCombinedPayloadHash( - appPayload: AppEntrypointPayload, - feePayload: FeeEntrypointPayload, -): Promise { - return poseidon2HashWithSeparator( - [await appPayload.hash(), await feePayload.hash()], - GeneratorIndex.COMBINED_PAYLOAD, - ); -} diff --git a/yarn-project/entrypoints/src/utils.ts b/yarn-project/entrypoints/src/utils.ts new file mode 100644 index 000000000000..316b8389372e --- /dev/null +++ b/yarn-project/entrypoints/src/utils.ts @@ -0,0 +1,43 @@ +import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; +import type { Fr } from '@aztec/foundation/fields'; + +import { GeneratorIndex } from '../../constants/src/constants.gen.js'; +import type { ExecutionRequestInit } from './interfaces.js'; +import type { AppEntrypointPayload, FeeEntrypointPayload } from './payload.js'; + +/** + * Merges an array of ExecutionRequestInits. + */ +export function mergeExecutionRequestInits( + requests: Pick[], + { nonce, cancellable }: Pick = {}, +): Omit { + const calls = requests.map(r => r.calls).flat(); + const authWitnesses = requests.map(r => r.authWitnesses ?? []).flat(); + const hashedArguments = requests.map(r => r.hashedArguments ?? []).flat(); + const capsules = requests.map(r => r.capsules ?? []).flat(); + return { + calls, + authWitnesses, + hashedArguments, + capsules, + nonce, + cancellable, + }; +} + +/** + * Computes a hash of a combined payload. + * @param appPayload - An app payload. + * @param feePayload - A fee payload. + * @returns A hash of a combined payload. + */ +export async function computeCombinedPayloadHash( + appPayload: AppEntrypointPayload, + feePayload: FeeEntrypointPayload, +): Promise { + return poseidon2HashWithSeparator( + [await appPayload.hash(), await feePayload.hash()], + GeneratorIndex.COMBINED_PAYLOAD, + ); +} From 24123308a7e8a3b1b78b56c179eafc3aa1ffd0f7 Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 11 Mar 2025 14:17:17 +0000 Subject: [PATCH 12/48] added deps --- yarn-project/aztec.js/package.json | 1 + yarn-project/aztec.js/tsconfig.json | 3 +++ yarn-project/package.json | 3 +++ yarn-project/yarn.lock | 2 ++ 4 files changed, 9 insertions(+) diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index bd41c305479e..2f5ebcf09ac5 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -80,6 +80,7 @@ }, "dependencies": { "@aztec/constants": "workspace:^", + "@aztec/entrypoints": "workspace:^", "@aztec/ethereum": "workspace:^", "@aztec/foundation": "workspace:^", "@aztec/l1-artifacts": "workspace:^", diff --git a/yarn-project/aztec.js/tsconfig.json b/yarn-project/aztec.js/tsconfig.json index 0be06a7f2079..9ca509bd7149 100644 --- a/yarn-project/aztec.js/tsconfig.json +++ b/yarn-project/aztec.js/tsconfig.json @@ -9,6 +9,9 @@ { "path": "../constants" }, + { + "path": "../entrypoints" + }, { "path": "../ethereum" }, diff --git a/yarn-project/package.json b/yarn-project/package.json index b6d5a8109f43..7a8b07bb865c 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -87,5 +87,8 @@ "@aztec/noir-noir_codegen": "portal:../noir/packages/noir_codegen", "@aztec/noir-noir_js": "file:../noir/packages/noir_js", "jest-runner@npm:^29.7.0": "patch:jest-runner@npm%3A29.7.0#~/.yarn/patches/jest-runner-npm-29.7.0-3bc9f82b58.patch" + }, + "dependencies": { + "@aztec/entrypoints": "workspace:^" } } diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 3f13153c05e4..b82febab1b4a 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -186,6 +186,7 @@ __metadata: resolution: "@aztec/aztec.js@workspace:aztec.js" dependencies: "@aztec/constants": "workspace:^" + "@aztec/entrypoints": "workspace:^" "@aztec/ethereum": "workspace:^" "@aztec/foundation": "workspace:^" "@aztec/l1-artifacts": "workspace:^" @@ -215,6 +216,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/aztec3-packages@workspace:." dependencies: + "@aztec/entrypoints": "workspace:^" "@monorepo-utils/workspaces-to-typescript-project-references": "npm:^2.9.0" "@swc-node/register": "npm:^1.10.9" "@swc/cli": "npm:^0.6.0" From 44218ac6c8d907da504d1e15b23906969f273629 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 12 Mar 2025 12:08:19 +0000 Subject: [PATCH 13/48] kill permanent authwits --- .../src/defaults/account_interface.ts | 2 +- yarn-project/aztec.js/src/api/contract.ts | 1 + .../src/contract/base_contract_interaction.ts | 2 + .../aztec.js/src/contract/batch_call.ts | 5 +- .../contract/contract_function_interaction.ts | 16 +- yarn-project/aztec.js/src/contract/sent_tx.ts | 2 - .../aztec.js/src/contract/wait_for_proven.ts | 30 ++ .../aztec.js/src/ethereum/portal_manager.ts | 8 +- .../aztec.js/src/wallet/account_wallet.ts | 21 +- .../aztec.js/src/wallet/base_wallet.ts | 15 +- yarn-project/aztec/src/sandbox/sandbox.ts | 7 +- yarn-project/bot/src/bot.ts | 11 +- .../cli-wallet/src/cmds/add_authwit.ts | 3 +- yarn-project/cli-wallet/src/cmds/cancel_tx.ts | 2 +- yarn-project/cli-wallet/src/cmds/index.ts | 21 +- yarn-project/cli-wallet/src/utils/accounts.ts | 30 -- .../cli/src/cmds/devnet/bootstrap_network.ts | 22 +- .../cmds/infrastructure/setup_l2_contract.ts | 24 +- .../cli/src/cmds/misc/setup_contracts.ts | 25 +- .../end-to-end/src/e2e_authwit.test.ts | 65 +-- .../pxe_oracle_interface.test.ts | 3 - .../pxe_oracle_interface.ts | 8 +- .../pxe/src/pxe_service/pxe_service.ts | 506 +++++++++--------- .../auth_witness_data_provider.ts | 34 -- .../auth_witness_data_providert.test.ts | 33 -- .../auth_witness_data_provider/index.ts | 1 - yarn-project/pxe/src/storage/index.ts | 1 - .../src/private/execution_data_provider.ts | 7 - .../simulator/src/private/simulator.ts | 4 +- .../private/unconstrained_execution.test.ts | 2 +- .../private/unconstrained_execution_oracle.ts | 5 +- .../stdlib/src/interfaces/pxe.test.ts | 32 +- yarn-project/stdlib/src/interfaces/pxe.ts | 40 +- yarn-project/txe/src/oracle/txe_oracle.ts | 10 +- 34 files changed, 429 insertions(+), 569 deletions(-) create mode 100644 yarn-project/aztec.js/src/contract/wait_for_proven.ts delete mode 100644 yarn-project/pxe/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts delete mode 100644 yarn-project/pxe/src/storage/auth_witness_data_provider/auth_witness_data_providert.test.ts delete mode 100644 yarn-project/pxe/src/storage/auth_witness_data_provider/index.ts diff --git a/yarn-project/accounts/src/defaults/account_interface.ts b/yarn-project/accounts/src/defaults/account_interface.ts index b221514b85ce..59ec934a071a 100644 --- a/yarn-project/accounts/src/defaults/account_interface.ts +++ b/yarn-project/accounts/src/defaults/account_interface.ts @@ -1,6 +1,6 @@ import type { AccountInterface, AuthWitnessProvider } from '@aztec/aztec.js/account'; -import type { EntrypointInterface, ExecutionRequestInit } from '@aztec/aztec.js/entrypoint'; import { DefaultAccountEntrypoint } from '@aztec/entrypoints/account'; +import type { EntrypointInterface, ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; diff --git a/yarn-project/aztec.js/src/api/contract.ts b/yarn-project/aztec.js/src/api/contract.ts index e128adf0e465..6eb35c032d81 100644 --- a/yarn-project/aztec.js/src/api/contract.ts +++ b/yarn-project/aztec.js/src/api/contract.ts @@ -51,6 +51,7 @@ export { export { BatchCall } from '../contract/batch_call.js'; export { type DeployOptions, DeployMethod } from '../contract/deploy_method.js'; export { DeploySentTx } from '../contract/deploy_sent_tx.js'; +export { waitForProven, type WaitForProvenOpts, DefaultWaitForProvenOpts } from '../contract/wait_for_proven.js'; export { type PartialAddress, diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index bbf7e9bb62a2..2f04b182664c 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -24,6 +24,8 @@ export type SendMethodOptions = { nonce?: Fr; /** Whether the transaction can be cancelled. If true, an extra nullifier will be emitted: H(nonce, GENERATOR_INDEX__TX_NULLIFIER) */ cancellable?: boolean; + /** Authwits to use in the simulation */ + authwits?: AuthWitness[]; }; /** diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 4434f49c2200..35d4fa6282f9 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -83,7 +83,10 @@ export class BatchCall extends BaseContractInteraction { const unconstrainedCalls = unconstrained.map( async ([call, index]) => - [await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.from), index] as const, + [ + await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.authwits, options?.from), + index, + ] as const, ); const [unconstrainedResults, simulatedTx] = await Promise.all([ diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index 0b090d0d9e14..ac48755dc976 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -1,5 +1,6 @@ import type { ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi'; +import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PrivateKernelProverProfileResult } from '@aztec/stdlib/kernel'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; @@ -22,6 +23,8 @@ export type SimulateMethodOptions = Pick & { skipTxValidation?: boolean; /** Whether to ensure the fee payer is not empty and has enough balance to pay for the fee. */ skipFeeEnforcement?: boolean; + /** Authwits to use in the simulation */ + authwits?: AuthWitness[]; }; /** @@ -90,6 +93,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction { returnTypes: this.functionDao.returnTypes, }, ]; + this.addAuthWitnesses(options.authwits ?? []); const authWitnesses = this.getAuthWitnesses(); const hashedArguments = this.getHashedArguments(); const capsules = this.getCapsules(); @@ -117,11 +121,17 @@ export class ContractFunctionInteraction extends BaseContractInteraction { public async simulate(options: SimulateMethodOptions = {}): Promise { // docs:end:simulate if (this.functionDao.functionType == FunctionType.UNCONSTRAINED) { - return this.wallet.simulateUnconstrained(this.functionDao.name, this.args, this.contractAddress, options?.from); + return this.wallet.simulateUnconstrained( + this.functionDao.name, + this.args, + this.contractAddress, + options.authwits ?? [], + options?.from, + ); } const fee = options.fee ?? { paymentMethod: new FeeJuicePaymentMethod(AztecAddress.ZERO) }; - const txRequest = await this.create({ fee }); + const txRequest = await this.create({ fee, authwits: options.authwits }); const simulatedTx = await this.wallet.simulateTx( txRequest, true /* simulatePublic */, @@ -159,7 +169,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction { throw new Error("Can't profile an unconstrained function."); } - const txRequest = await this.create({ fee: options.fee }); + const txRequest = await this.create({ fee: options.fee, authwits: options.authwits }); const simulatedTx = await this.wallet.simulateTx( txRequest, true, diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 99c7dd4fbb58..510ee74b9d67 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -11,8 +11,6 @@ export type WaitOpts = { ignoreDroppedReceiptsFor?: number; /** The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. */ timeout?: number; - /** The maximum time (in seconds) to wait for the transaction to be proven. Defaults to 600. */ - provenTimeout?: number; /** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */ interval?: number; /** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */ diff --git a/yarn-project/aztec.js/src/contract/wait_for_proven.ts b/yarn-project/aztec.js/src/contract/wait_for_proven.ts new file mode 100644 index 000000000000..76a6e28c17ed --- /dev/null +++ b/yarn-project/aztec.js/src/contract/wait_for_proven.ts @@ -0,0 +1,30 @@ +import { retryUntil } from '@aztec/foundation/retry'; +import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client'; + +import type { TxReceipt } from '../index.js'; +import { DefaultWaitOpts } from './sent_tx.js'; + +export type WaitForProvenOpts = { + provenTimeout?: number; + interval?: number; +}; + +export const DefaultWaitForProvenOpts: WaitForProvenOpts = { + provenTimeout: 600, + interval: DefaultWaitOpts.interval, +}; + +export async function waitForProven(pxeOrNode: PXE | AztecNode, receipt: TxReceipt, opts?: WaitForProvenOpts) { + if (!receipt.blockNumber) { + throw new Error(`Cannot wait for proven: receipt of tx ${receipt.txHash} does not have a block number`); + } + return await retryUntil( + async () => { + const provenBlock = await pxeOrNode.getProvenBlockNumber(); + return provenBlock >= receipt.blockNumber! ? provenBlock : undefined; + }, + 'isProven', + opts?.provenTimeout ?? DefaultWaitForProvenOpts.provenTimeout, + opts?.interval ?? DefaultWaitForProvenOpts.interval, + ); +} diff --git a/yarn-project/aztec.js/src/ethereum/portal_manager.ts b/yarn-project/aztec.js/src/ethereum/portal_manager.ts index 37ce8c50428a..6c84e9aaedae 100644 --- a/yarn-project/aztec.js/src/ethereum/portal_manager.ts +++ b/yarn-project/aztec.js/src/ethereum/portal_manager.ts @@ -15,6 +15,8 @@ import type { PXE } from '@aztec/stdlib/interfaces/client'; import { type GetContractReturnType, type Hex, getContract, toFunctionSelector } from 'viem'; +import type { Wallet } from '../index.js'; + // docs:start:claim_type // docs:start:claim_type_amount /** L1 to L2 message info to claim it on L2. */ @@ -178,20 +180,20 @@ export class L1FeeJuicePortalManager { /** * Creates a new instance - * @param pxe - PXE client used for retrieving the L1 contract addresses. + * @param walletOrPxe - Wallet or PXE client used for retrieving the L1 contract addresses. * @param publicClient - L1 public client. * @param walletClient - L1 wallet client. * @param logger - Logger. */ public static async new( - pxe: PXE, + walletOrPxe: Wallet | PXE, publicClient: ViemPublicClient, walletClient: ViemWalletClient, logger: Logger, ): Promise { const { l1ContractAddresses: { feeJuiceAddress, feeJuicePortalAddress }, - } = await pxe.getNodeInfo(); + } = await walletOrPxe.getNodeInfo(); if (feeJuiceAddress.isZero() || feeJuicePortalAddress.isZero()) { throw new Error('Portal or token not deployed on L1'); diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 2fa96ab32c85..ea8230d54207 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -2,7 +2,7 @@ import type { ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type ABIParameterVisibility, type FunctionAbi, FunctionType } from '@aztec/stdlib/abi'; -import type { AuthWitness } from '@aztec/stdlib/auth-witness'; +import { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; @@ -22,7 +22,7 @@ import { BaseWallet } from './base_wallet.js'; */ export class AccountWallet extends BaseWallet { constructor(pxe: PXE, protected account: AccountInterface) { - super(pxe, [account.getAddress()]); + super(pxe); } createTxExecutionRequest(exec: ExecutionRequestInit): Promise { @@ -57,9 +57,7 @@ export class AccountWallet extends BaseWallet { messageHash = await this.getMessageHash(messageHashOrIntent); } - const witness = await this.account.createAuthWit(messageHash); - await this.pxe.addAuthWitness(witness); - return witness; + return this.account.createAuthWit(messageHash); } /** @@ -134,6 +132,7 @@ export class AccountWallet extends BaseWallet { async lookupValidity( onBehalfOf: AztecAddress, intent: IntentInnerHash | IntentAction, + witness: AuthWitness, ): Promise<{ /** boolean flag indicating if the authwit is valid in private context */ isValidInPrivate: boolean; @@ -146,13 +145,11 @@ export class AccountWallet extends BaseWallet { const results = { isValidInPrivate: false, isValidInPublic: false }; // Check private - const witness = await this.pxe.getAuthWitness(messageHash); - if (witness !== undefined) { - results.isValidInPrivate = (await new ContractFunctionInteraction(this, onBehalfOf, this.getLookupValidityAbi(), [ - consumer, - innerHash, - ]).simulate()) as boolean; - } + + results.isValidInPrivate = (await new ContractFunctionInteraction(this, onBehalfOf, this.getLookupValidityAbi(), [ + consumer, + innerHash, + ]).simulate({ authwits: [witness] })) as boolean; // check public results.isValidInPublic = (await new ContractFunctionInteraction( diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index c6a7d2d02db8..5e012901e60a 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -23,7 +23,7 @@ import type { Wallet } from './wallet.js'; * A base class for Wallet implementations */ export abstract class BaseWallet implements Wallet { - constructor(protected readonly pxe: PXE, private scopes?: AztecAddress[]) {} + constructor(protected readonly pxe: PXE) {} abstract getCompleteAddress(): CompleteAddress; @@ -71,15 +71,7 @@ export abstract class BaseWallet implements Wallet { skipFeeEnforcement?: boolean, profile?: boolean, ): Promise { - return this.pxe.simulateTx( - txRequest, - simulatePublic, - msgSender, - skipTxValidation, - skipFeeEnforcement, - profile, - this.scopes, - ); + return this.pxe.simulateTx(txRequest, simulatePublic, msgSender, skipTxValidation, skipFeeEnforcement, profile); } sendTx(tx: Tx): Promise { return this.pxe.sendTx(tx); @@ -91,9 +83,10 @@ export abstract class BaseWallet implements Wallet { functionName: string, args: any[], to: AztecAddress, + authwits?: AuthWitness[], from?: AztecAddress | undefined, ): Promise { - return this.pxe.simulateUnconstrained(functionName, args, to, from); + return this.pxe.simulateUnconstrained(functionName, args, to, authwits, from); } getNodeInfo(): Promise { return this.pxe.getNodeInfo(); diff --git a/yarn-project/aztec/src/sandbox/sandbox.ts b/yarn-project/aztec/src/sandbox/sandbox.ts index 9c7ae1cde522..cf776263ec2e 100644 --- a/yarn-project/aztec/src/sandbox/sandbox.ts +++ b/yarn-project/aztec/src/sandbox/sandbox.ts @@ -168,12 +168,7 @@ export async function createSandbox(config: Partial = {}, userLog const node = await createAztecNode(aztecNodeConfig, { telemetry, blobSinkClient }, { prefilledPublicData }); const pxe = await createAztecPXE(node); - await setupCanonicalL2FeeJuice( - new SignerlessWallet(pxe), - aztecNodeConfig.l1Contracts.feeJuicePortalAddress, - undefined, - logger.info, - ); + await setupCanonicalL2FeeJuice(pxe, aztecNodeConfig.l1Contracts.feeJuicePortalAddress, logger.info); if (initialAccounts.length) { userLog('Setting up funded test accounts...'); diff --git a/yarn-project/bot/src/bot.ts b/yarn-project/bot/src/bot.ts index 34a9f179524c..a3c731571ae5 100644 --- a/yarn-project/bot/src/bot.ts +++ b/yarn-project/bot/src/bot.ts @@ -5,6 +5,7 @@ import { type SendMethodOptions, type Wallet, createLogger, + waitForProven, } from '@aztec/aztec.js'; import { times } from '@aztec/foundation/collection'; import type { EasyPrivateTokenContract } from '@aztec/noir-contracts.js/EasyPrivateToken'; @@ -25,6 +26,7 @@ export class Bot { private successes: number = 0; protected constructor( + public readonly pxe: PXE, public readonly wallet: Wallet, public readonly token: TokenContract | EasyPrivateTokenContract, public readonly recipient: AztecAddress, @@ -32,8 +34,8 @@ export class Bot { ) {} static async create(config: BotConfig, dependencies: { pxe?: PXE; node?: AztecNode } = {}): Promise { - const { wallet, token, recipient } = await new BotFactory(config, dependencies).setup(); - return new Bot(wallet, token, recipient, config); + const { pxe, wallet, token, recipient } = await new BotFactory(config, dependencies).setup(); + return new Bot(pxe, wallet, token, recipient, config); } public updateConfig(config: Partial) { @@ -86,9 +88,10 @@ export class Bot { ); const receipt = await tx.wait({ timeout: txMinedWaitSeconds, - provenTimeout: txMinedWaitSeconds, - proven: followChain === 'PROVEN', }); + if (followChain === 'PROVEN') { + await waitForProven(this.pxe, receipt, { provenTimeout: txMinedWaitSeconds }); + } this.log.info( `Tx #${this.attempts} ${receipt.txHash} successfully mined in block ${receipt.blockNumber} (stats: ${this.successes}/${this.attempts} success)`, logCtx, diff --git a/yarn-project/cli-wallet/src/cmds/add_authwit.ts b/yarn-project/cli-wallet/src/cmds/add_authwit.ts index 1adf26a6bc4e..38d65ad646f9 100644 --- a/yarn-project/cli-wallet/src/cmds/add_authwit.ts +++ b/yarn-project/cli-wallet/src/cmds/add_authwit.ts @@ -7,7 +7,8 @@ export async function addAuthwit( authorizer: AztecAddress, log: LogFn, ) { - await wallet.addAuthWitness(authwit); + //await wallet.addAuthWitness(authwit); + throw new Error('Not implemented'); log(`Added authorization witness from ${authorizer}`); } diff --git a/yarn-project/cli-wallet/src/cmds/cancel_tx.ts b/yarn-project/cli-wallet/src/cmds/cancel_tx.ts index 8d8253dd9e69..936c0e048bf0 100644 --- a/yarn-project/cli-wallet/src/cmds/cancel_tx.ts +++ b/yarn-project/cli-wallet/src/cmds/cancel_tx.ts @@ -1,5 +1,5 @@ import { type AccountWalletWithSecretKey, type FeePaymentMethod, SentTx, type TxHash, TxStatus } from '@aztec/aztec.js'; -import type { FeeOptions } from '@aztec/aztec.js/entrypoint'; +import type { FeeOptions } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import type { LogFn } from '@aztec/foundation/log'; import { GasFees, GasSettings } from '@aztec/stdlib/gas'; diff --git a/yarn-project/cli-wallet/src/cmds/index.ts b/yarn-project/cli-wallet/src/cmds/index.ts index 12a4d434cd04..e6070d412407 100644 --- a/yarn-project/cli-wallet/src/cmds/index.ts +++ b/yarn-project/cli-wallet/src/cmds/index.ts @@ -21,7 +21,7 @@ import { type Command, Option } from 'commander'; import inquirer from 'inquirer'; import type { WalletDB } from '../storage/wallet_db.js'; -import { type AccountType, addScopeToWallet, createOrRetrieveAccount, getWalletWithScopes } from '../utils/accounts.js'; +import { type AccountType, createOrRetrieveAccount } from '../utils/accounts.js'; import { FeeOpts, FeeOptsWithFeePayer } from '../utils/options/fees.js'; import { ARTIFACT_DESCRIPTION, @@ -219,7 +219,7 @@ export function injectCommands( } = options; const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); const artifactPath = await artifactPathPromise; debugLogger.info(`Using wallet with address ${wallet.getCompleteAddress().address.toString()}`); @@ -282,7 +282,7 @@ export function injectCommands( } = options; const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db); debugLogger.info(`Using wallet with address ${wallet.getCompleteAddress().address.toString()}`); @@ -332,7 +332,7 @@ export function injectCommands( const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db); await simulate(wallet, functionName, args, artifactPath, contractAddress, profile, log); }); @@ -428,7 +428,7 @@ export function injectCommands( const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db); const witness = await createAuthwit(wallet, functionName, caller, args, artifactPath, contractAddress, log); @@ -468,7 +468,7 @@ export function injectCommands( const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db); await authorizeAction(wallet, functionName, caller, args, artifactPath, contractAddress, log); }); @@ -497,9 +497,8 @@ export function injectCommands( const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); await addAuthwit(wallet, authwit, authorizer, log); - await addScopeToWallet(wallet, authorizer, db); }); program @@ -572,7 +571,7 @@ export function injectCommands( const { from: parsedFromAddress, rpcUrl, secretKey, payment, increasedFees, maxFeesPerGas } = options; const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); const txData = await db?.retrieveTxData(txHash); if (!txData) { @@ -600,7 +599,7 @@ export function injectCommands( const { from: parsedFromAddress, rpcUrl, secretKey, alias } = options; const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); await registerSender(wallet, address, log); @@ -626,7 +625,7 @@ export function injectCommands( const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const node = pxeWrapper?.getNode() ?? createAztecNodeClient(nodeUrl); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); const artifactPath = await artifactPathPromise; diff --git a/yarn-project/cli-wallet/src/utils/accounts.ts b/yarn-project/cli-wallet/src/utils/accounts.ts index c97ef033eaca..f69780557632 100644 --- a/yarn-project/cli-wallet/src/utils/accounts.ts +++ b/yarn-project/cli-wallet/src/utils/accounts.ts @@ -70,33 +70,3 @@ export async function createOrRetrieveAccount( return account; } - -export async function addScopeToWallet(wallet: AccountWalletWithSecretKey, scope: AztecAddress, db?: WalletDB) { - const address = wallet.getAddress().toString(); - const currentScopes = wallet.getScopes() ?? []; - const deduplicatedScopes = Array.from( - new Set([address, ...currentScopes, scope].map(scope => scope.toString())).values(), - ); - if (db) { - await db.storeAccountMetadata(wallet.getAddress(), 'scopes', Buffer.from(deduplicatedScopes.join(','))); - } - wallet.setScopes(deduplicatedScopes.map(scope => AztecAddress.fromString(scope))); -} - -export async function getWalletWithScopes(account: AccountManager, db?: WalletDB) { - const wallet = await account.getWallet(); - if (db) { - const address = wallet.getAddress().toString(); - let storedScopes: string[] = []; - try { - storedScopes = ((await db.retrieveAccountMetadata(wallet.getAddress(), 'scopes')) ?? '').toString().split(','); - // eslint-disable-next-line no-empty - } catch {} - const currentScopes = wallet.getScopes()?.map(scopes => scopes.toString()) ?? []; - const deduplicatedScopes = Array.from(new Set([address, ...currentScopes, ...storedScopes]).values()).map(scope => - AztecAddress.fromString(scope), - ); - wallet.setScopes(deduplicatedScopes); - } - return wallet; -} diff --git a/yarn-project/cli/src/cmds/devnet/bootstrap_network.ts b/yarn-project/cli/src/cmds/devnet/bootstrap_network.ts index 7496ae37697b..69f094dcb334 100644 --- a/yarn-project/cli/src/cmds/devnet/bootstrap_network.ts +++ b/yarn-project/cli/src/cmds/devnet/bootstrap_network.ts @@ -6,10 +6,12 @@ import { Fr, L1FeeJuicePortalManager, type PXE, + type WaitForProvenOpts, type WaitOpts, type Wallet, createCompatibleClient, retryUntil, + waitForProven, } from '@aztec/aztec.js'; import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants'; import { @@ -32,6 +34,10 @@ type ContractDeploymentInfo = { const waitOpts: WaitOpts = { timeout: 120, + interval: 1, +}; + +const provenWaitOpts: WaitForProvenOpts = { provenTimeout: 4800, interval: 1, }; @@ -72,7 +78,7 @@ export async function bootstrapNetwork( const counter = await deployCounter(wallet); - await fundFPC(counter.address, wallet, l1Clients, fpc.address, debugLog); + await fundFPC(pxe, counter.address, wallet, l1Clients, fpc.address, debugLog); if (json) { log( @@ -259,6 +265,7 @@ async function deployCounter(wallet: Wallet): Promise { // NOTE: Disabling for now in order to get devnet running async function fundFPC( + pxe: PXE, counterAddress: AztecAddress, wallet: Wallet, l1Clients: L1Clients, @@ -291,12 +298,7 @@ async function fundFPC( true, ); - await retryUntil( - async () => await wallet.isL1ToL2MessageSynced(Fr.fromHexString(messageHash)), - 'message sync', - 600, - 1, - ); + await retryUntil(async () => await pxe.isL1ToL2MessageSynced(Fr.fromHexString(messageHash)), 'message sync', 600, 1); const counter = await CounterContract.at(counterAddress, wallet); @@ -309,10 +311,12 @@ async function fundFPC( debugLog.info('Claiming FPC'); - await feeJuiceContract.methods + const receipt = await feeJuiceContract.methods .claim(fpcAddress, claimAmount, claimSecret, messageLeafIndex) .send() - .wait({ ...waitOpts, proven: true }); + .wait({ ...waitOpts }); + + await waitForProven(pxe, receipt, provenWaitOpts); debugLog.info('Finished claiming FPC'); } diff --git a/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts b/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts index f0a703c48dcf..573e9b09a981 100644 --- a/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts +++ b/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts @@ -1,5 +1,12 @@ import { type InitialAccountData, deployFundedSchnorrAccounts, getInitialTestAccounts } from '@aztec/accounts/testing'; -import { type AztecAddress, SignerlessWallet, type WaitOpts, createPXEClient, makeFetch } from '@aztec/aztec.js'; +import { + type AztecAddress, + SignerlessWallet, + type WaitForProvenOpts, + type WaitOpts, + createPXEClient, + makeFetch, +} from '@aztec/aztec.js'; import { jsonStringify } from '@aztec/foundation/json-rpc'; import type { LogFn } from '@aztec/foundation/log'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; @@ -16,19 +23,24 @@ export async function setupL2Contracts( const waitOpts: WaitOpts = { timeout: 180, interval: 1, - proven: !skipProofWait, - provenTimeout: 600, }; + const waitForProvenOptions: WaitForProvenOpts | undefined = !skipProofWait + ? { + provenTimeout: 600, + } + : undefined; log('setupL2Contracts: Wait options' + jsonStringify(waitOpts)); + if (waitForProvenOptions) { + log('setupL2Contracts: Wait for proven options' + jsonStringify(waitForProvenOptions)); + } log('setupL2Contracts: Creating PXE client...'); const pxe = createPXEClient(rpcUrl, {}, makeFetch([1, 1, 1, 1, 1], false)); - const wallet = new SignerlessWallet(pxe); log('setupL2Contracts: Getting fee juice portal address...'); // Deploy Fee Juice - const feeJuicePortalAddress = (await wallet.getNodeInfo()).l1ContractAddresses.feeJuicePortalAddress; + const feeJuicePortalAddress = (await pxe.getNodeInfo()).l1ContractAddresses.feeJuicePortalAddress; log('setupL2Contracts: Setting up fee juice portal...'); - await setupCanonicalL2FeeJuice(wallet, feeJuicePortalAddress, waitOpts, log); + await setupCanonicalL2FeeJuice(pxe, feeJuicePortalAddress, log, waitOpts, waitForProvenOptions); let deployedAccounts: InitialAccountData[] = []; if (testAccounts) { diff --git a/yarn-project/cli/src/cmds/misc/setup_contracts.ts b/yarn-project/cli/src/cmds/misc/setup_contracts.ts index 6ac81ca540a3..5243008daf16 100644 --- a/yarn-project/cli/src/cmds/misc/setup_contracts.ts +++ b/yarn-project/cli/src/cmds/misc/setup_contracts.ts @@ -1,4 +1,13 @@ -import { DefaultWaitOpts, type EthAddress, FeeJuicePaymentMethod, type Wallet } from '@aztec/aztec.js'; +import { + DefaultWaitForProvenOpts, + DefaultWaitOpts, + type EthAddress, + FeeJuicePaymentMethod, + type PXE, + SignerlessWallet, + type WaitForProvenOpts, + waitForProven, +} from '@aztec/aztec.js'; import { FEE_JUICE_INITIAL_MINT } from '@aztec/constants'; import type { LogFn } from '@aztec/foundation/log'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; @@ -8,18 +17,21 @@ import { Gas } from '@aztec/stdlib/gas'; * Deploys the contract to pay for gas on L2. */ export async function setupCanonicalL2FeeJuice( - deployer: Wallet, + pxe: PXE, feeJuicePortalAddress: EthAddress, - waitOpts = DefaultWaitOpts, log: LogFn, + waitOpts = DefaultWaitOpts, + waitForProvenOptions?: WaitForProvenOpts, ) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment const { FeeJuiceContract } = await import('@aztec/noir-contracts.js/FeeJuice'); + const deployer = new SignerlessWallet(pxe); + const feeJuiceContract = await FeeJuiceContract.at(ProtocolContractAddress.FeeJuice, deployer); - const portalAddress = await deployer.getPublicStorageAt( + const portalAddress = await pxe.getPublicStorageAt( feeJuiceContract.address, feeJuiceContract.artifact.storageLayout.portal_address.slot, ); @@ -27,10 +39,13 @@ export async function setupCanonicalL2FeeJuice( if (portalAddress.isZero()) { log('setupCanonicalL2FeeJuice: Calling initialize on fee juice contract...'); const paymentMethod = new FeeJuicePaymentMethod(ProtocolContractAddress.FeeJuice); - await feeJuiceContract.methods + const receipt = await feeJuiceContract.methods .initialize(feeJuicePortalAddress, FEE_JUICE_INITIAL_MINT) .send({ fee: { paymentMethod, gasSettings: { teardownGasLimits: Gas.empty() } } }) .wait(waitOpts); + if (waitForProvenOptions !== undefined) { + await waitForProven(pxe, receipt, waitForProvenOptions); + } } else { log( 'setupCanonicalL2FeeJuice: Fee juice contract already initialized. Fee Juice Portal address: ' + diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index 18b907e0af8f..327eb15e37ef 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -34,12 +34,11 @@ describe('e2e_authwit_tests', () => { describe('Private', () => { describe('arbitrary data', () => { - it('happy path', async () => { + it.only('happy path', async () => { // What are we doing here: // 1. We compute an inner hash which is here just a hash of random data // 2. We then compute the message hash, which is binding it to a "consumer" (here the "auth" contract) // 3. We then create an authwit for this message hash. - // 4. We add this authwit to the wallet[1] // 5. We check that the authwit is valid in private for wallet[0] (check that it is signed by 0) // 6. We check that the authwit is NOT valid in private for wallet[1] (check that it is not signed by 1) @@ -53,37 +52,44 @@ describe('e2e_authwit_tests', () => { // docs:start:create_authwit const witness = await wallets[0].createAuthWit(intent); // docs:end:create_authwit - await wallets[1].addAuthWitness(witness); // Check that the authwit is valid in private for wallets[0] - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: true, isValidInPublic: false, }); // We give wallets[0] access to wallets[1]'s notes. - wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); + //wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); // Check that the authwit is NOT valid in private for wallets[1] - expect(await wallets[0].lookupValidity(wallets[1].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[1].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); // We give wallets[1] access to wallets[0]'s notes. - wallets[1].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); + // wallets[1].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); // Consume the inner hash using the wallets[0] as the "on behalf of". - await auth.withWallet(wallets[1]).methods.consume(wallets[0].getAddress(), innerHash).send().wait(); + await auth + .withWallet(wallets[1]) + .methods.consume(wallets[0].getAddress(), innerHash) + .send({ authwits: [witness] }) + .wait(); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); // Try to consume the same authwit again, it should fail await expect( - auth.withWallet(wallets[1]).methods.consume(wallets[0].getAddress(), innerHash).send().wait(), + auth + .withWallet(wallets[1]) + .methods.consume(wallets[0].getAddress(), innerHash) + .send({ authwits: [witness] }) + .wait(), ).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); describe('failure case', () => { @@ -94,16 +100,10 @@ describe('e2e_authwit_tests', () => { const messageHash = await computeAuthWitMessageHash(intent, { chainId: Fr.random(), version }); const expectedMessageHash = await computeAuthWitMessageHash(intent, { chainId, version }); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ - isValidInPrivate: false, - isValidInPublic: false, - }); - const witness = await wallets[0].createAuthWit(messageHash); - await wallets[1].addAuthWitness(witness); // We should NOT see it as valid, even though we have the authwit, since the chain id is wrong - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); @@ -112,11 +112,6 @@ describe('e2e_authwit_tests', () => { await expect( auth.withWallet(wallets[1]).methods.consume(wallets[0].getAddress(), innerHash).simulate(), ).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`); - - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ - isValidInPrivate: false, - isValidInPublic: false, - }); }); it('invalid version', async () => { @@ -127,16 +122,10 @@ describe('e2e_authwit_tests', () => { const expectedMessageHash = await computeAuthWitMessageHash(intent, { chainId, version }); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ - isValidInPrivate: false, - isValidInPublic: false, - }); - const witness = await wallets[0].createAuthWit(messageHash); - await wallets[1].addAuthWitness(witness); // We should NOT see it as valid, even though we have the authwit, since the version is wrong - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); @@ -146,7 +135,7 @@ describe('e2e_authwit_tests', () => { auth.withWallet(wallets[1]).methods.consume(wallets[0].getAddress(), innerHash).simulate(), ).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); @@ -162,7 +151,9 @@ describe('e2e_authwit_tests', () => { const intent = { consumer: wallets[1].getAddress(), innerHash }; - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + const witness = await wallets[0].createAuthWit(intent); + + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); @@ -171,7 +162,7 @@ describe('e2e_authwit_tests', () => { const validateActionInteraction = await wallets[0].setPublicAuthWit(intent, true); await validateActionInteraction.send().wait(); // docs:end:set_public_authwit - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: true, }); @@ -179,7 +170,7 @@ describe('e2e_authwit_tests', () => { const registry = await AuthRegistryContract.at(ProtocolContractAddress.AuthRegistry, wallets[1]); await registry.methods.consume(wallets[0].getAddress(), innerHash).send().wait(); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); @@ -190,7 +181,9 @@ describe('e2e_authwit_tests', () => { const innerHash = await computeInnerAuthWitHash([Fr.fromHexString('0xdead'), Fr.fromHexString('0x02')]); const intent = { consumer: auth.address, innerHash }; - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + const witness = await wallets[0].createAuthWit(intent); + + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); @@ -198,7 +191,7 @@ describe('e2e_authwit_tests', () => { const validateActionInteraction = await wallets[0].setPublicAuthWit(intent, true); await validateActionInteraction.send().wait(); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: true, }); @@ -206,7 +199,7 @@ describe('e2e_authwit_tests', () => { const cancelActionInteraction = await wallets[0].setPublicAuthWit(intent, false); await cancelActionInteraction.send().wait(); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); diff --git a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts index 75c70306eadb..9275dc9282b9 100644 --- a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts +++ b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts @@ -110,7 +110,6 @@ describe('PXEOracleInterface', () => { let aztecNode: MockProxy; let addressDataProvider: AddressDataProvider; - let authWitnessDataProvider: AuthWitnessDataProvider; let contractDataProvider: ContractDataProvider; let noteDataProvider: NoteDataProvider; let syncDataProvider: SyncDataProvider; @@ -131,7 +130,6 @@ describe('PXEOracleInterface', () => { jest.spyOn(contractDataProvider, 'getDebugContractName').mockImplementation(() => Promise.resolve('TestContract')); addressDataProvider = new AddressDataProvider(store); - authWitnessDataProvider = new AuthWitnessDataProvider(store); noteDataProvider = await NoteDataProvider.create(store); syncDataProvider = new SyncDataProvider(store); taggingDataProvider = new TaggingDataProvider(store); @@ -148,7 +146,6 @@ describe('PXEOracleInterface', () => { syncDataProvider, taggingDataProvider, addressDataProvider, - authWitnessDataProvider, ); // Set up contract address contractAddress = await AztecAddress.random(); // Set up recipient account diff --git a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts index 654fc05ba54c..a671744a198a 100644 --- a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts +++ b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts @@ -67,8 +67,7 @@ export class PXEOracleInterface implements ExecutionDataProvider { private syncDataProvider: SyncDataProvider, private taggingDataProvider: TaggingDataProvider, private addressDataProvider: AddressDataProvider, - private authWitnessDataProvider: AuthWitnessDataProvider, - private log = createLogger('pxe:pxe_data_manager'), + private log = createLogger('pxe:pxe_oracle_interface'), ) {} getKeyValidationRequest(pkMHash: Fr, contractAddress: AztecAddress): Promise { @@ -94,11 +93,6 @@ export class PXEOracleInterface implements ExecutionDataProvider { return instance; } - async getAuthWitness(messageHash: Fr): Promise { - const witness = await this.authWitnessDataProvider.getAuthWitness(messageHash); - return witness; - } - async getNotes(contractAddress: AztecAddress, storageSlot: Fr, status: NoteStatus, scopes?: AztecAddress[]) { const noteDaos = await this.noteDataProvider.getNotes({ contractAddress, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 4471e59005a2..ce0d862932da 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -74,7 +74,6 @@ import { KernelOracle } from '../kernel_oracle/index.js'; import { KernelProver, type ProvingConfig } from '../kernel_prover/kernel_prover.js'; import { PXEOracleInterface } from '../pxe_oracle_interface/pxe_oracle_interface.js'; import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js'; -import { AuthWitnessDataProvider } from '../storage/auth_witness_data_provider/auth_witness_data_provider.js'; import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js'; import { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js'; import { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js'; @@ -97,7 +96,6 @@ export class PXEService implements PXE { private syncDataProvider: SyncDataProvider, private taggingDataProvider: TaggingDataProvider, private addressDataProvider: AddressDataProvider, - private authWitnessDataProvider: AuthWitnessDataProvider, private simulator: AcirSimulator, private packageVersion: string, private proverEnabled: boolean, @@ -131,7 +129,6 @@ export class PXEService implements PXE { const packageVersion = getPackageInfo().version; const proverEnabled = !!config.proverEnabled; const addressDataProvider = new AddressDataProvider(store); - const authWitnessDataProvider = new AuthWitnessDataProvider(store); const contractDataProvider = new ContractDataProvider(store); const noteDataProvider = await NoteDataProvider.create(store); const syncDataProvider = new SyncDataProvider(store); @@ -158,7 +155,6 @@ export class PXEService implements PXE { syncDataProvider, taggingDataProvider, addressDataProvider, - authWitnessDataProvider, log, ); const simulator = new AcirSimulator(pxeOracleInterface, simulationProvider); @@ -174,7 +170,6 @@ export class PXEService implements PXE { syncDataProvider, taggingDataProvider, addressDataProvider, - authWitnessDataProvider, simulator, packageVersion, proverEnabled, @@ -192,6 +187,68 @@ export class PXEService implements PXE { return pxeService; } + // Aztec node proxy methods + + public isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise { + return this.node.isL1ToL2MessageSynced(l1ToL2Message); + } + + public getL2ToL1MembershipWitness(blockNumber: number, l2Tol1Message: Fr): Promise<[bigint, SiblingPath]> { + return this.node.getL2ToL1MessageMembershipWitness(blockNumber, l2Tol1Message); + } + + public getTxReceipt(txHash: TxHash): Promise { + return this.node.getTxReceipt(txHash); + } + + public getTxEffect(txHash: TxHash): Promise | undefined> { + return this.node.getTxEffect(txHash); + } + + public async getBlockNumber(): Promise { + return this.node.getBlockNumber(); + } + + public async getProvenBlockNumber(): Promise { + return this.node.getProvenBlockNumber(); + } + + public getPublicLogs(filter: LogFilter): Promise { + return this.node.getPublicLogs(filter); + } + + public getContractClassLogs(filter: LogFilter): Promise { + return this.node.getContractClassLogs(filter); + } + + public async getPublicStorageAt(contract: AztecAddress, slot: Fr) { + return this.node.getPublicStorageAt('latest', contract, slot); + } + + public async getL1ToL2MembershipWitness( + contractAddress: AztecAddress, + messageHash: Fr, + secret: Fr, + ): Promise<[bigint, SiblingPath]> { + return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret); + } + + // Internal methods + + #contextualizeError(err: Error, ...context: string[]): Error { + let contextStr = ''; + if (context.length > 0) { + contextStr = `\nContext:\n${context.join('\n')}`; + } + if (err instanceof SimulationError) { + err.setAztecContext(contextStr); + } else { + this.log.error(err.name, err); + this.log.debug(contextStr); + } + return err; + } + /** * Enqueues a job for execution once no other jobs are running. Returns a promise that will resolve once the job is * complete. @@ -209,16 +266,187 @@ export class PXEService implements PXE { return this.jobQueue.put(fn); } - isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise { - return this.node.isL1ToL2MessageSynced(l1ToL2Message); + async #registerProtocolContracts() { + const registered: Record = {}; + for (const name of protocolContractNames) { + const { address, contractClass, instance, artifact } = + await this.protocolContractsProvider.getProtocolContractArtifact(name); + await this.contractDataProvider.addContractArtifact(contractClass.id, artifact); + await this.contractDataProvider.addContractInstance(instance); + registered[name] = address.toString(); + } + this.log.verbose(`Registered protocol contracts in pxe`, registered); + } + + async #isContractClassPubliclyRegistered(id: Fr): Promise { + return !!(await this.node.getContractClass(id)); + } + + async #isContractPubliclyDeployed(address: AztecAddress): Promise { + return !!(await this.node.getContract(address)); + } + + async #isContractInitialized(address: AztecAddress): Promise { + const initNullifier = await siloNullifier(address, address.toField()); + return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier)); + } + + /** + * Retrieves the simulation parameters required to run an ACIR simulation. + * This includes the contract address, function artifact, and historical tree roots. + * + * @param execRequest - The transaction request object containing details of the contract call. + * @returns An object containing the contract address, function artifact, and historical tree roots. + */ + #getSimulationParameters(execRequest: FunctionCall | TxExecutionRequest) { + const contractAddress = (execRequest as FunctionCall).to ?? (execRequest as TxExecutionRequest).origin; + const functionSelector = + (execRequest as FunctionCall).selector ?? (execRequest as TxExecutionRequest).functionSelector; + + return { + contractAddress, + functionSelector, + }; + } + + async #getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise { + const contract = await this.contractDataProvider.getContract(to); + if (!contract) { + throw new Error( + `Unknown contract ${to}: add it to PXE Service by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`, + ); + } + + const functionDao = contract.functions.find(f => f.name === functionName); + if (!functionDao) { + throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`); + } + + return { + name: functionDao.name, + args: encodeArguments(functionDao, args), + selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters), + type: functionDao.functionType, + to, + isStatic: functionDao.isStatic, + returnTypes: functionDao.returnTypes, + }; } + async #executePrivate( + txRequest: TxExecutionRequest, + msgSender?: AztecAddress, + scopes?: AztecAddress[], + ): Promise { + const { contractAddress, functionSelector } = this.#getSimulationParameters(txRequest); + + try { + const result = await this.simulator.run(txRequest, contractAddress, functionSelector, msgSender, scopes); + this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`); + return result; + } catch (err) { + if (err instanceof SimulationError) { + await enrichSimulationError(err, this.contractDataProvider, this.log); + } + throw err; + } + } + + /** + * Simulate an unconstrained transaction on the given contract, without considering constraints set by ACIR. + * The simulation parameters are fetched using ContractDataProvider and executed using AcirSimulator. + * Returns the simulation result containing the outputs of the unconstrained function. + * + * @param execRequest - The transaction request object containing the target contract and function data. + * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all. + * @returns The simulation result containing the outputs of the unconstrained function. + */ + async #simulateUnconstrained(execRequest: FunctionCall, authwits: AuthWitness[], scopes?: AztecAddress[]) { + const { contractAddress, functionSelector } = this.#getSimulationParameters(execRequest); + + this.log.debug('Executing unconstrained simulator...'); + try { + const result = await this.simulator.runUnconstrained( + execRequest, + contractAddress, + functionSelector, + authwits, + scopes, + ); + this.log.verbose(`Unconstrained simulation for ${contractAddress}.${functionSelector} completed`); + + return result; + } catch (err) { + if (err instanceof SimulationError) { + await enrichSimulationError(err, this.contractDataProvider, this.log); + } + throw err; + } + } + + /** + * Simulate the public part of a transaction. + * This allows to catch public execution errors before submitting the transaction. + * It can also be used for estimating gas in the future. + * @param tx - The transaction to be simulated. + */ + async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean) { + // Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup) + // Or return as reverted if it fails in a phase that allows reverts (app logic, teardown) + try { + const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement); + if (result.revertReason) { + throw result.revertReason; + } + return result; + } catch (err) { + if (err instanceof SimulationError) { + try { + await enrichPublicSimulationError(err, this.contractDataProvider, this.log); + } catch (enrichErr) { + this.log.error(`Failed to enrich public simulation error: ${enrichErr}`); + } + } + throw err; + } + } + + /** + * Generate a kernel proof, and create a private kernel output. + * The function takes in a transaction execution request, and the result of private execution + * and then generates a kernel proof. + * + * @param txExecutionRequest - The transaction request to be simulated and proved. + * @param proofCreator - The proof creator to use for proving the execution. + * @param privateExecutionResult - The result of the private execution + * @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled. + */ + async #prove( + txExecutionRequest: TxExecutionRequest, + proofCreator: PrivateKernelProver, + privateExecutionResult: PrivateExecutionResult, + { simulate, skipFeeEnforcement, profile }: ProvingConfig, + ): Promise> { + // use the block the tx was simulated against + const block = + privateExecutionResult.entrypoint.publicInputs.historicalHeader.globalVariables.blockNumber.toNumber(); + const kernelOracle = new KernelOracle(this.contractDataProvider, this.keyStore, this.node, block); + const kernelProver = new KernelProver(kernelOracle, proofCreator, !this.proverEnabled); + this.log.debug(`Executing kernel prover (simulate: ${simulate}, profile: ${profile})...`); + return await kernelProver.prove(txExecutionRequest.toTxRequest(), privateExecutionResult, { + simulate, + skipFeeEnforcement, + profile, + }); + } + + // Public API + /** Returns an estimate of the db size in bytes. */ public async estimateDbSize() { const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES; const dbSizes = await Promise.all([ this.addressDataProvider.getSize(), - this.authWitnessDataProvider.getSize(), this.capsuleDataProvider.getSize(), this.contractDataProvider.getSize(), this.noteDataProvider.getSize(), @@ -228,18 +456,6 @@ export class PXEService implements PXE { return [...dbSizes, treeRootsSize].reduce((sum, size) => sum + size, 0); } - public addAuthWitness(witness: AuthWitness) { - return this.authWitnessDataProvider.addAuthWitness(witness.requestHash, witness.witness); - } - - public getAuthWitness(messageHash: Fr): Promise { - return this.authWitnessDataProvider.getAuthWitness(messageHash); - } - - public storeCapsule(contract: AztecAddress, storageSlot: Fr, capsule: Fr[]) { - return this.capsuleDataProvider.storeCapsule(contract, storageSlot, capsule); - } - public getContractInstance(address: AztecAddress): Promise { return this.contractDataProvider.getContractInstance(address); } @@ -319,9 +535,7 @@ export class PXEService implements PXE { } public getSenders(): Promise { - const senders = this.taggingDataProvider.getSenderAddresses(); - - return Promise.resolve(senders); + return this.taggingDataProvider.getSenderAddresses(); } public async removeSender(address: AztecAddress): Promise { @@ -332,8 +546,6 @@ export class PXEService implements PXE { } else { this.log.info(`Sender:\n "${address.toString()}"\n not in address book.`); } - - return Promise.resolve(); } public async getRegisteredAccounts(): Promise { @@ -428,10 +640,6 @@ export class PXEService implements PXE { return this.contractDataProvider.getContractsAddresses(); } - public async getPublicStorageAt(contract: AztecAddress, slot: Fr) { - return await this.node.getPublicStorageAt('latest', contract, slot); - } - public async getNotes(filter: NotesFilter): Promise { const noteDaos = await this.noteDataProvider.getNotes(filter); @@ -461,18 +669,6 @@ export class PXEService implements PXE { return Promise.all(extendedNotes); } - public async getL1ToL2MembershipWitness( - contractAddress: AztecAddress, - messageHash: Fr, - secret: Fr, - ): Promise<[bigint, SiblingPath]> { - return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret); - } - - public getL2ToL1MembershipWitness(blockNumber: number, l2Tol1Message: Fr): Promise<[bigint, SiblingPath]> { - return this.node.getL2ToL1MessageMembershipWitness(blockNumber, l2Tol1Message); - } - public async getBlock(blockNumber: number): Promise { // If a negative block number is provided the current block number is fetched. if (blockNumber < 0) { @@ -505,7 +701,7 @@ export class PXEService implements PXE { ); return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!); } catch (err: any) { - throw this.contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult)); + throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult)); } }); } @@ -587,7 +783,7 @@ export class PXEService implements PXE { profileResult, ); } catch (err: any) { - throw this.contextualizeError( + throw this.#contextualizeError( err, inspect(txRequest), `simulatePublic=${simulatePublic}`, @@ -607,7 +803,7 @@ export class PXEService implements PXE { } this.log.debug(`Sending transaction ${txHash}`); await this.node.sendTx(tx).catch(err => { - throw this.contextualizeError(err, inspect(tx)); + throw this.#contextualizeError(err, inspect(tx)); }); this.log.info(`Sent transaction ${txHash}`); return txHash; @@ -617,6 +813,7 @@ export class PXEService implements PXE { functionName: string, args: any[], to: AztecAddress, + authwits?: AuthWitness[], _from?: AztecAddress, scopes?: AztecAddress[], ): Promise { @@ -628,13 +825,13 @@ export class PXEService implements PXE { await this.synchronizer.sync(); // TODO - Should check if `from` has the permission to call the view function. const functionCall = await this.#getFunctionCall(functionName, args, to); - const executionResult = await this.#simulateUnconstrained(functionCall, scopes); + const executionResult = await this.#simulateUnconstrained(functionCall, authwits ?? [], scopes); // TODO - Return typed result based on the function artifact. return executionResult; } catch (err: any) { const stringifiedArgs = args.map(arg => arg.toString()).join(', '); - throw this.contextualizeError( + throw this.#contextualizeError( err, `simulateUnconstrained ${to}:${functionName}(${stringifiedArgs})`, `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`, @@ -643,64 +840,6 @@ export class PXEService implements PXE { }); } - public getTxReceipt(txHash: TxHash): Promise { - return this.node.getTxReceipt(txHash); - } - - public getTxEffect(txHash: TxHash): Promise | undefined> { - return this.node.getTxEffect(txHash); - } - - public async getBlockNumber(): Promise { - return await this.node.getBlockNumber(); - } - - public async getProvenBlockNumber(): Promise { - return await this.node.getProvenBlockNumber(); - } - - /** - * Gets public logs based on the provided filter. - * @param filter - The filter to apply to the logs. - * @returns The requested logs. - */ - public getPublicLogs(filter: LogFilter): Promise { - return this.node.getPublicLogs(filter); - } - - /** - * Gets contract class logs based on the provided filter. - * @param filter - The filter to apply to the logs. - * @returns The requested logs. - */ - public getContractClassLogs(filter: LogFilter): Promise { - return this.node.getContractClassLogs(filter); - } - - async #getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise { - const contract = await this.contractDataProvider.getContract(to); - if (!contract) { - throw new Error( - `Unknown contract ${to}: add it to PXE Service by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`, - ); - } - - const functionDao = contract.functions.find(f => f.name === functionName); - if (!functionDao) { - throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`); - } - - return { - name: functionDao.name, - args: encodeArguments(functionDao, args), - selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters), - type: functionDao.functionType, - to, - isStatic: functionDao.isStatic, - returnTypes: functionDao.returnTypes, - }; - } - public async getNodeInfo(): Promise { const [nodeVersion, protocolVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([ @@ -736,151 +875,6 @@ export class PXEService implements PXE { }); } - async #registerProtocolContracts() { - const registered: Record = {}; - for (const name of protocolContractNames) { - const { address, contractClass, instance, artifact } = - await this.protocolContractsProvider.getProtocolContractArtifact(name); - await this.contractDataProvider.addContractArtifact(contractClass.id, artifact); - await this.contractDataProvider.addContractInstance(instance); - registered[name] = address.toString(); - } - this.log.verbose(`Registered protocol contracts in pxe`, registered); - } - - /** - * Retrieves the simulation parameters required to run an ACIR simulation. - * This includes the contract address, function artifact, and historical tree roots. - * - * @param execRequest - The transaction request object containing details of the contract call. - * @returns An object containing the contract address, function artifact, and historical tree roots. - */ - #getSimulationParameters(execRequest: FunctionCall | TxExecutionRequest) { - const contractAddress = (execRequest as FunctionCall).to ?? (execRequest as TxExecutionRequest).origin; - const functionSelector = - (execRequest as FunctionCall).selector ?? (execRequest as TxExecutionRequest).functionSelector; - - return { - contractAddress, - functionSelector, - }; - } - - async #executePrivate( - txRequest: TxExecutionRequest, - msgSender?: AztecAddress, - scopes?: AztecAddress[], - ): Promise { - // TODO - Pause syncing while simulating. - const { contractAddress, functionSelector } = this.#getSimulationParameters(txRequest); - - try { - const result = await this.simulator.run(txRequest, contractAddress, functionSelector, msgSender, scopes); - this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`); - return result; - } catch (err) { - if (err instanceof SimulationError) { - await enrichSimulationError(err, this.contractDataProvider, this.log); - } - throw err; - } - } - - /** - * Simulate an unconstrained transaction on the given contract, without considering constraints set by ACIR. - * The simulation parameters are fetched using ContractDataProvider and executed using AcirSimulator. - * Returns the simulation result containing the outputs of the unconstrained function. - * - * @param execRequest - The transaction request object containing the target contract and function data. - * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all. - * @returns The simulation result containing the outputs of the unconstrained function. - */ - async #simulateUnconstrained(execRequest: FunctionCall, scopes?: AztecAddress[]) { - const { contractAddress, functionSelector } = this.#getSimulationParameters(execRequest); - - this.log.debug('Executing unconstrained simulator...'); - try { - const result = await this.simulator.runUnconstrained(execRequest, contractAddress, functionSelector, scopes); - this.log.verbose(`Unconstrained simulation for ${contractAddress}.${functionSelector} completed`); - - return result; - } catch (err) { - if (err instanceof SimulationError) { - await enrichSimulationError(err, this.contractDataProvider, this.log); - } - throw err; - } - } - - /** - * Simulate the public part of a transaction. - * This allows to catch public execution errors before submitting the transaction. - * It can also be used for estimating gas in the future. - * @param tx - The transaction to be simulated. - */ - async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean) { - // Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup) - // Or return as reverted if it fails in a phase that allows reverts (app logic, teardown) - try { - const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement); - if (result.revertReason) { - throw result.revertReason; - } - return result; - } catch (err) { - if (err instanceof SimulationError) { - try { - await enrichPublicSimulationError(err, this.contractDataProvider, this.log); - } catch (enrichErr) { - this.log.error(`Failed to enrich public simulation error: ${enrichErr}`); - } - } - throw err; - } - } - - /** - * Generate a kernel proof, and create a private kernel output. - * The function takes in a transaction execution request, and the result of private execution - * and then generates a kernel proof. - * - * @param txExecutionRequest - The transaction request to be simulated and proved. - * @param proofCreator - The proof creator to use for proving the execution. - * @param privateExecutionResult - The result of the private execution - * @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled. - */ - async #prove( - txExecutionRequest: TxExecutionRequest, - proofCreator: PrivateKernelProver, - privateExecutionResult: PrivateExecutionResult, - { simulate, skipFeeEnforcement, profile }: ProvingConfig, - ): Promise> { - // use the block the tx was simulated against - const block = - privateExecutionResult.entrypoint.publicInputs.historicalHeader.globalVariables.blockNumber.toNumber(); - const kernelOracle = new KernelOracle(this.contractDataProvider, this.keyStore, this.node, block); - const kernelProver = new KernelProver(kernelOracle, proofCreator, !this.proverEnabled); - this.log.debug(`Executing kernel prover (simulate: ${simulate}, profile: ${profile})...`); - return await kernelProver.prove(txExecutionRequest.toTxRequest(), privateExecutionResult, { - simulate, - skipFeeEnforcement, - profile, - }); - } - - async #isContractClassPubliclyRegistered(id: Fr): Promise { - return !!(await this.node.getContractClass(id)); - } - - async #isContractPubliclyDeployed(address: AztecAddress): Promise { - return !!(await this.node.getContract(address)); - } - - async #isContractInitialized(address: AztecAddress): Promise { - const initNullifier = await siloNullifier(address, address.toField()); - return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier)); - } - public async getPrivateEvents( eventMetadataDef: EventMetadataDefinition, from: number, @@ -985,18 +979,4 @@ export class PXEService implements PXE { async resetNoteSyncData() { return await this.taggingDataProvider.resetNoteSyncData(); } - - private contextualizeError(err: Error, ...context: string[]): Error { - let contextStr = ''; - if (context.length > 0) { - contextStr = `\nContext:\n${context.join('\n')}`; - } - if (err instanceof SimulationError) { - err.setAztecContext(contextStr); - } else { - this.log.error(err.name, err); - this.log.debug(contextStr); - } - return err; - } } diff --git a/yarn-project/pxe/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts b/yarn-project/pxe/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts deleted file mode 100644 index 1b130691a1ea..000000000000 --- a/yarn-project/pxe/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Fr } from '@aztec/foundation/fields'; -import { toArray } from '@aztec/foundation/iterable'; -import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store'; - -import type { DataProvider } from '../data_provider.js'; - -export class AuthWitnessDataProvider implements DataProvider { - #store: AztecAsyncKVStore; - #authWitnesses: AztecAsyncMap; - - constructor(store: AztecAsyncKVStore) { - this.#store = store; - this.#authWitnesses = this.#store.openMap('auth_witnesses'); - } - - async addAuthWitness(messageHash: Fr, witness: Fr[]): Promise { - await this.#authWitnesses.set( - messageHash.toString(), - witness.map(w => w.toBuffer()), - ); - } - - async getAuthWitness(messageHash: Fr): Promise { - const witness = await this.#authWitnesses.getAsync(messageHash.toString()); - return witness?.map(w => Fr.fromBuffer(w)); - } - - async getSize(): Promise { - return (await toArray(this.#authWitnesses.valuesAsync())).reduce( - (sum, value) => sum + value.length * Fr.SIZE_IN_BYTES, - 0, - ); - } -} diff --git a/yarn-project/pxe/src/storage/auth_witness_data_provider/auth_witness_data_providert.test.ts b/yarn-project/pxe/src/storage/auth_witness_data_provider/auth_witness_data_providert.test.ts deleted file mode 100644 index e2cbb088c0e6..000000000000 --- a/yarn-project/pxe/src/storage/auth_witness_data_provider/auth_witness_data_providert.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Fr } from '@aztec/foundation/fields'; -import { openTmpStore } from '@aztec/kv-store/lmdb-v2'; - -import { AuthWitnessDataProvider } from './auth_witness_data_provider.js'; - -describe('auth witnesses', () => { - let authWitnessDataProvider: AuthWitnessDataProvider; - - beforeEach(async () => { - const store = await openTmpStore('auth_witness_data_provider_test'); - authWitnessDataProvider = new AuthWitnessDataProvider(store); - }); - it('stores and retrieves auth witnesses', async () => { - const messageHash = Fr.random(); - const witness = [Fr.random(), Fr.random()]; - - await authWitnessDataProvider.addAuthWitness(messageHash, witness); - await expect(authWitnessDataProvider.getAuthWitness(messageHash)).resolves.toEqual(witness); - }); - - it("returns undefined if it doesn't have auth witnesses for the message", async () => { - const messageHash = Fr.random(); - await expect(authWitnessDataProvider.getAuthWitness(messageHash)).resolves.toBeUndefined(); - }); - - it.skip('refuses to overwrite auth witnesses for the same message', async () => { - const messageHash = Fr.random(); - const witness = [Fr.random(), Fr.random()]; - - await authWitnessDataProvider.addAuthWitness(messageHash, witness); - await expect(authWitnessDataProvider.addAuthWitness(messageHash, witness)).rejects.toThrow(); - }); -}); diff --git a/yarn-project/pxe/src/storage/auth_witness_data_provider/index.ts b/yarn-project/pxe/src/storage/auth_witness_data_provider/index.ts deleted file mode 100644 index 9fcc2e76e803..000000000000 --- a/yarn-project/pxe/src/storage/auth_witness_data_provider/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { AuthWitnessDataProvider } from './auth_witness_data_provider.js'; diff --git a/yarn-project/pxe/src/storage/index.ts b/yarn-project/pxe/src/storage/index.ts index be6fb54e6a57..aaa477fe359f 100644 --- a/yarn-project/pxe/src/storage/index.ts +++ b/yarn-project/pxe/src/storage/index.ts @@ -1,5 +1,4 @@ export * from './address_data_provider/index.js'; -export * from './auth_witness_data_provider/index.js'; export * from './capsule_data_provider/index.js'; export * from './contract_data_provider/index.js'; export * from './note_data_provider/index.js'; diff --git a/yarn-project/simulator/src/private/execution_data_provider.ts b/yarn-project/simulator/src/private/execution_data_provider.ts index 5dff5778d87f..4370cf6c126b 100644 --- a/yarn-project/simulator/src/private/execution_data_provider.ts +++ b/yarn-project/simulator/src/private/execution_data_provider.ts @@ -49,13 +49,6 @@ export interface ExecutionDataProvider extends CommitmentsDB { */ getCompleteAddress(account: AztecAddress): Promise; - /** - * Retrieve the auth witness for a given message hash. - * @param messageHash - The message hash. - * @returns A Promise that resolves to an array of field elements representing the auth witness. - */ - getAuthWitness(messageHash: Fr): Promise; - /** * Retrieve keys associated with a specific master public key and app address. * @param pkMHash - The master public key hash. diff --git a/yarn-project/simulator/src/private/simulator.ts b/yarn-project/simulator/src/private/simulator.ts index 8a80da482125..bb895c6f97d7 100644 --- a/yarn-project/simulator/src/private/simulator.ts +++ b/yarn-project/simulator/src/private/simulator.ts @@ -2,6 +2,7 @@ import { Fr } from '@aztec/foundation/fields'; import { type Logger, createLogger } from '@aztec/foundation/log'; import type { FunctionCall } from '@aztec/stdlib/abi'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; +import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { CallContext, PrivateExecutionResult, TxExecutionRequest } from '@aztec/stdlib/tx'; @@ -113,6 +114,7 @@ export class AcirSimulator { request: FunctionCall, contractAddress: AztecAddress, selector: FunctionSelector, + authwits: AuthWitness[], scopes?: AztecAddress[], ) { await verifyCurrentClassId(contractAddress, this.executionDataProvider); @@ -124,7 +126,7 @@ export class AcirSimulator { const context = new UnconstrainedExecutionOracle( contractAddress, - [], + authwits, [], this.executionDataProvider, undefined, diff --git a/yarn-project/simulator/src/private/unconstrained_execution.test.ts b/yarn-project/simulator/src/private/unconstrained_execution.test.ts index 01d7d57b6b2a..0e6c59108c7a 100644 --- a/yarn-project/simulator/src/private/unconstrained_execution.test.ts +++ b/yarn-project/simulator/src/private/unconstrained_execution.test.ts @@ -94,7 +94,7 @@ describe('Unconstrained Execution test suite', () => { returnTypes: artifact.returnTypes, }; - const result = await acirSimulator.runUnconstrained(execRequest, contractAddress, FunctionSelector.empty()); + const result = await acirSimulator.runUnconstrained(execRequest, contractAddress, FunctionSelector.empty(), []); expect(result).toEqual(9n); }, 30_000); diff --git a/yarn-project/simulator/src/private/unconstrained_execution_oracle.ts b/yarn-project/simulator/src/private/unconstrained_execution_oracle.ts index 770c4a703b23..896a49bf4b7d 100644 --- a/yarn-project/simulator/src/private/unconstrained_execution_oracle.ts +++ b/yarn-project/simulator/src/private/unconstrained_execution_oracle.ts @@ -149,10 +149,7 @@ export class UnconstrainedExecutionOracle extends TypedOracle { * @returns Authentication witness for the requested message hash. */ public override getAuthWitness(messageHash: Fr): Promise { - return Promise.resolve( - this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness ?? - this.executionDataProvider.getAuthWitness(messageHash), - ); + return Promise.resolve(this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness); } /** diff --git a/yarn-project/stdlib/src/interfaces/pxe.test.ts b/yarn-project/stdlib/src/interfaces/pxe.test.ts index 8ec3c17a1585..3d32b3c3efc1 100644 --- a/yarn-project/stdlib/src/interfaces/pxe.test.ts +++ b/yarn-project/stdlib/src/interfaces/pxe.test.ts @@ -95,19 +95,6 @@ describe('PXESchema', () => { await context.client.isL1ToL2MessageSynced(Fr.random()); }); - it('addAuthWitness', async () => { - await context.client.addAuthWitness(AuthWitness.random()); - }); - - it('getAuthWitness', async () => { - const result = await context.client.getAuthWitness(Fr.random()); - expect(result).toEqual([expect.any(Fr)]); - }); - - it('storeCapsule', async () => { - await context.client.storeCapsule(address, Fr.random(), times(3, Fr.random)); - }); - it('registerAccount', async () => { const result = await context.client.registerAccount(Fr.random(), Fr.random()); expect(result).toBeInstanceOf(CompleteAddress); @@ -236,7 +223,7 @@ describe('PXESchema', () => { }); it('simulateUnconstrained', async () => { - const result = await context.client.simulateUnconstrained('function', [], address, address, [address]); + const result = await context.client.simulateUnconstrained('function', [], address, [], address, [address]); expect(result).toEqual(10n); }); @@ -324,21 +311,6 @@ class MockPXE implements PXE { isL1ToL2MessageSynced(_l1ToL2Message: Fr): Promise { return Promise.resolve(false); } - - addAuthWitness(authWitness: AuthWitness): Promise { - expect(authWitness).toBeInstanceOf(AuthWitness); - return Promise.resolve(); - } - getAuthWitness(messageHash: Fr): Promise { - expect(messageHash).toBeInstanceOf(Fr); - return Promise.resolve([Fr.random()]); - } - storeCapsule(contract: AztecAddress, storageSlot: Fr, capsule: Fr[]): Promise { - expect(contract).toBeInstanceOf(AztecAddress); - expect(storageSlot).toBeInstanceOf(Fr); - expect(capsule.every(c => c instanceof Fr)).toBeTruthy(); - return Promise.resolve(); - } registerAccount(secretKey: Fr, partialAddress: Fr): Promise { expect(secretKey).toBeInstanceOf(Fr); expect(partialAddress).toBeInstanceOf(Fr); @@ -453,12 +425,14 @@ class MockPXE implements PXE { _functionName: string, _args: any[], to: AztecAddress, + authwits?: AuthWitness[], from?: AztecAddress | undefined, scopes?: AztecAddress[] | undefined, ): Promise { expect(to).toEqual(this.address); expect(from).toEqual(this.address); expect(scopes).toEqual([this.address]); + expect(authwits).toEqual([]); return Promise.resolve(10n); } async getPublicLogs(filter: LogFilter): Promise { diff --git a/yarn-project/stdlib/src/interfaces/pxe.ts b/yarn-project/stdlib/src/interfaces/pxe.ts index 018fbbf6600f..c350246020e1 100644 --- a/yarn-project/stdlib/src/interfaces/pxe.ts +++ b/yarn-project/stdlib/src/interfaces/pxe.ts @@ -61,38 +61,6 @@ export interface PXE { */ isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise; - /** - * Insert an auth witness for a given message hash. Auth witnesses are used to authorize actions on - * behalf of a user. For instance, a token transfer initiated by a different address may request - * authorization from the user to move their tokens. This authorization is granted by the user - * account contract by verifying an auth witness requested to the execution oracle. Witnesses are - * usually a signature over a hash of the action to be authorized, but their actual contents depend - * on the account contract that consumes them. - * - * @param authWitness - The auth witness to insert. Composed of an identifier, which is the hash of - * the action to be authorized, and the actual witness as an array of fields, which are to be - * deserialized and processed by the account contract. - */ - addAuthWitness(authWitness: AuthWitness): Promise; - - /** - * Fetches the serialized auth witness for a given message hash or returns undefined if not found. - * @param messageHash - The hash of the message for which to get the auth witness. - * @returns The serialized auth witness for the given message hash. - */ - getAuthWitness(messageHash: Fr): Promise; - - /** - * Adds a capsule. - * @param contract - The address of the contract to add the capsule to. - * @param storageSlot - The storage slot to add the capsule to. - * @param capsule - An array of field elements representing the capsule. - * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly - * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global - * network state it's backed by local PXE db. - */ - storeCapsule(contract: AztecAddress, storageSlot: Fr, capsule: Fr[]): Promise; - /** * Registers a user account in PXE given its master encryption private key. * Once a new account is registered, the PXE Service will trial-decrypt all published notes on @@ -305,6 +273,7 @@ export interface PXE { functionName: string, args: any[], to: AztecAddress, + authwits?: AuthWitness[], from?: AztecAddress, scopes?: AztecAddress[], ): Promise; @@ -454,12 +423,6 @@ const PXEInfoSchema = z.object({ export const PXESchema: ApiSchemaFor = { isL1ToL2MessageSynced: z.function().args(schemas.Fr).returns(z.boolean()), - addAuthWitness: z.function().args(AuthWitness.schema).returns(z.void()), - getAuthWitness: z - .function() - .args(schemas.Fr) - .returns(z.union([z.undefined(), z.array(schemas.Fr)])), - storeCapsule: z.function().args(schemas.AztecAddress, schemas.Fr, z.array(schemas.Fr)).returns(z.void()), registerAccount: z.function().args(schemas.Fr, schemas.Fr).returns(CompleteAddress.schema), getRegisteredAccounts: z.function().returns(z.array(CompleteAddress.schema)), registerSender: z.function().args(schemas.AztecAddress).returns(schemas.AztecAddress), @@ -513,6 +476,7 @@ export const PXESchema: ApiSchemaFor = { z.string(), z.array(z.any()), schemas.AztecAddress, + optional(z.array(AuthWitness.schema)), optional(schemas.AztecAddress), optional(z.array(schemas.AztecAddress)), ) diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index eaf5801541ac..483dbc68cd55 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -130,6 +130,8 @@ export class TXE implements TypedOracle { private noteCache: ExecutionNoteCache; + private authwits: Map = new Map(); + private constructor( private logger: Logger, private keyStore: KeyStore, @@ -139,7 +141,6 @@ export class TXE implements TypedOracle { private syncDataProvider: SyncDataProvider, private taggingDataProvider: TaggingDataProvider, private addressDataProvider: AddressDataProvider, - private authWitnessDataProvider: AuthWitnessDataProvider, private accountDataProvider: TXEAccountDataProvider, private executionCache: HashedValuesCache, private contractAddress: AztecAddress, @@ -162,7 +163,6 @@ export class TXE implements TypedOracle { this.syncDataProvider, this.taggingDataProvider, this.addressDataProvider, - this.authWitnessDataProvider, this.logger, ); } @@ -198,7 +198,6 @@ export class TXE implements TypedOracle { syncDataProvider, taggingDataProvider, addressDataProvider, - authWitnessDataProvider, accountDataProvider, executionCache, await AztecAddress.random(), @@ -325,7 +324,7 @@ export class TXE implements TypedOracle { const schnorr = new Schnorr(); const signature = await schnorr.constructSignature(messageHash.toBuffer(), privateKey); const authWitness = new AuthWitness(messageHash, [...signature.toBuffer()]); - return this.authWitnessDataProvider.addAuthWitness(authWitness.requestHash, authWitness.witness); + return this.authwits.set(authWitness.requestHash.toString(), authWitness); } async addPublicDataWrites(writes: PublicDataWrite[]) { @@ -538,7 +537,8 @@ export class TXE implements TypedOracle { } getAuthWitness(messageHash: Fr) { - return this.pxeOracleInterface.getAuthWitness(messageHash); + const authwit = this.authwits.get(messageHash.toString()); + return Promise.resolve(authwit?.witness); } async getNotes( From b315b547b355722b723c2af0fa2da8027d16c4da Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 12 Mar 2025 14:17:20 +0000 Subject: [PATCH 14/48] wip --- yarn-project/end-to-end/src/e2e_authwit.test.ts | 8 +------- .../src/pxe_oracle_interface/pxe_oracle_interface.test.ts | 1 - .../pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts | 1 - yarn-project/txe/src/oracle/txe_oracle.ts | 1 - 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index 327eb15e37ef..121df3149528 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -34,7 +34,7 @@ describe('e2e_authwit_tests', () => { describe('Private', () => { describe('arbitrary data', () => { - it.only('happy path', async () => { + it('happy path', async () => { // What are we doing here: // 1. We compute an inner hash which is here just a hash of random data // 2. We then compute the message hash, which is binding it to a "consumer" (here the "auth" contract) @@ -59,18 +59,12 @@ describe('e2e_authwit_tests', () => { isValidInPublic: false, }); - // We give wallets[0] access to wallets[1]'s notes. - //wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); - // Check that the authwit is NOT valid in private for wallets[1] expect(await wallets[0].lookupValidity(wallets[1].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); - // We give wallets[1] access to wallets[0]'s notes. - // wallets[1].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); - // Consume the inner hash using the wallets[0] as the "on behalf of". await auth .withWallet(wallets[1]) diff --git a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts index 9275dc9282b9..0450af1bc6b7 100644 --- a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts +++ b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.test.ts @@ -20,7 +20,6 @@ import { jest } from '@jest/globals'; import { type MockProxy, mock } from 'jest-mock-extended'; import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js'; -import { AuthWitnessDataProvider } from '../storage/auth_witness_data_provider/auth_witness_data_provider.js'; import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js'; import { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js'; import { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js'; diff --git a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts index a671744a198a..126119f37bdc 100644 --- a/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts +++ b/yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts @@ -44,7 +44,6 @@ import { TxHash } from '@aztec/stdlib/tx'; import { getOrderedNoteItems } from '../note_decryption_utils/add_public_values_to_payload.js'; import type { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js'; -import type { AuthWitnessDataProvider } from '../storage/auth_witness_data_provider/auth_witness_data_provider.js'; import type { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js'; import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js'; import { NoteDao } from '../storage/note_data_provider/note_dao.js'; diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index 483dbc68cd55..d6ab48362ef7 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -20,7 +20,6 @@ import type { AztecAsyncKVStore } from '@aztec/kv-store'; import type { ProtocolContract } from '@aztec/protocol-contracts'; import { AddressDataProvider, - AuthWitnessDataProvider, CapsuleDataProvider, ContractDataProvider, NoteDataProvider, From 16f64393f9bac737bfb9c74088a0da68cd838605 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 12 Mar 2025 19:40:40 +0000 Subject: [PATCH 15/48] wip --- yarn-project/aztec.js/src/wallet/account_wallet.ts | 11 ++++++----- yarn-project/end-to-end/src/e2e_authwit.test.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index ea8230d54207..30a9bfdecd70 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -145,11 +145,12 @@ export class AccountWallet extends BaseWallet { const results = { isValidInPrivate: false, isValidInPublic: false }; // Check private - - results.isValidInPrivate = (await new ContractFunctionInteraction(this, onBehalfOf, this.getLookupValidityAbi(), [ - consumer, - innerHash, - ]).simulate({ authwits: [witness] })) as boolean; + try { + results.isValidInPrivate = (await new ContractFunctionInteraction(this, onBehalfOf, this.getLookupValidityAbi(), [ + consumer, + innerHash, + ]).simulate({ authwits: [witness] })) as boolean; + } catch {} // check public results.isValidInPublic = (await new ContractFunctionInteraction( diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index 121df3149528..1188afe54c3b 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -148,7 +148,7 @@ describe('e2e_authwit_tests', () => { const witness = await wallets[0].createAuthWit(intent); expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ - isValidInPrivate: false, + isValidInPrivate: true, isValidInPublic: false, }); @@ -157,7 +157,7 @@ describe('e2e_authwit_tests', () => { await validateActionInteraction.send().wait(); // docs:end:set_public_authwit expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ - isValidInPrivate: false, + isValidInPrivate: true, isValidInPublic: true, }); @@ -165,7 +165,7 @@ describe('e2e_authwit_tests', () => { await registry.methods.consume(wallets[0].getAddress(), innerHash).send().wait(); expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ - isValidInPrivate: false, + isValidInPrivate: true, isValidInPublic: false, }); }); @@ -178,7 +178,7 @@ describe('e2e_authwit_tests', () => { const witness = await wallets[0].createAuthWit(intent); expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ - isValidInPrivate: false, + isValidInPrivate: true, isValidInPublic: false, }); @@ -186,7 +186,7 @@ describe('e2e_authwit_tests', () => { await validateActionInteraction.send().wait(); expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ - isValidInPrivate: false, + isValidInPrivate: true, isValidInPublic: true, }); @@ -194,7 +194,7 @@ describe('e2e_authwit_tests', () => { await cancelActionInteraction.send().wait(); expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ - isValidInPrivate: false, + isValidInPrivate: true, isValidInPublic: false, }); From e4741bc686e7b8544789ab8c56d3e960a4d4fa84 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 12 Mar 2025 19:42:02 +0000 Subject: [PATCH 16/48] wip --- .../src/e2e_crowdfunding_and_claim.test.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index f8d615e473c3..3c4479396fcd 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -148,28 +148,21 @@ describe('e2e_crowdfunding_and_claim', () => { it('full donor flow', async () => { const donationAmount = 1000n; - // 1) We add authwit so that the Crowdfunding contract can transfer donor's DNT + // 1) We create an authwit so that the Crowdfunding contract can transfer donor's DNT and donate { const action = donationToken .withWallet(donorWallets[0]) .methods.transfer_in_private(donorWallets[0].getAddress(), crowdfundingContract.address, donationAmount, 0); const witness = await donorWallets[0].createAuthWit({ caller: crowdfundingContract.address, action }); - await donorWallets[0].addAuthWitness(witness); - } - - // 2) We donate to the crowdfunding contract - { const donateTxReceipt = await crowdfundingContract .withWallet(donorWallets[0]) .methods.donate(donationAmount) - .send() - .wait({ - debug: true, - }); + .send({ authwits: [witness] }) + .wait(); // Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the UintNote) await crowdfundingContract.withWallet(donorWallets[0]).methods.sync_notes().simulate(); - const notes = await donorWallets[0].getNotes({ txHash: donateTxReceipt.txHash }); + const notes = await pxe.getNotes({ txHash: donateTxReceipt.txHash }); const filteredNotes = notes.filter(x => x.contractAddress.equals(crowdfundingContract.address)); expect(filteredNotes!.length).toEqual(1); @@ -177,9 +170,9 @@ describe('e2e_crowdfunding_and_claim', () => { uintNote = processUniqueNote(filteredNotes![0]); } - // 3) We claim the reward token via the Claim contract + // 2) We claim the reward token via the Claim contract { - // We allow the donor wallet to use the crowdfunding contract's notes + // We allow the donor wallet to use the crowdfunding contract's notes∫ donorWallets[0].setScopes([donorWallets[0].getAddress(), crowdfundingContract.address]); await claimContract From 065fb76df6c0b56d6a990cdebe279b08add54883 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 13 Mar 2025 12:10:58 +0000 Subject: [PATCH 17/48] wip --- yarn-project/txe/src/oracle/txe_oracle.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index 99eb313078e6..51f4bda9ce55 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -172,7 +172,6 @@ export class TXE implements TypedOracle { const baseFork = await nativeWorldStateService.fork(); const addressDataProvider = new AddressDataProvider(store); - const authWitnessDataProvider = new AuthWitnessDataProvider(store); const contractDataProvider = new ContractDataProvider(store); const noteDataProvider = await NoteDataProvider.create(store); const syncDataProvider = new SyncDataProvider(store); From e0b7c4f0b059df39c67758f775fb55aaf018ba4a Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 13 Mar 2025 14:11:00 +0000 Subject: [PATCH 18/48] fixes --- .../accounts/src/testing/create_account.ts | 30 +++++-- .../aztec.js/src/wallet/base_wallet.ts | 22 +++++- yarn-project/aztec.js/src/wallet/wallet.ts | 2 + .../end-to-end/src/e2e_block_building.test.ts | 2 +- .../src/e2e_crowdfunding_and_claim.test.ts | 79 ++++++++----------- .../src/e2e_escrow_contract.test.ts | 3 - .../src/e2e_offchain_note_delivery.test.ts | 16 ++-- .../e2e_pending_note_hashes_contract.test.ts | 7 +- .../src/e2e_prover/e2e_prover_test.ts | 8 +- .../end-to-end/src/e2e_simple.test.ts | 11 ++- .../end-to-end/src/e2e_state_vars.test.ts | 46 ++++++----- .../src/fixtures/snapshot_manager.ts | 18 ++++- yarn-project/stdlib/src/tx/tx_receipt.ts | 36 --------- yarn-project/txe/src/node/txe_node.ts | 1 - 14 files changed, 143 insertions(+), 138 deletions(-) diff --git a/yarn-project/accounts/src/testing/create_account.ts b/yarn-project/accounts/src/testing/create_account.ts index fffb848c0d3f..4425dfde613f 100644 --- a/yarn-project/accounts/src/testing/create_account.ts +++ b/yarn-project/accounts/src/testing/create_account.ts @@ -1,4 +1,11 @@ -import { type AccountManager, FeeJuicePaymentMethod, type PXE, type WaitOpts } from '@aztec/aztec.js'; +import { + type AccountManager, + FeeJuicePaymentMethod, + type PXE, + type WaitForProvenOpts, + type WaitOpts, + waitForProven, +} from '@aztec/aztec.js'; import { Fr } from '@aztec/foundation/fields'; import { deriveSigningKey } from '@aztec/stdlib/keys'; @@ -46,6 +53,7 @@ export async function deployFundedSchnorrAccount( */ skipClassRegistration?: boolean; } = { interval: 0.1, skipClassRegistration: false }, + waitForProvenOptions?: WaitForProvenOpts, ): Promise { const signingKey = account.signingKey ?? deriveSigningKey(account.secret); const accountManager = await getSchnorrAccount(pxe, account.secret, signingKey, account.salt); @@ -54,7 +62,7 @@ export async function deployFundedSchnorrAccount( // This only works when the world state is prefilled with the balance for the account in test environment. const paymentMethod = new FeeJuicePaymentMethod(accountManager.getAddress()); - await accountManager + const receipt = await accountManager .deploy({ skipClassRegistration: opts.skipClassRegistration, skipPublicDeployment: true, @@ -62,6 +70,10 @@ export async function deployFundedSchnorrAccount( }) .wait(opts); + if (waitForProvenOptions !== undefined) { + await waitForProven(pxe, receipt, waitForProvenOptions); + } + return accountManager; } @@ -78,15 +90,21 @@ export async function deployFundedSchnorrAccounts( */ skipClassRegistration?: boolean; } = { interval: 0.1, skipClassRegistration: false }, + waitForProvenOptions?: WaitForProvenOpts, ): Promise { const accountManagers: AccountManager[] = []; // Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045 for (let i = 0; i < accounts.length; i++) { accountManagers.push( - await deployFundedSchnorrAccount(pxe, accounts[i], { - ...opts, - skipClassRegistration: i !== 0 || opts.skipClassRegistration, // Register the contract class at most once. - }), + await deployFundedSchnorrAccount( + pxe, + accounts[i], + { + ...opts, + skipClassRegistration: i !== 0 || opts.skipClassRegistration, // Register the contract class at most once. + }, + waitForProvenOptions, + ), ); } return accountManagers; diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 5e012901e60a..0b673d266d01 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -1,11 +1,17 @@ import type { ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; -import type { Fr } from '@aztec/foundation/fields'; +import type { Fr, Point } from '@aztec/foundation/fields'; import type { AbiDecoded, ContractArtifact } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { CompleteAddress, ContractInstanceWithAddress, NodeInfo } from '@aztec/stdlib/contract'; import type { GasFees } from '@aztec/stdlib/gas'; -import type { ContractClassMetadata, ContractMetadata, PXE, PXEInfo } from '@aztec/stdlib/interfaces/client'; +import type { + ContractClassMetadata, + ContractMetadata, + EventMetadataDefinition, + PXE, + PXEInfo, +} from '@aztec/stdlib/interfaces/client'; import type { PrivateExecutionResult, Tx, @@ -104,4 +110,16 @@ export abstract class BaseWallet implements Wallet { getTxReceipt(txHash: TxHash): Promise { return this.pxe.getTxReceipt(txHash); } + + getPrivateEvents( + event: EventMetadataDefinition, + from: number, + limit: number, + vpks: Point[] = [this.getCompleteAddress().publicKeys.masterIncomingViewingPublicKey], + ): Promise { + return this.pxe.getPrivateEvents(event, from, limit, vpks); + } + getPublicEvents(event: EventMetadataDefinition, from: number, limit: number): Promise { + return this.pxe.getPublicEvents(event, from, limit); + } } diff --git a/yarn-project/aztec.js/src/wallet/wallet.ts b/yarn-project/aztec.js/src/wallet/wallet.ts index 431b6817f499..3da9aaea5332 100644 --- a/yarn-project/aztec.js/src/wallet/wallet.ts +++ b/yarn-project/aztec.js/src/wallet/wallet.ts @@ -26,6 +26,8 @@ export type Wallet = AccountInterface & | 'getSenders' | 'removeSender' | 'getTxReceipt' + | 'getPrivateEvents' + | 'getPublicEvents' > & { createAuthWit(intent: IntentInnerHash | IntentAction): Promise; }; diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 82aa203dcf3b..cd74cb164be5 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -527,7 +527,7 @@ describe('e2e_block_building', () => { } logger.info('Waiting for txs to be mined'); - await Promise.all(txs.map(tx => tx.wait({ proven: false, timeout: 600 }))); + await Promise.all(txs.map(tx => tx.wait({ timeout: 600 }))); }); }); diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index 37c00ebe7d4d..134a51c6535b 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -172,9 +172,6 @@ describe('e2e_crowdfunding_and_claim', () => { // 2) We claim the reward token via the Claim contract { - // We allow the donor wallet to use the crowdfunding contract's notes∫ - donorWallets[0].setScopes([donorWallets[0].getAddress(), crowdfundingContract.address]); - await claimContract .withWallet(donorWallets[0]) .methods.claim(uintNote, donorWallets[0].getAddress()) @@ -191,8 +188,6 @@ describe('e2e_crowdfunding_and_claim', () => { .simulate(); expect(balanceDNTBeforeWithdrawal).toEqual(0n); - // We allow the operator wallet to use the crowdfunding contract's notes - operatorWallet.setScopes([operatorWallet.getAddress(), crowdfundingContract.address]); // 4) At last, we withdraw the raised funds from the crowdfunding contract to the operator's address await crowdfundingContract.methods.withdraw(donationAmount).send().wait(); @@ -217,43 +212,35 @@ describe('e2e_crowdfunding_and_claim', () => { const donorWallet = donorWallets[1]; const unrelatedWallet = donorWallets[0]; - // 1) We permit the crowdfunding contract to pull the donation amount from the donor's wallet - { - const action = donationToken - .withWallet(donorWallet) - .methods.transfer_in_private(donorWallet.getAddress(), crowdfundingContract.address, donationAmount, 0); - const witness = await donorWallet.createAuthWit({ caller: crowdfundingContract.address, action }); - await donorWallet.addAuthWitness(witness); - } + // 1) We permit the crowdfunding contract to pull the donation amount from the donor's wallet, and we donate - // 2) We donate to the crowdfunding contract + const action = donationToken + .withWallet(donorWallet) + .methods.transfer_in_private(donorWallet.getAddress(), crowdfundingContract.address, donationAmount, 0); + const witness = await donorWallet.createAuthWit({ caller: crowdfundingContract.address, action }); const donateTxReceipt = await crowdfundingContract .withWallet(donorWallet) .methods.donate(donationAmount) - .send() - .wait({ - debug: true, - }); + .send({ authwits: [witness] }) + .wait(); // Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the UintNote) await crowdfundingContract.withWallet(unrelatedWallet).methods.sync_notes().simulate(); - const notes = await unrelatedWallet.getNotes({ txHash: donateTxReceipt.txHash }); + const notes = await pxe.getNotes({ txHash: donateTxReceipt.txHash }); const filtered = notes.filter(x => x.contractAddress.equals(crowdfundingContract.address)); expect(filtered!.length).toEqual(1); // Set the UintNote in a format which can be passed to claim function const anotherDonationNote = processUniqueNote(filtered![0]); - // 3) We try to claim the reward token via the Claim contract with the unrelated wallet - { - await expect( - claimContract - .withWallet(unrelatedWallet) - .methods.claim(anotherDonationNote, donorWallet.getAddress()) - .send() - .wait(), - ).rejects.toThrow('Note does not belong to the sender'); - } + // 2) We try to claim the reward token via the Claim contract with the unrelated wallet + await expect( + claimContract + .withWallet(unrelatedWallet) + .methods.claim(anotherDonationNote, donorWallet.getAddress()) + .send() + .wait(), + ).rejects.toThrow('Note does not belong to the sender'); }); it('cannot claim with a non-existent note', async () => { @@ -284,9 +271,9 @@ describe('e2e_crowdfunding_and_claim', () => { const receipt = await testContract.methods .call_create_note(arbitraryValue, owner, sender, arbitraryStorageSlot) .send() - .wait({ debug: true }); + .wait(); await testContract.methods.sync_notes().simulate(); - const notes = await wallets[0].getNotes({ txHash: receipt.txHash }); + const notes = await pxe.getNotes({ txHash: receipt.txHash }); expect(notes.length).toEqual(1); note = processUniqueNote(notes[0]); } @@ -308,12 +295,13 @@ describe('e2e_crowdfunding_and_claim', () => { .withWallet(donorWallets[1]) .methods.transfer_in_private(donorWallets[1].getAddress(), crowdfundingContract.address, donationAmount, 0); const witness = await donorWallets[1].createAuthWit({ caller: crowdfundingContract.address, action }); - await donorWallets[1].addAuthWitness(witness); // 2) We donate to the crowdfunding contract - await crowdfundingContract.withWallet(donorWallets[1]).methods.donate(donationAmount).send().wait({ - debug: true, - }); + await crowdfundingContract + .withWallet(donorWallets[1]) + .methods.donate(donationAmount) + .send({ authwits: [witness] }) + .wait(); // Calling the function normally will fail as msg_sender != operator await expect( @@ -340,9 +328,6 @@ describe('e2e_crowdfunding_and_claim', () => { // This does not protect fully against impersonation as the contract could just call context.end_setup() and the below would pass. // => the private_init msg_sender assertion is required (#7190, #7404) - // We allow the donor wallet to use the crowdfunding contract's notes - donorWallets[1].setScopes([donorWallets[1].getAddress(), crowdfundingContract.address]); - await expect(donorWallets[1].simulateTx(request, true, operatorWallet.getAddress())).rejects.toThrow( 'Circuit execution failed: Users cannot set msg_sender in first call', ); @@ -352,20 +337,22 @@ describe('e2e_crowdfunding_and_claim', () => { const donationAmount = 1000n; // 1) We add authwit so that the Crowdfunding contract can transfer donor's DNT - { - const action = donationToken - .withWallet(donorWallets[1]) - .methods.transfer_in_private(donorWallets[1].getAddress(), crowdfundingContract.address, donationAmount, 0); - const witness = await donorWallets[1].createAuthWit({ caller: crowdfundingContract.address, action }); - await donorWallets[1].addAuthWitness(witness); - } + + const action = donationToken + .withWallet(donorWallets[1]) + .methods.transfer_in_private(donorWallets[1].getAddress(), crowdfundingContract.address, donationAmount, 0); + const witness = await donorWallets[1].createAuthWit({ caller: crowdfundingContract.address, action }); // 2) We set next block timestamp to be after the deadline await cheatCodes.eth.warp(deadline + 1); // 3) We donate to the crowdfunding contract await expect( - crowdfundingContract.withWallet(donorWallets[1]).methods.donate(donationAmount).send().wait(), + crowdfundingContract + .withWallet(donorWallets[1]) + .methods.donate(donationAmount) + .send({ authwits: [witness] }) + .wait(), ).rejects.toThrow(); }); }); diff --git a/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts index e0aabc6d47d4..5ecca8d65fa8 100644 --- a/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts @@ -57,9 +57,6 @@ describe('e2e_escrow_contract', () => { await mintTokensToPrivate(token, wallet, escrowContract.address, 100n); - // We allow our wallet to see the escrow contract's notes. - wallet.setScopes([wallet.getAddress(), escrowContract.address]); - logger.info(`Token contract deployed at ${token.address}`); }); diff --git a/yarn-project/end-to-end/src/e2e_offchain_note_delivery.test.ts b/yarn-project/end-to-end/src/e2e_offchain_note_delivery.test.ts index f3498a61797a..bc810a306a07 100644 --- a/yarn-project/end-to-end/src/e2e_offchain_note_delivery.test.ts +++ b/yarn-project/end-to-end/src/e2e_offchain_note_delivery.test.ts @@ -1,4 +1,4 @@ -import { Fr, type Wallet } from '@aztec/aztec.js'; +import { type AztecNode, Fr, type Wallet } from '@aztec/aztec.js'; import { MAX_NOTE_HASHES_PER_TX } from '@aztec/constants'; import { TestContract } from '@aztec/noir-contracts.js/Test'; @@ -9,9 +9,10 @@ describe('e2e_offchain_note_delivery', () => { let contract: TestContract; let wallet: Wallet; + let aztecNode: AztecNode; beforeEach(async () => { - ({ teardown, wallet } = await setup(1)); + ({ teardown, wallet, aztecNode } = await setup(1)); contract = await TestContract.deploy(wallet).send().deployed(); }); @@ -25,16 +26,15 @@ describe('e2e_offchain_note_delivery', () => { it('can create a note that is not broadcast, deliver it offchain and read it', async () => { const value = 123n; - const { txHash, debugInfo } = await contract.methods - .set_constant(value) - .send() - .wait({ interval: 0.1, debug: true }); + const { txHash } = await contract.methods.set_constant(value).send().wait({ interval: 0.1 }); + const txEffect = await aztecNode.getTxEffect(txHash); + const noteHashes = txEffect?.data.noteHashes; // check that 1 note hash was created - expect(debugInfo!.noteHashes.length).toBe(1); + expect(noteHashes?.length).toBe(1); // The note was not broadcast, so we must manually deliver it to the contract via the custom mechanism to do so. - const txEffect = await wallet.getTxEffect(txHash); + await contract.methods .deliver_note( contract.address, diff --git a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts index ff202bf2477e..19ba8b1fefb3 100644 --- a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts @@ -1,4 +1,4 @@ -import { type AztecAddress, type AztecNode, Fr, type Logger, type Wallet } from '@aztec/aztec.js'; +import { type AztecAddress, type AztecNode, Fr, type Logger, type PXE, type Wallet } from '@aztec/aztec.js'; import { MAX_NOTE_HASHES_PER_CALL, MAX_NOTE_HASHES_PER_TX, @@ -12,13 +12,14 @@ import { setup } from './fixtures/utils.js'; describe('e2e_pending_note_hashes_contract', () => { let aztecNode: AztecNode; let wallet: Wallet; + let pxe: PXE; let logger: Logger; let owner: AztecAddress; let teardown: () => Promise; let contract: PendingNoteHashesContract; beforeEach(async () => { - ({ teardown, aztecNode, wallet, logger } = await setup(2)); + ({ teardown, aztecNode, wallet, logger, pxe } = await setup(2)); owner = wallet.getAddress(); }); @@ -294,7 +295,7 @@ describe('e2e_pending_note_hashes_contract', () => { await deployedContract.methods.sync_notes().simulate(); - const notes = await wallet.getNotes({ txHash: txReceipt.txHash }); + const notes = await pxe.getNotes({ txHash: txReceipt.txHash }); expect(notes.length).toBe(1); }); diff --git a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts index 9bea56c2639a..b0d6f0f44e8e 100644 --- a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts @@ -121,7 +121,7 @@ export class FullProverTest { // Create the token contract state. // Move this account thing to addAccounts above? this.logger.verbose(`Public deploy accounts...`); - await publicDeployAccounts(this.wallets[0], this.accounts.slice(0, 2), false); + await publicDeployAccounts(this.wallets[0], this.accounts.slice(0, 2)); this.logger.verbose(`Deploying TokenContract...`); const asset = await TokenContract.deploy( @@ -345,16 +345,14 @@ export class FullProverTest { const privateAmount = 10000n; const publicAmount = 10000n; - const waitOpts = { proven: false }; - this.logger.verbose(`Minting ${privateAmount + publicAmount} publicly...`); await asset.methods .mint_to_public(accounts[0].address, privateAmount + publicAmount) .send() - .wait(waitOpts); + .wait(); this.logger.verbose(`Transferring ${privateAmount} to private...`); - await asset.methods.transfer_to_private(accounts[0].address, privateAmount).send().wait(waitOpts); + await asset.methods.transfer_to_private(accounts[0].address, privateAmount).send().wait(); this.logger.verbose(`Minting complete.`); diff --git a/yarn-project/end-to-end/src/e2e_simple.test.ts b/yarn-project/end-to-end/src/e2e_simple.test.ts index a4fb2565fbd9..6ac62b282c98 100644 --- a/yarn-project/end-to-end/src/e2e_simple.test.ts +++ b/yarn-project/end-to-end/src/e2e_simple.test.ts @@ -1,6 +1,6 @@ // docs:start:import_aztecjs import type { AztecNodeConfig } from '@aztec/aztec-node'; -import { ContractDeployer, Fr, type Wallet } from '@aztec/aztec.js'; +import { type AztecNode, ContractDeployer, Fr, type Wallet, waitForProven } from '@aztec/aztec.js'; // docs:end:import_aztecjs // eslint-disable-next-line no-restricted-imports import { EthAddress } from '@aztec/foundation/eth-address'; @@ -17,6 +17,7 @@ describe('e2e_simple', () => { let owner: Wallet; let teardown: () => Promise; let config: AztecNodeConfig; + let aztecNode: AztecNode; afterEach(() => { jest.restoreAllMocks(); @@ -30,6 +31,7 @@ describe('e2e_simple', () => { teardown, wallets: [owner], config, + aztecNode, } = await setup(1, { customForwarderContractAddress: EthAddress.ZERO, archiverPollingIntervalMS: 200, @@ -57,9 +59,10 @@ describe('e2e_simple', () => { skipClassRegistration: true, skipPublicDeployment: true, }); - const tx = await provenTx - .send() - .wait({ proven: true, provenTimeout: config.aztecProofSubmissionWindow * config.aztecSlotDuration }); + const tx = await provenTx.send().wait(); + await waitForProven(aztecNode, tx, { + provenTimeout: config.aztecProofSubmissionWindow * config.aztecSlotDuration, + }); expect(tx.blockNumber).toBeDefined(); }); }); diff --git a/yarn-project/end-to-end/src/e2e_state_vars.test.ts b/yarn-project/end-to-end/src/e2e_state_vars.test.ts index b86417eb8c40..a032c6b70b77 100644 --- a/yarn-project/end-to-end/src/e2e_state_vars.test.ts +++ b/yarn-project/end-to-end/src/e2e_state_vars.test.ts @@ -109,10 +109,12 @@ describe('e2e_state_vars', () => { it('initialize PrivateMutable', async () => { expect(await contract.methods.is_legendary_initialized().simulate()).toEqual(false); // Send the transaction and wait for it to be mined (wait function throws if the tx is not mined) - const { debugInfo } = await contract.methods.initialize_private(RANDOMNESS, POINTS).send().wait({ debug: true }); + const receipt = await contract.methods.initialize_private(RANDOMNESS, POINTS).send().wait(); + + const txEffects = await pxe.getTxEffect(receipt.txHash); // 1 for the tx, another for the initializer - expect(debugInfo!.nullifiers.length).toEqual(2); + expect(txEffects?.data.nullifiers.length).toEqual(2); expect(await contract.methods.is_legendary_initialized().simulate()).toEqual(true); }); @@ -132,14 +134,13 @@ describe('e2e_state_vars', () => { it('replace with same value', async () => { expect(await contract.methods.is_legendary_initialized().simulate()).toEqual(true); const noteBefore = await contract.methods.get_legendary_card().simulate(); - const { debugInfo } = await contract.methods - .update_legendary_card(RANDOMNESS, POINTS) - .send() - .wait({ debug: true }); + const receipt = await contract.methods.update_legendary_card(RANDOMNESS, POINTS).send().wait(); - expect(debugInfo!.noteHashes.length).toEqual(1); + const txEffects = await pxe.getTxEffect(receipt.txHash); + + expect(txEffects?.data.noteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note - expect(debugInfo!.nullifiers.length).toEqual(2); + expect(txEffects?.data.nullifiers.length).toEqual(2); const noteAfter = await contract.methods.get_legendary_card().simulate(); @@ -150,14 +151,16 @@ describe('e2e_state_vars', () => { it('replace PrivateMutable with other values', async () => { expect(await contract.methods.is_legendary_initialized().simulate()).toEqual(true); - const { debugInfo } = await contract.methods + const receipt = await contract.methods .update_legendary_card(RANDOMNESS + 2n, POINTS + 1n) .send() - .wait({ debug: true }); + .wait(); + + const txEffects = await pxe.getTxEffect(receipt.txHash); - expect(debugInfo!.noteHashes.length).toEqual(1); + expect(txEffects?.data.noteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note - expect(debugInfo!.nullifiers.length).toEqual(2); + expect(txEffects?.data.nullifiers.length).toEqual(2); const { points, randomness } = await contract.methods.get_legendary_card().simulate(); expect(points).toEqual(POINTS + 1n); @@ -167,11 +170,13 @@ describe('e2e_state_vars', () => { it('replace PrivateMutable dependent on prior value', async () => { expect(await contract.methods.is_legendary_initialized().simulate()).toEqual(true); const noteBefore = await contract.methods.get_legendary_card().simulate(); - const { debugInfo } = await contract.methods.increase_legendary_points().send().wait({ debug: true }); + const receipt = await contract.methods.increase_legendary_points().send().wait(); - expect(debugInfo!.noteHashes.length).toEqual(1); + const txEffects = await pxe.getTxEffect(receipt.txHash); + + expect(txEffects?.data.noteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note - expect(debugInfo!.nullifiers.length).toEqual(2); + expect(txEffects?.data.nullifiers.length).toEqual(2); const { points, randomness } = await contract.methods.get_legendary_card().simulate(); expect(points).toEqual(noteBefore.points + 1n); @@ -187,14 +192,13 @@ describe('e2e_state_vars', () => { it('initialize PrivateImmutable', async () => { expect(await contract.methods.is_priv_imm_initialized().simulate()).toEqual(false); - const { debugInfo } = await contract.methods - .initialize_private_immutable(RANDOMNESS, POINTS) - .send() - .wait({ debug: true }); + const receipt = await contract.methods.initialize_private_immutable(RANDOMNESS, POINTS).send().wait(); + + const txEffects = await pxe.getTxEffect(receipt.txHash); - expect(debugInfo!.noteHashes.length).toEqual(1); + expect(txEffects?.data.noteHashes.length).toEqual(1); // 1 for the tx, another for the initializer - expect(debugInfo!.nullifiers.length).toEqual(2); + expect(txEffects?.data.nullifiers.length).toEqual(2); expect(await contract.methods.is_priv_imm_initialized().simulate()).toEqual(true); }); diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index 8f54849f6a9d..a5a2fc0b7d28 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -3,15 +3,18 @@ import { type InitialAccountData, deployFundedSchnorrAccounts, generateSchnorrAc import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { type AztecAddress, + type AztecNode, BatchCall, type Capsule, type CompleteAddress, type ContractFunctionInteraction, + DefaultWaitForProvenOpts, type FunctionCall, type Logger, type PXE, type Wallet, getContractClassFromArtifact, + waitForProven, } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; import { AnvilTestWatcher, CheatCodes } from '@aztec/aztec.js/testing'; @@ -596,7 +599,12 @@ export const deployAccounts = logger.verbose('Deploying accounts funded with fee juice...'); const deployedAccounts = initialFundedAccounts.slice(0, numberOfAccounts); - await deployFundedSchnorrAccounts(pxe, deployedAccounts, { proven: waitUntilProven }); + await deployFundedSchnorrAccounts( + pxe, + deployedAccounts, + undefined, + waitUntilProven ? DefaultWaitForProvenOpts : undefined, + ); return { deployedAccounts }; }; @@ -611,6 +619,7 @@ export async function publicDeployAccounts( sender: Wallet, accountsToDeploy: (CompleteAddress | AztecAddress)[], waitUntilProven = false, + pxeOrNode?: PXE | AztecNode, ) { const accountAddressesToDeploy = accountsToDeploy.map(a => ('address' in a ? a.address : a)); const instances = ( @@ -627,5 +636,10 @@ export async function publicDeployAccounts( const batch = new BatchCall(sender, calls); - await batch.send().wait({ proven: waitUntilProven }); + const txReceipt = await batch.send().wait(); + if (waitUntilProven && pxeOrNode) { + await waitForProven(pxeOrNode, txReceipt); + } else { + throw new Error('Need to provide a PXE or AztecNode to wait for proven.'); + } } diff --git a/yarn-project/stdlib/src/tx/tx_receipt.ts b/yarn-project/stdlib/src/tx/tx_receipt.ts index 92f2d9ecaf1b..96060b74a64b 100644 --- a/yarn-project/stdlib/src/tx/tx_receipt.ts +++ b/yarn-project/stdlib/src/tx/tx_receipt.ts @@ -1,9 +1,7 @@ -import type { Fr } from '@aztec/foundation/fields'; import type { FieldsOf } from '@aztec/foundation/types'; import { z } from 'zod'; -import { PublicDataWrite } from '../avm/public_data_write.js'; import { RevertCode } from '../avm/revert_code.js'; import { L2BlockHash } from '../block/block_hash.js'; import { type ZodFor, schemas } from '../schemas/schemas.js'; @@ -41,8 +39,6 @@ export class TxReceipt { public blockHash?: L2BlockHash, /** The block number in which the transaction was included. */ public blockNumber?: number, - /** Information useful for testing/debugging, set when test flag is set to true in `waitOpts`. */ - public debugInfo?: DebugInfo, ) {} static empty() { @@ -58,7 +54,6 @@ export class TxReceipt { blockHash: L2BlockHash.schema.optional(), blockNumber: z.number().int().nonnegative().optional(), transactionFee: schemas.BigInt.optional(), - debugInfo: DebugInfoSchema.optional(), }) .transform(TxReceipt.from); } @@ -71,7 +66,6 @@ export class TxReceipt { fields.transactionFee, fields.blockHash, fields.blockNumber, - fields.debugInfo, ); } @@ -89,33 +83,3 @@ export class TxReceipt { } } } - -/** - * Information useful for debugging/testing purposes included in the receipt when the debug flag is set to true - * in `WaitOpts`. - */ -interface DebugInfo { - /** - * New note hashes created by the transaction. - */ - noteHashes: Fr[]; - /** - * New nullifiers created by the transaction. - */ - nullifiers: Fr[]; - /** - * New public data writes created by the transaction. - */ - publicDataWrites: PublicDataWrite[]; - /** - * New L2 to L1 messages created by the transaction. - */ - l2ToL1Msgs: Fr[]; -} - -const DebugInfoSchema = z.object({ - noteHashes: z.array(schemas.Fr), - nullifiers: z.array(schemas.Fr), - publicDataWrites: z.array(PublicDataWrite.schema), - l2ToL1Msgs: z.array(schemas.Fr), -}); diff --git a/yarn-project/txe/src/node/txe_node.ts b/yarn-project/txe/src/node/txe_node.ts index a63b8c1d3095..459c580313c3 100644 --- a/yarn-project/txe/src/node/txe_node.ts +++ b/yarn-project/txe/src/node/txe_node.ts @@ -118,7 +118,6 @@ export class TXENode implements AztecNode { undefined, new L2BlockHash(blockHash.toBuffer()), blockNumber, - undefined, ), ); } From 8e850b960ad720253d6b6e723cb84d87a6f0a97c Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 14 Mar 2025 13:09:15 +0000 Subject: [PATCH 19/48] wip --- .../account_manager/deploy_account_method.ts | 1 + .../src/contract/base_contract_interaction.ts | 22 +++-- .../aztec.js/src/contract/batch_call.ts | 13 ++- .../contract/contract_function_interaction.ts | 10 +-- .../aztec.js/src/contract/deploy_method.ts | 57 +++++++----- .../src/deployment/deploy_instance.ts | 35 +++++--- .../aztec.js/src/deployment/register_class.ts | 42 +++++---- .../default_multi_call_entrypoint.ts | 24 ++++-- .../src/fee/fee_juice_payment_method.ts | 7 +- .../fee_juice_payment_method_with_claim.ts | 40 +++++---- .../src/fee/private_fee_payment_method.ts | 35 ++++---- .../src/fee/public_fee_payment_method.ts | 33 +++---- yarn-project/aztec.js/src/fee/utils.ts | 2 +- yarn-project/aztec.js/src/utils/authwit.ts | 23 +++-- .../aztec.js/src/wallet/account_wallet.ts | 6 +- .../aztec.js/src/wallet/base_wallet.ts | 4 +- .../aztec.js/src/wallet/signerless_wallet.ts | 11 ++- .../sandbox/sponsored_fee_payment_method.ts | 30 ++++--- .../src/utils/sponsored_fee_payment.ts | 32 ++++--- .../src/composed/e2e_persistence.test.ts | 33 +++++-- .../blacklist_token_contract_test.ts | 14 +-- .../e2e_blacklist_token_contract/burn.test.ts | 27 +++--- .../minting.test.ts | 15 ++-- .../shielding.test.ts | 4 +- .../transfer_private.test.ts | 28 ++---- .../unshielding.test.ts | 17 +--- .../private_initialization.test.ts | 11 ++- .../src/e2e_fees/dapp_subscription.test.ts | 7 +- .../end-to-end/src/e2e_fees/failures.test.ts | 32 ++++--- .../src/e2e_fees/fee_juice_payments.test.ts | 3 - .../end-to-end/src/e2e_fees/fees_test.ts | 8 +- .../src/e2e_fees/gas_estimation.test.ts | 3 - .../src/e2e_fees/private_payments.test.ts | 21 +++-- .../src/e2e_fees/public_payments.test.ts | 3 - .../e2e_nested_contract/manual_public.test.ts | 2 +- .../end-to-end/src/e2e_prover/full.test.ts | 26 ++++-- .../src/e2e_token_contract/burn.test.ts | 27 +++--- .../private_transfer_recursion.test.ts | 18 ++-- .../e2e_token_contract/token_contract_test.ts | 6 +- .../src/e2e_token_contract/transfer.test.ts | 3 - .../transfer_in_private.test.ts | 30 +++---- .../transfer_in_public.test.ts | 27 ++---- .../transfer_to_public.test.ts | 15 +--- .../src/fixtures/snapshot_manager.ts | 10 ++- .../entrypoints/src/account_entrypoint.ts | 29 +++++-- .../entrypoints/src/dapp_entrypoint.ts | 25 ++++-- .../entrypoints/src/default_entrypoint.ts | 26 +++--- yarn-project/entrypoints/src/interfaces.ts | 68 ++++++++++++--- yarn-project/entrypoints/src/payload.ts | 86 ++++++------------- yarn-project/entrypoints/src/utils.ts | 50 ++++++++--- .../pxe/src/pxe_service/pxe_service.ts | 6 +- yarn-project/stdlib/package.json | 1 - 52 files changed, 619 insertions(+), 489 deletions(-) diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index bd5f52c1fb5a..067db3aae622 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -56,6 +56,7 @@ export class DeployAccountMethod extends DeployMethod { call.addAuthWitness( await this.#authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(emptyAppPayload, feePayload)), ); + call.addAuthWitnesses(feePayload.authWitnesses); call.addHashedArguments(emptyAppPayload.hashedArguments); call.addHashedArguments(feePayload.hashedArguments); diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 2f04b182664c..4a712da4673a 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -1,4 +1,10 @@ -import type { ExecutionRequestInit, FeeOptions, UserFeeOptions } from '@aztec/entrypoints/interfaces'; +import type { + ExecutionPayload, + ExecutionRequestInit, + FeeOptions, + UserExecutionRequest, + UserFeeOptions, +} from '@aztec/entrypoints/interfaces'; import type { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; @@ -54,7 +60,7 @@ export abstract class BaseContractInteraction { * @param options - An optional object containing additional configuration for the transaction. * @returns An execution request wrapped in promise. */ - public abstract request(options?: SendMethodOptions): Promise>; + public abstract request(options?: SendMethodOptions): Promise; /** * Creates a transaction execution request, simulates and proves it. Differs from .prove in @@ -146,19 +152,17 @@ export abstract class BaseContractInteraction { * @param pad - Percentage to pad the suggested gas limits by, as decimal (e.g., 0.10 for 10%). * @returns Fee options for the actual transaction. */ - protected async getFeeOptions( - request: Omit & { /** User-provided fee options */ fee?: UserFeeOptions }, - ): Promise { + protected async getFeeOptions(request: UserExecutionRequest, fee?: UserFeeOptions): Promise { // docs:end:getFeeOptions - const defaultFeeOptions = await this.getDefaultFeeOptions(request.fee); + const defaultFeeOptions = await this.getDefaultFeeOptions(fee); const paymentMethod = defaultFeeOptions.paymentMethod; const maxFeesPerGas = defaultFeeOptions.gasSettings.maxFeesPerGas; const maxPriorityFeesPerGas = defaultFeeOptions.gasSettings.maxPriorityFeesPerGas; let gasSettings = defaultFeeOptions.gasSettings; - if (request.fee?.estimateGas) { + if (fee?.estimateGas) { const feeForEstimation: FeeOptions = { paymentMethod, gasSettings }; - const txRequest = await this.wallet.createTxExecutionRequest({ ...request, fee: feeForEstimation }); + const txRequest = await this.wallet.createTxExecutionRequest(request, feeForEstimation); const simulationResult = await this.wallet.simulateTx( txRequest, true /*simulatePublic*/, @@ -168,7 +172,7 @@ export abstract class BaseContractInteraction { ); const { totalGas: gasLimits, teardownGas: teardownGasLimits } = getGasLimits( simulationResult, - request.fee?.estimatedGasPadding, + fee?.estimatedGasPadding, ); gasSettings = GasSettings.from({ maxFeesPerGas, maxPriorityFeesPerGas, gasLimits, teardownGasLimits }); this.log.verbose( diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 35d4fa6282f9..558212394d79 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -1,5 +1,4 @@ -import { type ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; -import { mergeExecutionRequestInits } from '@aztec/entrypoints/utils'; +import { type ExecutionRequestInit, type UserExecutionRequest } from '@aztec/entrypoints/interfaces'; import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; @@ -23,9 +22,9 @@ export class BatchCall extends BaseContractInteraction { const requestWithoutFee = await this.request(options); const { fee: userFee } = options; - const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee }); + const fee = await this.getFeeOptions(requestWithoutFee, userFee); - return await this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee }); + return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee); } /** @@ -33,7 +32,7 @@ export class BatchCall extends BaseContractInteraction { * @param options - An optional object containing additional configuration for the transaction. * @returns An execution request wrapped in promise. */ - public async request(options: SendMethodOptions = {}): Promise> { + public async request(options: SendMethodOptions = {}): Promise { const requests = await this.getRequests(); const { nonce, cancellable } = options; return mergeExecutionRequestInits(requests, { nonce, cancellable }); @@ -55,7 +54,7 @@ export class BatchCall extends BaseContractInteraction { /** Keep track of the number of public calls to retrieve the return values */ publicIndex: 0; /** The public and private function execution requests in the batch */ - indexedRequests: [Omit, number, number][]; + indexedRequests: [UserExecutionRequest, number, number][]; /** The unconstrained function calls in the batch. */ unconstrained: [FunctionCall, number][]; }>( @@ -79,7 +78,7 @@ export class BatchCall extends BaseContractInteraction { const requestWithoutFee = mergeExecutionRequestInits(requests); const { fee: userFee } = options; const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee }); - const txRequest = await this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee }); + const txRequest = await this.wallet.createTxExecutionRequest(requestWithoutFee, fee); const unconstrainedCalls = unconstrained.map( async ([call, index]) => diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index ac48755dc976..31e58f5607da 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -1,4 +1,4 @@ -import type { ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload, ExecutionRequestInit, UserExecutionRequest } from '@aztec/entrypoints/interfaces'; import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -67,9 +67,9 @@ export class ContractFunctionInteraction extends BaseContractInteraction { const requestWithoutFee = await this.request(options); const { fee: userFee } = options; - const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee }); + const fee = await this.getFeeOptions(requestWithoutFee, userFee); - return await this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee }); + return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee); } // docs:start:request @@ -79,7 +79,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction { * @param options - An optional object containing additional configuration for the transaction. * @returns An execution request wrapped in promise. */ - public async request(options: SendMethodOptions = {}): Promise> { + public async request(options: SendMethodOptions = {}): Promise { // docs:end:request const args = encodeArguments(this.functionDao, this.args); const calls = [ @@ -95,13 +95,11 @@ export class ContractFunctionInteraction extends BaseContractInteraction { ]; this.addAuthWitnesses(options.authwits ?? []); const authWitnesses = this.getAuthWitnesses(); - const hashedArguments = this.getHashedArguments(); const capsules = this.getCapsules(); const { nonce, cancellable } = options; return { calls, authWitnesses, - hashedArguments, capsules, nonce, cancellable, diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 567cf2fb4db1..7af191b9c69d 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -1,7 +1,14 @@ -import { type ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; -import { mergeExecutionRequestInits } from '@aztec/entrypoints/utils'; +import { type ExecutionPayload, type UserExecutionRequest } from '@aztec/entrypoints/interfaces'; +import { EntrypointPayload } from '@aztec/entrypoints/payload'; +import { mergeEncodedExecutionPayloads } from '@aztec/entrypoints/utils'; import type { Fr } from '@aztec/foundation/fields'; -import { type ContractArtifact, type FunctionAbi, type FunctionArtifact, getInitializer } from '@aztec/stdlib/abi'; +import { + type ContractArtifact, + type FunctionAbi, + type FunctionArtifact, + FunctionSelector, + getInitializer, +} from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { type ContractInstanceWithAddress, @@ -19,7 +26,6 @@ import type { Wallet } from '../wallet/wallet.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; import type { Contract } from './contract.js'; import type { ContractBase } from './contract_base.js'; -import { ContractFunctionInteraction } from './contract_function_interaction.js'; import { DeployProvenTx } from './deploy_proven_tx.js'; import { DeploySentTx } from './deploy_sent_tx.js'; @@ -77,8 +83,8 @@ export class DeployMethod extends Bas */ public async create(options: DeployOptions = {}): Promise { const requestWithoutFee = await this.request(options); - const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: options.fee }); - return this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee }); + const fee = await this.getFeeOptions(requestWithoutFee, options.fee); + return this.wallet.createTxExecutionRequest(requestWithoutFee, fee); } // REFACTOR: Having a `request` method with different semantics than the ones in the other @@ -92,7 +98,7 @@ export class DeployMethod extends Bas * @remarks This method does not have the same return type as the `request` in the ContractInteraction object, * it returns a promise for an array instead of a function call directly. */ - public async request(options: DeployOptions = {}): Promise> { + public async request(options: DeployOptions = {}): Promise { const deployment = await this.getDeploymentFunctionCalls(options); // NOTE: MEGA HACK. Remove with #10007 @@ -108,13 +114,13 @@ export class DeployMethod extends Bas const bootstrap = await this.getInitializeFunctionCalls(options); - const requests = await Promise.all([...deployment, ...bootstrap].map(c => c.request())); + const requests = [...deployment, bootstrap]; if (!requests.length) { throw new Error(`No function calls needed to deploy contract ${this.artifact.name}`); } const { nonce, cancellable } = options; - return mergeExecutionRequestInits(requests, { nonce, cancellable }); + return mergeEncodedExecutionPayloads(requests, { nonce, cancellable }); } /** @@ -132,8 +138,8 @@ export class DeployMethod extends Bas * @param options - Deployment options. * @returns A function call array with potentially requests to the class registerer and instance deployer. */ - protected async getDeploymentFunctionCalls(options: DeployOptions = {}): Promise { - const calls: ContractFunctionInteraction[] = []; + protected async getDeploymentFunctionCalls(options: DeployOptions = {}): Promise { + const calls: ExecutionPayload[] = []; // Set contract instance object so it's available for populating the DeploySendTx object const instance = await this.getInstance(options); @@ -176,19 +182,28 @@ export class DeployMethod extends Bas * @param options - Deployment options. * @returns - An array of function calls. */ - protected async getInitializeFunctionCalls(options: DeployOptions): Promise { - const calls: ContractFunctionInteraction[] = []; + protected async getInitializeFunctionCalls(options: DeployOptions): Promise { + const result: UserExecutionRequest = { + calls: [], + authWitnesses: [], + capsules: [], + }; if (this.constructorArtifact && !options.skipInitialization) { const { address } = await this.getInstance(options); - const constructorCall = new ContractFunctionInteraction( - this.wallet, - address, - this.constructorArtifact, - this.args, - ); - calls.push(constructorCall); + result.calls.push({ + name: this.constructorArtifact.name, + to: address, + selector: await FunctionSelector.fromNameAndParameters( + this.constructorArtifact.name, + this.constructorArtifact.parameters, + ), + type: this.constructorArtifact.functionType, + args: this.args, + isStatic: this.constructorArtifact.isStatic, + returnTypes: this.constructorArtifact.returnTypes, + }); } - return calls; + return result; } /** diff --git a/yarn-project/aztec.js/src/deployment/deploy_instance.ts b/yarn-project/aztec.js/src/deployment/deploy_instance.ts index e24fc43dc4b7..164df02f2869 100644 --- a/yarn-project/aztec.js/src/deployment/deploy_instance.ts +++ b/yarn-project/aztec.js/src/deployment/deploy_instance.ts @@ -1,7 +1,9 @@ +import type { ExecutionPayload } from '@aztec/entrypoints/interfaces'; import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { getDeployerContract } from '../contract/protocol_contracts.js'; +import { Fr, FunctionSelector, FunctionType } from '../index.js'; import type { Wallet } from '../wallet/index.js'; /** @@ -9,10 +11,7 @@ import type { Wallet } from '../wallet/index.js'; * @param wallet - The wallet to use for the deployment. * @param instance - The instance to deploy. */ -export async function deployInstance( - wallet: Wallet, - instance: ContractInstanceWithAddress, -): Promise { +export async function deployInstance(wallet: Wallet, instance: ContractInstanceWithAddress): Promise { const deployerContract = await getDeployerContract(wallet); const { salt, currentContractClassId: contractClassId, publicKeys, deployer } = instance; const isUniversalDeploy = deployer.isZero(); @@ -21,11 +20,25 @@ export async function deployInstance( `Expected deployer ${deployer.toString()} does not match sender wallet ${wallet.getAddress().toString()}`, ); } - return deployerContract.methods.deploy( - salt, - contractClassId, - instance.initializationHash, - publicKeys, - isUniversalDeploy, - ); + return { + calls: [ + { + name: 'deploy', + to: deployerContract.address, + selector: await FunctionSelector.fromSignature('deploy(Field,(Field),Field,-,boolean)'), + args: [ + salt, + contractClassId, + instance.initializationHash, + ...publicKeys.toFields(), + isUniversalDeploy ? Fr.ONE : Fr.ZERO, + ], + type: FunctionType.PRIVATE, + isStatic: false, + returnTypes: [], + }, + ], + authWitnesses: [], + capsules: [], + }; } diff --git a/yarn-project/aztec.js/src/deployment/register_class.ts b/yarn-project/aztec.js/src/deployment/register_class.ts index 4cd770c00a1c..61609a0db94e 100644 --- a/yarn-project/aztec.js/src/deployment/register_class.ts +++ b/yarn-project/aztec.js/src/deployment/register_class.ts @@ -1,7 +1,8 @@ import { MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT } from '@aztec/constants'; +import type { ExecutionPayload } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import { type ContractArtifact, bufferAsFields } from '@aztec/stdlib/abi'; +import { type ContractArtifact, FunctionSelector, FunctionType, bufferAsFields } from '@aztec/stdlib/abi'; import { getContractClassFromArtifact } from '@aztec/stdlib/contract'; import { Capsule } from '@aztec/stdlib/tx'; @@ -20,25 +21,32 @@ export async function registerContractClass( wallet: Wallet, artifact: ContractArtifact, emitPublicBytecode = defaultEmitPublicBytecode, -): Promise { +): Promise { const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode } = await getContractClassFromArtifact(artifact); const registerer = await getRegistererContract(wallet); - const fn = registerer.methods.register( - artifactHash, - privateFunctionsRoot, - publicBytecodeCommitment, - emitPublicBytecode, - ); - const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS); - fn.addCapsule( - new Capsule( - ProtocolContractAddress.ContractClassRegisterer, - new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), - encodedBytecode, - ), - ); + const executionPayload: ExecutionPayload = { + calls: [ + { + name: 'register', + to: registerer.address, + selector: await FunctionSelector.fromSignature('register'), + args: [artifactHash, privateFunctionsRoot, publicBytecodeCommitment, emitPublicBytecode ? Fr.ONE : Fr.ZERO], + type: FunctionType.PRIVATE, + isStatic: false, + returnTypes: [], + }, + ], + capsules: [ + new Capsule( + ProtocolContractAddress.ContractClassRegisterer, + new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), + encodedBytecode, + ), + ], + authWitnesses: [], + }; - return fn; + return executionPayload; } diff --git a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts index de826e90076a..84904a01c8b2 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts @@ -1,5 +1,11 @@ -import { type EntrypointInterface, type ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import { + type EntrypointInterface, + type ExecutionRequestInit, + type FeeOptions, + type UserExecutionRequest, +} from '@aztec/entrypoints/interfaces'; import { EntrypointPayload } from '@aztec/entrypoints/payload'; +import { mergeEncodedExecutionPayloads } from '@aztec/entrypoints/utils'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -15,20 +21,26 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface { private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint, ) {} - async createTxExecutionRequest(executions: ExecutionRequestInit): Promise { - const { fee, calls, authWitnesses = [], hashedArguments = [], capsules = [] } = executions; + async createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { + const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; const payload = await EntrypointPayload.fromAppExecution(calls); const abi = this.getEntrypointAbi(); const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload])); + const executionPayload = mergeEncodedExecutionPayloads([payload], { + extraHashedArgs: [entrypointHashedArgs], + extraAuthWitnesses: userAuthWitnesses, + extraCapsules: userCapsules, + }); + const txRequest = TxExecutionRequest.from({ firstCallArgsHash: entrypointHashedArgs.hash, origin: this.address, functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters), txContext: new TxContext(this.chainId, this.version, fee.gasSettings), - argsOfCalls: [...payload.hashedArguments, ...hashedArguments, entrypointHashedArgs], - authWitnesses, - capsules, + argsOfCalls: executionPayload.hashedArguments, + authWitnesses: executionPayload.authWitnesses, + capsules: executionPayload.capsules, }); return Promise.resolve(txRequest); diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts index e700a293cbf5..4d3902290063 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts @@ -1,6 +1,7 @@ -import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload, ExecutionRequestInit, FeePaymentMethod } from '@aztec/entrypoints/interfaces'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { FunctionCall } from '@aztec/stdlib/abi'; +import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; // docs:start:fee_juice_method @@ -15,8 +16,8 @@ export class FeeJuicePaymentMethod implements FeePaymentMethod { return Promise.resolve(ProtocolContractAddress.FeeJuice); } - getFunctionCalls(): Promise { - return Promise.resolve([]); + getExecutionPayload(): Promise { + return Promise.resolve({ calls: [], authWitnesses: [], capsules: [] }); } getFeePayer(): Promise { diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts index 28efae594188..888a6206750d 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts @@ -1,7 +1,9 @@ +import type { ExecutionPayload } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { FunctionCall } from '@aztec/stdlib/abi'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; +import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { getFeeJuice } from '../contract/protocol_contracts.js'; import type { L2AmountClaim } from '../ethereum/portal_manager.js'; @@ -23,27 +25,31 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod { * Creates a function call to pay the fee in Fee Juice. * @returns A function call */ - override async getFunctionCalls(): Promise { + override async getExecutionPayload(): Promise { const canonicalFeeJuice = await getFeeJuice(this.senderWallet); const selector = await FunctionSelector.fromNameAndParameters( canonicalFeeJuice.artifact.functions.find(f => f.name === 'claim')!, ); - return Promise.resolve([ - { - to: ProtocolContractAddress.FeeJuice, - name: 'claim', - selector, - isStatic: false, - args: [ - this.senderWallet.getAddress().toField(), - new Fr(this.claim.claimAmount), - this.claim.claimSecret, - new Fr(this.claim.messageLeafIndex), - ], - returnTypes: [], - type: FunctionType.PRIVATE, - }, - ]); + return { + calls: [ + { + to: ProtocolContractAddress.FeeJuice, + name: 'claim', + selector, + isStatic: false, + args: [ + this.senderWallet.getAddress().toField(), + new Fr(this.claim.claimAmount), + this.claim.claimSecret, + new Fr(this.claim.messageLeafIndex), + ], + returnTypes: [], + type: FunctionType.PRIVATE, + }, + ], + authWitnesses: [], + capsules: [], + }; } } diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index 95231547cc26..606b717e0e7b 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -1,11 +1,10 @@ -import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload, FeePaymentMethod } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; +import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; -import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; -import { SignerlessWallet } from '../wallet/signerless_wallet.js'; import type { Wallet } from '../wallet/wallet.js'; import { simulateWithoutSignature } from './utils.js'; @@ -76,13 +75,13 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { * @param gasSettings - The gas settings. * @returns The function call to pay the fee. */ - async getFunctionCalls(gasSettings: GasSettings): Promise { + async getExecutionPayload(gasSettings: GasSettings): Promise { // We assume 1:1 exchange rate between fee juice and token. But in reality you would need to convert feeLimit // (maxFee) to be in token denomination. const maxFee = this.setMaxFeeToOne ? Fr.ONE : gasSettings.getFeeLimit(); const nonce = Fr.random(); - await this.wallet.createAuthWit({ + const witness = await this.wallet.createAuthWit({ caller: this.paymentContract, action: { name: 'transfer_to_public', @@ -95,16 +94,20 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { }, }); - return [ - { - name: 'fee_entrypoint_private', - to: this.paymentContract, - selector: await FunctionSelector.fromSignature('fee_entrypoint_private(u128,Field)'), - type: FunctionType.PRIVATE, - isStatic: false, - args: [maxFee, nonce], - returnTypes: [], - }, - ]; + return { + calls: [ + { + name: 'fee_entrypoint_private', + to: this.paymentContract, + selector: await FunctionSelector.fromSignature('fee_entrypoint_private(u128,Field)'), + type: FunctionType.PRIVATE, + isStatic: false, + args: [maxFee, nonce], + returnTypes: [], + }, + ], + authWitnesses: [witness], + capsules: [], + }; } } diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index f54a29e6d1d8..1eedc541bb79 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -1,6 +1,5 @@ -import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload, FeePaymentMethod } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; -import type { FunctionCall } from '@aztec/stdlib/abi'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { GasSettings } from '@aztec/stdlib/gas'; @@ -68,7 +67,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { * @param gasSettings - The gas settings. * @returns The function call to pay the fee. */ - async getFunctionCalls(gasSettings: GasSettings): Promise { + async getExecutionPayload(gasSettings: GasSettings): Promise { const nonce = Fr.random(); const maxFee = gasSettings.getFeeLimit(); @@ -88,17 +87,21 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { true, ); - return [ - ...(await setPublicAuthWitInteraction.request()).calls, - { - name: 'fee_entrypoint_public', - to: this.paymentContract, - selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'), - type: FunctionType.PRIVATE, - isStatic: false, - args: [maxFee, nonce], - returnTypes: [], - }, - ]; + return { + calls: [ + ...(await setPublicAuthWitInteraction.request()).calls, + { + name: 'fee_entrypoint_public', + to: this.paymentContract, + selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'), + type: FunctionType.PRIVATE, + isStatic: false, + args: [maxFee, nonce], + returnTypes: [], + }, + ], + authWitnesses: [], + capsules: [], + }; } } diff --git a/yarn-project/aztec.js/src/fee/utils.ts b/yarn-project/aztec.js/src/fee/utils.ts index 07eb9050244a..0fa0e506c568 100644 --- a/yarn-project/aztec.js/src/fee/utils.ts +++ b/yarn-project/aztec.js/src/fee/utils.ts @@ -18,7 +18,7 @@ export async function simulateWithoutSignature(wallet: Wallet, contractAddress: const { l1ChainId: chainId, protocolVersion } = await wallet.getNodeInfo(); const entrypoint = new DefaultEntrypoint(chainId, protocolVersion); - const signerlessTxExecutionRequest = await entrypoint.createTxExecutionRequest({ ...request, fee }); + const signerlessTxExecutionRequest = await entrypoint.createTxExecutionRequest(request, fee); const simulationResult = await wallet.simulateTx(signerlessTxExecutionRequest, false, undefined, undefined, true); const rawReturnValues = simulationResult.getPrivateReturnValues().values; diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index 49fdb900ddeb..c95d69939cad 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -57,13 +57,13 @@ export const computeAuthWitMessageHash = async (intent: IntentInnerHash | Intent const version = metadata.version; if ('caller' in intent) { - const action = + const fnCall = intent.action instanceof ContractFunctionInteraction ? (await intent.action.request()).calls[0] : intent.action; return computeOuterAuthWitHash( - action.to, + fnCall.to, chainId, version, - await computeInnerAuthWitHashFromAction(intent.caller, action), + await computeInnerAuthWitHashFromFunctionCall(intent.caller, fnCall), ); } else { const inner = Buffer.isBuffer(intent.innerHash) ? Fr.fromBuffer(intent.innerHash) : intent.innerHash; @@ -72,9 +72,22 @@ export const computeAuthWitMessageHash = async (intent: IntentInnerHash | Intent }; // docs:end:authwit_computeAuthWitMessageHash -export const computeInnerAuthWitHashFromAction = async (caller: AztecAddress, action: FunctionCall) => - computeInnerAuthWitHash([ +export const computeInnerAuthWitHashFromFunctionCall = async (caller: AztecAddress, fnCall: FunctionCall) => { + return computeInnerAuthWitHash([ + caller.toField(), + fnCall.selector.toField(), + (await HashedValues.fromValues(fnCall.args)).hash, + ]); +}; + +export const computeInnerAuthWitHashFromAction = async ( + caller: AztecAddress, + action: FunctionCall | ContractFunctionInteraction, +) => { + action = action instanceof ContractFunctionInteraction ? (await action.request()).calls[0] : action; + return computeInnerAuthWitHash([ caller.toField(), action.selector.toField(), (await HashedValues.fromValues(action.args)).hash, ]); +}; diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 30a9bfdecd70..0588259ef06a 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -1,4 +1,4 @@ -import type { ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import type { ExecutionRequestInit, FeeOptions, UserExecutionRequest } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type ABIParameterVisibility, type FunctionAbi, FunctionType } from '@aztec/stdlib/abi'; @@ -25,8 +25,8 @@ export class AccountWallet extends BaseWallet { super(pxe); } - createTxExecutionRequest(exec: ExecutionRequestInit): Promise { - return this.account.createTxExecutionRequest(exec); + createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { + return this.account.createTxExecutionRequest(exec, fee); } getChainId(): Fr { diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 0b673d266d01..9c9482506ee8 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -1,4 +1,4 @@ -import type { ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import type { ExecutionRequestInit, FeeOptions, UserExecutionRequest } from '@aztec/entrypoints/interfaces'; import type { Fr, Point } from '@aztec/foundation/fields'; import type { AbiDecoded, ContractArtifact } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; @@ -37,7 +37,7 @@ export abstract class BaseWallet implements Wallet { abstract getVersion(): Fr; - abstract createTxExecutionRequest(exec: ExecutionRequestInit): Promise; + abstract createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise; abstract createAuthWit(intent: Fr | Buffer | IntentInnerHash | IntentAction): Promise; diff --git a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts index 6d4505474baf..b4f80c57f4a1 100644 --- a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts @@ -1,5 +1,10 @@ import { DefaultEntrypoint } from '@aztec/entrypoints/default'; -import type { EntrypointInterface, ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import type { + EntrypointInterface, + ExecutionRequestInit, + FeeOptions, + UserExecutionRequest, +} from '@aztec/entrypoints/interfaces'; import type { Fr } from '@aztec/foundation/fields'; import { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { CompleteAddress } from '@aztec/stdlib/contract'; @@ -16,14 +21,14 @@ export class SignerlessWallet extends BaseWallet { constructor(pxe: PXE, private entrypoint?: EntrypointInterface) { super(pxe); } - async createTxExecutionRequest(execution: ExecutionRequestInit): Promise { + async createTxExecutionRequest(execution: UserExecutionRequest, fee: FeeOptions): Promise { let entrypoint = this.entrypoint; if (!entrypoint) { const { l1ChainId: chainId, protocolVersion } = await this.pxe.getNodeInfo(); entrypoint = new DefaultEntrypoint(chainId, protocolVersion); } - return entrypoint.createTxExecutionRequest(execution); + return entrypoint.createTxExecutionRequest(execution, fee); } getChainId(): Fr { diff --git a/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts b/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts index c35207377985..3b0b475f8bdd 100644 --- a/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts +++ b/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts @@ -1,6 +1,8 @@ import type { FeePaymentMethod } from '@aztec/aztec.js'; +import type { ExecutionPayload } from '@aztec/entrypoints/interfaces'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; +import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PXE } from '@aztec/stdlib/interfaces/client'; @@ -30,17 +32,21 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod { return Promise.resolve(this.paymentContract); } - async getFunctionCalls(): Promise { - return [ - { - name: 'sponsor_unconditionally', - to: this.paymentContract, - selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'), - type: FunctionType.PRIVATE, - isStatic: false, - args: [], - returnTypes: [], - }, - ]; + async getExecutionPayload(): Promise { + return { + calls: [ + { + name: 'sponsor_unconditionally', + to: this.paymentContract, + selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'), + type: FunctionType.PRIVATE, + isStatic: false, + args: [], + returnTypes: [], + }, + ], + authWitnesses: [], + capsules: [], + }; } } diff --git a/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts b/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts index 45f3dd4270b6..890dbdc24bed 100644 --- a/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts +++ b/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts @@ -1,5 +1,7 @@ import type { FeePaymentMethod } from '@aztec/aztec.js/fee'; -import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; +import type { ExecutionPayload, ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; +import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; export class SponsoredFeePaymentMethod implements FeePaymentMethod { @@ -13,17 +15,21 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod { return Promise.resolve(this.paymentContract); } - async getFunctionCalls() { - return [ - { - name: 'sponsor_unconditionally', - to: this.paymentContract, - selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'), - type: FunctionType.PRIVATE, - isStatic: false, - args: [], - returnTypes: [], - }, - ]; + async getExecutionPayload(): Promise { + return { + calls: [ + { + name: 'sponsor_unconditionally', + to: this.paymentContract, + selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'), + type: FunctionType.PRIVATE, + isStatic: false, + args: [], + returnTypes: [], + }, + ], + authWitnesses: [], + capsules: [], + }; } } diff --git a/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts b/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts index 1f98c24eae29..44034b6d4a3e 100644 --- a/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts +++ b/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts @@ -1,6 +1,12 @@ import { getSchnorrAccount, getSchnorrWallet } from '@aztec/accounts/schnorr'; import { type InitialAccountData, deployFundedSchnorrAccount } from '@aztec/accounts/testing'; -import { type AccountWallet, type ContractInstanceWithAddress, type TxHash, computeSecretHash } from '@aztec/aztec.js'; +import { + type AccountWallet, + type ContractInstanceWithAddress, + type PXE, + type TxHash, + computeSecretHash, +} from '@aztec/aztec.js'; import { MAX_NOTE_HASHES_PER_TX } from '@aztec/constants'; import type { DeployL1ContractsReturnType } from '@aztec/ethereum'; import { Fr } from '@aztec/foundation/fields'; @@ -33,6 +39,8 @@ describe('Aztec persistence', () => { * All five scenarios use the same L1 state, which is deployed in the `beforeAll` hook. */ + let pxe: PXE; + // the test contract and account deploying it let contractInstance: ContractInstanceWithAddress; let contractAddress: AztecAddress; @@ -55,6 +63,7 @@ describe('Aztec persistence', () => { dataDirectory = await mkdtemp(join(tmpdir(), 'aztec-node-')); const initialContext = await setup(0, { dataDirectory, numberOfInitialFundedAccounts: 3 }, { dataDirectory }); + pxe = initialContext.pxe; deployL1ContractsValues = initialContext.deployL1ContractsValues; initialFundedAccounts = initialContext.initialFundedAccounts; @@ -82,10 +91,11 @@ describe('Aztec persistence', () => { await addPendingShieldNoteToPXE( contract, - ownerWallet, + ownerWallet.getAddress(), 1000n, await computeSecretHash(secret), mintTxReceipt.txHash, + pxe, ); await contract.methods.redeem_shield(owner.address, 1000n, secret).send().wait(); @@ -149,10 +159,11 @@ describe('Aztec persistence', () => { .wait(); await addPendingShieldNoteToPXE( contract, - ownerWallet, + ownerWallet.getAddress(), 1000n, await computeSecretHash(secret), mintTxReceipt.txHash, + pxe, ); await contract.methods.redeem_shield(ownerWallet.getAddress(), 1000n, secret).send().wait(); @@ -319,7 +330,14 @@ describe('Aztec persistence', () => { it('allows consuming transparent note created on another PXE', async () => { // this was created in the temporary PXE in `beforeAll` - await addPendingShieldNoteToPXE(contract, ownerWallet, mintAmount, await computeSecretHash(secret), mintTxHash); + await addPendingShieldNoteToPXE( + contract, + ownerWallet.getAddress(), + mintAmount, + await computeSecretHash(secret), + mintTxHash, + pxe, + ); const balanceBeforeRedeem = await contract.methods.balance_of_private(ownerWallet.getAddress()).simulate(); @@ -337,13 +355,14 @@ function toBoundedVec(arr: Fr[], maxLen: number) { async function addPendingShieldNoteToPXE( contract: TokenBlacklistContract, - wallet: AccountWallet, + address: AztecAddress, amount: bigint, secretHash: Fr, txHash: TxHash, + pxe: PXE, ) { // docs:start:offchain_delivery - const txEffects = await wallet.getTxEffect(txHash); + const txEffects = await pxe.getTxEffect(txHash); await contract.methods .deliver_transparent_note( contract.address, @@ -352,7 +371,7 @@ async function addPendingShieldNoteToPXE( txHash.hash, toBoundedVec(txEffects!.data.noteHashes, MAX_NOTE_HASHES_PER_TX), txEffects!.data.nullifiers[0], - wallet.getAddress(), + address, ) .simulate(); // docs:end:offchain_delivery diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts index 7ce2a70455a7..fe40445827b2 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts @@ -1,9 +1,11 @@ import { getSchnorrWallet } from '@aztec/accounts/schnorr'; import { type AccountWallet, + AztecAddress, type CompleteAddress, Fr, type Logger, + type PXE, type TxHash, computeSecretHash, createLogger, @@ -61,6 +63,7 @@ export class BlacklistTokenContractTest { private snapshotManager: ISnapshotManager; logger: Logger; wallets: AccountWallet[] = []; + pxe!: PXE; accounts: CompleteAddress[] = []; asset!: TokenBlacklistContract; tokenSim!: TokenSimulator; @@ -94,6 +97,7 @@ export class BlacklistTokenContractTest { '3_accounts', deployAccounts(3, this.logger), async ({ deployedAccounts }, { pxe }) => { + this.pxe = pxe; this.wallets = await Promise.all(deployedAccounts.map(a => getSchnorrWallet(pxe, a.address, a.signingKey))); this.admin = this.wallets[0]; this.other = this.wallets[1]; @@ -164,12 +168,12 @@ export class BlacklistTokenContractTest { async addPendingShieldNoteToPXE( contract: TokenBlacklistContract, - wallet: AccountWallet, + address: AztecAddress, amount: bigint, secretHash: Fr, txHash: TxHash, ) { - const txEffects = await wallet.getTxEffect(txHash); + const txEffects = await this.pxe.getTxEffect(txHash); await contract.methods .deliver_transparent_note( contract.address, @@ -178,7 +182,7 @@ export class BlacklistTokenContractTest { txHash.hash, this.#toBoundedVec(txEffects!.data.noteHashes, MAX_NOTE_HASHES_PER_TX), txEffects!.data.nullifiers[0], - wallet.getAddress(), + address, ) .simulate(); } @@ -218,9 +222,9 @@ export class BlacklistTokenContractTest { const secretHash = await computeSecretHash(secret); const receipt = await asset.methods.mint_private(amount, secretHash).send().wait(); - await this.addPendingShieldNoteToPXE(asset, wallets[0], amount, secretHash, receipt.txHash); + await this.addPendingShieldNoteToPXE(asset, wallets[0].getAddress(), amount, secretHash, receipt.txHash); const txClaim = asset.methods.redeem_shield(accounts[0].address, amount, secret).send(); - await txClaim.wait({ debug: true }); + await txClaim.wait(); this.logger.verbose(`Minting complete.`); return { amount }; diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts index 26082c958375..52eb5d258667 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts @@ -151,16 +151,19 @@ describe('e2e_blacklist_token_contract burn', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await wallets[1].addAuthWitness(witness); - // We give wallets[1] access to wallets[0]'s notes to be able to burn the notes. - wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]); - - await asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send().wait(); + await asset + .withWallet(wallets[1]) + .methods.burn(wallets[0].getAddress(), amount, nonce) + .send({ authwits: [witness] }) + .wait(); tokenSim.burnPrivate(wallets[0].getAddress(), amount); // Perform the transfer again, should fail - const txReplay = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send(); + const txReplay = asset + .withWallet(wallets[1]) + .methods.burn(wallets[0].getAddress(), amount, nonce) + .send({ authwits: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); @@ -195,9 +198,8 @@ describe('e2e_blacklist_token_contract burn', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await wallets[1].addAuthWitness(witness); - await expect(action.prove()).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.prove({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); }); it('burn on behalf of other without approval', async () => { @@ -213,9 +215,6 @@ describe('e2e_blacklist_token_contract burn', () => { { chainId: wallets[0].getChainId(), version: wallets[0].getVersion() }, ); - // We give wallets[1] access to wallets[0]'s notes to test the authwit. - wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]); - await expect(action.prove()).rejects.toThrow(`Unknown auth witness for message hash ${messageHash.toString()}`); }); @@ -233,12 +232,8 @@ describe('e2e_blacklist_token_contract burn', () => { ); const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await wallets[2].addAuthWitness(witness); - - // We give wallets[2] access to wallets[0]'s notes to test the authwit. - wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]); - await expect(action.prove()).rejects.toThrow( + await expect(action.prove({ authwits: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts index af941a30432a..b12a974feb89 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts @@ -5,7 +5,7 @@ import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js'; describe('e2e_blacklist_token_contract mint', () => { const t = new BlacklistTokenContractTest('mint'); - let { asset, tokenSim, wallets, blacklisted } = t; + let { asset, tokenSim, wallets, blacklisted, pxe } = t; beforeAll(async () => { await t.applyBaseSnapshots(); @@ -13,7 +13,7 @@ describe('e2e_blacklist_token_contract mint', () => { await t.applyMintSnapshot(); await t.setup(); // Have to destructure again to ensure we have latest refs. - ({ asset, tokenSim, wallets, blacklisted } = t); + ({ asset, tokenSim, wallets, blacklisted, pxe } = t); }, 600_000); afterAll(async () => { @@ -88,18 +88,15 @@ describe('e2e_blacklist_token_contract mint', () => { const receipt = await asset.methods.mint_private(amount, secretHash).send().wait(); txHash = receipt.txHash; - await t.addPendingShieldNoteToPXE(asset, wallets[0], amount, secretHash, txHash); + await t.addPendingShieldNoteToPXE(asset, wallets[0].getAddress(), amount, secretHash, txHash); - const receiptClaim = await asset.methods - .redeem_shield(wallets[0].getAddress(), amount, secret) - .send() - .wait({ debug: true }); + const receiptClaim = await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait(); tokenSim.mintPrivate(wallets[0].getAddress(), amount); // Trigger a note sync await asset.methods.sync_notes().simulate(); // 1 note should have been created containing `amount` of tokens - const visibleNotes = await wallets[0].getNotes({ txHash: receiptClaim.txHash }); + const visibleNotes = await pxe.getNotes({ txHash: receiptClaim.txHash }); expect(visibleNotes.length).toBe(1); expect(visibleNotes[0].note.items[0].toBigInt()).toBe(amount); }); @@ -111,7 +108,7 @@ describe('e2e_blacklist_token_contract mint', () => { // add it, but PXE will realize that the note has been nullified already and not inject it into the circuit // during execution of redeem_shield, resulting in a simulation failure. - await t.addPendingShieldNoteToPXE(asset, wallets[1], amount, secretHash, txHash); + await t.addPendingShieldNoteToPXE(asset, wallets[1].getAddress(), amount, secretHash, txHash); await expect( asset.withWallet(wallets[1]).methods.redeem_shield(wallets[1].getAddress(), amount, secret).prove(), diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/shielding.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/shielding.test.ts index 8aea08f540dd..ea80f8b846f9 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/shielding.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/shielding.test.ts @@ -38,7 +38,7 @@ describe('e2e_blacklist_token_contract shield + redeem_shield', () => { const receipt = await asset.methods.shield(wallets[0].getAddress(), amount, secretHash, 0).send().wait(); // Redeem it - await t.addPendingShieldNoteToPXE(asset, wallets[0], amount, secretHash, receipt.txHash); + await t.addPendingShieldNoteToPXE(asset, wallets[0].getAddress(), amount, secretHash, receipt.txHash); await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait(); // Check that the result matches token sim @@ -68,7 +68,7 @@ describe('e2e_blacklist_token_contract shield + redeem_shield', () => { ).rejects.toThrow(/unauthorized/); // Redeem it - await t.addPendingShieldNoteToPXE(asset, wallets[0], amount, secretHash, receipt.txHash); + await t.addPendingShieldNoteToPXE(asset, wallets[0].getAddress(), amount, secretHash, receipt.txHash); await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait(); // Check that the result matches token sim diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts index ba524f3a41af..5679aa5ff20d 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts @@ -30,9 +30,6 @@ describe('e2e_blacklist_token_contract transfer private', () => { expect(amount).toBeGreaterThan(0n); await asset.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, 0).send().wait(); tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount); - - // We give wallets[0] access to wallets[1]'s notes to be able to check balances after the test. - wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); }); it('transfer to self', async () => { @@ -60,27 +57,21 @@ describe('e2e_blacklist_token_contract transfer private', () => { // docs:start:create_authwit const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); // docs:end:create_authwit + + // Perform the transfer + // docs:start:add_authwit - await wallets[1].addAuthWitness(witness); + await action.send({ authwits: [witness] }).wait(); // docs:end:add_authwit // docs:end:authwit_transfer_example - - // We give wallets[1] access to wallets[0]'s notes to be able to transfer the notes. - wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]); - - // Perform the transfer - await action.send().wait(); tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount); // Perform the transfer again, should fail const txReplay = asset .withWallet(wallets[1]) .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) - .send(); + .send({ authwits: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); - - // We give wallets[0] access to wallets[1]'s notes to be able to check balances after the test. - wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); }); describe('failure cases', () => { @@ -119,10 +110,9 @@ describe('e2e_blacklist_token_contract transfer private', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await wallets[1].addAuthWitness(witness); // Perform the transfer - await expect(action.prove()).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.prove({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); expect(await asset.methods.balance_of_private(wallets[0].getAddress()).simulate()).toEqual(balance0); expect(await asset.methods.balance_of_private(wallets[1].getAddress()).simulate()).toEqual(balance1); }); @@ -168,12 +158,8 @@ describe('e2e_blacklist_token_contract transfer private', () => { ); const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await wallets[2].addAuthWitness(witness); - - // We give wallets[2] access to wallets[0]'s notes to test the authwit. - wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]); - await expect(action.prove()).rejects.toThrow( + await expect(action.prove({ authwits: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); expect(await asset.methods.balance_of_private(wallets[0].getAddress()).simulate()).toEqual(balance0); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts index be3c4ce7af77..b7d9127124bf 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts @@ -48,19 +48,15 @@ describe('e2e_blacklist_token_contract unshielding', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await wallets[1].addAuthWitness(witness); - // We give wallets[1] access to wallets[0]'s notes to unshield the note. - wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]); - - await action.send().wait(); + await action.send({ authwits: [witness] }).wait(); tokenSim.transferToPublic(wallets[0].getAddress(), wallets[1].getAddress(), amount); // Perform the transfer again, should fail const txReplay = asset .withWallet(wallets[1]) .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) - .send(); + .send({ authwits: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); // @todo @LHerskind This error is weird? }); @@ -100,9 +96,8 @@ describe('e2e_blacklist_token_contract unshielding', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await wallets[1].addAuthWitness(witness); - await expect(action.prove()).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.prove({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); }); it('on behalf of other (invalid designated caller)', async () => { @@ -123,12 +118,8 @@ describe('e2e_blacklist_token_contract unshielding', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await wallets[2].addAuthWitness(witness); - - // We give wallets[2] access to wallets[0]'s notes to test the authwit. - wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]); - await expect(action.prove()).rejects.toThrow( + await expect(action.prove({ authwits: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract/private_initialization.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract/private_initialization.test.ts index b7f104575785..f0a9b5b8ab39 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract/private_initialization.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract/private_initialization.test.ts @@ -1,4 +1,4 @@ -import { BatchCall, Fr, type Logger, type Wallet } from '@aztec/aztec.js'; +import { type AztecNode, BatchCall, Fr, type Logger, type Wallet } from '@aztec/aztec.js'; import { StatefulTestContract } from '@aztec/noir-contracts.js/StatefulTest'; import { TestContract } from '@aztec/noir-contracts.js/Test'; import { siloNullifier } from '@aztec/stdlib/hash'; @@ -10,9 +10,10 @@ describe('e2e_deploy_contract private initialization', () => { let logger: Logger; let wallet: Wallet; + let aztecNode: AztecNode; beforeAll(async () => { - ({ logger, wallet } = await t.setup()); + ({ logger, wallet, aztecNode } = await t.setup()); }); afterAll(() => t.teardown()); @@ -21,9 +22,11 @@ describe('e2e_deploy_contract private initialization', () => { // it still requires registering the contract artifact and instance locally in the pxe. it('executes a function in an undeployed contract from an account contract', async () => { const contract = await t.registerContract(wallet, TestContract); - const receipt = await contract.methods.emit_nullifier(10).send().wait({ debug: true }); + const receipt = await contract.methods.emit_nullifier(10).send().wait(); + const txEffects = await aztecNode.getTxEffect(receipt.txHash); + const expected = await siloNullifier(contract.address, new Fr(10)); - expect(receipt.debugInfo?.nullifiers).toContainEqual(expected); + expect(txEffects!.data.nullifiers).toContainEqual(expected); }); // Tests privately initializing an undeployed contract. Also requires pxe registration in advance. diff --git a/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts b/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts index 2ecb52e4b35d..be2eef780072 100644 --- a/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts @@ -102,9 +102,6 @@ describe('e2e_fees dapp_subscription', () => { const { transactionFee } = await subscribe(new PrivateFeePaymentMethod(bananaFPC.address, aliceWallet)); - // We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state. - aliceWallet.setScopes([aliceAddress, bobAddress]); - await expectMapping( t.getGasBalanceFn, [sequencerAddress, bananaFPC.address], @@ -187,12 +184,12 @@ describe('e2e_fees dapp_subscription', () => { // This authwit is made because the subscription recipient is Bob, so we are approving the contract to send funds // to him, on our behalf, as part of the subscription process. const action = bananaCoin.methods.transfer_in_private(aliceAddress, bobAddress, t.SUBSCRIPTION_AMOUNT, nonce); - await aliceWallet.createAuthWit({ caller: subscriptionContract.address, action }); + const witness = await aliceWallet.createAuthWit({ caller: subscriptionContract.address, action }); return subscriptionContract .withWallet(aliceWallet) .methods.subscribe(aliceAddress, nonce, (await pxe.getBlockNumber()) + blockDelta, txCount) - .send({ fee: { paymentMethod } }) + .send({ authwits: [witness], fee: { paymentMethod } }) .wait(); } diff --git a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts index a878b05c8146..f83dcbf8faa3 100644 --- a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts @@ -1,5 +1,6 @@ import { type AccountWallet, + AuthWitness, type AztecAddress, Fr, type FunctionCall, @@ -324,7 +325,9 @@ describe('e2e_fees failures', () => { }); class BuggedSetupFeePaymentMethod extends PublicFeePaymentMethod { - override async getFunctionCalls(gasSettings: GasSettings): Promise { + override async getFunctionCalls( + gasSettings: GasSettings, + ): Promise> { const maxFee = gasSettings.getFeeLimit(); const nonce = Fr.random(); @@ -348,17 +351,20 @@ class BuggedSetupFeePaymentMethod extends PublicFeePaymentMethod { true, ); - return [ - ...(await setPublicAuthWitInteraction.request()).calls, - { - name: 'fee_entrypoint_public', - to: this.paymentContract, - selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'), - type: FunctionType.PRIVATE, - isStatic: false, - args: [tooMuchFee, nonce], - returnTypes: [], - }, - ]; + return { + calls: [ + ...(await setPublicAuthWitInteraction.request()).calls, + { + name: 'fee_entrypoint_public', + to: this.paymentContract, + selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'), + type: FunctionType.PRIVATE, + isStatic: false, + args: [tooMuchFee, nonce], + returnTypes: [], + }, + ], + authwits: [], + }; } } diff --git a/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts b/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts index 4f18d087e2f0..1c490ec3d985 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts @@ -40,9 +40,6 @@ describe('e2e_fees Fee Juice payments', () => { // Alice pays for Bob's account contract deployment. await bobAccount.deploy({ deployWallet: aliceWallet }).wait(); - - // We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state. - aliceWallet.setScopes([aliceAddress, bobAddress]); }); afterAll(async () => { diff --git a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts index e66dab0362f2..4c5fe793b443 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts @@ -180,10 +180,10 @@ export class FeesTest { const canonicalFeeJuice = await getCanonicalFeeJuice(); this.feeJuiceContract = await FeeJuiceContract.at(canonicalFeeJuice.address, this.aliceWallet); - if (this.numberOfAccounts > 1) { - const bobInstance = (await this.bobWallet.getContractMetadata(this.bobAddress)).contractInstance; - await this.aliceWallet.registerAccount(deployedAccounts[1].secret, await computePartialAddress(bobInstance!)); - } + // if (this.numberOfAccounts > 1) { + // const bobInstance = (await this.bobWallet.getContractMetadata(this.bobAddress)).contractInstance; + // await this.aliceWallet.registerAccount(deployedAccounts[1].secret, await computePartialAddress(bobInstance!)); + // } this.coinbase = EthAddress.random(); const { publicClient, walletClient } = createL1Clients(aztecNodeConfig.l1RpcUrls, MNEMONIC); diff --git a/yarn-project/end-to-end/src/e2e_fees/gas_estimation.test.ts b/yarn-project/end-to-end/src/e2e_fees/gas_estimation.test.ts index 0ea40d7195c8..02367929d40e 100644 --- a/yarn-project/end-to-end/src/e2e_fees/gas_estimation.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/gas_estimation.test.ts @@ -31,9 +31,6 @@ describe('e2e_fees gas_estimation', () => { await t.applyFPCSetupSnapshot(); await t.applyFundAliceWithBananas(); ({ aliceWallet, aliceAddress, bobAddress, bananaCoin, bananaFPC, gasSettings, logger } = await t.setup()); - - // We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state. - aliceWallet.setScopes([aliceAddress, bobAddress]); }); beforeEach(async () => { diff --git a/yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts b/yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts index 716b9169c5dd..8dc813c26d75 100644 --- a/yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts @@ -1,4 +1,11 @@ -import { type AccountWallet, type AztecAddress, BatchCall, PrivateFeePaymentMethod } from '@aztec/aztec.js'; +import { + type AccountWallet, + type AztecAddress, + BatchCall, + type PXE, + PrivateFeePaymentMethod, + waitForProven, +} from '@aztec/aztec.js'; import { FPCContract } from '@aztec/noir-contracts.js/FPC'; import type { TokenContract as BananaCoin } from '@aztec/noir-contracts.js/Token'; import { GasSettings } from '@aztec/stdlib/gas'; @@ -14,6 +21,7 @@ describe('e2e_fees private_payment', () => { let bananaCoin: BananaCoin; let bananaFPC: FPCContract; let gasSettings: GasSettings; + let pxe: PXE; const t = new FeesTest('private_payment'); @@ -21,7 +29,8 @@ describe('e2e_fees private_payment', () => { await t.applyBaseSnapshots(); await t.applyFPCSetupSnapshot(); await t.applyFundAliceWithBananas(); - ({ aliceWallet, aliceAddress, bobAddress, sequencerAddress, bananaCoin, bananaFPC, gasSettings } = await t.setup()); + ({ aliceWallet, aliceAddress, bobAddress, sequencerAddress, bananaCoin, bananaFPC, gasSettings, pxe } = + await t.setup()); // Prove up until the current state by just marking it as proven. // Then turn off the watcher to prevent it from keep proving @@ -62,9 +71,6 @@ describe('e2e_fees private_payment', () => { t.getBananaPublicBalanceFn(aliceAddress, bobAddress, bananaFPC.address), t.getGasBalanceFn(aliceAddress, bananaFPC.address, sequencerAddress), ]); - - // We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state. - aliceWallet.setScopes([aliceAddress, bobAddress]); }); it('pays fees for tx that dont run public app logic', async () => { @@ -104,10 +110,11 @@ describe('e2e_fees private_payment', () => { const sequencerRewardsBefore = await t.getCoinbaseSequencerRewards(); const tx = localTx.send(); - await tx.wait({ timeout: 300, interval: 10, proven: false }); + await tx.wait({ timeout: 300, interval: 10 }); await t.cheatCodes.rollup.advanceToNextEpoch(); - const receipt = await tx.wait({ timeout: 300, interval: 10, proven: true, provenTimeout: 300 }); + const receipt = await tx.wait({ timeout: 300, interval: 10 }); + await waitForProven(pxe, receipt, { provenTimeout: 300 }); // @note There is a potential race condition here if other tests send transactions that get into the same // epoch and thereby pays out fees at the same time (when proven). diff --git a/yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts b/yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts index 8f68e5a2c2e1..e83f8e17a810 100644 --- a/yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/public_payments.test.ts @@ -52,9 +52,6 @@ describe('e2e_fees public_payment', () => { t.getBananaPublicBalanceFn(aliceAddress, bobAddress, bananaFPC.address), t.getGasBalanceFn(aliceAddress, bananaFPC.address, sequencerAddress), ]); - - // We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state. - aliceWallet.setScopes([aliceAddress, bobAddress]); }); it('pays fees for tx that make public transfer', async () => { diff --git a/yarn-project/end-to-end/src/e2e_nested_contract/manual_public.test.ts b/yarn-project/end-to-end/src/e2e_nested_contract/manual_public.test.ts index 1c2929fe7228..24f571ca94bf 100644 --- a/yarn-project/end-to-end/src/e2e_nested_contract/manual_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_nested_contract/manual_public.test.ts @@ -51,7 +51,7 @@ describe('e2e_nested_contract manual', () => { const tx = await new BatchCall(wallet, actions).send().wait(); const extendedLogs = ( - await wallet.getPublicLogs({ + await pxe.getPublicLogs({ fromBlock: tx.blockNumber!, }) ).logs; diff --git a/yarn-project/end-to-end/src/e2e_prover/full.test.ts b/yarn-project/end-to-end/src/e2e_prover/full.test.ts index 61e33890ba7d..ed84404a3e21 100644 --- a/yarn-project/end-to-end/src/e2e_prover/full.test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/full.test.ts @@ -1,4 +1,4 @@ -import { type AztecAddress, EthAddress } from '@aztec/aztec.js'; +import { type AztecAddress, EthAddress, waitForProven } from '@aztec/aztec.js'; import { parseBooleanEnv } from '@aztec/foundation/config'; import { getTestData, isGenerateTestDataEnabled } from '@aztec/foundation/testing'; import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing/files'; @@ -118,11 +118,11 @@ describe('full_prover', () => { // and we have more than one block in the epoch we end up proving logger.info(`Sending private tx`); const txPrivate = privateProvenTx.send(); - await txPrivate.wait({ timeout: 300, interval: 10, proven: false }); + await txPrivate.wait({ timeout: 300, interval: 10 }); logger.info(`Sending public tx`); const txPublic = publicProvenTx.send(); - await txPublic.wait({ timeout: 300, interval: 10, proven: false }); + await txPublic.wait({ timeout: 300, interval: 10 }); logger.info(`Both txs have been mined`); const txs = [txPrivate, txPublic]; @@ -145,7 +145,12 @@ describe('full_prover', () => { // And wait for the first pair of txs to be proven logger.info(`Awaiting proof for the previous epoch`); - await Promise.all(txs.map(tx => tx.wait({ timeout: 300, interval: 10, proven: true, provenTimeout: 3000 }))); + await Promise.all( + txs.map(async tx => { + const receipt = await tx.wait({ timeout: 300, interval: 10 }); + await waitForProven(t.aztecNode, receipt, { provenTimeout: 3000 }); + }), + ); const newProvenBlockNumber = await rollup.read.getProvenBlockNumber(); expect(newProvenBlockNumber).toBeGreaterThan(oldProvenBlockNumber); @@ -208,7 +213,7 @@ describe('full_prover', () => { logger.info(`Sending private txs`); // First block, one private tx const firstTxPrivate = firstPrivateProvenTx.send(); - await firstTxPrivate.wait({ timeout: 300, interval: 10, proven: false }); + await firstTxPrivate.wait({ timeout: 300, interval: 10 }); // Create and send a set of 3 txs for the second block, // so we end up with three blocks and have merge and block-merge circuits @@ -219,12 +224,12 @@ describe('full_prover', () => { ]; const secondBlockProvenTxs = await Promise.all(secondBlockInteractions.map(p => p.prove(provingOpts))); const secondBlockTxs = await Promise.all(secondBlockProvenTxs.map(p => p.send())); - await Promise.all(secondBlockTxs.map(t => t.wait({ timeout: 300, interval: 10, proven: false }))); + await Promise.all(secondBlockTxs.map(t => t.wait({ timeout: 300, interval: 10 }))); logger.info(`Sending public tx`); // Third block, one public tx const txPublic = publicProvenTx.send(); - await txPublic.wait({ timeout: 300, interval: 10, proven: false }); + await txPublic.wait({ timeout: 300, interval: 10 }); logger.info(`All txs have been mined`); const txs = [firstTxPrivate, ...secondBlockTxs, txPublic]; @@ -242,7 +247,12 @@ describe('full_prover', () => { // And wait for the first pair of txs to be proven logger.info(`Awaiting proof for the previous epoch`); - await Promise.all(txs.map(tx => tx.wait({ timeout: 300, interval: 10, proven: true, provenTimeout: 1500 }))); + await Promise.all( + txs.map(async tx => { + const receipt = await tx.wait({ timeout: 300, interval: 10 }); + await waitForProven(t.aztecNode, receipt, { provenTimeout: 1500 }); + }), + ); [ 'private-kernel-init', diff --git a/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts index 54dd85869074..78f5c73be9e3 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts @@ -144,16 +144,19 @@ describe('e2e_token_contract burn', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await wallets[1].addAuthWitness(witness); - // We give wallets[1] access to wallets[0]'s notes to burn the note. - wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]); - - await asset.withWallet(wallets[1]).methods.burn_private(accounts[0].address, amount, nonce).send().wait(); + await asset + .withWallet(wallets[1]) + .methods.burn_private(accounts[0].address, amount, nonce) + .send({ authwits: [witness] }) + .wait(); tokenSim.burnPrivate(accounts[0].address, amount); // Perform the transfer again, should fail - const txReplay = asset.withWallet(wallets[1]).methods.burn_private(accounts[0].address, amount, nonce).send(); + const txReplay = asset + .withWallet(wallets[1]) + .methods.burn_private(accounts[0].address, amount, nonce) + .send({ authwits: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); @@ -188,9 +191,8 @@ describe('e2e_token_contract burn', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await wallets[1].addAuthWitness(witness); - await expect(action.simulate()).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.simulate({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); }); it('burn on behalf of other without approval', async () => { @@ -206,9 +208,6 @@ describe('e2e_token_contract burn', () => { { chainId: wallets[0].getChainId(), version: wallets[0].getVersion() }, ); - // We give wallets[1] access to wallets[0]'s notes to test the authwit. - wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]); - await expect(action.simulate()).rejects.toThrow( `Unknown auth witness for message hash ${messageHash.toString()}`, ); @@ -228,12 +227,8 @@ describe('e2e_token_contract burn', () => { ); const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await wallets[2].addAuthWitness(witness); - // We give wallets[2] access to wallets[0]'s notes to test the authwit. - wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]); - - await expect(action.simulate()).rejects.toThrow( + await expect(action.simulate({ authwits: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/private_transfer_recursion.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/private_transfer_recursion.test.ts index aa6db7b8a59c..62b5ca3a0588 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/private_transfer_recursion.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/private_transfer_recursion.test.ts @@ -5,12 +5,12 @@ import { TokenContractTest } from './token_contract_test.js'; describe('e2e_token_contract private transfer recursion', () => { const t = new TokenContractTest('odd_transfer_private'); - let { asset, accounts, wallets } = t; + let { asset, accounts, wallets, node } = t; beforeAll(async () => { await t.applyBaseSnapshots(); await t.setup(); - ({ asset, accounts, wallets } = t); + ({ asset, accounts, wallets, node } = t); }); afterAll(async () => { @@ -36,13 +36,14 @@ describe('e2e_token_contract private transfer recursion', () => { const totalNotes = 16; const totalBalance = await mintNotes(Array(totalNotes).fill(10n)); // docs:start:debug - const tx = await asset.methods.transfer(accounts[1].address, totalBalance).send().wait({ debug: true }); + const tx = await asset.methods.transfer(accounts[1].address, totalBalance).send().wait(); + const txEffects = await node.getTxEffect(tx.txHash); // docs:end:debug // We should have nullified all notes, plus an extra nullifier for the transaction - expect(tx.debugInfo?.nullifiers.length).toBe(totalNotes + 1); + expect(txEffects!.data.nullifiers.length).toBe(totalNotes + 1); // We should have created a single new note, for the recipient - expect(tx.debugInfo?.noteHashes.length).toBe(1); + expect(txEffects!.data.noteHashes.length).toBe(1); const events = await wallets[1].getPrivateEvents(TokenContract.events.Transfer, tx.blockNumber!, 1); @@ -60,12 +61,13 @@ describe('e2e_token_contract private transfer recursion', () => { const totalBalance = await mintNotes(noteAmounts); const toSend = totalBalance - expectedChange; - const tx = await asset.methods.transfer(accounts[1].address, toSend).send().wait({ debug: true }); + const tx = await asset.methods.transfer(accounts[1].address, toSend).send().wait(); + const txEffects = await node.getTxEffect(tx.txHash); // We should have nullified all notes, plus an extra nullifier for the transaction - expect(tx.debugInfo?.nullifiers.length).toBe(noteAmounts.length + 1); + expect(txEffects!.data.nullifiers.length).toBe(noteAmounts.length + 1); // We should have created two new notes, one for the recipient and one for the sender (with the change) - expect(tx.debugInfo?.noteHashes.length).toBe(2); + expect(txEffects!.data.noteHashes.length).toBe(2); const senderBalance = await asset.methods.balance_of_private(accounts[0].address).simulate(); expect(senderBalance).toEqual(expectedChange); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts b/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts index 229eafbcb333..4b1a32debedb 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts @@ -1,5 +1,5 @@ import { getSchnorrWallet } from '@aztec/accounts/schnorr'; -import { type AccountWallet, type CompleteAddress, type Logger, createLogger } from '@aztec/aztec.js'; +import { type AccountWallet, type AztecNode, type CompleteAddress, type Logger, createLogger } from '@aztec/aztec.js'; import { DocsExampleContract } from '@aztec/noir-contracts.js/DocsExample'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; @@ -28,6 +28,7 @@ export class TokenContractTest { asset!: TokenContract; tokenSim!: TokenSimulator; badAccount!: DocsExampleContract; + node!: AztecNode; constructor(testName: string) { this.logger = createLogger(`e2e:e2e_token_contract:${testName}`); @@ -48,7 +49,8 @@ export class TokenContractTest { await this.snapshotManager.snapshot( '3_accounts', deployAccounts(3, this.logger), - async ({ deployedAccounts }, { pxe }) => { + async ({ deployedAccounts }, { pxe, aztecNode }) => { + this.node = aztecNode; this.wallets = await Promise.all(deployedAccounts.map(a => getSchnorrWallet(pxe, a.address, a.signingKey))); this.accounts = this.wallets.map(w => w.getCompleteAddress()); }, diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer.test.ts index 073ba3014c5b..8de87fad24cf 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer.test.ts @@ -27,9 +27,6 @@ describe('e2e_token_contract transfer private', () => { const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - // We give wallets[0] access to wallets[1]'s notes to be able to transfer the notes. - wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); - const tx = await asset.methods.transfer(accounts[1].address, amount).send().wait(); tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts index 7449b812ea16..d95555eec790 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts @@ -35,25 +35,23 @@ describe('e2e_token_contract transfer private', () => { .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce); const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await wallets[1].addAuthWitness(witness); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: accounts[1].address, action })).toEqual({ + expect( + await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: accounts[1].address, action }, witness), + ).toEqual({ isValidInPrivate: true, isValidInPublic: false, }); // docs:end:authwit_transfer_example - // We give wallets[1] access to wallets[0]'s notes to be able to transfer the notes. - wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]); - // Perform the transfer - await action.send().wait(); + await action.send({ authwits: [witness] }).wait(); tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); // Perform the transfer again, should fail const txReplay = asset .withWallet(wallets[1]) .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce) - .send(); + .send({ authwits: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); @@ -83,10 +81,9 @@ describe('e2e_token_contract transfer private', () => { // await wallet.signAndAddAuthWitness(messageHash, ); // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await wallets[1].addAuthWitness(witness); // Perform the transfer - await expect(action.simulate()).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.simulate({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); expect(await asset.methods.balance_of_private(accounts[0].address).simulate()).toEqual(balance0); expect(await asset.methods.balance_of_private(accounts[1].address).simulate()).toEqual(balance1); }); @@ -140,12 +137,8 @@ describe('e2e_token_contract transfer private', () => { ); const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await wallets[2].addAuthWitness(witness); - - // We give wallets[2] access to wallets[0]'s notes to test the authwit. - wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]); - await expect(action.simulate()).rejects.toThrow( + await expect(action.simulate({ authwits: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); expect(await asset.methods.balance_of_private(accounts[0].address).simulate()).toEqual(balance0); @@ -165,17 +158,16 @@ describe('e2e_token_contract transfer private', () => { const intent = { caller: accounts[1].address, action }; const witness = await wallets[0].createAuthWit(intent); - await wallets[1].addAuthWitness(witness); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: true, isValidInPublic: false, }); - const innerHash = await computeInnerAuthWitHashFromAction(accounts[1].address, (await action.request()).calls[0]); + const innerHash = await computeInnerAuthWitHashFromAction(accounts[1].address, action); await asset.withWallet(wallets[0]).methods.cancel_authwit(innerHash).send().wait(); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); @@ -184,7 +176,7 @@ describe('e2e_token_contract transfer private', () => { const txCancelledAuthwit = asset .withWallet(wallets[1]) .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce) - .send(); + .send({ authwits: [witness] }); await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR); }); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts index 82d6586490e1..1d5d53b9e3fa 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts @@ -131,29 +131,20 @@ describe('e2e_token_contract transfer public', () => { .withWallet(wallets[1]) .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: accounts[1].address, action })).toEqual( - { - isValidInPrivate: false, - isValidInPublic: false, - }, - ); - + const intent = { caller: accounts[1].address, action }; // We need to compute the message we want to sign and add it to the wallet as approved - const validateActionInteraction = await wallets[0].setPublicAuthWit( - { caller: accounts[1].address, action }, - true, - ); + const validateActionInteraction = await wallets[0].setPublicAuthWit(intent, true); await validateActionInteraction.send().wait(); - expect(await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: accounts[1].address, action })).toEqual( - { - isValidInPrivate: false, - isValidInPublic: true, - }, - ); + const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + + expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ + isValidInPrivate: true, + isValidInPublic: true, + }); // Perform the transfer - await expect(action.simulate()).rejects.toThrow(U128_UNDERFLOW_ERROR); + await expect(action.simulate({ authwits: [witness] })).rejects.toThrow(U128_UNDERFLOW_ERROR); expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts index 4525d5025340..ebf3b4d63961 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts @@ -47,12 +47,8 @@ describe('e2e_token_contract transfer_to_public', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await wallets[1].addAuthWitness(witness); - // We give wallets[1] access to wallets[0]'s notes to transfer the tokens to public. - wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]); - - await action.send().wait(); + await action.send({ authwits: [witness] }).wait(); tokenSim.transferToPublic(accounts[0].address, accounts[1].address, amount); // Perform the transfer again, should fail @@ -98,9 +94,8 @@ describe('e2e_token_contract transfer_to_public', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await wallets[1].addAuthWitness(witness); - await expect(action.simulate()).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.simulate({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); }); it('on behalf of other (invalid designated caller)', async () => { @@ -121,12 +116,8 @@ describe('e2e_token_contract transfer_to_public', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await wallets[2].addAuthWitness(witness); - - // We give wallets[2] access to wallets[0]'s notes to test the authwit. - wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]); - await expect(action.simulate()).rejects.toThrow( + await expect(action.simulate({ authwits: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index a5a2fc0b7d28..9705492207aa 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -637,9 +637,11 @@ export async function publicDeployAccounts( const batch = new BatchCall(sender, calls); const txReceipt = await batch.send().wait(); - if (waitUntilProven && pxeOrNode) { - await waitForProven(pxeOrNode, txReceipt); - } else { - throw new Error('Need to provide a PXE or AztecNode to wait for proven.'); + if (waitUntilProven) { + if (!pxeOrNode) { + throw new Error('Need to provide a PXE or AztecNode to wait for proven.'); + } else { + await waitForProven(pxeOrNode, txReceipt); + } } } diff --git a/yarn-project/entrypoints/src/account_entrypoint.ts b/yarn-project/entrypoints/src/account_entrypoint.ts index 54b4ac1349f5..3846ce8172c7 100644 --- a/yarn-project/entrypoints/src/account_entrypoint.ts +++ b/yarn-project/entrypoints/src/account_entrypoint.ts @@ -3,9 +3,14 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; -import { type AuthWitnessProvider, type EntrypointInterface, type ExecutionRequestInit } from './interfaces.js'; +import { + type AuthWitnessProvider, + type EntrypointInterface, + type FeeOptions, + type UserExecutionRequest, +} from './interfaces.js'; import { EntrypointPayload } from './payload.js'; -import { computeCombinedPayloadHash } from './utils.js'; +import { computeCombinedPayloadHash, mergeEncodedExecutionPayloads } from './utils.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature @@ -19,9 +24,9 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { private version: number = DEFAULT_VERSION, ) {} - async createTxExecutionRequest(exec: ExecutionRequestInit): Promise { - const { calls, fee, nonce, cancellable, authWitnesses = [], capsules = [] } = exec; - const appPayload = await EntrypointPayload.fromAppExecution(calls, nonce); + async createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { + const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [], nonce, cancellable } = exec; + const appPayload = await EntrypointPayload.fromAppExecution(calls); const feePayload = await EntrypointPayload.fromFeeOptions(this.address, fee); const abi = this.getEntrypointAbi(); @@ -33,14 +38,22 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { await computeCombinedPayloadHash(appPayload, feePayload), ); + const executionPayload = mergeEncodedExecutionPayloads([appPayload, feePayload], { + nonce, + cancellable, + extraHashedArgs: [entrypointHashedArgs], + extraAuthWitnesses: [combinedPayloadAuthWitness, ...userAuthWitnesses], + extraCapsules: userCapsules, + }); + const txRequest = TxExecutionRequest.from({ firstCallArgsHash: entrypointHashedArgs.hash, origin: this.address, functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters), txContext: new TxContext(this.chainId, this.version, fee.gasSettings), - argsOfCalls: [...appPayload.hashedArguments, ...feePayload.hashedArguments, entrypointHashedArgs], - authWitnesses: [...authWitnesses, combinedPayloadAuthWitness], - capsules, + argsOfCalls: executionPayload.hashedArguments, + authWitnesses: executionPayload.authWitnesses, + capsules: executionPayload.capsules, }); return txRequest; diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index bf9e583efe1d..77a0bf44053f 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -5,8 +5,15 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; -import { type AuthWitnessProvider, type EntrypointInterface, type ExecutionRequestInit } from './interfaces.js'; +import { + type AuthWitnessProvider, + type EntrypointInterface, + type ExecutionRequestInit, + type FeeOptions, + type UserExecutionRequest, +} from './interfaces.js'; import { EntrypointPayload } from './payload.js'; +import { mergeEncodedExecutionPayloads } from './utils.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature @@ -21,8 +28,8 @@ export class DefaultDappEntrypoint implements EntrypointInterface { private version: number = DEFAULT_VERSION, ) {} - async createTxExecutionRequest(exec: ExecutionRequestInit): Promise { - const { calls, fee, authWitnesses = [], capsules = [] } = exec; + async createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { + const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; if (calls.length !== 1) { throw new Error(`Expected exactly 1 function call, got ${calls.length}`); } @@ -47,14 +54,20 @@ export class DefaultDappEntrypoint implements EntrypointInterface { const authWitness = await this.userAuthWitnessProvider.createAuthWit(outerHash); + const executionPayload = await mergeEncodedExecutionPayloads([payload], { + extraAuthWitnesses: [authWitness, ...userAuthWitnesses], + extraHashedArgs: [entrypointHashedArgs], + extraCapsules: userCapsules, + }); + const txRequest = TxExecutionRequest.from({ firstCallArgsHash: entrypointHashedArgs.hash, origin: this.dappEntrypointAddress, functionSelector, txContext: new TxContext(this.chainId, this.version, fee.gasSettings), - argsOfCalls: [...payload.hashedArguments, entrypointHashedArgs], - authWitnesses: [...authWitnesses, authWitness], - capsules, + argsOfCalls: executionPayload.hashedArguments, + authWitnesses: executionPayload.authWitnesses, + capsules: executionPayload.capsules, }); return txRequest; diff --git a/yarn-project/entrypoints/src/default_entrypoint.ts b/yarn-project/entrypoints/src/default_entrypoint.ts index 87dfe77221e9..a066c51a3daf 100644 --- a/yarn-project/entrypoints/src/default_entrypoint.ts +++ b/yarn-project/entrypoints/src/default_entrypoint.ts @@ -1,7 +1,7 @@ import { FunctionType } from '@aztec/stdlib/abi'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { EntrypointInterface, ExecutionRequestInit } from './interfaces.js'; +import type { EntrypointInterface, FeeOptions, UserExecutionRequest } from './interfaces.js'; /** * Default implementation of the entrypoint interface. It calls a function on a contract directly @@ -9,8 +9,8 @@ import type { EntrypointInterface, ExecutionRequestInit } from './interfaces.js' export class DefaultEntrypoint implements EntrypointInterface { constructor(private chainId: number, private protocolVersion: number) {} - async createTxExecutionRequest(exec: ExecutionRequestInit): Promise { - const { fee, calls, authWitnesses = [], hashedArguments = [], capsules = [] } = exec; + async createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { + const { calls, authWitnesses = [], capsules = [] } = exec; if (calls.length > 1) { throw new Error(`Expected a single call, got ${calls.length}`); @@ -18,22 +18,22 @@ export class DefaultEntrypoint implements EntrypointInterface { const call = calls[0]; + const hashedArguments = [await HashedValues.fromValues(call.args)]; + if (call.type !== FunctionType.PRIVATE) { throw new Error('Public entrypoints are not allowed'); } const entrypointHashedValues = await HashedValues.fromValues(call.args); const txContext = new TxContext(this.chainId, this.protocolVersion, fee.gasSettings); - return Promise.resolve( - new TxExecutionRequest( - call.to, - call.selector, - entrypointHashedValues.hash, - txContext, - [...hashedArguments, entrypointHashedValues], - authWitnesses, - capsules, - ), + return new TxExecutionRequest( + call.to, + call.selector, + entrypointHashedValues.hash, + txContext, + [...hashedArguments, entrypointHashedValues], + authWitnesses, + capsules, ); } } diff --git a/yarn-project/entrypoints/src/interfaces.ts b/yarn-project/entrypoints/src/interfaces.ts index 1b5e326d42bf..b09c103e5d51 100644 --- a/yarn-project/entrypoints/src/interfaces.ts +++ b/yarn-project/entrypoints/src/interfaces.ts @@ -6,24 +6,67 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; import type { Capsule, HashedValues, TxExecutionRequest } from '@aztec/stdlib/tx'; -/** Encodes the calls to be done in a transaction. */ -export type ExecutionRequestInit = { +export type UserExecutionRequest = { + calls: FunctionCall[]; + authWitnesses?: AuthWitness[]; + capsules?: Capsule[]; + nonce?: Fr; + cancellable?: boolean; +}; + +/** Represents data necessary to execute a list of function calls successfully */ +export interface ExecutionPayload { /** The function calls to be executed. */ calls: FunctionCall[]; /** Any transient auth witnesses needed for this execution */ - authWitnesses?: AuthWitness[]; - /** Any transient hashed arguments for this execution */ - hashedArguments?: HashedValues[]; + authWitnesses: AuthWitness[]; /** Data passed through an oracle for this execution. */ - capsules?: Capsule[]; - /** How the fee is going to be payed */ - fee: FeeOptions; + capsules: Capsule[]; +} + +/* eslint-disable camelcase */ +/** Encoded function call for an Aztec entrypoint */ +export type EncodedFunctionCall = { + /** Arguments hash for the call */ + args_hash: Fr; + /** Selector of the function to call */ + function_selector: Fr; + /** Address of the contract to call */ + target_address: Fr; + /** Whether the function is public or private */ + is_public: boolean; + /** Whether the function can alter state */ + is_static: boolean; +}; +/* eslint-enable camelcase */ + +/** Represents the ExecutionPayload after encoding for the entrypint to execute */ +export type EncodedExecutionPayload = Omit & { + /** The function calls to be executed. */ + encodedFunctionCalls: EncodedFunctionCall[]; + /** Any transient hashed arguments for this execution */ + hashedArguments: HashedValues[]; +}; + +/** + * Represents a transaction execution request, complete with the encoded payload, a nonce + * and whether the transaction can be cancelled. + */ +export type ExecutionRequestInit = EncodedExecutionPayload & { /** An optional nonce. Used to repeat a previous tx with a higher fee so that the first one is cancelled */ nonce?: Fr; /** Whether the transaction can be cancelled. If true, an extra nullifier will be emitted: H(nonce, GENERATOR_INDEX__TX_NULLIFIER) */ cancellable?: boolean; }; +/** + * Completes a ExecutionRequest by including the fee payment method and gas settings. + */ +export type ExecutionRequest = ExecutionRequestInit & { + /** How the fee is going to be payed */ + fee: FeeOptions; +}; + /** Creates transaction execution requests out of a set of function calls. */ export interface EntrypointInterface { /** @@ -31,7 +74,7 @@ export interface EntrypointInterface { * @param execution - The execution intents to be run. * @returns The authenticated transaction execution request. */ - createTxExecutionRequest(execution: ExecutionRequestInit): Promise; + createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise; } /** Creates authorization witnesses. */ @@ -51,11 +94,12 @@ export interface FeePaymentMethod { /** The asset used to pay the fee. */ getAsset(): Promise; /** - * Creates a function call to pay the fee in the given asset. + * Returns the data to be added to the final execution request + * to pay the fee in the given asset * @param gasSettings - The gas limits and max fees. - * @returns The function call to pay the fee. + * @returns The function calls to pay the fee. */ - getFunctionCalls(gasSettings: GasSettings): Promise; + getExecutionPayload(gasSettings: GasSettings): Promise; /** * The expected fee payer for this tx. * @param gasSettings - The gas limits and max fees. diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index ce99e134b72d..ee5b3f33d5fd 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -4,10 +4,11 @@ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import type { Tuple } from '@aztec/foundation/serialize'; import { FunctionCall, FunctionType } from '@aztec/stdlib/abi'; +import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; -import { HashedValues } from '@aztec/stdlib/tx'; +import { Capsule, HashedValues } from '@aztec/stdlib/tx'; -import type { FeeOptions } from './interfaces.js'; +import type { EncodedExecutionPayload, EncodedFunctionCall, FeeOptions } from './interfaces.js'; // These must match the values defined in: // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr @@ -15,39 +16,26 @@ const APP_MAX_CALLS = 4; // - and noir-projects/aztec-nr/aztec/src/entrypoint/fee.nr const FEE_MAX_CALLS = 2; -/* eslint-disable camelcase */ -/** Encoded function call for account contract entrypoint */ -type EncodedFunctionCall = { - /** Arguments hash for the call */ - args_hash: Fr; - /** Selector of the function to call */ - function_selector: Fr; - /** Address of the contract to call */ - target_address: Fr; - /** Whether the function is public or private */ - is_public: boolean; - /** Whether the function can alter state */ - is_static: boolean; -}; -/* eslint-enable camelcase */ - /** Assembles an entrypoint payload */ -export abstract class EntrypointPayload { +export abstract class EntrypointPayload implements EncodedExecutionPayload { protected constructor( - private functionCalls: EncodedFunctionCall[], - private _hashedArguments: HashedValues[], + public encodedFunctionCalls: EncodedFunctionCall[], + public hashedArguments: HashedValues[], + public authWitnesses: AuthWitness[], + public capsules: Capsule[], private generatorIndex: number, - private _nonce: Fr, ) {} - protected static async create(functionCalls: FunctionCall[]) { + protected static async create( + calls: FunctionCall[], + ): Promise> { const hashedArguments: HashedValues[] = []; - for (const call of functionCalls) { + for (const call of calls) { hashedArguments.push(await HashedValues.fromValues(call.args)); } /* eslint-disable camelcase */ - const encodedFunctionCalls = functionCalls.map((call, index) => ({ + const encodedFunctionCalls: EncodedFunctionCall[] = calls.map((call, index) => ({ args_hash: hashedArguments[index].hash, function_selector: call.selector.toField(), target_address: call.to.toField(), @@ -62,31 +50,6 @@ export abstract class EntrypointPayload { }; } - /* eslint-disable camelcase */ - /** - * The function calls to execute. This uses snake_case naming so that it is compatible with Noir encoding - * @internal - */ - get function_calls() { - return this.functionCalls; - } - /* eslint-enable camelcase */ - - /** - * The nonce - * @internal - */ - get nonce() { - return this._nonce; - } - - /** - * The hashed arguments for the function calls - */ - get hashedArguments() { - return this._hashedArguments; - } - /** * Serializes the payload to an array of fields * @returns The fields of the payload @@ -103,7 +66,7 @@ export abstract class EntrypointPayload { /** Serializes the function calls to an array of fields. */ protected functionCallsToFields() { - return this.functionCalls.flatMap(call => [ + return this.encodedFunctionCalls.flatMap(call => [ call.args_hash, call.function_selector, call.target_address, @@ -119,7 +82,7 @@ export abstract class EntrypointPayload { */ static async fromFunctionCalls(functionCalls: FunctionCall[]) { const { encodedFunctionCalls, hashedArguments } = await this.create(functionCalls); - return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, 0, Fr.random()); + return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, [], [], 0); } /** @@ -128,13 +91,13 @@ export abstract class EntrypointPayload { * @param nonce - The nonce for the payload, used to emit a nullifier identifying the call * @returns The execution payload */ - static async fromAppExecution(functionCalls: FunctionCall[] | Tuple, nonce = Fr.random()) { + static async fromAppExecution(functionCalls: FunctionCall[] | Tuple) { if (functionCalls.length > APP_MAX_CALLS) { throw new Error(`Expected at most ${APP_MAX_CALLS} function calls, got ${functionCalls.length}`); } const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS); const { encodedFunctionCalls, hashedArguments } = await this.create(paddedCalls); - return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, GeneratorIndex.SIGNATURE_PAYLOAD, nonce); + return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, [], [], GeneratorIndex.SIGNATURE_PAYLOAD); } /** @@ -144,7 +107,10 @@ export abstract class EntrypointPayload { * @returns The execution payload */ static async fromFeeOptions(sender: AztecAddress, feeOpts?: FeeOptions) { - const calls = (await feeOpts?.paymentMethod.getFunctionCalls(feeOpts?.gasSettings)) ?? []; + const { calls, authWitnesses } = (await feeOpts?.paymentMethod.getExecutionPayload(feeOpts?.gasSettings)) ?? { + calls: [], + authWitnesses: [], + }; const feePayer = await feeOpts?.paymentMethod.getFeePayer(feeOpts?.gasSettings); const isFeePayer = !!feePayer && feePayer.equals(sender); const paddedCalls = padArrayEnd(calls, FunctionCall.empty(), FEE_MAX_CALLS); @@ -152,8 +118,8 @@ export abstract class EntrypointPayload { return new FeeEntrypointPayload( encodedFunctionCalls, hashedArguments, + authWitnesses ?? [], GeneratorIndex.FEE_PAYLOAD, - Fr.random(), isFeePayer, ); } @@ -162,7 +128,7 @@ export abstract class EntrypointPayload { /** Entrypoint payload for app phase execution. */ export class AppEntrypointPayload extends EntrypointPayload { override toFields(): Fr[] { - return [...this.functionCallsToFields(), this.nonce]; + return [...this.functionCallsToFields()]; } } @@ -173,16 +139,16 @@ export class FeeEntrypointPayload extends EntrypointPayload { constructor( functionCalls: EncodedFunctionCall[], hashedArguments: HashedValues[], + authWitnesses: AuthWitness[], generatorIndex: number, - nonce: Fr, isFeePayer: boolean, ) { - super(functionCalls, hashedArguments, generatorIndex, nonce); + super(functionCalls, hashedArguments, authWitnesses, [], generatorIndex); this.#isFeePayer = isFeePayer; } override toFields(): Fr[] { - return [...this.functionCallsToFields(), this.nonce, new Fr(this.#isFeePayer)]; + return [...this.functionCallsToFields(), new Fr(this.#isFeePayer)]; } /* eslint-disable camelcase */ diff --git a/yarn-project/entrypoints/src/utils.ts b/yarn-project/entrypoints/src/utils.ts index 316b8389372e..ccadb89ce916 100644 --- a/yarn-project/entrypoints/src/utils.ts +++ b/yarn-project/entrypoints/src/utils.ts @@ -1,26 +1,50 @@ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import type { Fr } from '@aztec/foundation/fields'; +import type { AuthWitness } from '@aztec/stdlib/auth-witness'; +import type { Capsule, HashedValues } from '@aztec/stdlib/tx'; import { GeneratorIndex } from '../../constants/src/constants.gen.js'; -import type { ExecutionRequestInit } from './interfaces.js'; +import type { EncodedExecutionPayload, ExecutionRequestInit } from './interfaces.js'; import type { AppEntrypointPayload, FeeEntrypointPayload } from './payload.js'; /** - * Merges an array of ExecutionRequestInits. + * Merges an array of EncodedExecutionPayloads and adds a nonce and cancellable flags, + * in order to create a single ExecutionRequestInit. */ -export function mergeExecutionRequestInits( - requests: Pick[], - { nonce, cancellable }: Pick = {}, -): Omit { - const calls = requests.map(r => r.calls).flat(); - const authWitnesses = requests.map(r => r.authWitnesses ?? []).flat(); - const hashedArguments = requests.map(r => r.hashedArguments ?? []).flat(); - const capsules = requests.map(r => r.capsules ?? []).flat(); +export function mergeEncodedExecutionPayloads( + requests: EncodedExecutionPayload[], + { + nonce, + cancellable, + extraHashedArgs, + extraAuthWitnesses, + extraCapsules, + }: { + nonce?: Fr; + cancellable?: boolean; + extraHashedArgs?: HashedValues[]; + extraAuthWitnesses?: AuthWitness[]; + extraCapsules?: Capsule[]; + } = { extraAuthWitnesses: [], extraCapsules: [], extraHashedArgs: [] }, +): ExecutionRequestInit { + const encodedFunctionCalls = requests.map(r => r.encodedFunctionCalls).flat(); + const combinedAuthWitnesses = requests + .map(r => r.authWitnesses ?? []) + .flat() + .concat(extraAuthWitnesses ?? []); + const hashedArguments = requests + .map(r => r.hashedArguments ?? []) + .flat() + .concat(extraHashedArgs ?? []); + const combinedCapsules = requests + .map(r => r.capsules ?? []) + .flat() + .concat(extraCapsules ?? []); return { - calls, - authWitnesses, + encodedFunctionCalls, + authWitnesses: combinedAuthWitnesses, hashedArguments, - capsules, + capsules: combinedCapsules, nonce, cancellable, }; diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 843bc829db15..9331df2472a6 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -417,13 +417,13 @@ export class PXEService implements PXE { * The function takes in a transaction execution request, and the result of private execution * and then generates a kernel proof. * - * @param txExecutionRequest - The transaction request to be simulated and proved. + * @param TxExecutionRequest - The transaction request to be simulated and proved. * @param proofCreator - The proof creator to use for proving the execution. * @param privateExecutionResult - The result of the private execution * @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled. */ async #prove( - txExecutionRequest: TxExecutionRequest, + TxExecutionRequest: TxExecutionRequest, proofCreator: PrivateKernelProver, privateExecutionResult: PrivateExecutionResult, { simulate, skipFeeEnforcement, profile }: ProvingConfig, @@ -434,7 +434,7 @@ export class PXEService implements PXE { const kernelOracle = new KernelOracle(this.contractDataProvider, this.keyStore, this.node, block); const kernelProver = new KernelProver(kernelOracle, proofCreator, !this.proverEnabled); this.log.debug(`Executing kernel prover (simulate: ${simulate}, profile: ${profile})...`); - return await kernelProver.prove(txExecutionRequest.toTxRequest(), privateExecutionResult, { + return await kernelProver.prove(TxExecutionRequest.toTxRequest(), privateExecutionResult, { simulate, skipFeeEnforcement, profile, diff --git a/yarn-project/stdlib/package.json b/yarn-project/stdlib/package.json index 3c043461a769..565fb4d91b56 100644 --- a/yarn-project/stdlib/package.json +++ b/yarn-project/stdlib/package.json @@ -13,7 +13,6 @@ "./keys": "./dest/keys/index.js", "./testing": "./dest/tests/index.js", "./testing/fixtures": "./dest/tests/fixtures.js", - "./interfaces": "./dest/interfaces/index.js", "./network": "./dest/network/index.js", "./utils": "./dest/utils/index.js", "./types": "./dest/types/index.js", From 4bce308b59ec7b4c14e34e6accb37e53e3b3f6df Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 07:44:34 +0000 Subject: [PATCH 20/48] wip --- .../src/defaults/account_interface.ts | 11 +- .../account_manager/deploy_account_method.ts | 6 +- .../src/contract/base_contract_interaction.ts | 19 +-- .../aztec.js/src/contract/batch_call.ts | 32 ++-- .../contract/contract_function_interaction.ts | 26 ++-- .../aztec.js/src/contract/deploy_method.ts | 56 +++---- .../src/deployment/deploy_instance.ts | 35 ++--- .../aztec.js/src/deployment/register_class.ts | 42 +++--- .../default_multi_call_entrypoint.ts | 23 ++- .../src/fee/fee_juice_payment_method.ts | 5 +- .../fee_juice_payment_method_with_claim.ts | 4 +- .../src/fee/private_fee_payment_method.ts | 6 +- .../src/fee/public_fee_payment_method.ts | 3 +- yarn-project/aztec.js/src/fee/utils.ts | 2 +- .../aztec.js/src/wallet/account_wallet.ts | 13 +- .../aztec.js/src/wallet/base_wallet.ts | 9 +- .../aztec.js/src/wallet/signerless_wallet.ts | 16 +- .../sandbox/sponsored_fee_payment_method.ts | 5 +- yarn-project/cli-wallet/src/cmds/cancel_tx.ts | 5 +- .../src/utils/sponsored_fee_payment.ts | 5 +- .../end-to-end/src/e2e_authwit.test.ts | 6 +- .../e2e_blacklist_token_contract/burn.test.ts | 8 +- .../transfer_private.test.ts | 8 +- .../unshielding.test.ts | 8 +- .../src/e2e_crowdfunding_and_claim.test.ts | 8 +- .../src/e2e_fees/dapp_subscription.test.ts | 2 +- .../end-to-end/src/e2e_fees/failures.test.ts | 8 +- .../src/e2e_token_contract/burn.test.ts | 10 +- .../transfer_in_private.test.ts | 10 +- .../transfer_in_public.test.ts | 2 +- .../transfer_to_public.test.ts | 6 +- .../entrypoints/src/account_entrypoint.ts | 29 ++-- .../entrypoints/src/dapp_entrypoint.ts | 17 ++- .../entrypoints/src/default_entrypoint.ts | 9 +- yarn-project/entrypoints/src/interfaces.ts | 53 ++----- yarn-project/entrypoints/src/payload.ts | 139 ++++++++++++------ yarn-project/entrypoints/src/utils.ts | 55 +++++-- 37 files changed, 358 insertions(+), 343 deletions(-) diff --git a/yarn-project/accounts/src/defaults/account_interface.ts b/yarn-project/accounts/src/defaults/account_interface.ts index 59ec934a071a..af98483b50c2 100644 --- a/yarn-project/accounts/src/defaults/account_interface.ts +++ b/yarn-project/accounts/src/defaults/account_interface.ts @@ -1,6 +1,7 @@ import type { AccountInterface, AuthWitnessProvider } from '@aztec/aztec.js/account'; import { DefaultAccountEntrypoint } from '@aztec/entrypoints/account'; -import type { EntrypointInterface, ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; +import type { EntrypointInterface, FeeOptions, TxExecutionOptions } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import { Fr } from '@aztec/foundation/fields'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -33,8 +34,12 @@ export class DefaultAccountInterface implements AccountInterface { this.version = new Fr(nodeInfo.protocolVersion); } - createTxExecutionRequest(execution: ExecutionRequestInit): Promise { - return this.entrypoint.createTxExecutionRequest(execution); + createTxExecutionRequest( + exec: ExecutionPayload, + fee: FeeOptions, + options: TxExecutionOptions, + ): Promise { + return this.entrypoint.createTxExecutionRequest(exec, fee, options); } createAuthWit(messageHash: Fr): Promise { diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 067db3aae622..2309fa007dbc 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -1,5 +1,5 @@ import { type AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; -import { EntrypointPayload } from '@aztec/entrypoints/payload'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { computeCombinedPayloadHash } from '@aztec/entrypoints/utils'; import { type ContractArtifact, type FunctionArtifact, getFunctionArtifactByName } from '@aztec/stdlib/abi'; import type { PublicKeys } from '@aztec/stdlib/keys'; @@ -46,9 +46,9 @@ export class DeployAccountMethod extends DeployMethod { if (options.fee && this.#feePaymentArtifact) { const { address } = await this.getInstance(); - const emptyAppPayload = await EntrypointPayload.fromAppExecution([]); + const emptyAppPayload = await ExecutionPayload.fromAppExecution([]); const fee = await this.getDefaultFeeOptions(options.fee); - const feePayload = await EntrypointPayload.fromFeeOptions(address, fee); + const feePayload = await ExecutionPayload.fromFeeOptions(address, fee); const args = [emptyAppPayload, feePayload, false]; const call = new ContractFunctionInteraction(this.wallet, address, this.#feePaymentArtifact, args); diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 4a712da4673a..92816b20f63f 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -1,10 +1,5 @@ -import type { - ExecutionPayload, - ExecutionRequestInit, - FeeOptions, - UserExecutionRequest, - UserFeeOptions, -} from '@aztec/entrypoints/interfaces'; +import type { FeeOptions, UserFeeOptions } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import type { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; @@ -31,7 +26,9 @@ export type SendMethodOptions = { /** Whether the transaction can be cancelled. If true, an extra nullifier will be emitted: H(nonce, GENERATOR_INDEX__TX_NULLIFIER) */ cancellable?: boolean; /** Authwits to use in the simulation */ - authwits?: AuthWitness[]; + authWitnesses?: AuthWitness[]; + /** Capsules to use in the simulation */ + capsules?: Capsule[]; }; /** @@ -60,7 +57,7 @@ export abstract class BaseContractInteraction { * @param options - An optional object containing additional configuration for the transaction. * @returns An execution request wrapped in promise. */ - public abstract request(options?: SendMethodOptions): Promise; + public abstract request(options?: SendMethodOptions): Promise; /** * Creates a transaction execution request, simulates and proves it. Differs from .prove in @@ -152,7 +149,7 @@ export abstract class BaseContractInteraction { * @param pad - Percentage to pad the suggested gas limits by, as decimal (e.g., 0.10 for 10%). * @returns Fee options for the actual transaction. */ - protected async getFeeOptions(request: UserExecutionRequest, fee?: UserFeeOptions): Promise { + protected async getFeeOptions(executionPayload: ExecutionPayload, fee?: UserFeeOptions): Promise { // docs:end:getFeeOptions const defaultFeeOptions = await this.getDefaultFeeOptions(fee); const paymentMethod = defaultFeeOptions.paymentMethod; @@ -162,7 +159,7 @@ export abstract class BaseContractInteraction { let gasSettings = defaultFeeOptions.gasSettings; if (fee?.estimateGas) { const feeForEstimation: FeeOptions = { paymentMethod, gasSettings }; - const txRequest = await this.wallet.createTxExecutionRequest(request, feeForEstimation); + const txRequest = await this.wallet.createTxExecutionRequest(executionPayload, feeForEstimation, {}); const simulationResult = await this.wallet.simulateTx( txRequest, true /*simulatePublic*/, diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 558212394d79..a60ce5ade4e3 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -1,4 +1,5 @@ -import { type ExecutionRequestInit, type UserExecutionRequest } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { mergeExecutionPayloads } from '@aztec/entrypoints/utils'; import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; @@ -21,10 +22,10 @@ export class BatchCall extends BaseContractInteraction { public async create(options: SendMethodOptions = {}): Promise { const requestWithoutFee = await this.request(options); - const { fee: userFee } = options; + const { fee: userFee, nonce, cancellable } = options; const fee = await this.getFeeOptions(requestWithoutFee, userFee); - return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee); + return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable }); } /** @@ -32,10 +33,9 @@ export class BatchCall extends BaseContractInteraction { * @param options - An optional object containing additional configuration for the transaction. * @returns An execution request wrapped in promise. */ - public async request(options: SendMethodOptions = {}): Promise { + public async request(options: SendMethodOptions = {}): Promise { const requests = await this.getRequests(); - const { nonce, cancellable } = options; - return mergeExecutionRequestInits(requests, { nonce, cancellable }); + return mergeExecutionPayloads(requests); } /** @@ -48,13 +48,13 @@ export class BatchCall extends BaseContractInteraction { * @returns The result of the transaction as returned by the contract function. */ public async simulate(options: SimulateMethodOptions = {}): Promise { - const { indexedRequests, unconstrained } = (await this.getRequests()).reduce<{ + const { indexedExecutionPayloads, unconstrained } = (await this.getRequests()).reduce<{ /** Keep track of the number of private calls to retrieve the return values */ privateIndex: 0; /** Keep track of the number of public calls to retrieve the return values */ publicIndex: 0; /** The public and private function execution requests in the batch */ - indexedRequests: [UserExecutionRequest, number, number][]; + indexedExecutionPayloads: [ExecutionPayload, number, number][]; /** The unconstrained function calls in the batch. */ unconstrained: [FunctionCall, number][]; }>( @@ -63,7 +63,7 @@ export class BatchCall extends BaseContractInteraction { if (call.type === FunctionType.UNCONSTRAINED) { acc.unconstrained.push([call, index]); } else { - acc.indexedRequests.push([ + acc.indexedExecutionPayloads.push([ current, index, call.type === FunctionType.PRIVATE ? acc.privateIndex++ : acc.publicIndex++, @@ -71,19 +71,19 @@ export class BatchCall extends BaseContractInteraction { } return acc; }, - { indexedRequests: [], unconstrained: [], publicIndex: 0, privateIndex: 0 }, + { indexedExecutionPayloads: [], unconstrained: [], publicIndex: 0, privateIndex: 0 }, ); - const requests = indexedRequests.map(([request]) => request); - const requestWithoutFee = mergeExecutionRequestInits(requests); + const payloads = indexedExecutionPayloads.map(([request]) => request); + const requestWithoutFee = mergeExecutionPayloads(payloads); const { fee: userFee } = options; - const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee }); - const txRequest = await this.wallet.createTxExecutionRequest(requestWithoutFee, fee); + const fee = await this.getFeeOptions(requestWithoutFee, userFee); + const txRequest = await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, {}); const unconstrainedCalls = unconstrained.map( async ([call, index]) => [ - await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.authwits, options?.from), + await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.authWitnesses, options?.from), index, ] as const, ); @@ -98,7 +98,7 @@ export class BatchCall extends BaseContractInteraction { unconstrainedResults.forEach(([result, index]) => { results[index] = result; }); - indexedRequests.forEach(([request, callIndex, resultIndex]) => { + indexedExecutionPayloads.forEach(([request, callIndex, resultIndex]) => { const call = request.calls[0]; // As account entrypoints are private, for private functions we retrieve the return values from the first nested call // since we're interested in the first set of values AFTER the account entrypoint diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index 31e58f5607da..df6658dc2db1 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -1,4 +1,4 @@ -import type { ExecutionPayload, ExecutionRequestInit, UserExecutionRequest } from '@aztec/entrypoints/interfaces'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -24,7 +24,7 @@ export type SimulateMethodOptions = Pick & { /** Whether to ensure the fee payer is not empty and has enough balance to pay for the fee. */ skipFeeEnforcement?: boolean; /** Authwits to use in the simulation */ - authwits?: AuthWitness[]; + authWitnesses?: AuthWitness[]; }; /** @@ -67,9 +67,10 @@ export class ContractFunctionInteraction extends BaseContractInteraction { const requestWithoutFee = await this.request(options); const { fee: userFee } = options; + const { nonce, cancellable } = options; const fee = await this.getFeeOptions(requestWithoutFee, userFee); - return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee); + return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable }); } // docs:start:request @@ -79,7 +80,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction { * @param options - An optional object containing additional configuration for the transaction. * @returns An execution request wrapped in promise. */ - public async request(options: SendMethodOptions = {}): Promise { + public async request(options: SendMethodOptions = {}): Promise { // docs:end:request const args = encodeArguments(this.functionDao, this.args); const calls = [ @@ -93,16 +94,11 @@ export class ContractFunctionInteraction extends BaseContractInteraction { returnTypes: this.functionDao.returnTypes, }, ]; - this.addAuthWitnesses(options.authwits ?? []); - const authWitnesses = this.getAuthWitnesses(); - const capsules = this.getCapsules(); - const { nonce, cancellable } = options; + const { authWitnesses, capsules } = options; return { calls, - authWitnesses, - capsules, - nonce, - cancellable, + authWitnesses: authWitnesses ?? [], + capsules: capsules ?? [], }; } @@ -123,13 +119,13 @@ export class ContractFunctionInteraction extends BaseContractInteraction { this.functionDao.name, this.args, this.contractAddress, - options.authwits ?? [], + options.authWitnesses ?? [], options?.from, ); } const fee = options.fee ?? { paymentMethod: new FeeJuicePaymentMethod(AztecAddress.ZERO) }; - const txRequest = await this.create({ fee, authwits: options.authwits }); + const txRequest = await this.create({ fee, authWitnesses: options.authWitnesses }); const simulatedTx = await this.wallet.simulateTx( txRequest, true /* simulatePublic */, @@ -167,7 +163,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction { throw new Error("Can't profile an unconstrained function."); } - const txRequest = await this.create({ fee: options.fee, authwits: options.authwits }); + const txRequest = await this.create({ fee: options.fee, authWitnesses: options.authWitnesses }); const simulatedTx = await this.wallet.simulateTx( txRequest, true, diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 7af191b9c69d..44246a54a86e 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -1,14 +1,7 @@ -import { type ExecutionPayload, type UserExecutionRequest } from '@aztec/entrypoints/interfaces'; -import { EntrypointPayload } from '@aztec/entrypoints/payload'; -import { mergeEncodedExecutionPayloads } from '@aztec/entrypoints/utils'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { mergeExecutionPayloads } from '@aztec/entrypoints/utils'; import type { Fr } from '@aztec/foundation/fields'; -import { - type ContractArtifact, - type FunctionAbi, - type FunctionArtifact, - FunctionSelector, - getInitializer, -} from '@aztec/stdlib/abi'; +import { type ContractArtifact, type FunctionAbi, type FunctionArtifact, getInitializer } from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { type ContractInstanceWithAddress, @@ -26,6 +19,7 @@ import type { Wallet } from '../wallet/wallet.js'; import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js'; import type { Contract } from './contract.js'; import type { ContractBase } from './contract_base.js'; +import { ContractFunctionInteraction } from './contract_function_interaction.js'; import { DeployProvenTx } from './deploy_proven_tx.js'; import { DeploySentTx } from './deploy_sent_tx.js'; @@ -83,8 +77,9 @@ export class DeployMethod extends Bas */ public async create(options: DeployOptions = {}): Promise { const requestWithoutFee = await this.request(options); + const { nonce, cancellable } = options; const fee = await this.getFeeOptions(requestWithoutFee, options.fee); - return this.wallet.createTxExecutionRequest(requestWithoutFee, fee); + return this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable }); } // REFACTOR: Having a `request` method with different semantics than the ones in the other @@ -114,13 +109,13 @@ export class DeployMethod extends Bas const bootstrap = await this.getInitializeFunctionCalls(options); - const requests = [...deployment, bootstrap]; + const requests = await Promise.all([...deployment, ...bootstrap].map(c => c.request())); + console.log(requests); if (!requests.length) { throw new Error(`No function calls needed to deploy contract ${this.artifact.name}`); } - const { nonce, cancellable } = options; - return mergeEncodedExecutionPayloads(requests, { nonce, cancellable }); + return mergeExecutionPayloads(requests); } /** @@ -138,8 +133,8 @@ export class DeployMethod extends Bas * @param options - Deployment options. * @returns A function call array with potentially requests to the class registerer and instance deployer. */ - protected async getDeploymentFunctionCalls(options: DeployOptions = {}): Promise { - const calls: ExecutionPayload[] = []; + protected async getDeploymentFunctionCalls(options: DeployOptions = {}): Promise { + const calls: ContractFunctionInteraction[] = []; // Set contract instance object so it's available for populating the DeploySendTx object const instance = await this.getInstance(options); @@ -182,28 +177,19 @@ export class DeployMethod extends Bas * @param options - Deployment options. * @returns - An array of function calls. */ - protected async getInitializeFunctionCalls(options: DeployOptions): Promise { - const result: UserExecutionRequest = { - calls: [], - authWitnesses: [], - capsules: [], - }; + protected async getInitializeFunctionCalls(options: DeployOptions): Promise { + const calls: ContractFunctionInteraction[] = []; if (this.constructorArtifact && !options.skipInitialization) { const { address } = await this.getInstance(options); - result.calls.push({ - name: this.constructorArtifact.name, - to: address, - selector: await FunctionSelector.fromNameAndParameters( - this.constructorArtifact.name, - this.constructorArtifact.parameters, - ), - type: this.constructorArtifact.functionType, - args: this.args, - isStatic: this.constructorArtifact.isStatic, - returnTypes: this.constructorArtifact.returnTypes, - }); + const constructorCall = new ContractFunctionInteraction( + this.wallet, + address, + this.constructorArtifact, + this.args, + ); + calls.push(constructorCall); } - return result; + return calls; } /** diff --git a/yarn-project/aztec.js/src/deployment/deploy_instance.ts b/yarn-project/aztec.js/src/deployment/deploy_instance.ts index 164df02f2869..e24fc43dc4b7 100644 --- a/yarn-project/aztec.js/src/deployment/deploy_instance.ts +++ b/yarn-project/aztec.js/src/deployment/deploy_instance.ts @@ -1,9 +1,7 @@ -import type { ExecutionPayload } from '@aztec/entrypoints/interfaces'; import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { getDeployerContract } from '../contract/protocol_contracts.js'; -import { Fr, FunctionSelector, FunctionType } from '../index.js'; import type { Wallet } from '../wallet/index.js'; /** @@ -11,7 +9,10 @@ import type { Wallet } from '../wallet/index.js'; * @param wallet - The wallet to use for the deployment. * @param instance - The instance to deploy. */ -export async function deployInstance(wallet: Wallet, instance: ContractInstanceWithAddress): Promise { +export async function deployInstance( + wallet: Wallet, + instance: ContractInstanceWithAddress, +): Promise { const deployerContract = await getDeployerContract(wallet); const { salt, currentContractClassId: contractClassId, publicKeys, deployer } = instance; const isUniversalDeploy = deployer.isZero(); @@ -20,25 +21,11 @@ export async function deployInstance(wallet: Wallet, instance: ContractInstanceW `Expected deployer ${deployer.toString()} does not match sender wallet ${wallet.getAddress().toString()}`, ); } - return { - calls: [ - { - name: 'deploy', - to: deployerContract.address, - selector: await FunctionSelector.fromSignature('deploy(Field,(Field),Field,-,boolean)'), - args: [ - salt, - contractClassId, - instance.initializationHash, - ...publicKeys.toFields(), - isUniversalDeploy ? Fr.ONE : Fr.ZERO, - ], - type: FunctionType.PRIVATE, - isStatic: false, - returnTypes: [], - }, - ], - authWitnesses: [], - capsules: [], - }; + return deployerContract.methods.deploy( + salt, + contractClassId, + instance.initializationHash, + publicKeys, + isUniversalDeploy, + ); } diff --git a/yarn-project/aztec.js/src/deployment/register_class.ts b/yarn-project/aztec.js/src/deployment/register_class.ts index 61609a0db94e..4cd770c00a1c 100644 --- a/yarn-project/aztec.js/src/deployment/register_class.ts +++ b/yarn-project/aztec.js/src/deployment/register_class.ts @@ -1,8 +1,7 @@ import { MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT } from '@aztec/constants'; -import type { ExecutionPayload } from '@aztec/entrypoints/interfaces'; import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import { type ContractArtifact, FunctionSelector, FunctionType, bufferAsFields } from '@aztec/stdlib/abi'; +import { type ContractArtifact, bufferAsFields } from '@aztec/stdlib/abi'; import { getContractClassFromArtifact } from '@aztec/stdlib/contract'; import { Capsule } from '@aztec/stdlib/tx'; @@ -21,32 +20,25 @@ export async function registerContractClass( wallet: Wallet, artifact: ContractArtifact, emitPublicBytecode = defaultEmitPublicBytecode, -): Promise { +): Promise { const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode } = await getContractClassFromArtifact(artifact); const registerer = await getRegistererContract(wallet); + const fn = registerer.methods.register( + artifactHash, + privateFunctionsRoot, + publicBytecodeCommitment, + emitPublicBytecode, + ); + const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS); - const executionPayload: ExecutionPayload = { - calls: [ - { - name: 'register', - to: registerer.address, - selector: await FunctionSelector.fromSignature('register'), - args: [artifactHash, privateFunctionsRoot, publicBytecodeCommitment, emitPublicBytecode ? Fr.ONE : Fr.ZERO], - type: FunctionType.PRIVATE, - isStatic: false, - returnTypes: [], - }, - ], - capsules: [ - new Capsule( - ProtocolContractAddress.ContractClassRegisterer, - new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), - encodedBytecode, - ), - ], - authWitnesses: [], - }; + fn.addCapsule( + new Capsule( + ProtocolContractAddress.ContractClassRegisterer, + new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), + encodedBytecode, + ), + ); - return executionPayload; + return fn; } diff --git a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts index 84904a01c8b2..972f4b184875 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts @@ -1,11 +1,6 @@ -import { - type EntrypointInterface, - type ExecutionRequestInit, - type FeeOptions, - type UserExecutionRequest, -} from '@aztec/entrypoints/interfaces'; -import { EntrypointPayload } from '@aztec/entrypoints/payload'; -import { mergeEncodedExecutionPayloads } from '@aztec/entrypoints/utils'; +import { type EntrypointInterface, type FeeOptions } from '@aztec/entrypoints/interfaces'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { mergeAndEncodeExecutionPayloads } from '@aztec/entrypoints/utils'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -21,13 +16,13 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface { private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint, ) {} - async createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { + async createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise { const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; - const payload = await EntrypointPayload.fromAppExecution(calls); + const payload = await ExecutionPayload.fromAppExecution(calls); const abi = this.getEntrypointAbi(); const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload])); - const executionPayload = mergeEncodedExecutionPayloads([payload], { + const encodedExecutionPayload = await mergeAndEncodeExecutionPayloads([payload], { extraHashedArgs: [entrypointHashedArgs], extraAuthWitnesses: userAuthWitnesses, extraCapsules: userCapsules, @@ -38,9 +33,9 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface { origin: this.address, functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters), txContext: new TxContext(this.chainId, this.version, fee.gasSettings), - argsOfCalls: executionPayload.hashedArguments, - authWitnesses: executionPayload.authWitnesses, - capsules: executionPayload.capsules, + argsOfCalls: encodedExecutionPayload.hashedArguments, + authWitnesses: encodedExecutionPayload.authWitnesses, + capsules: encodedExecutionPayload.capsules, }); return Promise.resolve(txRequest); diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts index 4d3902290063..7d48f244836c 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts @@ -1,7 +1,6 @@ -import type { ExecutionPayload, ExecutionRequestInit, FeePaymentMethod } from '@aztec/entrypoints/interfaces'; +import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import type { FunctionCall } from '@aztec/stdlib/abi'; -import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; // docs:start:fee_juice_method diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts index 888a6206750d..74b8c555fdd5 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts @@ -1,9 +1,7 @@ -import type { ExecutionPayload } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import type { FunctionCall } from '@aztec/stdlib/abi'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; -import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { getFeeJuice } from '../contract/protocol_contracts.js'; import type { L2AmountClaim } from '../ethereum/portal_manager.js'; diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index 606b717e0e7b..2789ffabedbb 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -1,7 +1,7 @@ -import type { ExecutionPayload, FeePaymentMethod } from '@aztec/entrypoints/interfaces'; +import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import { Fr } from '@aztec/foundation/fields'; -import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; -import type { AuthWitness } from '@aztec/stdlib/auth-witness'; +import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index 1eedc541bb79..4c974584f5de 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -1,4 +1,5 @@ -import type { ExecutionPayload, FeePaymentMethod } from '@aztec/entrypoints/interfaces'; +import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import { Fr } from '@aztec/foundation/fields'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; diff --git a/yarn-project/aztec.js/src/fee/utils.ts b/yarn-project/aztec.js/src/fee/utils.ts index 0fa0e506c568..6016040cb33f 100644 --- a/yarn-project/aztec.js/src/fee/utils.ts +++ b/yarn-project/aztec.js/src/fee/utils.ts @@ -18,7 +18,7 @@ export async function simulateWithoutSignature(wallet: Wallet, contractAddress: const { l1ChainId: chainId, protocolVersion } = await wallet.getNodeInfo(); const entrypoint = new DefaultEntrypoint(chainId, protocolVersion); - const signerlessTxExecutionRequest = await entrypoint.createTxExecutionRequest(request, fee); + const signerlessTxExecutionRequest = await entrypoint.createTxExecutionRequest(request, fee, {}); const simulationResult = await wallet.simulateTx(signerlessTxExecutionRequest, false, undefined, undefined, true); const rawReturnValues = simulationResult.getPrivateReturnValues().values; diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 0588259ef06a..f1fe1c934905 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -1,4 +1,5 @@ -import type { ExecutionRequestInit, FeeOptions, UserExecutionRequest } from '@aztec/entrypoints/interfaces'; +import type { FeeOptions, TxExecutionOptions } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type ABIParameterVisibility, type FunctionAbi, FunctionType } from '@aztec/stdlib/abi'; @@ -25,8 +26,12 @@ export class AccountWallet extends BaseWallet { super(pxe); } - createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { - return this.account.createTxExecutionRequest(exec, fee); + createTxExecutionRequest( + exec: ExecutionPayload, + fee: FeeOptions, + options: TxExecutionOptions, + ): Promise { + return this.account.createTxExecutionRequest(exec, fee, options); } getChainId(): Fr { @@ -149,7 +154,7 @@ export class AccountWallet extends BaseWallet { results.isValidInPrivate = (await new ContractFunctionInteraction(this, onBehalfOf, this.getLookupValidityAbi(), [ consumer, innerHash, - ]).simulate({ authwits: [witness] })) as boolean; + ]).simulate({ authWitnesses: [witness] })) as boolean; } catch {} // check public diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 9c9482506ee8..f12252c922c7 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -1,4 +1,5 @@ -import type { ExecutionRequestInit, FeeOptions, UserExecutionRequest } from '@aztec/entrypoints/interfaces'; +import type { FeeOptions, TxExecutionOptions } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import type { Fr, Point } from '@aztec/foundation/fields'; import type { AbiDecoded, ContractArtifact } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; @@ -37,7 +38,11 @@ export abstract class BaseWallet implements Wallet { abstract getVersion(): Fr; - abstract createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise; + abstract createTxExecutionRequest( + exec: ExecutionPayload, + fee: FeeOptions, + options: TxExecutionOptions, + ): Promise; abstract createAuthWit(intent: Fr | Buffer | IntentInnerHash | IntentAction): Promise; diff --git a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts index b4f80c57f4a1..a20517e85be7 100644 --- a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts @@ -1,10 +1,6 @@ import { DefaultEntrypoint } from '@aztec/entrypoints/default'; -import type { - EntrypointInterface, - ExecutionRequestInit, - FeeOptions, - UserExecutionRequest, -} from '@aztec/entrypoints/interfaces'; +import type { EntrypointInterface, FeeOptions, TxExecutionOptions } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import type { Fr } from '@aztec/foundation/fields'; import { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { CompleteAddress } from '@aztec/stdlib/contract'; @@ -21,14 +17,18 @@ export class SignerlessWallet extends BaseWallet { constructor(pxe: PXE, private entrypoint?: EntrypointInterface) { super(pxe); } - async createTxExecutionRequest(execution: UserExecutionRequest, fee: FeeOptions): Promise { + async createTxExecutionRequest( + execution: ExecutionPayload, + fee: FeeOptions, + options: TxExecutionOptions, + ): Promise { let entrypoint = this.entrypoint; if (!entrypoint) { const { l1ChainId: chainId, protocolVersion } = await this.pxe.getNodeInfo(); entrypoint = new DefaultEntrypoint(chainId, protocolVersion); } - return entrypoint.createTxExecutionRequest(execution, fee); + return entrypoint.createTxExecutionRequest(execution, fee, options); } getChainId(): Fr { diff --git a/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts b/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts index 3b0b475f8bdd..4fd88b3e9ad3 100644 --- a/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts +++ b/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts @@ -1,8 +1,7 @@ import type { FeePaymentMethod } from '@aztec/aztec.js'; -import type { ExecutionPayload } from '@aztec/entrypoints/interfaces'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; -import type { AuthWitness } from '@aztec/stdlib/auth-witness'; +import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PXE } from '@aztec/stdlib/interfaces/client'; diff --git a/yarn-project/cli-wallet/src/cmds/cancel_tx.ts b/yarn-project/cli-wallet/src/cmds/cancel_tx.ts index 936c0e048bf0..0ca1572d5b6e 100644 --- a/yarn-project/cli-wallet/src/cmds/cancel_tx.ts +++ b/yarn-project/cli-wallet/src/cmds/cancel_tx.ts @@ -1,5 +1,6 @@ import { type AccountWalletWithSecretKey, type FeePaymentMethod, SentTx, type TxHash, TxStatus } from '@aztec/aztec.js'; import type { FeeOptions } from '@aztec/entrypoints/interfaces'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { Fr } from '@aztec/foundation/fields'; import type { LogFn } from '@aztec/foundation/log'; import { GasFees, GasSettings } from '@aztec/stdlib/gas'; @@ -37,9 +38,7 @@ export async function cancelTx( }), }; - const txRequest = await wallet.createTxExecutionRequest({ - calls: [], - fee, + const txRequest = await wallet.createTxExecutionRequest(ExecutionPayload.empty(), fee, { nonce, cancellable: true, }); diff --git a/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts b/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts index 890dbdc24bed..e3d5a7d52d1f 100644 --- a/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts +++ b/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts @@ -1,7 +1,6 @@ import type { FeePaymentMethod } from '@aztec/aztec.js/fee'; -import type { ExecutionPayload, ExecutionRequestInit } from '@aztec/entrypoints/interfaces'; -import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; -import type { AuthWitness } from '@aztec/stdlib/auth-witness'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; export class SponsoredFeePaymentMethod implements FeePaymentMethod { diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index 1188afe54c3b..18fe1cff37b2 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -34,7 +34,7 @@ describe('e2e_authwit_tests', () => { describe('Private', () => { describe('arbitrary data', () => { - it('happy path', async () => { + it.only('happy path', async () => { // What are we doing here: // 1. We compute an inner hash which is here just a hash of random data // 2. We then compute the message hash, which is binding it to a "consumer" (here the "auth" contract) @@ -69,7 +69,7 @@ describe('e2e_authwit_tests', () => { await auth .withWallet(wallets[1]) .methods.consume(wallets[0].getAddress(), innerHash) - .send({ authwits: [witness] }) + .send({ authWitnesses: [witness] }) .wait(); expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent, witness)).toEqual({ @@ -82,7 +82,7 @@ describe('e2e_authwit_tests', () => { auth .withWallet(wallets[1]) .methods.consume(wallets[0].getAddress(), innerHash) - .send({ authwits: [witness] }) + .send({ authWitnesses: [witness] }) .wait(), ).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts index 52eb5d258667..b5063b8415da 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts @@ -155,7 +155,7 @@ describe('e2e_blacklist_token_contract burn', () => { await asset .withWallet(wallets[1]) .methods.burn(wallets[0].getAddress(), amount, nonce) - .send({ authwits: [witness] }) + .send({ authWitnesses: [witness] }) .wait(); tokenSim.burnPrivate(wallets[0].getAddress(), amount); @@ -163,7 +163,7 @@ describe('e2e_blacklist_token_contract burn', () => { const txReplay = asset .withWallet(wallets[1]) .methods.burn(wallets[0].getAddress(), amount, nonce) - .send({ authwits: [witness] }); + .send({ authWitnesses: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); @@ -199,7 +199,7 @@ describe('e2e_blacklist_token_contract burn', () => { // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await expect(action.prove({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.prove({ authWitnesses: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); }); it('burn on behalf of other without approval', async () => { @@ -233,7 +233,7 @@ describe('e2e_blacklist_token_contract burn', () => { const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await expect(action.prove({ authwits: [witness] })).rejects.toThrow( + await expect(action.prove({ authWitnesses: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts index 5679aa5ff20d..3848129cf30b 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts @@ -61,7 +61,7 @@ describe('e2e_blacklist_token_contract transfer private', () => { // Perform the transfer // docs:start:add_authwit - await action.send({ authwits: [witness] }).wait(); + await action.send({ authWitnesses: [witness] }).wait(); // docs:end:add_authwit // docs:end:authwit_transfer_example tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount); @@ -70,7 +70,7 @@ describe('e2e_blacklist_token_contract transfer private', () => { const txReplay = asset .withWallet(wallets[1]) .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) - .send({ authwits: [witness] }); + .send({ authWitnesses: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); @@ -112,7 +112,7 @@ describe('e2e_blacklist_token_contract transfer private', () => { const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); // Perform the transfer - await expect(action.prove({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.prove({ authWitnesses: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); expect(await asset.methods.balance_of_private(wallets[0].getAddress()).simulate()).toEqual(balance0); expect(await asset.methods.balance_of_private(wallets[1].getAddress()).simulate()).toEqual(balance1); }); @@ -159,7 +159,7 @@ describe('e2e_blacklist_token_contract transfer private', () => { const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await expect(action.prove({ authwits: [witness] })).rejects.toThrow( + await expect(action.prove({ authWitnesses: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); expect(await asset.methods.balance_of_private(wallets[0].getAddress()).simulate()).toEqual(balance0); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts index b7d9127124bf..83ff0b4a1593 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts @@ -49,14 +49,14 @@ describe('e2e_blacklist_token_contract unshielding', () => { // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await action.send({ authwits: [witness] }).wait(); + await action.send({ authWitnesses: [witness] }).wait(); tokenSim.transferToPublic(wallets[0].getAddress(), wallets[1].getAddress(), amount); // Perform the transfer again, should fail const txReplay = asset .withWallet(wallets[1]) .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) - .send({ authwits: [witness] }); + .send({ authWitnesses: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); // @todo @LHerskind This error is weird? }); @@ -97,7 +97,7 @@ describe('e2e_blacklist_token_contract unshielding', () => { // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await expect(action.prove({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.prove({ authWitnesses: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); }); it('on behalf of other (invalid designated caller)', async () => { @@ -119,7 +119,7 @@ describe('e2e_blacklist_token_contract unshielding', () => { // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); - await expect(action.prove({ authwits: [witness] })).rejects.toThrow( + await expect(action.prove({ authWitnesses: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index 134a51c6535b..f08fa2ceec20 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -157,7 +157,7 @@ describe('e2e_crowdfunding_and_claim', () => { const donateTxReceipt = await crowdfundingContract .withWallet(donorWallets[0]) .methods.donate(donationAmount) - .send({ authwits: [witness] }) + .send({ authWitnesses: [witness] }) .wait(); // Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the UintNote) @@ -221,7 +221,7 @@ describe('e2e_crowdfunding_and_claim', () => { const donateTxReceipt = await crowdfundingContract .withWallet(donorWallet) .methods.donate(donationAmount) - .send({ authwits: [witness] }) + .send({ authWitnesses: [witness] }) .wait(); // Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the UintNote) @@ -300,7 +300,7 @@ describe('e2e_crowdfunding_and_claim', () => { await crowdfundingContract .withWallet(donorWallets[1]) .methods.donate(donationAmount) - .send({ authwits: [witness] }) + .send({ authWitnesses: [witness] }) .wait(); // Calling the function normally will fail as msg_sender != operator @@ -351,7 +351,7 @@ describe('e2e_crowdfunding_and_claim', () => { crowdfundingContract .withWallet(donorWallets[1]) .methods.donate(donationAmount) - .send({ authwits: [witness] }) + .send({ authWitnesses: [witness] }) .wait(), ).rejects.toThrow(); }); diff --git a/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts b/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts index be2eef780072..b350ad45d67a 100644 --- a/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts @@ -189,7 +189,7 @@ describe('e2e_fees dapp_subscription', () => { return subscriptionContract .withWallet(aliceWallet) .methods.subscribe(aliceAddress, nonce, (await pxe.getBlockNumber()) + blockDelta, txCount) - .send({ authwits: [witness], fee: { paymentMethod } }) + .send({ authWitnesses: [witness], fee: { paymentMethod } }) .wait(); } diff --git a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts index f83dcbf8faa3..ce40d6e81dc8 100644 --- a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts @@ -9,6 +9,7 @@ import { PublicFeePaymentMethod, TxStatus, } from '@aztec/aztec.js'; +import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import type { FPCContract } from '@aztec/noir-contracts.js/FPC'; import type { TokenContract as BananaCoin } from '@aztec/noir-contracts.js/Token'; import { FunctionType } from '@aztec/stdlib/abi'; @@ -325,9 +326,7 @@ describe('e2e_fees failures', () => { }); class BuggedSetupFeePaymentMethod extends PublicFeePaymentMethod { - override async getFunctionCalls( - gasSettings: GasSettings, - ): Promise> { + override async getExecutionPayload(gasSettings: GasSettings): Promise { const maxFee = gasSettings.getFeeLimit(); const nonce = Fr.random(); @@ -364,7 +363,8 @@ class BuggedSetupFeePaymentMethod extends PublicFeePaymentMethod { returnTypes: [], }, ], - authwits: [], + authWitnesses: [], + capsules: [], }; } } diff --git a/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts index 78f5c73be9e3..7578f85593a9 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts @@ -148,7 +148,7 @@ describe('e2e_token_contract burn', () => { await asset .withWallet(wallets[1]) .methods.burn_private(accounts[0].address, amount, nonce) - .send({ authwits: [witness] }) + .send({ authWitnesses: [witness] }) .wait(); tokenSim.burnPrivate(accounts[0].address, amount); @@ -156,7 +156,7 @@ describe('e2e_token_contract burn', () => { const txReplay = asset .withWallet(wallets[1]) .methods.burn_private(accounts[0].address, amount, nonce) - .send({ authwits: [witness] }); + .send({ authWitnesses: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); @@ -192,7 +192,9 @@ describe('e2e_token_contract burn', () => { // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await expect(action.simulate({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.simulate({ authWitnesses: [witness] })).rejects.toThrow( + 'Assertion failed: Balance too low', + ); }); it('burn on behalf of other without approval', async () => { @@ -228,7 +230,7 @@ describe('e2e_token_contract burn', () => { const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await expect(action.simulate({ authwits: [witness] })).rejects.toThrow( + await expect(action.simulate({ authWitnesses: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts index d95555eec790..6da9c24758dc 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts @@ -44,14 +44,14 @@ describe('e2e_token_contract transfer private', () => { // docs:end:authwit_transfer_example // Perform the transfer - await action.send({ authwits: [witness] }).wait(); + await action.send({ authWitnesses: [witness] }).wait(); tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); // Perform the transfer again, should fail const txReplay = asset .withWallet(wallets[1]) .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce) - .send({ authwits: [witness] }); + .send({ authWitnesses: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); @@ -83,7 +83,7 @@ describe('e2e_token_contract transfer private', () => { const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); // Perform the transfer - await expect(action.simulate({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.simulate({ authWitnesses: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); expect(await asset.methods.balance_of_private(accounts[0].address).simulate()).toEqual(balance0); expect(await asset.methods.balance_of_private(accounts[1].address).simulate()).toEqual(balance1); }); @@ -138,7 +138,7 @@ describe('e2e_token_contract transfer private', () => { const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await expect(action.simulate({ authwits: [witness] })).rejects.toThrow( + await expect(action.simulate({ authWitnesses: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); expect(await asset.methods.balance_of_private(accounts[0].address).simulate()).toEqual(balance0); @@ -176,7 +176,7 @@ describe('e2e_token_contract transfer private', () => { const txCancelledAuthwit = asset .withWallet(wallets[1]) .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce) - .send({ authwits: [witness] }); + .send({ authWitnesses: [witness] }); await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR); }); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts index 1d5d53b9e3fa..c5ca0ca1d10a 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts @@ -144,7 +144,7 @@ describe('e2e_token_contract transfer public', () => { }); // Perform the transfer - await expect(action.simulate({ authwits: [witness] })).rejects.toThrow(U128_UNDERFLOW_ERROR); + await expect(action.simulate({ authWitnesses: [witness] })).rejects.toThrow(U128_UNDERFLOW_ERROR); expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts index ebf3b4d63961..f688d296ffe8 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts @@ -48,7 +48,7 @@ describe('e2e_token_contract transfer_to_public', () => { // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await action.send({ authwits: [witness] }).wait(); + await action.send({ authWitnesses: [witness] }).wait(); tokenSim.transferToPublic(accounts[0].address, accounts[1].address, amount); // Perform the transfer again, should fail @@ -95,7 +95,7 @@ describe('e2e_token_contract transfer_to_public', () => { // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await expect(action.simulate({ authwits: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); + await expect(action.simulate({ authWitnesses: [witness] })).rejects.toThrow('Assertion failed: Balance too low'); }); it('on behalf of other (invalid designated caller)', async () => { @@ -117,7 +117,7 @@ describe('e2e_token_contract transfer_to_public', () => { // But doing it in two actions to show the flow. const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); - await expect(action.simulate({ authwits: [witness] })).rejects.toThrow( + await expect(action.simulate({ authWitnesses: [witness] })).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); diff --git a/yarn-project/entrypoints/src/account_entrypoint.ts b/yarn-project/entrypoints/src/account_entrypoint.ts index 3846ce8172c7..1c74c5531c38 100644 --- a/yarn-project/entrypoints/src/account_entrypoint.ts +++ b/yarn-project/entrypoints/src/account_entrypoint.ts @@ -7,10 +7,10 @@ import { type AuthWitnessProvider, type EntrypointInterface, type FeeOptions, - type UserExecutionRequest, + type TxExecutionOptions, } from './interfaces.js'; -import { EntrypointPayload } from './payload.js'; -import { computeCombinedPayloadHash, mergeEncodedExecutionPayloads } from './utils.js'; +import { ExecutionPayload } from './payload.js'; +import { computeCombinedPayloadHash, mergeAndEncodeExecutionPayloads, mergeExecutionPayloads } from './utils.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature @@ -24,10 +24,15 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { private version: number = DEFAULT_VERSION, ) {} - async createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { - const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [], nonce, cancellable } = exec; - const appPayload = await EntrypointPayload.fromAppExecution(calls); - const feePayload = await EntrypointPayload.fromFeeOptions(this.address, fee); + async createTxExecutionRequest( + exec: ExecutionPayload, + fee: FeeOptions, + options: TxExecutionOptions, + ): Promise { + const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; + const { cancellable, nonce } = options; + const appPayload = await ExecutionPayload.fromAppExecution(calls, nonce); + const feePayload = await ExecutionPayload.fromFeeOptions(this.address, fee); const abi = this.getEntrypointAbi(); const entrypointHashedArgs = await HashedValues.fromValues( @@ -38,9 +43,7 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { await computeCombinedPayloadHash(appPayload, feePayload), ); - const executionPayload = mergeEncodedExecutionPayloads([appPayload, feePayload], { - nonce, - cancellable, + const encodedExecutionPayload = await mergeAndEncodeExecutionPayloads([appPayload, feePayload], { extraHashedArgs: [entrypointHashedArgs], extraAuthWitnesses: [combinedPayloadAuthWitness, ...userAuthWitnesses], extraCapsules: userCapsules, @@ -51,9 +54,9 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { origin: this.address, functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters), txContext: new TxContext(this.chainId, this.version, fee.gasSettings), - argsOfCalls: executionPayload.hashedArguments, - authWitnesses: executionPayload.authWitnesses, - capsules: executionPayload.capsules, + argsOfCalls: encodedExecutionPayload.hashedArguments, + authWitnesses: encodedExecutionPayload.authWitnesses, + capsules: encodedExecutionPayload.capsules, }); return txRequest; diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index 77a0bf44053f..ad28386b432b 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -8,12 +8,11 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; import { type AuthWitnessProvider, type EntrypointInterface, - type ExecutionRequestInit, type FeeOptions, - type UserExecutionRequest, + type TxExecutionOptions, } from './interfaces.js'; -import { EntrypointPayload } from './payload.js'; -import { mergeEncodedExecutionPayloads } from './utils.js'; +import { ExecutionPayload } from './payload.js'; +import { mergeAndEncodeExecutionPayloads } from './utils.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature @@ -28,13 +27,17 @@ export class DefaultDappEntrypoint implements EntrypointInterface { private version: number = DEFAULT_VERSION, ) {} - async createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { + async createTxExecutionRequest( + exec: ExecutionPayload, + fee: FeeOptions, + _options: TxExecutionOptions, + ): Promise { const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; if (calls.length !== 1) { throw new Error(`Expected exactly 1 function call, got ${calls.length}`); } - const payload = await EntrypointPayload.fromFunctionCalls(calls); + const payload = await ExecutionPayload.fromFunctionCalls(calls); const abi = this.getEntrypointAbi(); const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload, this.userAddress])); @@ -54,7 +57,7 @@ export class DefaultDappEntrypoint implements EntrypointInterface { const authWitness = await this.userAuthWitnessProvider.createAuthWit(outerHash); - const executionPayload = await mergeEncodedExecutionPayloads([payload], { + const executionPayload = await mergeAndEncodeExecutionPayloads([payload], { extraAuthWitnesses: [authWitness, ...userAuthWitnesses], extraHashedArgs: [entrypointHashedArgs], extraCapsules: userCapsules, diff --git a/yarn-project/entrypoints/src/default_entrypoint.ts b/yarn-project/entrypoints/src/default_entrypoint.ts index a066c51a3daf..a80a810ebd80 100644 --- a/yarn-project/entrypoints/src/default_entrypoint.ts +++ b/yarn-project/entrypoints/src/default_entrypoint.ts @@ -1,7 +1,8 @@ import { FunctionType } from '@aztec/stdlib/abi'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; -import type { EntrypointInterface, FeeOptions, UserExecutionRequest } from './interfaces.js'; +import type { EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js'; +import type { ExecutionPayload } from './payload.js'; /** * Default implementation of the entrypoint interface. It calls a function on a contract directly @@ -9,7 +10,11 @@ import type { EntrypointInterface, FeeOptions, UserExecutionRequest } from './in export class DefaultEntrypoint implements EntrypointInterface { constructor(private chainId: number, private protocolVersion: number) {} - async createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise { + async createTxExecutionRequest( + exec: ExecutionPayload, + fee: FeeOptions, + _options: TxExecutionOptions, + ): Promise { const { calls, authWitnesses = [], capsules = [] } = exec; if (calls.length > 1) { diff --git a/yarn-project/entrypoints/src/interfaces.ts b/yarn-project/entrypoints/src/interfaces.ts index b09c103e5d51..766570a8497a 100644 --- a/yarn-project/entrypoints/src/interfaces.ts +++ b/yarn-project/entrypoints/src/interfaces.ts @@ -1,28 +1,11 @@ import type { Fr } from '@aztec/foundation/fields'; import type { FieldsOf } from '@aztec/foundation/types'; -import type { FunctionCall } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { GasSettings } from '@aztec/stdlib/gas'; -import type { Capsule, HashedValues, TxExecutionRequest } from '@aztec/stdlib/tx'; +import type { TxExecutionRequest } from '@aztec/stdlib/tx'; -export type UserExecutionRequest = { - calls: FunctionCall[]; - authWitnesses?: AuthWitness[]; - capsules?: Capsule[]; - nonce?: Fr; - cancellable?: boolean; -}; - -/** Represents data necessary to execute a list of function calls successfully */ -export interface ExecutionPayload { - /** The function calls to be executed. */ - calls: FunctionCall[]; - /** Any transient auth witnesses needed for this execution */ - authWitnesses: AuthWitness[]; - /** Data passed through an oracle for this execution. */ - capsules: Capsule[]; -} +import type { ExecutionPayload } from './payload.js'; /* eslint-disable camelcase */ /** Encoded function call for an Aztec entrypoint */ @@ -40,31 +23,9 @@ export type EncodedFunctionCall = { }; /* eslint-enable camelcase */ -/** Represents the ExecutionPayload after encoding for the entrypint to execute */ -export type EncodedExecutionPayload = Omit & { - /** The function calls to be executed. */ - encodedFunctionCalls: EncodedFunctionCall[]; - /** Any transient hashed arguments for this execution */ - hashedArguments: HashedValues[]; -}; - -/** - * Represents a transaction execution request, complete with the encoded payload, a nonce - * and whether the transaction can be cancelled. - */ -export type ExecutionRequestInit = EncodedExecutionPayload & { - /** An optional nonce. Used to repeat a previous tx with a higher fee so that the first one is cancelled */ - nonce?: Fr; - /** Whether the transaction can be cancelled. If true, an extra nullifier will be emitted: H(nonce, GENERATOR_INDEX__TX_NULLIFIER) */ +export type TxExecutionOptions = { cancellable?: boolean; -}; - -/** - * Completes a ExecutionRequest by including the fee payment method and gas settings. - */ -export type ExecutionRequest = ExecutionRequestInit & { - /** How the fee is going to be payed */ - fee: FeeOptions; + nonce?: Fr; }; /** Creates transaction execution requests out of a set of function calls. */ @@ -74,7 +35,11 @@ export interface EntrypointInterface { * @param execution - The execution intents to be run. * @returns The authenticated transaction execution request. */ - createTxExecutionRequest(exec: UserExecutionRequest, fee: FeeOptions): Promise; + createTxExecutionRequest( + exec: ExecutionPayload, + fee: FeeOptions, + options: TxExecutionOptions, + ): Promise; } /** Creates authorization witnesses. */ diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index ee5b3f33d5fd..7baa02aecaf8 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -3,12 +3,13 @@ import { padArrayEnd } from '@aztec/foundation/collection'; import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import type { Tuple } from '@aztec/foundation/serialize'; +import type { FieldsOf } from '@aztec/foundation/types'; import { FunctionCall, FunctionType } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { Capsule, HashedValues } from '@aztec/stdlib/tx'; -import type { EncodedExecutionPayload, EncodedFunctionCall, FeeOptions } from './interfaces.js'; +import type { EncodedFunctionCall, FeeOptions } from './interfaces.js'; // These must match the values defined in: // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr @@ -16,19 +17,24 @@ const APP_MAX_CALLS = 4; // - and noir-projects/aztec-nr/aztec/src/entrypoint/fee.nr const FEE_MAX_CALLS = 2; -/** Assembles an entrypoint payload */ -export abstract class EntrypointPayload implements EncodedExecutionPayload { +/** Represents data necessary to execute a list of function calls successfully */ +export abstract class ExecutionPayload { protected constructor( - public encodedFunctionCalls: EncodedFunctionCall[], - public hashedArguments: HashedValues[], + /** The function calls to be executed. */ + public calls: FunctionCall[], + /** Any transient auth witnesses needed for this execution */ public authWitnesses: AuthWitness[], + /** Data passed through an oracle for this execution. */ public capsules: Capsule[], - private generatorIndex: number, ) {} - protected static async create( + static empty(): ExecutionPayload { + return { calls: [], authWitnesses: [], capsules: [] }; + } + + public static async encodeCalls( calls: FunctionCall[], - ): Promise> { + ): Promise> { const hashedArguments: HashedValues[] = []; for (const call of calls) { hashedArguments.push(await HashedValues.fromValues(call.args)); @@ -50,39 +56,14 @@ export abstract class EntrypointPayload implements EncodedExecutionPayload { }; } - /** - * Serializes the payload to an array of fields - * @returns The fields of the payload - */ - abstract toFields(): Fr[]; - - /** - * Hashes the payload - * @returns The hash of the payload - */ - hash() { - return poseidon2HashWithSeparator(this.toFields(), this.generatorIndex); - } - - /** Serializes the function calls to an array of fields. */ - protected functionCallsToFields() { - return this.encodedFunctionCalls.flatMap(call => [ - call.args_hash, - call.function_selector, - call.target_address, - new Fr(call.is_public), - new Fr(call.is_static), - ]); - } - /** * Creates an execution payload for a dapp from a set of function calls * @param functionCalls - The function calls to execute * @returns The execution payload */ static async fromFunctionCalls(functionCalls: FunctionCall[]) { - const { encodedFunctionCalls, hashedArguments } = await this.create(functionCalls); - return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, [], [], 0); + const { encodedFunctionCalls, hashedArguments } = await this.encodeCalls(functionCalls); + return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, [], [], 0, Fr.random()); } /** @@ -91,13 +72,20 @@ export abstract class EntrypointPayload implements EncodedExecutionPayload { * @param nonce - The nonce for the payload, used to emit a nullifier identifying the call * @returns The execution payload */ - static async fromAppExecution(functionCalls: FunctionCall[] | Tuple) { + static async fromAppExecution(functionCalls: FunctionCall[] | Tuple, nonce = Fr.random()) { if (functionCalls.length > APP_MAX_CALLS) { throw new Error(`Expected at most ${APP_MAX_CALLS} function calls, got ${functionCalls.length}`); } const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS); - const { encodedFunctionCalls, hashedArguments } = await this.create(paddedCalls); - return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, [], [], GeneratorIndex.SIGNATURE_PAYLOAD); + const { encodedFunctionCalls, hashedArguments } = await this.encodeCalls(paddedCalls); + return new AppEntrypointPayload( + encodedFunctionCalls, + hashedArguments, + [], + [], + GeneratorIndex.SIGNATURE_PAYLOAD, + nonce, + ); } /** @@ -114,41 +102,102 @@ export abstract class EntrypointPayload implements EncodedExecutionPayload { const feePayer = await feeOpts?.paymentMethod.getFeePayer(feeOpts?.gasSettings); const isFeePayer = !!feePayer && feePayer.equals(sender); const paddedCalls = padArrayEnd(calls, FunctionCall.empty(), FEE_MAX_CALLS); - const { encodedFunctionCalls, hashedArguments } = await this.create(paddedCalls); + const { encodedFunctionCalls, hashedArguments } = await this.encodeCalls(paddedCalls); return new FeeEntrypointPayload( encodedFunctionCalls, hashedArguments, authWitnesses ?? [], + [], GeneratorIndex.FEE_PAYLOAD, + Fr.random(), isFeePayer, ); } } +export type EncodedExecutionPayload = Omit & { + encodedFunctionCalls: EncodedFunctionCall[]; + hashedArguments: HashedValues[]; +}; + +/** Represents the ExecutionPayload after encoding for the entrypint to execute */ +export abstract class HashableExecutionPayload implements EncodedExecutionPayload { + constructor( + public encodedFunctionCalls: EncodedFunctionCall[], + public hashedArguments: HashedValues[], + /** Any transient auth witnesses needed for this execution */ + public authWitnesses: AuthWitness[], + /** Data passed through an oracle for this execution. */ + public capsules: Capsule[], + /** The index of the generator to use for hashing */ + private generatorIndex: number, + /** The nonce for the payload, used to emit a nullifier identifying the call */ + public nonce: Fr, + ) {} + + /** + * Serializes the payload to an array of fields + * @returns The fields of the payload + */ + abstract toFields(): Fr[]; + + /** + * Hashes the payload + * @returns The hash of the payload + */ + hash() { + return poseidon2HashWithSeparator(this.toFields(), this.generatorIndex); + } + + /** Serializes the function calls to an array of fields. */ + protected functionCallsToFields() { + return this.encodedFunctionCalls.flatMap(call => [ + call.args_hash, + call.function_selector, + call.target_address, + new Fr(call.is_public), + new Fr(call.is_static), + ]); + } +} + /** Entrypoint payload for app phase execution. */ -export class AppEntrypointPayload extends EntrypointPayload { +export class AppEntrypointPayload extends HashableExecutionPayload { + constructor( + encodedFunctionCalls: EncodedFunctionCall[], + hashedArguments: HashedValues[], + authWitnesses: AuthWitness[], + capsules: Capsule[], + generatorIndex: number, + nonce: Fr, + ) { + super(encodedFunctionCalls, hashedArguments, authWitnesses, capsules, generatorIndex, nonce); + } + override toFields(): Fr[] { - return [...this.functionCallsToFields()]; + return [...this.functionCallsToFields(), this.nonce]; } } /** Entrypoint payload for fee payment to be run during setup phase. */ -export class FeeEntrypointPayload extends EntrypointPayload { +export class FeeEntrypointPayload extends HashableExecutionPayload { #isFeePayer: boolean; constructor( - functionCalls: EncodedFunctionCall[], + encodedFunctionCalls: EncodedFunctionCall[], hashedArguments: HashedValues[], authWitnesses: AuthWitness[], + capsules: Capsule[], generatorIndex: number, + nonce: Fr, isFeePayer: boolean, ) { - super(functionCalls, hashedArguments, authWitnesses, [], generatorIndex); + super(encodedFunctionCalls, hashedArguments, authWitnesses, capsules, generatorIndex, nonce); this.#isFeePayer = isFeePayer; } override toFields(): Fr[] { - return [...this.functionCallsToFields(), new Fr(this.#isFeePayer)]; + return [...this.functionCallsToFields(), this.nonce, new Fr(this.#isFeePayer)]; } /* eslint-disable camelcase */ diff --git a/yarn-project/entrypoints/src/utils.ts b/yarn-project/entrypoints/src/utils.ts index ccadb89ce916..6e82f9729d04 100644 --- a/yarn-project/entrypoints/src/utils.ts +++ b/yarn-project/entrypoints/src/utils.ts @@ -4,35 +4,62 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { Capsule, HashedValues } from '@aztec/stdlib/tx'; import { GeneratorIndex } from '../../constants/src/constants.gen.js'; -import type { EncodedExecutionPayload, ExecutionRequestInit } from './interfaces.js'; -import type { AppEntrypointPayload, FeeEntrypointPayload } from './payload.js'; +import { + type AppEntrypointPayload, + type EncodedExecutionPayload, + ExecutionPayload, + type FeeEntrypointPayload, +} from './payload.js'; /** - * Merges an array of EncodedExecutionPayloads and adds a nonce and cancellable flags, - * in order to create a single ExecutionRequestInit. + * Merges an array ExecutionPayloads combining their calls, authWitnesses and capsules */ -export function mergeEncodedExecutionPayloads( - requests: EncodedExecutionPayload[], +export function mergeExecutionPayloads(requests: ExecutionPayload[]): ExecutionPayload { + const calls = requests.map(r => r.calls).flat(); + const combinedAuthWitnesses = requests.map(r => r.authWitnesses ?? []).flat(); + const combinedCapsules = requests.map(r => r.capsules ?? []).flat(); + return { + calls, + authWitnesses: combinedAuthWitnesses, + capsules: combinedCapsules, + }; +} + +/** + * Merges an array of mixed ExecutionPayloads and EncodedExecutionPayloads and adds a nonce and cancellable flags, + * in order to create a single EncodedExecutionPayload. + */ +export async function mergeAndEncodeExecutionPayloads( + requests: (ExecutionPayload | EncodedExecutionPayload)[], { - nonce, - cancellable, extraHashedArgs, extraAuthWitnesses, extraCapsules, }: { - nonce?: Fr; - cancellable?: boolean; extraHashedArgs?: HashedValues[]; extraAuthWitnesses?: AuthWitness[]; extraCapsules?: Capsule[]; } = { extraAuthWitnesses: [], extraCapsules: [], extraHashedArgs: [] }, -): ExecutionRequestInit { - const encodedFunctionCalls = requests.map(r => r.encodedFunctionCalls).flat(); +): Promise { + const isEncoded = (value: ExecutionPayload | EncodedExecutionPayload): value is EncodedExecutionPayload => + 'encodedFunctionCalls' in value; + const encoded = ( + await Promise.all( + requests.map(async r => { + if (!isEncoded(r)) { + return await ExecutionPayload.encodeCalls(r.calls); + } else { + return { encodedFunctionCalls: r.encodedFunctionCalls, hashedArguments: r.hashedArguments }; + } + }), + ) + ).flat(); + const encodedFunctionCalls = encoded.map(r => r.encodedFunctionCalls).flat(); const combinedAuthWitnesses = requests .map(r => r.authWitnesses ?? []) .flat() .concat(extraAuthWitnesses ?? []); - const hashedArguments = requests + const hashedArguments = encoded .map(r => r.hashedArguments ?? []) .flat() .concat(extraHashedArgs ?? []); @@ -45,8 +72,6 @@ export function mergeEncodedExecutionPayloads( authWitnesses: combinedAuthWitnesses, hashedArguments, capsules: combinedCapsules, - nonce, - cancellable, }; } From 7e22efa16229270c29ee3a21214fd64857b7da61 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 08:29:11 +0000 Subject: [PATCH 21/48] fixes --- yarn-project/aztec.js/src/wallet/wallet.ts | 1 + yarn-project/cli-wallet/src/cmds/index.ts | 2 +- yarn-project/entrypoints/src/dapp_entrypoint.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/yarn-project/aztec.js/src/wallet/wallet.ts b/yarn-project/aztec.js/src/wallet/wallet.ts index 3da9aaea5332..58651bfaddc1 100644 --- a/yarn-project/aztec.js/src/wallet/wallet.ts +++ b/yarn-project/aztec.js/src/wallet/wallet.ts @@ -12,6 +12,7 @@ export type Wallet = AccountInterface & PXE, | 'simulateTx' | 'simulateUnconstrained' + | 'profileTx' | 'sendTx' | 'getContractClassMetadata' | 'getContractMetadata' diff --git a/yarn-project/cli-wallet/src/cmds/index.ts b/yarn-project/cli-wallet/src/cmds/index.ts index 2dab3088e6fd..85bf8095136e 100644 --- a/yarn-project/cli-wallet/src/cmds/index.ts +++ b/yarn-project/cli-wallet/src/cmds/index.ts @@ -363,7 +363,7 @@ export function injectCommands( const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await getWalletWithScopes(account, db); + const wallet = await account.getWallet(); const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db); await profile(wallet, functionName, args, artifactPath, contractAddress, debugExecutionStepsDir, log); }); diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index 1614aac1fa18..288139ec50a9 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -1,5 +1,5 @@ import { Fr } from '@aztec/foundation/fields'; -import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi'; +import { type FunctionAbi, FunctionSelector, FunctionType, encodeArguments } from '@aztec/stdlib/abi'; import { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; From dff12ebbb6d808316a13e9a39e0a33b654831ecf Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 11:04:47 +0000 Subject: [PATCH 22/48] saner entrypoint payload building --- .../account_manager/deploy_account_method.ts | 54 ++++-- .../src/contract/base_contract_interaction.ts | 65 +------ .../aztec.js/src/contract/batch_call.ts | 7 - .../contract/contract_function_interaction.ts | 14 +- .../aztec.js/src/contract/deploy_method.ts | 31 ++-- .../src/deployment/broadcast_function.ts | 83 +++++---- .../aztec.js/src/deployment/register_class.ts | 32 ++-- .../default_multi_call_entrypoint.ts | 4 +- .../src/fee/fee_juice_payment_method.ts | 4 +- .../fee_juice_payment_method_with_claim.ts | 12 +- .../src/fee/private_fee_payment_method.ts | 12 +- .../src/fee/public_fee_payment_method.ts | 12 +- .../end-to-end/src/e2e_authwit.test.ts | 2 +- .../entrypoints/src/account_entrypoint.ts | 6 +- .../entrypoints/src/dapp_entrypoint.ts | 4 +- .../entrypoints/src/default_entrypoint.ts | 5 +- yarn-project/entrypoints/src/payload.ts | 162 ++++++++++-------- yarn-project/entrypoints/src/utils.ts | 14 +- 18 files changed, 255 insertions(+), 268 deletions(-) diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 2309fa007dbc..e14e70a80b85 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -1,7 +1,14 @@ import { type AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; -import { ExecutionPayload } from '@aztec/entrypoints/payload'; -import { computeCombinedPayloadHash } from '@aztec/entrypoints/utils'; -import { type ContractArtifact, type FunctionArtifact, getFunctionArtifactByName } from '@aztec/stdlib/abi'; +import { EntrypointExecutionPayload, ExecutionPayload } from '@aztec/entrypoints/payload'; +import { computeCombinedPayloadHash, mergeExecutionPayloads } from '@aztec/entrypoints/utils'; +import { + type ContractArtifact, + type FunctionArtifact, + FunctionCall, + FunctionSelector, + encodeArguments, + getFunctionArtifactByName, +} from '@aztec/stdlib/abi'; import type { PublicKeys } from '@aztec/stdlib/keys'; import { Contract } from '../contract/contract.js'; @@ -41,29 +48,38 @@ export class DeployAccountMethod extends DeployMethod { : feePaymentNameOrArtifact; } - protected override async getInitializeFunctionCalls(options: DeployOptions): Promise { - const calls = await super.getInitializeFunctionCalls(options); + protected override async getInitializeExecutionPayload(options: DeployOptions): Promise { + let executionPayload = await super.getInitializeExecutionPayload(options); if (options.fee && this.#feePaymentArtifact) { const { address } = await this.getInstance(); - const emptyAppPayload = await ExecutionPayload.fromAppExecution([]); + const emptyAppPayload = await EntrypointExecutionPayload.fromAppExecution([]); const fee = await this.getDefaultFeeOptions(options.fee); - const feePayload = await ExecutionPayload.fromFeeOptions(address, fee); + const feePayload = await EntrypointExecutionPayload.fromFeeOptions(address, fee); const args = [emptyAppPayload, feePayload, false]; - - const call = new ContractFunctionInteraction(this.wallet, address, this.#feePaymentArtifact, args); - - call.addAuthWitness( - await this.#authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(emptyAppPayload, feePayload)), + const entrypointFunctionCall = new FunctionCall( + this.#feePaymentArtifact.name, + address, + await FunctionSelector.fromNameAndParameters( + this.#feePaymentArtifact.name, + this.#feePaymentArtifact.parameters, + ), + this.#feePaymentArtifact.functionType, + this.#feePaymentArtifact.isStatic, + encodeArguments(this.#feePaymentArtifact, args), + this.#feePaymentArtifact.returnTypes, ); - call.addAuthWitnesses(feePayload.authWitnesses); - - call.addHashedArguments(emptyAppPayload.hashedArguments); - call.addHashedArguments(feePayload.hashedArguments); - - calls.push(call); + const entrypointPayload = new ExecutionPayload( + [entrypointFunctionCall], + [ + await this.#authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(emptyAppPayload, feePayload)), + ...feePayload.authWitnesses, + ], + [], + ); + executionPayload = mergeExecutionPayloads([executionPayload, entrypointPayload]); } - return calls; + return executionPayload; } } diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 92816b20f63f..ffbe7425a94f 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -38,11 +38,11 @@ export type SendMethodOptions = { export abstract class BaseContractInteraction { protected log = createLogger('aztecjs:contract_interaction'); - protected authWitnesses: AuthWitness[] = []; - protected hashedArguments: HashedValues[] = []; - protected capsules: Capsule[] = []; - - constructor(protected wallet: Wallet) {} + constructor( + protected wallet: Wallet, + protected authWitnesses: AuthWitness[] = [], + protected capsules: Capsule[] = [], + ) {} /** * Create a transaction execution request ready to be simulated. @@ -180,22 +180,6 @@ export abstract class BaseContractInteraction { return { gasSettings, paymentMethod }; } - /** - * Add authWitness used in this contract interaction. - * @param authWitness - authWitness used in the contract interaction. - */ - public addAuthWitness(authWitness: AuthWitness) { - this.authWitnesses.push(authWitness); - } - - /** - * Add authWitness used in this contract interaction. - * @param authWitnesses - authWitnesses used in the contract interaction. - */ - public addAuthWitnesses(authWitnesses: AuthWitness[]) { - this.authWitnesses.push(...authWitnesses); - } - /** * Return all authWitnesses added for this interaction. */ @@ -203,45 +187,6 @@ export abstract class BaseContractInteraction { return this.authWitnesses; } - /** - * Add hashedArgument used in this contract interaction. - * @param hashedArgument - hashedArgument used in the contract interaction. - */ - public addHashedArgument(hashedArgument: HashedValues) { - this.hashedArguments.push(hashedArgument); - } - - /** - * Add hashedArguments used in this contract interaction. - * @param hashedArguments - hashedArguments used in the contract interaction. - */ - public addHashedArguments(hashedArguments: HashedValues[]) { - this.hashedArguments.push(...hashedArguments); - } - - /** - * Return all hashedArguments added for this interaction. - */ - public getHashedArguments() { - return this.hashedArguments; - } - - /** - * Add data passed to the oracle calls during this contract interaction. - * @param capsule - Data passed to oracle calls. - */ - public addCapsule(capsule: Capsule) { - this.capsules.push(capsule); - } - - /** - * Add data passed to the oracle calls during this contract interaction. - * @param capsules - Data passed to oracle calls. - */ - public addCapsules(capsules: Capsule[]) { - this.capsules.push(...capsules); - } - /** * Return all capsules added for this contract interaction. */ diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index a60ce5ade4e3..7ac480fba2b7 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -120,13 +120,6 @@ export class BatchCall extends BaseContractInteraction { return [this.authWitnesses, ...this.calls.map(c => c.getAuthWitnesses())].flat(); } - /** - * Return all hashedArguments added for this interaction. - */ - public override getHashedArguments() { - return [this.hashedArguments, ...this.calls.map(c => c.getHashedArguments())].flat(); - } - /** * Return all capsules added for this interaction. */ diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index 99844eda86e9..6bb7da00989d 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -2,7 +2,7 @@ import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; -import type { TxExecutionRequest, TxProfileResult } from '@aztec/stdlib/tx'; +import type { Capsule, HashedValues, TxExecutionRequest, TxProfileResult } from '@aztec/stdlib/tx'; import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; import type { Wallet } from '../wallet/wallet.js'; @@ -48,8 +48,10 @@ export class ContractFunctionInteraction extends BaseContractInteraction { protected contractAddress: AztecAddress, protected functionDao: FunctionAbi, protected args: any[], + authWitnesses: AuthWitness[] = [], + capsules: Capsule[] = [], ) { - super(wallet); + super(wallet, authWitnesses, capsules); if (args.some(arg => arg === undefined || arg === null)) { throw new Error('All function interaction arguments must be defined and not null. Received: ' + args); } @@ -98,11 +100,11 @@ export class ContractFunctionInteraction extends BaseContractInteraction { }, ]; const { authWitnesses, capsules } = options; - return { + return new ExecutionPayload( calls, - authWitnesses: authWitnesses ?? [], - capsules: capsules ?? [], - }; + this.authWitnesses.concat(authWitnesses ?? []), + this.capsules.concat(capsules ?? []), + ); } // docs:start:simulate diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 44246a54a86e..e650678d57a7 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -94,7 +94,7 @@ export class DeployMethod extends Bas * it returns a promise for an array instead of a function call directly. */ public async request(options: DeployOptions = {}): Promise { - const deployment = await this.getDeploymentFunctionCalls(options); + const deployment = await this.getDeploymentExecutionPayload(options); // NOTE: MEGA HACK. Remove with #10007 // register the contract after generating deployment function calls in order to publicly register the class and (optioanlly) emit its bytecode @@ -107,15 +107,14 @@ export class DeployMethod extends Bas // once this tx has gone through. await this.wallet.registerContract({ artifact: this.artifact, instance: await this.getInstance(options) }); - const bootstrap = await this.getInitializeFunctionCalls(options); - - const requests = await Promise.all([...deployment, ...bootstrap].map(c => c.request())); - console.log(requests); - if (!requests.length) { + const bootstrap = await this.getInitializeExecutionPayload(options); + const exec = [deployment, bootstrap]; + const fnCalls = exec.map(exec => exec.calls).flat(); + if (!fnCalls.length) { throw new Error(`No function calls needed to deploy contract ${this.artifact.name}`); } - return mergeExecutionPayloads(requests); + return mergeExecutionPayloads(exec); } /** @@ -133,8 +132,8 @@ export class DeployMethod extends Bas * @param options - Deployment options. * @returns A function call array with potentially requests to the class registerer and instance deployer. */ - protected async getDeploymentFunctionCalls(options: DeployOptions = {}): Promise { - const calls: ContractFunctionInteraction[] = []; + protected async getDeploymentExecutionPayload(options: DeployOptions = {}): Promise { + const calls: ExecutionPayload[] = []; // Set contract instance object so it's available for populating the DeploySendTx object const instance = await this.getInstance(options); @@ -159,17 +158,17 @@ export class DeployMethod extends Bas `Creating request for registering contract class ${contractClass.id.toString()} as part of deployment for ${instance.address.toString()}`, ); const registerContractClassInteraction = await registerContractClass(this.wallet, this.artifact); - calls.push(registerContractClassInteraction); + calls.push(await registerContractClassInteraction.request()); } } // Deploy the contract via the instance deployer. if (!options.skipPublicDeployment) { const deploymentInteraction = await deployInstance(this.wallet, instance); - calls.push(deploymentInteraction); + calls.push(await deploymentInteraction.request()); } - return calls; + return mergeExecutionPayloads(calls); } /** @@ -177,8 +176,8 @@ export class DeployMethod extends Bas * @param options - Deployment options. * @returns - An array of function calls. */ - protected async getInitializeFunctionCalls(options: DeployOptions): Promise { - const calls: ContractFunctionInteraction[] = []; + protected async getInitializeExecutionPayload(options: DeployOptions): Promise { + const executionsPayloads: ExecutionPayload[] = []; if (this.constructorArtifact && !options.skipInitialization) { const { address } = await this.getInstance(options); const constructorCall = new ContractFunctionInteraction( @@ -187,9 +186,9 @@ export class DeployMethod extends Bas this.constructorArtifact, this.args, ); - calls.push(constructorCall); + executionsPayloads.push(await constructorCall.request()); } - return calls; + return mergeExecutionPayloads(executionsPayloads); } /** diff --git a/yarn-project/aztec.js/src/deployment/broadcast_function.ts b/yarn-project/aztec.js/src/deployment/broadcast_function.ts index 5cf1cdf39b99..451ca4a93a7b 100644 --- a/yarn-project/aztec.js/src/deployment/broadcast_function.ts +++ b/yarn-project/aztec.js/src/deployment/broadcast_function.ts @@ -15,7 +15,7 @@ import { } from '@aztec/stdlib/contract'; import { Capsule } from '@aztec/stdlib/tx'; -import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; +import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { getRegistererContract } from '../contract/protocol_contracts.js'; import type { Wallet } from '../wallet/index.js'; @@ -59,28 +59,34 @@ export async function broadcastPrivateFunction( const vkHash = await computeVerificationKeyHash(privateFunctionArtifact); const registerer = await getRegistererContract(wallet); - const fn = registerer.methods.broadcast_private_function( - contractClass.id, - artifactMetadataHash, - unconstrainedFunctionsArtifactTreeRoot, - privateFunctionTreeSiblingPath, - privateFunctionTreeLeafIndex, - padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT), - artifactTreeLeafIndex, - // eslint-disable-next-line camelcase - { selector, metadata_hash: functionMetadataHash, vk_hash: vkHash }, - ); - + const functionArtifact = registerer.artifact.functions.find(f => f.name === 'broadcast_private_function')!; const bytecode = bufferAsFields( privateFunctionArtifact.bytecode, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS, ); - fn.addCapsule( - new Capsule( - ProtocolContractAddress.ContractClassRegisterer, - new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), - bytecode, - ), + const fn = new ContractFunctionInteraction( + wallet, + registerer.address, + functionArtifact!, + [ + contractClass.id, + artifactMetadataHash, + unconstrainedFunctionsArtifactTreeRoot, + privateFunctionTreeSiblingPath, + privateFunctionTreeLeafIndex, + padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT), + artifactTreeLeafIndex, + // eslint-disable-next-line camelcase + { selector, metadata_hash: functionMetadataHash, vk_hash: vkHash }, + ], + [], + [ + new Capsule( + ProtocolContractAddress.ContractClassRegisterer, + new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), + bytecode, + ), + ], ); return fn; @@ -122,26 +128,33 @@ export async function broadcastUnconstrainedFunction( } = await createUnconstrainedFunctionMembershipProof(selector, artifact); const registerer = await getRegistererContract(wallet); - const fn = registerer.methods.broadcast_unconstrained_function( - contractClass.id, - artifactMetadataHash, - privateFunctionsArtifactTreeRoot, - padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT), - artifactTreeLeafIndex, - // eslint-disable-next-line camelcase - { selector, metadata_hash: functionMetadataHash }, - ); - + const functionArtifact = registerer.artifact.functions.find(f => f.name === 'broadcast_unconstrained_function'); const bytecode = bufferAsFields( unconstrainedFunctionArtifact.bytecode, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS, ); - fn.addCapsule( - new Capsule( - ProtocolContractAddress.ContractClassRegisterer, - new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), - bytecode, - ), + + const fn = new ContractFunctionInteraction( + wallet, + registerer.address, + functionArtifact!, + [ + contractClass.id, + artifactMetadataHash, + privateFunctionsArtifactTreeRoot, + padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT), + artifactTreeLeafIndex, + // eslint-disable-next-line camelcase + { selector, metadata_hash: functionMetadataHash }, + ], + [], + [ + new Capsule( + ProtocolContractAddress.ContractClassRegisterer, + new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), + bytecode, + ), + ], ); return fn; diff --git a/yarn-project/aztec.js/src/deployment/register_class.ts b/yarn-project/aztec.js/src/deployment/register_class.ts index 4cd770c00a1c..dc1b687352b7 100644 --- a/yarn-project/aztec.js/src/deployment/register_class.ts +++ b/yarn-project/aztec.js/src/deployment/register_class.ts @@ -5,7 +5,7 @@ import { type ContractArtifact, bufferAsFields } from '@aztec/stdlib/abi'; import { getContractClassFromArtifact } from '@aztec/stdlib/contract'; import { Capsule } from '@aztec/stdlib/tx'; -import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; +import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { getRegistererContract } from '../contract/protocol_contracts.js'; import type { Wallet } from '../wallet/index.js'; @@ -24,21 +24,21 @@ export async function registerContractClass( const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode } = await getContractClassFromArtifact(artifact); const registerer = await getRegistererContract(wallet); - const fn = registerer.methods.register( - artifactHash, - privateFunctionsRoot, - publicBytecodeCommitment, - emitPublicBytecode, - ); - + const functionArtifact = registerer.artifact.functions.find(f => f.name === 'register'); const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS); - fn.addCapsule( - new Capsule( - ProtocolContractAddress.ContractClassRegisterer, - new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), - encodedBytecode, - ), + const interaction = new ContractFunctionInteraction( + wallet, + registerer.address, + functionArtifact!, + [artifactHash, privateFunctionsRoot, publicBytecodeCommitment, emitPublicBytecode], + [], + [ + new Capsule( + ProtocolContractAddress.ContractClassRegisterer, + new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), + encodedBytecode, + ), + ], ); - - return fn; + return interaction; } diff --git a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts index 972f4b184875..c804de55cfd1 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts @@ -1,5 +1,5 @@ import { type EntrypointInterface, type FeeOptions } from '@aztec/entrypoints/interfaces'; -import { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { EntrypointExecutionPayload, ExecutionPayload } from '@aztec/entrypoints/payload'; import { mergeAndEncodeExecutionPayloads } from '@aztec/entrypoints/utils'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi'; @@ -18,7 +18,7 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface { async createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise { const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; - const payload = await ExecutionPayload.fromAppExecution(calls); + const payload = await EntrypointExecutionPayload.fromAppExecution(calls); const abi = this.getEntrypointAbi(); const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload])); diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts index 7d48f244836c..30f1c4febcbf 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts @@ -1,5 +1,5 @@ import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; -import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -16,7 +16,7 @@ export class FeeJuicePaymentMethod implements FeePaymentMethod { } getExecutionPayload(): Promise { - return Promise.resolve({ calls: [], authWitnesses: [], capsules: [] }); + return Promise.resolve(ExecutionPayload.empty()); } getFeePayer(): Promise { diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts index 74b8c555fdd5..516a67a6de2f 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts @@ -1,4 +1,4 @@ -import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; @@ -29,8 +29,8 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod { canonicalFeeJuice.artifact.functions.find(f => f.name === 'claim')!, ); - return { - calls: [ + return new ExecutionPayload( + [ { to: ProtocolContractAddress.FeeJuice, name: 'claim', @@ -46,8 +46,8 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod { type: FunctionType.PRIVATE, }, ], - authWitnesses: [], - capsules: [], - }; + [], + [], + ); } } diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index 2789ffabedbb..33a1a1b21c69 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -1,5 +1,5 @@ import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; -import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { Fr } from '@aztec/foundation/fields'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -94,8 +94,8 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { }, }); - return { - calls: [ + return new ExecutionPayload( + [ { name: 'fee_entrypoint_private', to: this.paymentContract, @@ -106,8 +106,8 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { returnTypes: [], }, ], - authWitnesses: [witness], - capsules: [], - }; + [witness], + [], + ); } } diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index 4c974584f5de..59549b48f601 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -1,5 +1,5 @@ import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces'; -import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { Fr } from '@aztec/foundation/fields'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -88,8 +88,8 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { true, ); - return { - calls: [ + return new ExecutionPayload( + [ ...(await setPublicAuthWitInteraction.request()).calls, { name: 'fee_entrypoint_public', @@ -101,8 +101,8 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { returnTypes: [], }, ], - authWitnesses: [], - capsules: [], - }; + [], + [], + ); } } diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index 18fe1cff37b2..9cd9bb438694 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -34,7 +34,7 @@ describe('e2e_authwit_tests', () => { describe('Private', () => { describe('arbitrary data', () => { - it.only('happy path', async () => { + it('happy path', async () => { // What are we doing here: // 1. We compute an inner hash which is here just a hash of random data // 2. We then compute the message hash, which is binding it to a "consumer" (here the "auth" contract) diff --git a/yarn-project/entrypoints/src/account_entrypoint.ts b/yarn-project/entrypoints/src/account_entrypoint.ts index 1c74c5531c38..6b56628a17dd 100644 --- a/yarn-project/entrypoints/src/account_entrypoint.ts +++ b/yarn-project/entrypoints/src/account_entrypoint.ts @@ -9,7 +9,7 @@ import { type FeeOptions, type TxExecutionOptions, } from './interfaces.js'; -import { ExecutionPayload } from './payload.js'; +import { EntrypointExecutionPayload, ExecutionPayload } from './payload.js'; import { computeCombinedPayloadHash, mergeAndEncodeExecutionPayloads, mergeExecutionPayloads } from './utils.js'; /** @@ -31,8 +31,8 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { ): Promise { const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; const { cancellable, nonce } = options; - const appPayload = await ExecutionPayload.fromAppExecution(calls, nonce); - const feePayload = await ExecutionPayload.fromFeeOptions(this.address, fee); + const appPayload = await EntrypointExecutionPayload.fromAppExecution(calls, nonce); + const feePayload = await EntrypointExecutionPayload.fromFeeOptions(this.address, fee); const abi = this.getEntrypointAbi(); const entrypointHashedArgs = await HashedValues.fromValues( diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index 288139ec50a9..1edf005d6bd0 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -11,7 +11,7 @@ import { type FeeOptions, type TxExecutionOptions, } from './interfaces.js'; -import { ExecutionPayload } from './payload.js'; +import { EntrypointExecutionPayload, ExecutionPayload } from './payload.js'; import { mergeAndEncodeExecutionPayloads } from './utils.js'; /** @@ -37,7 +37,7 @@ export class DefaultDappEntrypoint implements EntrypointInterface { throw new Error(`Expected exactly 1 function call, got ${calls.length}`); } - const payload = await ExecutionPayload.fromFunctionCalls(calls); + const payload = await EntrypointExecutionPayload.fromFunctionCalls(calls); const abi = this.getEntrypointAbi(); const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload, this.userAddress])); diff --git a/yarn-project/entrypoints/src/default_entrypoint.ts b/yarn-project/entrypoints/src/default_entrypoint.ts index a80a810ebd80..240a4dd46d06 100644 --- a/yarn-project/entrypoints/src/default_entrypoint.ts +++ b/yarn-project/entrypoints/src/default_entrypoint.ts @@ -29,14 +29,13 @@ export class DefaultEntrypoint implements EntrypointInterface { throw new Error('Public entrypoints are not allowed'); } - const entrypointHashedValues = await HashedValues.fromValues(call.args); const txContext = new TxContext(this.chainId, this.protocolVersion, fee.gasSettings); return new TxExecutionRequest( call.to, call.selector, - entrypointHashedValues.hash, + hashedArguments[0].hash, txContext, - [...hashedArguments, entrypointHashedValues], + [...hashedArguments], authWitnesses, capsules, ); diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index 7baa02aecaf8..6e0cdd9fad5b 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -4,7 +4,13 @@ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import type { Tuple } from '@aztec/foundation/serialize'; import type { FieldsOf } from '@aztec/foundation/types'; -import { FunctionCall, FunctionType } from '@aztec/stdlib/abi'; +import { + type FunctionArtifact, + FunctionCall, + FunctionSelector, + FunctionType, + encodeArguments, +} from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { Capsule, HashedValues } from '@aztec/stdlib/tx'; @@ -18,8 +24,8 @@ const APP_MAX_CALLS = 4; const FEE_MAX_CALLS = 2; /** Represents data necessary to execute a list of function calls successfully */ -export abstract class ExecutionPayload { - protected constructor( +export class ExecutionPayload { + public constructor( /** The function calls to be executed. */ public calls: FunctionCall[], /** Any transient auth witnesses needed for this execution */ @@ -28,20 +34,18 @@ export abstract class ExecutionPayload { public capsules: Capsule[], ) {} - static empty(): ExecutionPayload { - return { calls: [], authWitnesses: [], capsules: [] }; + static empty() { + return new ExecutionPayload([], [], []); } - public static async encodeCalls( - calls: FunctionCall[], - ): Promise> { + public async encode(): Promise { const hashedArguments: HashedValues[] = []; - for (const call of calls) { + for (const call of this.calls) { hashedArguments.push(await HashedValues.fromValues(call.args)); } /* eslint-disable camelcase */ - const encodedFunctionCalls: EncodedFunctionCall[] = calls.map((call, index) => ({ + const encodedFunctionCalls: EncodedFunctionCall[] = this.calls.map((call, index) => ({ args_hash: hashedArguments[index].hash, function_selector: call.selector.toField(), target_address: call.to.toField(), @@ -53,17 +57,78 @@ export abstract class ExecutionPayload { return { encodedFunctionCalls, hashedArguments, + authWitnesses: this.authWitnesses, + capsules: this.capsules, }; } +} + +export type EncodedExecutionPayload = Omit & { + encodedFunctionCalls: EncodedFunctionCall[]; + hashedArguments: HashedValues[]; +}; + +/** Represents the ExecutionPayload after encoding for the entrypint to execute */ +export abstract class EntrypointExecutionPayload implements EncodedExecutionPayload { + constructor( + public encodedFunctionCalls: EncodedFunctionCall[], + public hashedArguments: HashedValues[], + /** Any transient auth witnesses needed for this execution */ + public authWitnesses: AuthWitness[], + /** Data passed through an oracle for this execution. */ + public capsules: Capsule[], + /** The index of the generator to use for hashing */ + public generatorIndex: number, + /** The nonce for the payload, used to emit a nullifier identifying the call */ + public nonce: Fr, + ) {} + + /* eslint-disable camelcase */ + /** + * The function calls to execute. This uses snake_case naming so that it is compatible with Noir encoding + * @internal + */ + get function_calls() { + return this.encodedFunctionCalls; + } + /* eslint-enable camelcase */ + + /** + * Serializes the payload to an array of fields + * @returns The fields of the payload + */ + abstract toFields(): Fr[]; + + /** + * Hashes the payload + * @returns The hash of the payload + */ + hash() { + return poseidon2HashWithSeparator(this.toFields(), this.generatorIndex); + } + + /** Serializes the function calls to an array of fields. */ + protected functionCallsToFields() { + return this.encodedFunctionCalls.flatMap(call => [ + call.args_hash, + call.function_selector, + call.target_address, + new Fr(call.is_public), + new Fr(call.is_static), + ]); + } /** * Creates an execution payload for a dapp from a set of function calls * @param functionCalls - The function calls to execute * @returns The execution payload */ - static async fromFunctionCalls(functionCalls: FunctionCall[]) { - const { encodedFunctionCalls, hashedArguments } = await this.encodeCalls(functionCalls); - return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, [], [], 0, Fr.random()); + static async fromFunctionCalls( + functionCalls: FunctionCall[], + authWitnesses: AuthWitness[] = [], + capsules: Capsule[] = [], + ) { + return new ExecutionPayload(functionCalls, authWitnesses, capsules).encode(); } /** @@ -72,15 +137,20 @@ export abstract class ExecutionPayload { * @param nonce - The nonce for the payload, used to emit a nullifier identifying the call * @returns The execution payload */ - static async fromAppExecution(functionCalls: FunctionCall[] | Tuple, nonce = Fr.random()) { + static async fromAppExecution( + functionCalls: FunctionCall[] | Tuple, + nonce = Fr.random(), + authWitnesses: AuthWitness[] = [], + capsules: Capsule[] = [], + ) { if (functionCalls.length > APP_MAX_CALLS) { throw new Error(`Expected at most ${APP_MAX_CALLS} function calls, got ${functionCalls.length}`); } const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS); - const { encodedFunctionCalls, hashedArguments } = await this.encodeCalls(paddedCalls); + const encoded = await new ExecutionPayload(paddedCalls, authWitnesses, capsules).encode(); return new AppEntrypointPayload( - encodedFunctionCalls, - hashedArguments, + encoded.encodedFunctionCalls, + encoded.hashedArguments, [], [], GeneratorIndex.SIGNATURE_PAYLOAD, @@ -102,11 +172,11 @@ export abstract class ExecutionPayload { const feePayer = await feeOpts?.paymentMethod.getFeePayer(feeOpts?.gasSettings); const isFeePayer = !!feePayer && feePayer.equals(sender); const paddedCalls = padArrayEnd(calls, FunctionCall.empty(), FEE_MAX_CALLS); - const { encodedFunctionCalls, hashedArguments } = await this.encodeCalls(paddedCalls); + const encoded = await new ExecutionPayload(paddedCalls, authWitnesses, []).encode(); return new FeeEntrypointPayload( - encodedFunctionCalls, - hashedArguments, - authWitnesses ?? [], + encoded.encodedFunctionCalls, + encoded.hashedArguments, + encoded.authWitnesses, [], GeneratorIndex.FEE_PAYLOAD, Fr.random(), @@ -115,54 +185,8 @@ export abstract class ExecutionPayload { } } -export type EncodedExecutionPayload = Omit & { - encodedFunctionCalls: EncodedFunctionCall[]; - hashedArguments: HashedValues[]; -}; - -/** Represents the ExecutionPayload after encoding for the entrypint to execute */ -export abstract class HashableExecutionPayload implements EncodedExecutionPayload { - constructor( - public encodedFunctionCalls: EncodedFunctionCall[], - public hashedArguments: HashedValues[], - /** Any transient auth witnesses needed for this execution */ - public authWitnesses: AuthWitness[], - /** Data passed through an oracle for this execution. */ - public capsules: Capsule[], - /** The index of the generator to use for hashing */ - private generatorIndex: number, - /** The nonce for the payload, used to emit a nullifier identifying the call */ - public nonce: Fr, - ) {} - - /** - * Serializes the payload to an array of fields - * @returns The fields of the payload - */ - abstract toFields(): Fr[]; - - /** - * Hashes the payload - * @returns The hash of the payload - */ - hash() { - return poseidon2HashWithSeparator(this.toFields(), this.generatorIndex); - } - - /** Serializes the function calls to an array of fields. */ - protected functionCallsToFields() { - return this.encodedFunctionCalls.flatMap(call => [ - call.args_hash, - call.function_selector, - call.target_address, - new Fr(call.is_public), - new Fr(call.is_static), - ]); - } -} - /** Entrypoint payload for app phase execution. */ -export class AppEntrypointPayload extends HashableExecutionPayload { +export class AppEntrypointPayload extends EntrypointExecutionPayload { constructor( encodedFunctionCalls: EncodedFunctionCall[], hashedArguments: HashedValues[], @@ -180,7 +204,7 @@ export class AppEntrypointPayload extends HashableExecutionPayload { } /** Entrypoint payload for fee payment to be run during setup phase. */ -export class FeeEntrypointPayload extends HashableExecutionPayload { +export class FeeEntrypointPayload extends EntrypointExecutionPayload { #isFeePayer: boolean; constructor( diff --git a/yarn-project/entrypoints/src/utils.ts b/yarn-project/entrypoints/src/utils.ts index 6e82f9729d04..b819a31b3c4d 100644 --- a/yarn-project/entrypoints/src/utils.ts +++ b/yarn-project/entrypoints/src/utils.ts @@ -18,11 +18,7 @@ export function mergeExecutionPayloads(requests: ExecutionPayload[]): ExecutionP const calls = requests.map(r => r.calls).flat(); const combinedAuthWitnesses = requests.map(r => r.authWitnesses ?? []).flat(); const combinedCapsules = requests.map(r => r.capsules ?? []).flat(); - return { - calls, - authWitnesses: combinedAuthWitnesses, - capsules: combinedCapsules, - }; + return new ExecutionPayload(calls, combinedAuthWitnesses, combinedCapsules); } /** @@ -47,15 +43,15 @@ export async function mergeAndEncodeExecutionPayloads( await Promise.all( requests.map(async r => { if (!isEncoded(r)) { - return await ExecutionPayload.encodeCalls(r.calls); + return new ExecutionPayload(r.calls, r.authWitnesses, r.capsules).encode(); } else { - return { encodedFunctionCalls: r.encodedFunctionCalls, hashedArguments: r.hashedArguments }; + return r; } }), ) ).flat(); const encodedFunctionCalls = encoded.map(r => r.encodedFunctionCalls).flat(); - const combinedAuthWitnesses = requests + const combinedAuthWitnesses = encoded .map(r => r.authWitnesses ?? []) .flat() .concat(extraAuthWitnesses ?? []); @@ -63,7 +59,7 @@ export async function mergeAndEncodeExecutionPayloads( .map(r => r.hashedArguments ?? []) .flat() .concat(extraHashedArgs ?? []); - const combinedCapsules = requests + const combinedCapsules = encoded .map(r => r.capsules ?? []) .flat() .concat(extraCapsules ?? []); From b43c1d44a65db89c717491d2b95640b122fcb901 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 11:14:21 +0000 Subject: [PATCH 23/48] yay progress --- .../src/e2e_token_contract/transfer_to_public.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts index f688d296ffe8..715a68c794d3 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_to_public.test.ts @@ -55,7 +55,7 @@ describe('e2e_token_contract transfer_to_public', () => { const txReplay = asset .withWallet(wallets[1]) .methods.transfer_to_public(accounts[0].address, accounts[1].address, amount, nonce) - .send(); + .send({ authWitnesses: [witness] }); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); From 7c70082efc54e8a04dc07cac06407428ea6e677e Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 15:53:31 +0000 Subject: [PATCH 24/48] fixes --- .../account_manager/deploy_account_method.ts | 40 ++------- .../default_multi_call_entrypoint.ts | 8 +- .../sandbox/sponsored_fee_payment_method.ts | 12 +-- .../src/utils/sponsored_fee_payment.ts | 12 +-- .../end-to-end/src/e2e_fees/failures.test.ts | 12 +-- .../entrypoints/src/account_entrypoint.ts | 6 +- .../entrypoints/src/dapp_entrypoint.ts | 10 ++- yarn-project/entrypoints/src/payload.ts | 88 ++++++++++++++----- yarn-project/entrypoints/src/utils.ts | 13 +-- 9 files changed, 115 insertions(+), 86 deletions(-) diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index e14e70a80b85..7c0c633d5546 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -1,18 +1,10 @@ import { type AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; -import { EntrypointExecutionPayload, ExecutionPayload } from '@aztec/entrypoints/payload'; -import { computeCombinedPayloadHash, mergeExecutionPayloads } from '@aztec/entrypoints/utils'; -import { - type ContractArtifact, - type FunctionArtifact, - FunctionCall, - FunctionSelector, - encodeArguments, - getFunctionArtifactByName, -} from '@aztec/stdlib/abi'; +import { AccountDeploymentExecutionPayload, ExecutionPayload } from '@aztec/entrypoints/payload'; +import { mergeExecutionPayloads } from '@aztec/entrypoints/utils'; +import { type ContractArtifact, type FunctionArtifact, getFunctionArtifactByName } from '@aztec/stdlib/abi'; import type { PublicKeys } from '@aztec/stdlib/keys'; import { Contract } from '../contract/contract.js'; -import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; import type { Wallet } from '../wallet/wallet.js'; @@ -53,29 +45,13 @@ export class DeployAccountMethod extends DeployMethod { if (options.fee && this.#feePaymentArtifact) { const { address } = await this.getInstance(); - const emptyAppPayload = await EntrypointExecutionPayload.fromAppExecution([]); const fee = await this.getDefaultFeeOptions(options.fee); - const feePayload = await EntrypointExecutionPayload.fromFeeOptions(address, fee); - const args = [emptyAppPayload, feePayload, false]; - const entrypointFunctionCall = new FunctionCall( - this.#feePaymentArtifact.name, - address, - await FunctionSelector.fromNameAndParameters( - this.#feePaymentArtifact.name, - this.#feePaymentArtifact.parameters, - ), - this.#feePaymentArtifact.functionType, - this.#feePaymentArtifact.isStatic, - encodeArguments(this.#feePaymentArtifact, args), - this.#feePaymentArtifact.returnTypes, - ); - const entrypointPayload = new ExecutionPayload( - [entrypointFunctionCall], - [ - await this.#authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(emptyAppPayload, feePayload)), - ...feePayload.authWitnesses, - ], + const entrypointPayload = await AccountDeploymentExecutionPayload.fromAccountDeployment( [], + address, + this.#feePaymentArtifact, + fee, + this.#authWitnessProvider, ); executionPayload = mergeExecutionPayloads([executionPayload, entrypointPayload]); } diff --git a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts index c804de55cfd1..f6cf47ca86ea 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts @@ -1,5 +1,5 @@ import { type EntrypointInterface, type FeeOptions } from '@aztec/entrypoints/interfaces'; -import { EntrypointExecutionPayload, ExecutionPayload } from '@aztec/entrypoints/payload'; +import { EncodedExecutionPayloadForEntrypoint, ExecutionPayload } from '@aztec/entrypoints/payload'; import { mergeAndEncodeExecutionPayloads } from '@aztec/entrypoints/utils'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi'; @@ -18,11 +18,11 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface { async createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise { const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; - const payload = await EntrypointExecutionPayload.fromAppExecution(calls); + const encodedPayload = await EncodedExecutionPayloadForEntrypoint.fromAppExecution(calls); const abi = this.getEntrypointAbi(); - const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload])); + const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [encodedPayload])); - const encodedExecutionPayload = await mergeAndEncodeExecutionPayloads([payload], { + const encodedExecutionPayload = await mergeAndEncodeExecutionPayloads([encodedPayload], { extraHashedArgs: [entrypointHashedArgs], extraAuthWitnesses: userAuthWitnesses, extraCapsules: userCapsules, diff --git a/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts b/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts index 4fd88b3e9ad3..29485d326011 100644 --- a/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts +++ b/yarn-project/aztec/src/sandbox/sponsored_fee_payment_method.ts @@ -1,5 +1,5 @@ import type { FeePaymentMethod } from '@aztec/aztec.js'; -import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -32,8 +32,8 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod { } async getExecutionPayload(): Promise { - return { - calls: [ + return new ExecutionPayload( + [ { name: 'sponsor_unconditionally', to: this.paymentContract, @@ -44,8 +44,8 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod { returnTypes: [], }, ], - authWitnesses: [], - capsules: [], - }; + [], + [], + ); } } diff --git a/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts b/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts index e3d5a7d52d1f..f63f34a2d022 100644 --- a/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts +++ b/yarn-project/cli-wallet/src/utils/sponsored_fee_payment.ts @@ -1,5 +1,5 @@ import type { FeePaymentMethod } from '@aztec/aztec.js/fee'; -import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; @@ -15,8 +15,8 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod { } async getExecutionPayload(): Promise { - return { - calls: [ + return new ExecutionPayload( + [ { name: 'sponsor_unconditionally', to: this.paymentContract, @@ -27,8 +27,8 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod { returnTypes: [], }, ], - authWitnesses: [], - capsules: [], - }; + [], + [], + ); } } diff --git a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts index ce40d6e81dc8..81c3a67e2c52 100644 --- a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts @@ -9,7 +9,7 @@ import { PublicFeePaymentMethod, TxStatus, } from '@aztec/aztec.js'; -import type { ExecutionPayload } from '@aztec/entrypoints/payload'; +import { ExecutionPayload } from '@aztec/entrypoints/payload'; import type { FPCContract } from '@aztec/noir-contracts.js/FPC'; import type { TokenContract as BananaCoin } from '@aztec/noir-contracts.js/Token'; import { FunctionType } from '@aztec/stdlib/abi'; @@ -350,8 +350,8 @@ class BuggedSetupFeePaymentMethod extends PublicFeePaymentMethod { true, ); - return { - calls: [ + return new ExecutionPayload( + [ ...(await setPublicAuthWitInteraction.request()).calls, { name: 'fee_entrypoint_public', @@ -363,8 +363,8 @@ class BuggedSetupFeePaymentMethod extends PublicFeePaymentMethod { returnTypes: [], }, ], - authWitnesses: [], - capsules: [], - }; + [], + [], + ); } } diff --git a/yarn-project/entrypoints/src/account_entrypoint.ts b/yarn-project/entrypoints/src/account_entrypoint.ts index 6b56628a17dd..429313b4f027 100644 --- a/yarn-project/entrypoints/src/account_entrypoint.ts +++ b/yarn-project/entrypoints/src/account_entrypoint.ts @@ -9,7 +9,7 @@ import { type FeeOptions, type TxExecutionOptions, } from './interfaces.js'; -import { EntrypointExecutionPayload, ExecutionPayload } from './payload.js'; +import { EncodedExecutionPayloadForEntrypoint, ExecutionPayload } from './payload.js'; import { computeCombinedPayloadHash, mergeAndEncodeExecutionPayloads, mergeExecutionPayloads } from './utils.js'; /** @@ -31,8 +31,8 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { ): Promise { const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; const { cancellable, nonce } = options; - const appPayload = await EntrypointExecutionPayload.fromAppExecution(calls, nonce); - const feePayload = await EntrypointExecutionPayload.fromFeeOptions(this.address, fee); + const appPayload = await EncodedExecutionPayloadForEntrypoint.fromAppExecution(calls, nonce); + const feePayload = await EncodedExecutionPayloadForEntrypoint.fromFeeOptions(this.address, fee); const abi = this.getEntrypointAbi(); const entrypointHashedArgs = await HashedValues.fromValues( diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index 1edf005d6bd0..8426859a57f4 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -11,7 +11,7 @@ import { type FeeOptions, type TxExecutionOptions, } from './interfaces.js'; -import { EntrypointExecutionPayload, ExecutionPayload } from './payload.js'; +import { EncodedExecutionPayloadForEntrypoint, ExecutionPayload } from './payload.js'; import { mergeAndEncodeExecutionPayloads } from './utils.js'; /** @@ -37,10 +37,12 @@ export class DefaultDappEntrypoint implements EntrypointInterface { throw new Error(`Expected exactly 1 function call, got ${calls.length}`); } - const payload = await EntrypointExecutionPayload.fromFunctionCalls(calls); + const encodedPayload = await EncodedExecutionPayloadForEntrypoint.fromFunctionCalls(calls); const abi = this.getEntrypointAbi(); - const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload, this.userAddress])); + const entrypointHashedArgs = await HashedValues.fromValues( + encodeArguments(abi, [encodedPayload, this.userAddress]), + ); const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters); // Default msg_sender for entrypoints is now Fr.max_value rather than 0 addr (see #7190 & #7404) const innerHash = await computeInnerAuthWitHash([ @@ -57,7 +59,7 @@ export class DefaultDappEntrypoint implements EntrypointInterface { const authWitness = await this.userAuthWitnessProvider.createAuthWit(outerHash); - const executionPayload = await mergeAndEncodeExecutionPayloads([payload], { + const executionPayload = await mergeAndEncodeExecutionPayloads([encodedPayload], { extraAuthWitnesses: [authWitness, ...userAuthWitnesses], extraHashedArgs: [entrypointHashedArgs], extraCapsules: userCapsules, diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index 6e0cdd9fad5b..87e6982b58fe 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -3,7 +3,6 @@ import { padArrayEnd } from '@aztec/foundation/collection'; import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import type { Tuple } from '@aztec/foundation/serialize'; -import type { FieldsOf } from '@aztec/foundation/types'; import { type FunctionArtifact, FunctionCall, @@ -15,7 +14,8 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { Capsule, HashedValues } from '@aztec/stdlib/tx'; -import type { EncodedFunctionCall, FeeOptions } from './interfaces.js'; +import type { AuthWitnessProvider, EncodedFunctionCall, FeeOptions } from './interfaces.js'; +import { computeCombinedPayloadHash } from './utils.js'; // These must match the values defined in: // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr @@ -59,17 +59,66 @@ export class ExecutionPayload { hashedArguments, authWitnesses: this.authWitnesses, capsules: this.capsules, + function_calls: encodedFunctionCalls, }; } } +export class AccountDeploymentExecutionPayload extends ExecutionPayload { + constructor( + calls: FunctionCall[], + authWitnesses: AuthWitness[], + capsules: Capsule[], + private extraHashedArgs: HashedValues[], + ) { + super(calls, authWitnesses, capsules); + } + + static async fromAccountDeployment( + functionCalls: FunctionCall[], + address: AztecAddress, + feePaymentArtifact: FunctionArtifact, + fee: FeeOptions, + authWitnessProvider: AuthWitnessProvider, + ) { + const appPayload = await EncodedExecutionPayloadForEntrypoint.fromAppExecution(functionCalls); + const feePayload = await EncodedExecutionPayloadForEntrypoint.fromFeeOptions(address, fee); + const args = encodeArguments(feePaymentArtifact, [appPayload, feePayload, false]); + const entrypointFunctionCall = new FunctionCall( + feePaymentArtifact.name, + address, + await FunctionSelector.fromNameAndParameters(feePaymentArtifact.name, feePaymentArtifact.parameters), + feePaymentArtifact.functionType, + feePaymentArtifact.isStatic, + args, + feePaymentArtifact.returnTypes, + ); + return new AccountDeploymentExecutionPayload( + [entrypointFunctionCall], + [ + await authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(appPayload, feePayload)), + ...feePayload.authWitnesses, + ], + [], + [...appPayload.hashedArguments, ...feePayload.hashedArguments], + ); + } + + public override async encode(): Promise { + const encoded = await super.encode(); + encoded.hashedArguments.push(...this.extraHashedArgs); + return encoded; + } +} + export type EncodedExecutionPayload = Omit & { encodedFunctionCalls: EncodedFunctionCall[]; hashedArguments: HashedValues[]; + get function_calls(): EncodedFunctionCall[]; }; /** Represents the ExecutionPayload after encoding for the entrypint to execute */ -export abstract class EntrypointExecutionPayload implements EncodedExecutionPayload { +export abstract class EncodedExecutionPayloadForEntrypoint implements EncodedExecutionPayload { constructor( public encodedFunctionCalls: EncodedFunctionCall[], public hashedArguments: HashedValues[], @@ -123,12 +172,16 @@ export abstract class EntrypointExecutionPayload implements EncodedExecutionPayl * @param functionCalls - The function calls to execute * @returns The execution payload */ - static async fromFunctionCalls( - functionCalls: FunctionCall[], - authWitnesses: AuthWitness[] = [], - capsules: Capsule[] = [], - ) { - return new ExecutionPayload(functionCalls, authWitnesses, capsules).encode(); + static async fromFunctionCalls(functionCalls: FunctionCall[]) { + const encoded = await new ExecutionPayload(functionCalls, [], []).encode(); + return new EncodedAppEntrypointPayload( + encoded.encodedFunctionCalls, + encoded.hashedArguments, + [], + [], + 0, + Fr.random(), + ); } /** @@ -137,18 +190,13 @@ export abstract class EntrypointExecutionPayload implements EncodedExecutionPayl * @param nonce - The nonce for the payload, used to emit a nullifier identifying the call * @returns The execution payload */ - static async fromAppExecution( - functionCalls: FunctionCall[] | Tuple, - nonce = Fr.random(), - authWitnesses: AuthWitness[] = [], - capsules: Capsule[] = [], - ) { + static async fromAppExecution(functionCalls: FunctionCall[] | Tuple, nonce = Fr.random()) { if (functionCalls.length > APP_MAX_CALLS) { throw new Error(`Expected at most ${APP_MAX_CALLS} function calls, got ${functionCalls.length}`); } const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS); - const encoded = await new ExecutionPayload(paddedCalls, authWitnesses, capsules).encode(); - return new AppEntrypointPayload( + const encoded = await new ExecutionPayload(paddedCalls, [], []).encode(); + return new EncodedAppEntrypointPayload( encoded.encodedFunctionCalls, encoded.hashedArguments, [], @@ -173,7 +221,7 @@ export abstract class EntrypointExecutionPayload implements EncodedExecutionPayl const isFeePayer = !!feePayer && feePayer.equals(sender); const paddedCalls = padArrayEnd(calls, FunctionCall.empty(), FEE_MAX_CALLS); const encoded = await new ExecutionPayload(paddedCalls, authWitnesses, []).encode(); - return new FeeEntrypointPayload( + return new EncodedFeeEntrypointPayload( encoded.encodedFunctionCalls, encoded.hashedArguments, encoded.authWitnesses, @@ -186,7 +234,7 @@ export abstract class EntrypointExecutionPayload implements EncodedExecutionPayl } /** Entrypoint payload for app phase execution. */ -export class AppEntrypointPayload extends EntrypointExecutionPayload { +export class EncodedAppEntrypointPayload extends EncodedExecutionPayloadForEntrypoint { constructor( encodedFunctionCalls: EncodedFunctionCall[], hashedArguments: HashedValues[], @@ -204,7 +252,7 @@ export class AppEntrypointPayload extends EntrypointExecutionPayload { } /** Entrypoint payload for fee payment to be run during setup phase. */ -export class FeeEntrypointPayload extends EntrypointExecutionPayload { +export class EncodedFeeEntrypointPayload extends EncodedExecutionPayloadForEntrypoint { #isFeePayer: boolean; constructor( diff --git a/yarn-project/entrypoints/src/utils.ts b/yarn-project/entrypoints/src/utils.ts index b819a31b3c4d..686cafc72931 100644 --- a/yarn-project/entrypoints/src/utils.ts +++ b/yarn-project/entrypoints/src/utils.ts @@ -1,14 +1,16 @@ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import type { Fr } from '@aztec/foundation/fields'; +import { type FunctionCall, FunctionType } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; -import type { Capsule, HashedValues } from '@aztec/stdlib/tx'; +import { type Capsule, HashedValues } from '@aztec/stdlib/tx'; import { GeneratorIndex } from '../../constants/src/constants.gen.js'; +import type { EncodedFunctionCall } from './interfaces.js'; import { - type AppEntrypointPayload, + EncodedAppEntrypointPayload, type EncodedExecutionPayload, + EncodedFeeEntrypointPayload, ExecutionPayload, - type FeeEntrypointPayload, } from './payload.js'; /** @@ -68,6 +70,7 @@ export async function mergeAndEncodeExecutionPayloads( authWitnesses: combinedAuthWitnesses, hashedArguments, capsules: combinedCapsules, + function_calls: encodedFunctionCalls, }; } @@ -78,8 +81,8 @@ export async function mergeAndEncodeExecutionPayloads( * @returns A hash of a combined payload. */ export async function computeCombinedPayloadHash( - appPayload: AppEntrypointPayload, - feePayload: FeeEntrypointPayload, + appPayload: EncodedAppEntrypointPayload, + feePayload: EncodedFeeEntrypointPayload, ): Promise { return poseidon2HashWithSeparator( [await appPayload.hash(), await feePayload.hash()], From 5b9ad812aab98d6e2377e36f127a9b348b6fdbad Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 16:06:42 +0000 Subject: [PATCH 25/48] fmt --- .../account_manager/deploy_account_method.ts | 2 +- .../src/contract/base_contract_interaction.ts | 2 + .../aztec.js/src/contract/wait_for_proven.ts | 12 +++++ .../default_multi_call_entrypoint.ts | 2 +- yarn-project/aztec.js/src/fee/utils.ts | 3 ++ .../aztec.js/src/wallet/account_wallet.ts | 1 + yarn-project/cli-wallet/package.json | 1 + .../cli-wallet/src/cmds/add_authwit.ts | 2 +- yarn-project/cli-wallet/src/utils/accounts.ts | 2 +- yarn-project/constants/src/constants.gen.ts | 17 ++++--- .../end-to-end/src/e2e_fees/failures.test.ts | 2 - .../end-to-end/src/e2e_fees/fees_test.ts | 1 - .../src/fixtures/snapshot_manager.ts | 2 - yarn-project/entrypoints/package.json | 1 + .../entrypoints/src/account_entrypoint.ts | 9 +--- .../entrypoints/src/dapp_entrypoint.ts | 10 ++--- yarn-project/entrypoints/src/interfaces.ts | 9 +++- yarn-project/entrypoints/src/payload.ts | 44 ++++++++++++++++++- yarn-project/entrypoints/src/utils.ts | 33 +++----------- .../pxe/src/pxe_service/pxe_service.ts | 6 +-- yarn-project/yarn.lock | 2 + 21 files changed, 103 insertions(+), 60 deletions(-) diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 7c0c633d5546..7b60bd48658c 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -1,4 +1,4 @@ -import { type AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; +import type { AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; import { AccountDeploymentExecutionPayload, ExecutionPayload } from '@aztec/entrypoints/payload'; import { mergeExecutionPayloads } from '@aztec/entrypoints/utils'; import { type ContractArtifact, type FunctionArtifact, getFunctionArtifactByName } from '@aztec/stdlib/abi'; diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index ffbe7425a94f..0850275247bc 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -147,6 +147,8 @@ export abstract class BaseContractInteraction { * Return fee options based on the user opts, estimating tx gas if needed. * @param request - Request to execute for this interaction. * @param pad - Percentage to pad the suggested gas limits by, as decimal (e.g., 0.10 for 10%). + * @param executionPayload + * @param fee * @returns Fee options for the actual transaction. */ protected async getFeeOptions(executionPayload: ExecutionPayload, fee?: UserFeeOptions): Promise { diff --git a/yarn-project/aztec.js/src/contract/wait_for_proven.ts b/yarn-project/aztec.js/src/contract/wait_for_proven.ts index 76a6e28c17ed..8987ad4ad553 100644 --- a/yarn-project/aztec.js/src/contract/wait_for_proven.ts +++ b/yarn-project/aztec.js/src/contract/wait_for_proven.ts @@ -4,8 +4,17 @@ import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client'; import type { TxReceipt } from '../index.js'; import { DefaultWaitOpts } from './sent_tx.js'; +/** + * + */ export type WaitForProvenOpts = { + /** + * + */ provenTimeout?: number; + /** + * + */ interval?: number; }; @@ -14,6 +23,9 @@ export const DefaultWaitForProvenOpts: WaitForProvenOpts = { interval: DefaultWaitOpts.interval, }; +/** + * + */ export async function waitForProven(pxeOrNode: PXE | AztecNode, receipt: TxReceipt, opts?: WaitForProvenOpts) { if (!receipt.blockNumber) { throw new Error(`Cannot wait for proven: receipt of tx ${receipt.txHash} does not have a block number`); diff --git a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts index f6cf47ca86ea..8615e9aa935d 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts @@ -1,4 +1,4 @@ -import { type EntrypointInterface, type FeeOptions } from '@aztec/entrypoints/interfaces'; +import type { EntrypointInterface, FeeOptions } from '@aztec/entrypoints/interfaces'; import { EncodedExecutionPayloadForEntrypoint, ExecutionPayload } from '@aztec/entrypoints/payload'; import { mergeAndEncodeExecutionPayloads } from '@aztec/entrypoints/utils'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; diff --git a/yarn-project/aztec.js/src/fee/utils.ts b/yarn-project/aztec.js/src/fee/utils.ts index 6016040cb33f..e1a74e2929a0 100644 --- a/yarn-project/aztec.js/src/fee/utils.ts +++ b/yarn-project/aztec.js/src/fee/utils.ts @@ -7,6 +7,9 @@ import { ContractFunctionInteraction } from '../contract/contract_function_inter import type { Wallet } from '../wallet/wallet.js'; import { FeeJuicePaymentMethod } from './fee_juice_payment_method.js'; +/** + * + */ export async function simulateWithoutSignature(wallet: Wallet, contractAddress: AztecAddress, abi: FunctionAbi) { const interaction = new ContractFunctionInteraction(wallet, contractAddress, abi, []); diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index f1fe1c934905..c143423ab0b5 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -132,6 +132,7 @@ export class AccountWallet extends BaseWallet { * @param onBehalfOf - The address of the "approver" * @param intent - The consumer and inner hash or the caller and action to lookup * + * @param witness * @returns - A struct containing the validity of the authwit in private and public contexts. */ async lookupValidity( diff --git a/yarn-project/cli-wallet/package.json b/yarn-project/cli-wallet/package.json index f3631fbaa461..ef933ececcc0 100644 --- a/yarn-project/cli-wallet/package.json +++ b/yarn-project/cli-wallet/package.json @@ -68,6 +68,7 @@ "@aztec/accounts": "workspace:^", "@aztec/aztec.js": "workspace:^", "@aztec/cli": "workspace:^", + "@aztec/entrypoints": "workspace:^", "@aztec/ethereum": "workspace:^", "@aztec/foundation": "workspace:^", "@aztec/kv-store": "workspace:^", diff --git a/yarn-project/cli-wallet/src/cmds/add_authwit.ts b/yarn-project/cli-wallet/src/cmds/add_authwit.ts index 38d65ad646f9..25f2ecfae2f4 100644 --- a/yarn-project/cli-wallet/src/cmds/add_authwit.ts +++ b/yarn-project/cli-wallet/src/cmds/add_authwit.ts @@ -1,7 +1,7 @@ import type { AccountWalletWithSecretKey, AuthWitness, AztecAddress } from '@aztec/aztec.js'; import type { LogFn } from '@aztec/foundation/log'; -export async function addAuthwit( +export function addAuthwit( wallet: AccountWalletWithSecretKey, authwit: AuthWitness, authorizer: AztecAddress, diff --git a/yarn-project/cli-wallet/src/utils/accounts.ts b/yarn-project/cli-wallet/src/utils/accounts.ts index f69780557632..1b527ba6735a 100644 --- a/yarn-project/cli-wallet/src/utils/accounts.ts +++ b/yarn-project/cli-wallet/src/utils/accounts.ts @@ -1,5 +1,5 @@ import { getIdentities } from '@aztec/accounts/utils'; -import type { AccountManager, AccountWalletWithSecretKey } from '@aztec/aztec.js'; +import type { AccountManager } from '@aztec/aztec.js'; import { Fr } from '@aztec/foundation/fields'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PXE } from '@aztec/stdlib/interfaces/client'; diff --git a/yarn-project/constants/src/constants.gen.ts b/yarn-project/constants/src/constants.gen.ts index 037a0aa4e2cd..95be108b37d3 100644 --- a/yarn-project/constants/src/constants.gen.ts +++ b/yarn-project/constants/src/constants.gen.ts @@ -92,11 +92,16 @@ export const MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; export const MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 3000; export const REGISTERER_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 19; export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 12; -export const REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE = 11121068431693264234253912047066709627593769337094408533543930778360n; -export const REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE = 2889881020989534926461066592611988634597302675057895885580456197069n; -export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 24399338136397901754495080759185489776044879232766421623673792970137n; -export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 14061769416655647708490531650437236735160113654556896985372298487345n; -export const DEPLOYER_CONTRACT_INSTANCE_UPDATED_MAGIC_VALUE = 1534834688047131268740281708431107902615560100979874281215533519862n; +export const REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE = + 11121068431693264234253912047066709627593769337094408533543930778360n; +export const REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE = + 2889881020989534926461066592611988634597302675057895885580456197069n; +export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = + 24399338136397901754495080759185489776044879232766421623673792970137n; +export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = + 14061769416655647708490531650437236735160113654556896985372298487345n; +export const DEPLOYER_CONTRACT_INSTANCE_UPDATED_MAGIC_VALUE = + 1534834688047131268740281708431107902615560100979874281215533519862n; export const MAX_PROTOCOL_CONTRACTS = 7; export const CANONICAL_AUTH_REGISTRY_ADDRESS = 1; export const DEPLOYER_CONTRACT_ADDRESS = 2; @@ -411,4 +416,4 @@ export enum GeneratorIndex { SYMMETRIC_KEY_2 = 55, PUBLIC_TX_HASH = 56, PRIVATE_TX_HASH = 57, -} \ No newline at end of file +} diff --git a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts index 81c3a67e2c52..7e083a4c27a3 100644 --- a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts @@ -1,9 +1,7 @@ import { type AccountWallet, - AuthWitness, type AztecAddress, Fr, - type FunctionCall, FunctionSelector, PrivateFeePaymentMethod, PublicFeePaymentMethod, diff --git a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts index 4c5fe793b443..1c50af6734e9 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts @@ -21,7 +21,6 @@ import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice'; import { TokenContract as BananaCoin } from '@aztec/noir-contracts.js/Token'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice'; -import { computePartialAddress } from '@aztec/stdlib/contract'; import { GasSettings } from '@aztec/stdlib/gas'; import { getContract } from 'viem'; diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index 9705492207aa..08e323f00cfa 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -5,11 +5,9 @@ import { type AztecAddress, type AztecNode, BatchCall, - type Capsule, type CompleteAddress, type ContractFunctionInteraction, DefaultWaitForProvenOpts, - type FunctionCall, type Logger, type PXE, type Wallet, diff --git a/yarn-project/entrypoints/package.json b/yarn-project/entrypoints/package.json index 4be02217c0a3..a1067853c861 100644 --- a/yarn-project/entrypoints/package.json +++ b/yarn-project/entrypoints/package.json @@ -65,6 +65,7 @@ ] }, "dependencies": { + "@aztec/constants": "workspace:^", "@aztec/foundation": "workspace:^", "@aztec/protocol-contracts": "workspace:^", "@aztec/stdlib": "workspace:^", diff --git a/yarn-project/entrypoints/src/account_entrypoint.ts b/yarn-project/entrypoints/src/account_entrypoint.ts index 429313b4f027..9a54cf847f1c 100644 --- a/yarn-project/entrypoints/src/account_entrypoint.ts +++ b/yarn-project/entrypoints/src/account_entrypoint.ts @@ -3,14 +3,9 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; -import { - type AuthWitnessProvider, - type EntrypointInterface, - type FeeOptions, - type TxExecutionOptions, -} from './interfaces.js'; +import type { AuthWitnessProvider, EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js'; import { EncodedExecutionPayloadForEntrypoint, ExecutionPayload } from './payload.js'; -import { computeCombinedPayloadHash, mergeAndEncodeExecutionPayloads, mergeExecutionPayloads } from './utils.js'; +import { computeCombinedPayloadHash, mergeAndEncodeExecutionPayloads } from './utils.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index 8426859a57f4..6c02387ec681 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -5,11 +5,11 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; -import { - type AuthWitnessProvider, - type EntrypointInterface, - type FeeOptions, - type TxExecutionOptions, +import type { + AuthWitnessProvider, + EntrypointInterface, + FeeOptions, + TxExecutionOptions, } from './interfaces.js'; import { EncodedExecutionPayloadForEntrypoint, ExecutionPayload } from './payload.js'; import { mergeAndEncodeExecutionPayloads } from './utils.js'; diff --git a/yarn-project/entrypoints/src/interfaces.ts b/yarn-project/entrypoints/src/interfaces.ts index 766570a8497a..fe8055f45fbd 100644 --- a/yarn-project/entrypoints/src/interfaces.ts +++ b/yarn-project/entrypoints/src/interfaces.ts @@ -23,8 +23,13 @@ export type EncodedFunctionCall = { }; /* eslint-enable camelcase */ +/** + * General options for the tx execution. + */ export type TxExecutionOptions = { + /** Whether the transaction can be cancelled. */ cancellable?: boolean; + /** The nonce to use for the transaction. */ nonce?: Fr; }; @@ -32,7 +37,9 @@ export type TxExecutionOptions = { export interface EntrypointInterface { /** * Generates an execution request out of set of function calls. - * @param execution - The execution intents to be run. + * @param exec - The execution intents to be run. + * @param fee - The fee options for the transaction. + * @param options - Nonce and whether the transaction is cancellable. * @returns The authenticated transaction execution request. */ createTxExecutionRequest( diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index 87e6982b58fe..4e37e4c45625 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -15,7 +15,6 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { Capsule, HashedValues } from '@aztec/stdlib/tx'; import type { AuthWitnessProvider, EncodedFunctionCall, FeeOptions } from './interfaces.js'; -import { computeCombinedPayloadHash } from './utils.js'; // These must match the values defined in: // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr @@ -38,6 +37,9 @@ export class ExecutionPayload { return new ExecutionPayload([], [], []); } + /** + * Encodes the payload for execution, following Noir's convention + */ public async encode(): Promise { const hashedArguments: HashedValues[] = []; for (const call of this.calls) { @@ -52,7 +54,6 @@ export class ExecutionPayload { is_public: call.type == FunctionType.PUBLIC, is_static: call.isStatic, })); - /* eslint-enable camelcase */ return { encodedFunctionCalls, @@ -61,9 +62,17 @@ export class ExecutionPayload { capsules: this.capsules, function_calls: encodedFunctionCalls, }; + /* eslint-enable camelcase */ } } +/** + * Special handling of the Account deployment payload. Since we deploy accounts via the MultiCallEntrypoint + * and there's the option to pay for the deployment of the account itself in the same tx, we need this + * to generate the payload correctly. This is mainly due to the fact that we're calling the account contract + * entrypoint through another entrypoint (the MultiCall one) and we need to add certain precomputed hash for + * the args of the former. + */ export class AccountDeploymentExecutionPayload extends ExecutionPayload { constructor( calls: FunctionCall[], @@ -104,6 +113,9 @@ export class AccountDeploymentExecutionPayload extends ExecutionPayload { ); } + /** + * Encode using the parent's implementation, but allow the extra hashed args for the account entrypoint payload + */ public override async encode(): Promise { const encoded = await super.encode(); encoded.hashedArguments.push(...this.extraHashedArgs); @@ -111,16 +123,28 @@ export class AccountDeploymentExecutionPayload extends ExecutionPayload { } } +/** + * Representation of the encoded payload for execution + */ export type EncodedExecutionPayload = Omit & { + /** Function calls in the expected format (Noir's convention) */ encodedFunctionCalls: EncodedFunctionCall[]; + /** The hashed args for the call, ready to be injected in the execution cache */ hashedArguments: HashedValues[]; + /* eslint-disable camelcase */ + /** + * The function calls to execute. This uses snake_case naming so that it is compatible with Noir encoding + * */ get function_calls(): EncodedFunctionCall[]; + /* eslint-enable camelcase */ }; /** Represents the ExecutionPayload after encoding for the entrypint to execute */ export abstract class EncodedExecutionPayloadForEntrypoint implements EncodedExecutionPayload { constructor( + /** Function calls in the expected format (Noir's convention) */ public encodedFunctionCalls: EncodedFunctionCall[], + /** The hashed args for the call, ready to be injected in the execution cache */ public hashedArguments: HashedValues[], /** Any transient auth witnesses needed for this execution */ public authWitnesses: AuthWitness[], @@ -279,3 +303,19 @@ export class EncodedFeeEntrypointPayload extends EncodedExecutionPayloadForEntry } /* eslint-enable camelcase */ } + +/** + * Computes a hash of a combined payload. + * @param appPayload - An app payload. + * @param feePayload - A fee payload. + * @returns A hash of a combined payload. + */ +export async function computeCombinedPayloadHash( + appPayload: EncodedAppEntrypointPayload, + feePayload: EncodedFeeEntrypointPayload, +): Promise { + return poseidon2HashWithSeparator( + [await appPayload.hash(), await feePayload.hash()], + GeneratorIndex.COMBINED_PAYLOAD, + ); +} diff --git a/yarn-project/entrypoints/src/utils.ts b/yarn-project/entrypoints/src/utils.ts index 686cafc72931..5f792538f36c 100644 --- a/yarn-project/entrypoints/src/utils.ts +++ b/yarn-project/entrypoints/src/utils.ts @@ -1,17 +1,7 @@ -import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; -import type { Fr } from '@aztec/foundation/fields'; -import { type FunctionCall, FunctionType } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { type Capsule, HashedValues } from '@aztec/stdlib/tx'; -import { GeneratorIndex } from '../../constants/src/constants.gen.js'; -import type { EncodedFunctionCall } from './interfaces.js'; -import { - EncodedAppEntrypointPayload, - type EncodedExecutionPayload, - EncodedFeeEntrypointPayload, - ExecutionPayload, -} from './payload.js'; +import { type EncodedExecutionPayload, ExecutionPayload } from './payload.js'; /** * Merges an array ExecutionPayloads combining their calls, authWitnesses and capsules @@ -34,8 +24,11 @@ export async function mergeAndEncodeExecutionPayloads( extraAuthWitnesses, extraCapsules, }: { + /** Extra hashed args to be added to the resulting payload (e.g: app_payload and fee_payload args in entrypoint calls) */ extraHashedArgs?: HashedValues[]; + /** Extra authwitnesses to be added to the resulting payload */ extraAuthWitnesses?: AuthWitness[]; + /** Extra capsules to be added to the resulting payload */ extraCapsules?: Capsule[]; } = { extraAuthWitnesses: [], extraCapsules: [], extraHashedArgs: [] }, ): Promise { @@ -70,22 +63,8 @@ export async function mergeAndEncodeExecutionPayloads( authWitnesses: combinedAuthWitnesses, hashedArguments, capsules: combinedCapsules, + /* eslint-disable camelcase */ function_calls: encodedFunctionCalls, + /* eslint-enable camelcase */ }; } - -/** - * Computes a hash of a combined payload. - * @param appPayload - An app payload. - * @param feePayload - A fee payload. - * @returns A hash of a combined payload. - */ -export async function computeCombinedPayloadHash( - appPayload: EncodedAppEntrypointPayload, - feePayload: EncodedFeeEntrypointPayload, -): Promise { - return poseidon2HashWithSeparator( - [await appPayload.hash(), await feePayload.hash()], - GeneratorIndex.COMBINED_PAYLOAD, - ); -} diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 93f728a454e2..f02e1b493ca4 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -210,11 +210,11 @@ export class PXEService implements PXE { return this.node.getTxEffect(txHash); } - public async getBlockNumber(): Promise { + public getBlockNumber(): Promise { return this.node.getBlockNumber(); } - public async getProvenBlockNumber(): Promise { + public getProvenBlockNumber(): Promise { return this.node.getProvenBlockNumber(); } @@ -226,7 +226,7 @@ export class PXEService implements PXE { return this.node.getContractClassLogs(filter); } - public async getPublicStorageAt(contract: AztecAddress, slot: Fr) { + public getPublicStorageAt(contract: AztecAddress, slot: Fr) { return this.node.getPublicStorageAt('latest', contract, slot); } diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index f90e00ab704a..aad13254c6db 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -465,6 +465,7 @@ __metadata: "@aztec/accounts": "workspace:^" "@aztec/aztec.js": "workspace:^" "@aztec/cli": "workspace:^" + "@aztec/entrypoints": "workspace:^" "@aztec/ethereum": "workspace:^" "@aztec/foundation": "workspace:^" "@aztec/kv-store": "workspace:^" @@ -652,6 +653,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/entrypoints@workspace:entrypoints" dependencies: + "@aztec/constants": "workspace:^" "@aztec/foundation": "workspace:^" "@aztec/protocol-contracts": "workspace:^" "@aztec/stdlib": "workspace:^" From 1faeba97a8087e04d39d4e959b01cc018b517e0f Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 16:07:42 +0000 Subject: [PATCH 26/48] fmt --- yarn-project/cli-wallet/src/cmds/index.ts | 2 +- .../cli/src/cmds/infrastructure/setup_l2_contract.ts | 9 +-------- yarn-project/cli/src/cmds/misc/setup_contracts.ts | 1 - yarn-project/entrypoints/src/dapp_entrypoint.ts | 7 +------ yarn-project/entrypoints/src/utils.ts | 2 +- 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/yarn-project/cli-wallet/src/cmds/index.ts b/yarn-project/cli-wallet/src/cmds/index.ts index 85bf8095136e..a1162e4d7476 100644 --- a/yarn-project/cli-wallet/src/cmds/index.ts +++ b/yarn-project/cli-wallet/src/cmds/index.ts @@ -529,7 +529,7 @@ export function injectCommands( const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); const wallet = await account.getWallet(); - await addAuthwit(wallet, authwit, authorizer, log); + addAuthwit(wallet, authwit, authorizer, log); }); program diff --git a/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts b/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts index 573e9b09a981..cd5d301535c0 100644 --- a/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts +++ b/yarn-project/cli/src/cmds/infrastructure/setup_l2_contract.ts @@ -1,12 +1,5 @@ import { type InitialAccountData, deployFundedSchnorrAccounts, getInitialTestAccounts } from '@aztec/accounts/testing'; -import { - type AztecAddress, - SignerlessWallet, - type WaitForProvenOpts, - type WaitOpts, - createPXEClient, - makeFetch, -} from '@aztec/aztec.js'; +import { type AztecAddress, type WaitForProvenOpts, type WaitOpts, createPXEClient, makeFetch } from '@aztec/aztec.js'; import { jsonStringify } from '@aztec/foundation/json-rpc'; import type { LogFn } from '@aztec/foundation/log'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; diff --git a/yarn-project/cli/src/cmds/misc/setup_contracts.ts b/yarn-project/cli/src/cmds/misc/setup_contracts.ts index 5243008daf16..d7eb7afb5007 100644 --- a/yarn-project/cli/src/cmds/misc/setup_contracts.ts +++ b/yarn-project/cli/src/cmds/misc/setup_contracts.ts @@ -1,5 +1,4 @@ import { - DefaultWaitForProvenOpts, DefaultWaitOpts, type EthAddress, FeeJuicePaymentMethod, diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index 6c02387ec681..10747dd1ffad 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -5,12 +5,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; -import type { - AuthWitnessProvider, - EntrypointInterface, - FeeOptions, - TxExecutionOptions, -} from './interfaces.js'; +import type { AuthWitnessProvider, EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js'; import { EncodedExecutionPayloadForEntrypoint, ExecutionPayload } from './payload.js'; import { mergeAndEncodeExecutionPayloads } from './utils.js'; diff --git a/yarn-project/entrypoints/src/utils.ts b/yarn-project/entrypoints/src/utils.ts index 5f792538f36c..830a7e05f25b 100644 --- a/yarn-project/entrypoints/src/utils.ts +++ b/yarn-project/entrypoints/src/utils.ts @@ -36,7 +36,7 @@ export async function mergeAndEncodeExecutionPayloads( 'encodedFunctionCalls' in value; const encoded = ( await Promise.all( - requests.map(async r => { + requests.map(r => { if (!isEncoded(r)) { return new ExecutionPayload(r.calls, r.authWitnesses, r.capsules).encode(); } else { From ce6e3b92ef43dc57fdf46013c68d6566c802d8be Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 16:07:59 +0000 Subject: [PATCH 27/48] fmt --- yarn-project/cli-wallet/tsconfig.json | 3 +++ yarn-project/entrypoints/tsconfig.json | 3 +++ 2 files changed, 6 insertions(+) diff --git a/yarn-project/cli-wallet/tsconfig.json b/yarn-project/cli-wallet/tsconfig.json index f6fd6a9f2a4e..38658fefee38 100644 --- a/yarn-project/cli-wallet/tsconfig.json +++ b/yarn-project/cli-wallet/tsconfig.json @@ -15,6 +15,9 @@ { "path": "../cli" }, + { + "path": "../entrypoints" + }, { "path": "../ethereum" }, diff --git a/yarn-project/entrypoints/tsconfig.json b/yarn-project/entrypoints/tsconfig.json index f95bf43c8387..d731cf7a6a1c 100644 --- a/yarn-project/entrypoints/tsconfig.json +++ b/yarn-project/entrypoints/tsconfig.json @@ -6,6 +6,9 @@ "tsBuildInfoFile": ".tsbuildinfo" }, "references": [ + { + "path": "../constants" + }, { "path": "../foundation" }, From f4113def1b12ab0924b927158adacd4c5568f324 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 16:16:25 +0000 Subject: [PATCH 28/48] fix --- yarn-project/entrypoints/src/account_entrypoint.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/entrypoints/src/account_entrypoint.ts b/yarn-project/entrypoints/src/account_entrypoint.ts index 9a54cf847f1c..8cc3301995f2 100644 --- a/yarn-project/entrypoints/src/account_entrypoint.ts +++ b/yarn-project/entrypoints/src/account_entrypoint.ts @@ -4,8 +4,8 @@ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; import type { AuthWitnessProvider, EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js'; -import { EncodedExecutionPayloadForEntrypoint, ExecutionPayload } from './payload.js'; -import { computeCombinedPayloadHash, mergeAndEncodeExecutionPayloads } from './utils.js'; +import { EncodedExecutionPayloadForEntrypoint, ExecutionPayload, computeCombinedPayloadHash } from './payload.js'; +import { mergeAndEncodeExecutionPayloads } from './utils.js'; /** * Implementation for an entrypoint interface that follows the default entrypoint signature From 517343ab4b5d5e44c0bc5a2a89c63c38348c0891 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 18:04:56 +0000 Subject: [PATCH 29/48] fmt --- .../src/contract/base_contract_interaction.ts | 6 +++--- yarn-project/aztec.js/src/contract/batch_call.ts | 4 ++-- .../src/contract/contract_function_interaction.ts | 2 +- .../aztec.js/src/contract/deploy_proven_tx.ts | 1 - .../aztec.js/src/contract/wait_for_proven.ts | 12 ++++-------- .../aztec.js/src/fee/public_fee_payment_method.ts | 2 +- yarn-project/aztec.js/src/wallet/account_wallet.ts | 4 ++-- yarn-project/aztec/src/sandbox/sandbox.ts | 1 - yarn-project/stdlib/src/interfaces/pxe.test.ts | 1 - 9 files changed, 13 insertions(+), 20 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 0850275247bc..3fab18e642c0 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -4,7 +4,7 @@ import type { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { GasSettings } from '@aztec/stdlib/gas'; -import type { Capsule, HashedValues, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx'; +import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx'; import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; import type { Wallet } from '../wallet/wallet.js'; @@ -147,8 +147,8 @@ export abstract class BaseContractInteraction { * Return fee options based on the user opts, estimating tx gas if needed. * @param request - Request to execute for this interaction. * @param pad - Percentage to pad the suggested gas limits by, as decimal (e.g., 0.10 for 10%). - * @param executionPayload - * @param fee + * @param executionPayload - Execution payload to get the fee for + * @param fee - User-provided fee options. * @returns Fee options for the actual transaction. */ protected async getFeeOptions(executionPayload: ExecutionPayload, fee?: UserFeeOptions): Promise { diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 7ac480fba2b7..4358724cd012 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -30,10 +30,10 @@ export class BatchCall extends BaseContractInteraction { /** * Returns an execution request that represents this operation. - * @param options - An optional object containing additional configuration for the transaction. + * @param _options - (ignored) An optional object containing additional configuration for the transaction. * @returns An execution request wrapped in promise. */ - public async request(options: SendMethodOptions = {}): Promise { + public async request(_options: SendMethodOptions = {}): Promise { const requests = await this.getRequests(); return mergeExecutionPayloads(requests); } diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index 6bb7da00989d..8c1c9a8785e5 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -2,7 +2,7 @@ import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; -import type { Capsule, HashedValues, TxExecutionRequest, TxProfileResult } from '@aztec/stdlib/tx'; +import type { Capsule, TxExecutionRequest, TxProfileResult } from '@aztec/stdlib/tx'; import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; import type { Wallet } from '../wallet/wallet.js'; diff --git a/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts b/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts index 68a6ee085d7c..e19a59e35f3e 100644 --- a/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts +++ b/yarn-project/aztec.js/src/contract/deploy_proven_tx.ts @@ -1,6 +1,5 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract'; -import type { PXE } from '@aztec/stdlib/interfaces/client'; import type { Tx } from '@aztec/stdlib/tx'; import type { Wallet } from '../wallet/wallet.js'; diff --git a/yarn-project/aztec.js/src/contract/wait_for_proven.ts b/yarn-project/aztec.js/src/contract/wait_for_proven.ts index 8987ad4ad553..73f49dbe12d6 100644 --- a/yarn-project/aztec.js/src/contract/wait_for_proven.ts +++ b/yarn-project/aztec.js/src/contract/wait_for_proven.ts @@ -5,16 +5,12 @@ import type { TxReceipt } from '../index.js'; import { DefaultWaitOpts } from './sent_tx.js'; /** - * + * Options for waiting for a transaction to be proven. */ export type WaitForProvenOpts = { - /** - * - */ + /** Time to wait for the tx to be proven before timing out */ provenTimeout?: number; - /** - * - */ + /** Ellapsed time between polls to the node */ interval?: number; }; @@ -24,7 +20,7 @@ export const DefaultWaitForProvenOpts: WaitForProvenOpts = { }; /** - * + * Wait for a transaction to be proven by polling the node */ export async function waitForProven(pxeOrNode: PXE | AztecNode, receipt: TxReceipt, opts?: WaitForProvenOpts) { if (!receipt.blockNumber) { diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index 59549b48f601..89a23b75c193 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -29,7 +29,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { * The asset used to pay the fee. * @returns The asset used to pay the fee. */ - async getAsset(): Promise { + getAsset(): Promise { if (!this.assetPromise) { // We use the utility method to avoid a signature because this function could be triggered before the associated account is deployed. this.assetPromise = simulateWithoutSignature(this.wallet, this.paymentContract, { diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index c143423ab0b5..75f37c02626c 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -131,8 +131,7 @@ export class AccountWallet extends BaseWallet { * * @param onBehalfOf - The address of the "approver" * @param intent - The consumer and inner hash or the caller and action to lookup - * - * @param witness + * @param witness - The computed authentication witness to check * @returns - A struct containing the validity of the authwit in private and public contexts. */ async lookupValidity( @@ -156,6 +155,7 @@ export class AccountWallet extends BaseWallet { consumer, innerHash, ]).simulate({ authWitnesses: [witness] })) as boolean; + // eslint-disable-next-line no-empty } catch {} // check public diff --git a/yarn-project/aztec/src/sandbox/sandbox.ts b/yarn-project/aztec/src/sandbox/sandbox.ts index cf776263ec2e..c21f13b16bfd 100644 --- a/yarn-project/aztec/src/sandbox/sandbox.ts +++ b/yarn-project/aztec/src/sandbox/sandbox.ts @@ -2,7 +2,6 @@ import { getSchnorrWallet } from '@aztec/accounts/schnorr'; import { deployFundedSchnorrAccounts, getInitialTestAccounts } from '@aztec/accounts/testing'; import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; -import { SignerlessWallet } from '@aztec/aztec.js'; import { AnvilTestWatcher, EthCheatCodes } from '@aztec/aztec.js/testing'; import { type BlobSinkClientInterface, createBlobSinkClient } from '@aztec/blob-sink/client'; import { setupCanonicalL2FeeJuice } from '@aztec/cli/setup-contracts'; diff --git a/yarn-project/stdlib/src/interfaces/pxe.test.ts b/yarn-project/stdlib/src/interfaces/pxe.test.ts index 04dbcf78fb1e..e1135bdd28dc 100644 --- a/yarn-project/stdlib/src/interfaces/pxe.test.ts +++ b/yarn-project/stdlib/src/interfaces/pxe.test.ts @@ -9,7 +9,6 @@ import { SiblingPath } from '@aztec/foundation/trees'; import { jest } from '@jest/globals'; import { deepStrictEqual } from 'assert'; import omit from 'lodash.omit'; -import times from 'lodash.times'; import type { ContractArtifact } from '../abi/abi.js'; import type { AbiDecoded } from '../abi/decoder.js'; From cd12f8377aa07d21bbcecad672c57d346369006b Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 18:12:41 +0000 Subject: [PATCH 30/48] fix boxes --- boxes/boxes/react/tests/node.test.ts | 16 ++---------- boxes/boxes/vite/tests/node.test.ts | 37 +++++++++++++++------------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/boxes/boxes/react/tests/node.test.ts b/boxes/boxes/react/tests/node.test.ts index 89d4da53f0c8..af16a61dc044 100644 --- a/boxes/boxes/react/tests/node.test.ts +++ b/boxes/boxes/react/tests/node.test.ts @@ -15,11 +15,7 @@ describe('BoxReact Contract Tests', () => { accountCompleteAddress = wallet.getCompleteAddress(); const salt = Fr.random(); - contract = await BoxReactContract.deploy( - wallet, - Fr.random(), - accountCompleteAddress.address - ) + contract = await BoxReactContract.deploy(wallet, Fr.random(), accountCompleteAddress.address) .send({ contractAddressSalt: salt }) .deployed(); @@ -27,15 +23,7 @@ describe('BoxReact Contract Tests', () => { }, 60000); test('Can set a number', async () => { - logger.info(`${await wallet.getRegisteredAccounts()}`); - - await contract.methods - .setNumber( - numberToSet, - accountCompleteAddress.address - ) - .send() - .wait(); + await contract.methods.setNumber(numberToSet, accountCompleteAddress.address).send().wait(); }, 40000); test('Can read a number', async () => { diff --git a/boxes/boxes/vite/tests/node.test.ts b/boxes/boxes/vite/tests/node.test.ts index 89d4da53f0c8..bdeabc890fc9 100644 --- a/boxes/boxes/vite/tests/node.test.ts +++ b/boxes/boxes/vite/tests/node.test.ts @@ -1,10 +1,16 @@ -import { AccountWallet, CompleteAddress, Contract, Fr, createLogger } from '@aztec/aztec.js'; -import { BoxReactContract } from '../artifacts/BoxReact.js'; -import { deployerEnv } from '../src/config.js'; - -const logger = createLogger('aztec:http-pxe-client'); - -describe('BoxReact Contract Tests', () => { +import { + AccountWallet, + CompleteAddress, + Contract, + Fr, + createLogger, +} from "@aztec/aztec.js"; +import { BoxReactContract } from "../artifacts/BoxReact.js"; +import { deployerEnv } from "../src/config.js"; + +const logger = createLogger("aztec:http-pxe-client"); + +describe("BoxReact Contract Tests", () => { let wallet: AccountWallet; let contract: Contract; const numberToSet = Fr.random(); @@ -18,7 +24,7 @@ describe('BoxReact Contract Tests', () => { contract = await BoxReactContract.deploy( wallet, Fr.random(), - accountCompleteAddress.address + accountCompleteAddress.address, ) .send({ contractAddressSalt: salt }) .deployed(); @@ -26,20 +32,17 @@ describe('BoxReact Contract Tests', () => { logger.info(`L2 contract deployed at ${contract.address}`); }, 60000); - test('Can set a number', async () => { - logger.info(`${await wallet.getRegisteredAccounts()}`); - + test("Can set a number", async () => { await contract.methods - .setNumber( - numberToSet, - accountCompleteAddress.address - ) + .setNumber(numberToSet, accountCompleteAddress.address) .send() .wait(); }, 40000); - test('Can read a number', async () => { - const viewTxReceipt = await contract.methods.getNumber(accountCompleteAddress.address).simulate(); + test("Can read a number", async () => { + const viewTxReceipt = await contract.methods + .getNumber(accountCompleteAddress.address) + .simulate(); expect(numberToSet.toBigInt()).toEqual(viewTxReceipt.value); }, 40000); }); From b5c00b2b0ff29612e726120eb7bb60cd8c8a510e Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 18:26:12 +0000 Subject: [PATCH 31/48] make playground not blow up --- playground/src/components/contract/contract.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/playground/src/components/contract/contract.tsx b/playground/src/components/contract/contract.tsx index 4e22d73c309a..699dc8e54374 100644 --- a/playground/src/components/contract/contract.tsx +++ b/playground/src/components/contract/contract.tsx @@ -297,7 +297,6 @@ export function ContractComponent() { const handleAuthwitCreation = async (witness?: AuthWitness, alias?: string) => { if (witness && alias) { - await wallet.addAuthWitness(witness); await walletDB.storeAuthwitness(witness, undefined, alias); } setAuthwitFnData({ name: '', parameters: [], isPrivate: false }); From c570b578f8d01a3975e4456d202b8d7eae938ec0 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 18:45:47 +0000 Subject: [PATCH 32/48] docs --- docs/docs/developers/guides/js_apps/pay_fees.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/developers/guides/js_apps/pay_fees.md b/docs/docs/developers/guides/js_apps/pay_fees.md index 920485bff762..26ac8b24b62e 100644 --- a/docs/docs/developers/guides/js_apps/pay_fees.md +++ b/docs/docs/developers/guides/js_apps/pay_fees.md @@ -25,7 +25,7 @@ A fee paying contract (FPC) is created and nominates a token that it accepts to Functions pertaining to sending a transaction, such as `deploy` and `send`, each include a `fee` variable defined with the following (optional) parameters: -#include_code user_fee_options yarn-project/aztec.js/src/entrypoint/payload.ts javascript +#include_code user_fee_options yarn-project/entrypoints/src/interfaces.ts javascript ### Fee Payment Method From d99dabc7143b01df6a457319324ae127524e51cd Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 19:26:01 +0000 Subject: [PATCH 33/48] test pass --- yarn-project/end-to-end/src/e2e_amm.test.ts | 24 +++++++++---------- .../token_bridge_private.test.ts | 4 ++-- .../src/shared/cross_chain_test_harness.ts | 9 +++++-- .../end-to-end/src/shared/uniswap_l1_l2.ts | 4 ++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_amm.test.ts b/yarn-project/end-to-end/src/e2e_amm.test.ts index a08a90b625e5..892ca108540b 100644 --- a/yarn-project/end-to-end/src/e2e_amm.test.ts +++ b/yarn-project/end-to-end/src/e2e_amm.test.ts @@ -106,7 +106,7 @@ describe('AMM', () => { // authwits are for the full amount, since the AMM will first transfer that to itself, and later refund any excess // during public execution. const nonceForAuthwits = Fr.random(); - await liquidityProvider.createAuthWit({ + const token0Authwit = await liquidityProvider.createAuthWit({ caller: amm.address, action: token0.methods.transfer_to_public( liquidityProvider.getAddress(), @@ -115,7 +115,7 @@ describe('AMM', () => { nonceForAuthwits, ), }); - await liquidityProvider.createAuthWit({ + const token1Authwit = await liquidityProvider.createAuthWit({ caller: amm.address, action: token1.methods.transfer_to_public( liquidityProvider.getAddress(), @@ -129,7 +129,7 @@ describe('AMM', () => { .withWallet(liquidityProvider) .methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, nonceForAuthwits); await capturePrivateExecutionStepsIfEnvSet('amm-add-liquidity', addLiquidityInteraction); - await addLiquidityInteraction.send().wait(); + await addLiquidityInteraction.send({ authWitnesses: [token0Authwit, token1Authwit] }).wait(); const ammBalancesAfter = await getAmmBalances(); const lpBalancesAfter = await getWalletBalances(liquidityProvider); @@ -172,7 +172,7 @@ describe('AMM', () => { // public execution. We expect for there to be excess since our maximum amounts do not have the same balance ratio // as the pool currently holds. const nonceForAuthwits = Fr.random(); - await otherLiquidityProvider.createAuthWit({ + const token1Authwih = await otherLiquidityProvider.createAuthWit({ caller: amm.address, action: token0.methods.transfer_to_public( otherLiquidityProvider.getAddress(), @@ -181,7 +181,7 @@ describe('AMM', () => { nonceForAuthwits, ), }); - await otherLiquidityProvider.createAuthWit({ + const token2Authwit = await otherLiquidityProvider.createAuthWit({ caller: amm.address, action: token1.methods.transfer_to_public( otherLiquidityProvider.getAddress(), @@ -194,7 +194,7 @@ describe('AMM', () => { await amm .withWallet(otherLiquidityProvider) .methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, nonceForAuthwits) - .send() + .send({ authWitnesses: [token1Authwih, token2Authwit] }) .wait(); const ammBalancesAfter = await getAmmBalances(); @@ -223,7 +223,7 @@ describe('AMM', () => { // Swaps also transfer tokens into the AMM, so we provide an authwit for the full amount in. const nonceForAuthwits = Fr.random(); - await swapper.createAuthWit({ + const swapAuthwit = await swapper.createAuthWit({ caller: amm.address, action: token0.methods.transfer_to_public(swapper.getAddress(), amm.address, amountIn, nonceForAuthwits), }); @@ -239,7 +239,7 @@ describe('AMM', () => { .withWallet(swapper) .methods.swap_exact_tokens_for_tokens(token0.address, token1.address, amountIn, amountOutMin, nonceForAuthwits); await capturePrivateExecutionStepsIfEnvSet('amm-swap-exact-tokens', swapExactTokensInteraction); - await swapExactTokensInteraction.send().wait(); + await swapExactTokensInteraction.send({ authWitnesses: [swapAuthwit] }).wait(); // We know exactly how many tokens we're supposed to get because we know nobody else interacted with the AMM // before we did. @@ -265,7 +265,7 @@ describe('AMM', () => { // Swaps also transfer tokens into the AMM, so we provide an authwit for the full amount in (any change will be // later returned, though in this case there won't be any). const nonceForAuthwits = Fr.random(); - await swapper.createAuthWit({ + const swapAuthwit = await swapper.createAuthWit({ caller: amm.address, action: token1.methods.transfer_to_public(swapper.getAddress(), amm.address, amountInMax, nonceForAuthwits), }); @@ -273,7 +273,7 @@ describe('AMM', () => { await amm .withWallet(swapper) .methods.swap_tokens_for_exact_tokens(token1.address, token0.address, amountOut, amountInMax, nonceForAuthwits) - .send() + .send({ authWitnesses: [swapAuthwit] }) .wait(); // Because nobody else interacted with the AMM, we know the amount in will be the maximum (i.e. the value the @@ -297,7 +297,7 @@ describe('AMM', () => { // Because private burning requires first transfering the tokens into the AMM, we again need to provide an // authwit. const nonceForAuthwits = Fr.random(); - await otherLiquidityProvider.createAuthWit({ + const liquidityAuthwit = await otherLiquidityProvider.createAuthWit({ caller: amm.address, action: liquidityToken.methods.transfer_to_public( otherLiquidityProvider.getAddress(), @@ -315,7 +315,7 @@ describe('AMM', () => { await amm .withWallet(otherLiquidityProvider) .methods.remove_liquidity(liquidityTokenBalance, amount0Min, amount1Min, nonceForAuthwits) - .send() + .send({ authWitnesses: [liquidityAuthwit] }) .wait(); // The liquidity provider should have no remaining liquidity tokens, and should have recovered the value they diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts index 6c4158db185b..5a79848c50ac 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts @@ -74,7 +74,7 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => { // 4. Give approval to bridge to burn owner's funds: const withdrawAmount = 9n; const nonce = Fr.random(); - await user1Wallet.createAuthWit({ + const burnAuthwit = await user1Wallet.createAuthWit({ caller: l2Bridge.address, action: l2Token.methods.burn_private(ownerAddress, withdrawAmount, nonce), }); @@ -82,7 +82,7 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => { // 5. Withdraw owner's funds from L2 to L1 const l2ToL1Message = crossChainTestHarness.getL2ToL1MessageLeaf(withdrawAmount); - const l2TxReceipt = await crossChainTestHarness.withdrawPrivateFromAztecToL1(withdrawAmount, nonce); + const l2TxReceipt = await crossChainTestHarness.withdrawPrivateFromAztecToL1(withdrawAmount, nonce, burnAuthwit); await crossChainTestHarness.expectPrivateBalanceOnL2(ownerAddress, bridgeAmount - withdrawAmount); const [l2ToL1MessageIndex, siblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness( diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index d21b28d1efca..afe4f8a51c8b 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -1,6 +1,7 @@ // docs:start:cross_chain_test_harness import { type AccountWallet, + AuthWitness, type AztecAddress, type AztecNode, EthAddress, @@ -266,10 +267,14 @@ export class CrossChainTestHarness { .wait(); } - async withdrawPrivateFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO): Promise> { + async withdrawPrivateFromAztecToL1( + withdrawAmount: bigint, + nonce: Fr = Fr.ZERO, + authWitness: AuthWitness, + ): Promise> { const withdrawReceipt = await this.l2Bridge.methods .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce) - .send() + .send({ authWitnesses: [authWitness] }) .wait(); return withdrawReceipt; diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index 708516525dc2..4e2068486548 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -218,7 +218,7 @@ export const uniswapL1L2TestSuite = ( // 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf logger.info('Approving uniswap to transfer funds to public to self on my behalf'); const nonceForWETHTransferToPublicApproval = new Fr(1n); - await ownerWallet.createAuthWit({ + const transferToPublicAuhtwit = await ownerWallet.createAuthWit({ caller: uniswapL2Contract.address, action: wethCrossChainHarness.l2Token.methods.transfer_to_public( ownerAddress, @@ -244,7 +244,7 @@ export const uniswapL1L2TestSuite = ( secretHashForDepositingSwappedDai, ownerEthAddress, ) - .send() + .send({ authWitnesses: [transferToPublicAuhtwit] }) .wait(); const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)'; From 7f5aa725fa0927e4c27a42f976e68b27fe7a7cc5 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 19:47:54 +0000 Subject: [PATCH 34/48] more e2e --- .../end-to-end/src/e2e_lending_contract.test.ts | 16 ++++++++-------- .../end-to-end/src/shared/uniswap_l1_l2.ts | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts index d7740f51b5fa..5690735521bc 100644 --- a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts @@ -132,7 +132,7 @@ describe('e2e_lending_contract', () => { it('Depositing 🥸 : 💰 -> 🏦', async () => { const depositAmount = 420n; const nonce = Fr.random(); - await wallet.createAuthWit({ + const transferToPublicAuthwit = await wallet.createAuthWit({ caller: lendingContract.address, action: collateralAsset.methods.transfer_to_public( lendingAccount.address, @@ -159,14 +159,14 @@ describe('e2e_lending_contract', () => { 0n, collateralAsset.address, ) - .send() + .send({ authWitnesses: [transferToPublicAuthwit] }) .wait(); }); it('Depositing 🥸 on behalf of recipient: 💰 -> 🏦', async () => { const depositAmount = 421n; const nonce = Fr.random(); - await wallet.createAuthWit({ + const transferToPublicAuhtwit = await wallet.createAuthWit({ caller: lendingContract.address, action: collateralAsset.methods.transfer_to_public( lendingAccount.address, @@ -193,7 +193,7 @@ describe('e2e_lending_contract', () => { lendingAccount.address, collateralAsset.address, ) - .send() + .send({ authWitnesses: [transferToPublicAuhtwit] }) .wait(); }); @@ -273,7 +273,7 @@ describe('e2e_lending_contract', () => { it('Repay 🥸 : 🍌 -> 🏦', async () => { const repayAmount = 20n; const nonce = Fr.random(); - await wallet.createAuthWit({ + const burnPrivateAuthwit = await wallet.createAuthWit({ caller: lendingContract.address, action: stableCoin.methods.burn_private(lendingAccount.address, repayAmount, nonce), }); @@ -290,14 +290,14 @@ describe('e2e_lending_contract', () => { logger.info('Repay 🥸 : 🍌 -> 🏦'); await lendingContract.methods .repay_private(lendingAccount.address, repayAmount, nonce, lendingAccount.secret, 0n, stableCoin.address) - .send() + .send({ authWitnesses: [burnPrivateAuthwit] }) .wait(); }); it('Repay 🥸 on behalf of public: 🍌 -> 🏦', async () => { const repayAmount = 21n; const nonce = Fr.random(); - await wallet.createAuthWit({ + const burnPrivateAuthwit = await wallet.createAuthWit({ caller: lendingContract.address, action: stableCoin.methods.burn_private(lendingAccount.address, repayAmount, nonce), }); @@ -314,7 +314,7 @@ describe('e2e_lending_contract', () => { logger.info('Repay 🥸 on behalf of public: 🍌 -> 🏦'); await lendingContract.methods .repay_private(lendingAccount.address, repayAmount, nonce, 0n, lendingAccount.address, stableCoin.address) - .send() + .send({ authWitnesses: [burnPrivateAuthwit] }) .wait(); }); diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index 4e2068486548..937aa51c0590 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -655,7 +655,7 @@ export const uniswapL1L2TestSuite = ( // 2. owner gives uniswap approval to transfer the funds to public: logger.info('Approving uniswap to transfer funds to public to self on my behalf'); const nonceForWETHTransferToPublicApproval = new Fr(3n); - await ownerWallet.createAuthWit({ + const transferToPublicAuthwith = await ownerWallet.createAuthWit({ caller: uniswapL2Contract.address, action: wethCrossChainHarness.l2Token.methods.transfer_to_public( ownerAddress, @@ -680,7 +680,7 @@ export const uniswapL1L2TestSuite = ( Fr.random(), ownerEthAddress, ) - .prove(), + .prove({ authWitnesses: [transferToPublicAuthwith] }), ).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract'); }); @@ -803,7 +803,7 @@ export const uniswapL1L2TestSuite = ( // Owner gives uniswap approval to transfer the funds to public to self on its behalf logger.info('Approving uniswap to transfer the funds to public to self on my behalf'); const nonceForWETHTransferToPublicApproval = new Fr(4n); - await ownerWallet.createAuthWit({ + const transferToPublicAuhtwit = await ownerWallet.createAuthWit({ caller: uniswapL2Contract.address, action: wethCrossChainHarness.l2Token.methods.transfer_to_public( ownerAddress, @@ -830,7 +830,7 @@ export const uniswapL1L2TestSuite = ( secretHashForDepositingSwappedDai, ownerEthAddress, ) - .send() + .send({ authWitnesses: [transferToPublicAuhtwit] }) .wait(); const swapPrivateContent = sha256ToField([ From 7dcc93283a86811dd7b0812bcc3a4fe4169e260a Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 20:38:22 +0000 Subject: [PATCH 35/48] surrender --- .../account_manager/deploy_account_method.ts | 34 +++++++--- .../src/contract/base_contract_interaction.ts | 10 ++- .../aztec.js/src/contract/contract.test.ts | 2 +- .../contract/contract_function_interaction.ts | 6 +- .../aztec.js/src/contract/sent_tx.test.ts | 10 --- yarn-project/entrypoints/src/payload.ts | 63 ++----------------- 6 files changed, 43 insertions(+), 82 deletions(-) diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 7b60bd48658c..abec2f985e06 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -1,10 +1,16 @@ -import type { AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; -import { AccountDeploymentExecutionPayload, ExecutionPayload } from '@aztec/entrypoints/payload'; +import { type AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; +import { + EncodedAppEntrypointPayload, + EncodedFeeEntrypointPayload, + ExecutionPayload, + computeCombinedPayloadHash, +} from '@aztec/entrypoints/payload'; import { mergeExecutionPayloads } from '@aztec/entrypoints/utils'; import { type ContractArtifact, type FunctionArtifact, getFunctionArtifactByName } from '@aztec/stdlib/abi'; import type { PublicKeys } from '@aztec/stdlib/keys'; import { Contract } from '../contract/contract.js'; +import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; import type { Wallet } from '../wallet/wallet.js'; @@ -41,21 +47,31 @@ export class DeployAccountMethod extends DeployMethod { } protected override async getInitializeExecutionPayload(options: DeployOptions): Promise { - let executionPayload = await super.getInitializeExecutionPayload(options); + let exec = await super.getInitializeExecutionPayload(options); if (options.fee && this.#feePaymentArtifact) { const { address } = await this.getInstance(); + const emptyAppPayload = await EncodedAppEntrypointPayload.fromAppExecution([]); const fee = await this.getDefaultFeeOptions(options.fee); - const entrypointPayload = await AccountDeploymentExecutionPayload.fromAccountDeployment( - [], + const feePayload = await EncodedFeeEntrypointPayload.fromFeeOptions(address, fee); + const args = [emptyAppPayload, feePayload, false]; + + const call = new ContractFunctionInteraction( + this.wallet, address, this.#feePaymentArtifact, - fee, - this.#authWitnessProvider, + args, + [ + await this.#authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(emptyAppPayload, feePayload)), + ...feePayload.authWitnesses, + ], + [], + [...emptyAppPayload.hashedArguments, ...feePayload.hashedArguments], ); - executionPayload = mergeExecutionPayloads([executionPayload, entrypointPayload]); + + exec = mergeExecutionPayloads([exec, await call.request()]); } - return executionPayload; + return exec; } } diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 3fab18e642c0..54bf522d4ad6 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -4,7 +4,7 @@ import type { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { GasSettings } from '@aztec/stdlib/gas'; -import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx'; +import type { Capsule, HashedValues, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx'; import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; import type { Wallet } from '../wallet/wallet.js'; @@ -42,6 +42,7 @@ export abstract class BaseContractInteraction { protected wallet: Wallet, protected authWitnesses: AuthWitness[] = [], protected capsules: Capsule[] = [], + protected extraHashedValues: HashedValues[] = [], ) {} /** @@ -195,4 +196,11 @@ export abstract class BaseContractInteraction { public getCapsules() { return this.capsules; } + + /** + * Return all extra hashed values added for this contract interaction. + */ + public getExtraHashedValues() { + return this.extraHashedValues; + } } diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 91932c675d44..46f3ec4c6191 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -192,7 +192,7 @@ describe('Contract Class', () => { from: account.address, }); expect(wallet.simulateUnconstrained).toHaveBeenCalledTimes(1); - expect(wallet.simulateUnconstrained).toHaveBeenCalledWith('qux', [123n], contractAddress, account.address); + expect(wallet.simulateUnconstrained).toHaveBeenCalledWith('qux', [123n], contractAddress, [], account.address); expect(result).toBe(mockUnconstrainedResultValue); }); diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index 8c1c9a8785e5..9701b304b243 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -2,7 +2,7 @@ import { ExecutionPayload } from '@aztec/entrypoints/payload'; import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; -import type { Capsule, TxExecutionRequest, TxProfileResult } from '@aztec/stdlib/tx'; +import type { Capsule, HashedValues, TxExecutionRequest, TxProfileResult } from '@aztec/stdlib/tx'; import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js'; import type { Wallet } from '../wallet/wallet.js'; @@ -50,8 +50,9 @@ export class ContractFunctionInteraction extends BaseContractInteraction { protected args: any[], authWitnesses: AuthWitness[] = [], capsules: Capsule[] = [], + extraHashedValues: HashedValues[] = [], ) { - super(wallet, authWitnesses, capsules); + super(wallet, authWitnesses, capsules, extraHashedValues); if (args.some(arg => arg === undefined || arg === null)) { throw new Error('All function interaction arguments must be defined and not null. Received: ' + args); } @@ -104,6 +105,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction { calls, this.authWitnesses.concat(authWitnesses ?? []), this.capsules.concat(capsules ?? []), + this.extraHashedValues, ); } diff --git a/yarn-project/aztec.js/src/contract/sent_tx.test.ts b/yarn-project/aztec.js/src/contract/sent_tx.test.ts index 8cba15687133..da4a220bdce6 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.test.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.test.ts @@ -55,15 +55,5 @@ describe('SentTx', () => { node.getTxReceipt.mockResolvedValue({ ...txReceipt, status: TxStatus.DROPPED } as TxReceipt); await expect(sentTx.wait({ timeout: 1, interval: 0.4, ignoreDroppedReceiptsFor: 0 })).rejects.toThrow(/dropped/); }); - - it('waits for the tx to be proven', async () => { - const waitOpts = { timeout: 1, interval: 0.4, proven: true, provenTimeout: 2 }; - node.getProvenBlockNumber.mockResolvedValue(10); - await expect(sentTx.wait(waitOpts)).rejects.toThrow(/timeout/i); - - node.getProvenBlockNumber.mockResolvedValue(20); - const actual = await sentTx.wait(waitOpts); - expect(actual).toEqual(txReceipt); - }); }); }); diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index 4e37e4c45625..18b5428c4dcf 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -31,6 +31,8 @@ export class ExecutionPayload { public authWitnesses: AuthWitness[], /** Data passed through an oracle for this execution. */ public capsules: Capsule[], + /* Extra hashed values to be injected in the execution cache */ + public extraHashedValues: HashedValues[] = [], ) {} static empty() { @@ -57,7 +59,7 @@ export class ExecutionPayload { return { encodedFunctionCalls, - hashedArguments, + hashedArguments: [...hashedArguments, ...this.extraHashedValues], authWitnesses: this.authWitnesses, capsules: this.capsules, function_calls: encodedFunctionCalls, @@ -66,67 +68,10 @@ export class ExecutionPayload { } } -/** - * Special handling of the Account deployment payload. Since we deploy accounts via the MultiCallEntrypoint - * and there's the option to pay for the deployment of the account itself in the same tx, we need this - * to generate the payload correctly. This is mainly due to the fact that we're calling the account contract - * entrypoint through another entrypoint (the MultiCall one) and we need to add certain precomputed hash for - * the args of the former. - */ -export class AccountDeploymentExecutionPayload extends ExecutionPayload { - constructor( - calls: FunctionCall[], - authWitnesses: AuthWitness[], - capsules: Capsule[], - private extraHashedArgs: HashedValues[], - ) { - super(calls, authWitnesses, capsules); - } - - static async fromAccountDeployment( - functionCalls: FunctionCall[], - address: AztecAddress, - feePaymentArtifact: FunctionArtifact, - fee: FeeOptions, - authWitnessProvider: AuthWitnessProvider, - ) { - const appPayload = await EncodedExecutionPayloadForEntrypoint.fromAppExecution(functionCalls); - const feePayload = await EncodedExecutionPayloadForEntrypoint.fromFeeOptions(address, fee); - const args = encodeArguments(feePaymentArtifact, [appPayload, feePayload, false]); - const entrypointFunctionCall = new FunctionCall( - feePaymentArtifact.name, - address, - await FunctionSelector.fromNameAndParameters(feePaymentArtifact.name, feePaymentArtifact.parameters), - feePaymentArtifact.functionType, - feePaymentArtifact.isStatic, - args, - feePaymentArtifact.returnTypes, - ); - return new AccountDeploymentExecutionPayload( - [entrypointFunctionCall], - [ - await authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(appPayload, feePayload)), - ...feePayload.authWitnesses, - ], - [], - [...appPayload.hashedArguments, ...feePayload.hashedArguments], - ); - } - - /** - * Encode using the parent's implementation, but allow the extra hashed args for the account entrypoint payload - */ - public override async encode(): Promise { - const encoded = await super.encode(); - encoded.hashedArguments.push(...this.extraHashedArgs); - return encoded; - } -} - /** * Representation of the encoded payload for execution */ -export type EncodedExecutionPayload = Omit & { +export type EncodedExecutionPayload = Omit & { /** Function calls in the expected format (Noir's convention) */ encodedFunctionCalls: EncodedFunctionCall[]; /** The hashed args for the call, ready to be injected in the execution cache */ From c73190359f95b3c3a12fe9f434e46ba5e43ce044 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 17 Mar 2025 21:08:34 +0000 Subject: [PATCH 36/48] fix --- .../aztec.js/src/entrypoint/default_multi_call_entrypoint.ts | 4 ++-- yarn-project/entrypoints/src/utils.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts index 8615e9aa935d..94479349d79c 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_multi_call_entrypoint.ts @@ -17,13 +17,13 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface { ) {} async createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise { - const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [] } = exec; + const { calls, authWitnesses: userAuthWitnesses = [], capsules: userCapsules = [], extraHashedValues = [] } = exec; const encodedPayload = await EncodedExecutionPayloadForEntrypoint.fromAppExecution(calls); const abi = this.getEntrypointAbi(); const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [encodedPayload])); const encodedExecutionPayload = await mergeAndEncodeExecutionPayloads([encodedPayload], { - extraHashedArgs: [entrypointHashedArgs], + extraHashedArgs: [entrypointHashedArgs, ...extraHashedValues], extraAuthWitnesses: userAuthWitnesses, extraCapsules: userCapsules, }); diff --git a/yarn-project/entrypoints/src/utils.ts b/yarn-project/entrypoints/src/utils.ts index 830a7e05f25b..7f019efc32d3 100644 --- a/yarn-project/entrypoints/src/utils.ts +++ b/yarn-project/entrypoints/src/utils.ts @@ -10,7 +10,8 @@ export function mergeExecutionPayloads(requests: ExecutionPayload[]): ExecutionP const calls = requests.map(r => r.calls).flat(); const combinedAuthWitnesses = requests.map(r => r.authWitnesses ?? []).flat(); const combinedCapsules = requests.map(r => r.capsules ?? []).flat(); - return new ExecutionPayload(calls, combinedAuthWitnesses, combinedCapsules); + const combinedExtraHashedValues = requests.map(r => r.extraHashedValues ?? []).flat(); + return new ExecutionPayload(calls, combinedAuthWitnesses, combinedCapsules, combinedExtraHashedValues); } /** From d59097b9c838aac511343ad8a74b5d5819d4f377 Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 08:07:42 +0000 Subject: [PATCH 37/48] more fixes --- .../contract/contract_function_interaction.ts | 12 ++++- .../cli-wallet/src/cmds/add_authwit.ts | 14 ----- yarn-project/cli-wallet/src/cmds/index.ts | 53 ++++++++----------- yarn-project/cli-wallet/src/cmds/profile.ts | 5 +- yarn-project/cli-wallet/src/cmds/send.ts | 5 +- yarn-project/cli-wallet/src/cmds/simulate.ts | 6 +-- .../cli-wallet/src/utils/options/options.ts | 11 ++++ 7 files changed, 53 insertions(+), 53 deletions(-) delete mode 100644 yarn-project/cli-wallet/src/cmds/add_authwit.ts diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index 9701b304b243..c63d29ea3c35 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -20,6 +20,10 @@ export type ProfileMethodOptions = Pick & { profileMode: 'gates' | 'execution-steps' | 'full'; /** The sender's Aztec address. */ from?: AztecAddress; + /** Authwits to use in the simulation */ + authWitnesses?: AuthWitness[]; + /** Capsules to use in the simulation */ + capsules?: Capsule[]; }; /** @@ -36,6 +40,8 @@ export type SimulateMethodOptions = Pick & { skipFeeEnforcement?: boolean; /** Authwits to use in the simulation */ authWitnesses?: AuthWitness[]; + /** Capsules to use in the simulation */ + capsules?: Capsule[]; }; /** @@ -132,7 +138,8 @@ export class ContractFunctionInteraction extends BaseContractInteraction { } const fee = options.fee ?? { paymentMethod: new FeeJuicePaymentMethod(AztecAddress.ZERO) }; - const txRequest = await this.create({ fee, authWitnesses: options.authWitnesses }); + const { authWitnesses, capsules } = options; + const txRequest = await this.create({ fee, authWitnesses, capsules }); const simulatedTx = await this.wallet.simulateTx( txRequest, true /* simulatePublic */, @@ -169,8 +176,9 @@ export class ContractFunctionInteraction extends BaseContractInteraction { if (this.functionDao.functionType == FunctionType.UNCONSTRAINED) { throw new Error("Can't profile an unconstrained function."); } + const { authWitnesses, capsules, fee } = options; - const txRequest = await this.create({ fee: options.fee }); + const txRequest = await this.create({ fee, authWitnesses, capsules }); return await this.wallet.profileTx(txRequest, options.profileMode, options?.from); } } diff --git a/yarn-project/cli-wallet/src/cmds/add_authwit.ts b/yarn-project/cli-wallet/src/cmds/add_authwit.ts deleted file mode 100644 index 25f2ecfae2f4..000000000000 --- a/yarn-project/cli-wallet/src/cmds/add_authwit.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { AccountWalletWithSecretKey, AuthWitness, AztecAddress } from '@aztec/aztec.js'; -import type { LogFn } from '@aztec/foundation/log'; - -export function addAuthwit( - wallet: AccountWalletWithSecretKey, - authwit: AuthWitness, - authorizer: AztecAddress, - log: LogFn, -) { - //await wallet.addAuthWitness(authwit); - throw new Error('Not implemented'); - - log(`Added authorization witness from ${authorizer}`); -} diff --git a/yarn-project/cli-wallet/src/cmds/index.ts b/yarn-project/cli-wallet/src/cmds/index.ts index a1162e4d7476..40a231489c53 100644 --- a/yarn-project/cli-wallet/src/cmds/index.ts +++ b/yarn-project/cli-wallet/src/cmds/index.ts @@ -31,10 +31,12 @@ import { aliasedTxHashParser, artifactPathFromPromiseOrAlias, artifactPathParser, + cleanupAuthWitnesses, createAccountOption, createAliasOption, createArgsOption, createArtifactOption, + createAuthwitnessOption, createContractAddressOption, createDebugExecutionStepsDirOption, createTypeOption, @@ -262,6 +264,7 @@ export function injectCommands( .addOption( createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'), ) + .addOption(createAuthwitnessOption('Authorization witness to use for the transaction', !db, db)) .addOption(createAccountOption('Alias or address of the account to send the transaction from', !db, db)) .option('--no-wait', 'Print transaction hash without waiting for it to be mined') .option('--no-cancel', 'Do not allow the transaction to be cancelled. This makes for cheaper transactions.'); @@ -279,6 +282,7 @@ export function injectCommands( secretKey, alias, cancel, + authWitness, } = options; const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); @@ -287,6 +291,7 @@ export function injectCommands( debugLogger.info(`Using wallet with address ${wallet.getCompleteAddress().address.toString()}`); + const authWitnesses = cleanupAuthWitnesses(authWitness); const sentTx = await send( wallet, functionName, @@ -296,6 +301,7 @@ export function injectCommands( wait, cancel, await FeeOpts.fromCli(options, client, log, db), + authWitnesses, log, ); if (db && sentTx) { @@ -315,6 +321,7 @@ export function injectCommands( .addOption( createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'), ) + .addOption(createAuthwitnessOption('Authorization witness to use for the simulation', !db, db)) .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)) .action(async (functionName, _options, command) => { const { simulate } = await import('./simulate.js'); @@ -326,13 +333,15 @@ export function injectCommands( from: parsedFromAddress, rpcUrl, secretKey, + authWitness, } = options; const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); const wallet = await account.getWallet(); const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db); - await simulate(wallet, functionName, args, artifactPath, contractAddress, log); + const authWitnesses = cleanupAuthWitnesses(authWitness); + await simulate(wallet, functionName, args, artifactPath, contractAddress, authWitnesses, log); }); program @@ -347,6 +356,7 @@ export function injectCommands( .addOption( createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'), ) + .addOption(createAuthwitnessOption('Authorization witness to use for the simulation', !db, db)) .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)) .action(async (functionName, _options, command) => { const { profile } = await import('./profile.js'); @@ -359,13 +369,24 @@ export function injectCommands( rpcUrl, secretKey, debugExecutionStepsDir, + authWitness, } = options; const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); const wallet = await account.getWallet(); const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db); - await profile(wallet, functionName, args, artifactPath, contractAddress, debugExecutionStepsDir, log); + const authWitnesses = cleanupAuthWitnesses(authWitness); + await profile( + wallet, + functionName, + args, + artifactPath, + contractAddress, + debugExecutionStepsDir, + authWitnesses, + log, + ); }); program @@ -504,34 +525,6 @@ export function injectCommands( await authorizeAction(wallet, functionName, caller, args, artifactPath, contractAddress, log); }); - program - .command('add-authwit') - .description( - 'Adds an authorization witness to the provided account, granting PXE access to the notes of the authorizer so that it can be verified', - ) - .argument('', 'Authorization witness to add to the account', witness => aliasedAuthWitParser(witness, db)) - .argument('', 'Account that provides the authorization to perform the action', address => - aliasedAddressParser('accounts', address, db), - ) - .addOption(pxeOption) - .addOption( - createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)).conflicts('account'), - ) - .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)) - .addOption( - createAliasOption('Alias for the authorization witness. Used for easy reference in subsequent commands.', !db), - ) - .action(async (authwit, authorizer, _options, command) => { - const { addAuthwit } = await import('./add_authwit.js'); - const options = command.optsWithGlobals(); - const { from: parsedFromAddress, rpcUrl, secretKey } = options; - - const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); - const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); - const wallet = await account.getWallet(); - addAuthwit(wallet, authwit, authorizer, log); - }); - program .command('get-tx') .description('Gets the status of the recent txs, or a detailed view if a specific transaction hash is provided') diff --git a/yarn-project/cli-wallet/src/cmds/profile.ts b/yarn-project/cli-wallet/src/cmds/profile.ts index f4c686e87040..296a54572d8e 100644 --- a/yarn-project/cli-wallet/src/cmds/profile.ts +++ b/yarn-project/cli-wallet/src/cmds/profile.ts @@ -1,4 +1,4 @@ -import { type AccountWalletWithSecretKey, type AztecAddress, Contract } from '@aztec/aztec.js'; +import { type AccountWalletWithSecretKey, AuthWitness, type AztecAddress, Contract } from '@aztec/aztec.js'; import { prepTx } from '@aztec/cli/utils'; import type { LogFn } from '@aztec/foundation/log'; import { serializeWitness } from '@aztec/noir-noirc_abi'; @@ -53,6 +53,7 @@ export async function profile( contractArtifactPath: string, contractAddress: AztecAddress, debugOutputPath: string | undefined, + authWitnesses: AuthWitness[], log: LogFn, ) { const profileMode = debugOutputPath ? ('full' as const) : ('gates' as const); @@ -61,7 +62,7 @@ export async function profile( const contract = await Contract.at(contractAddress, contractArtifact, wallet); const call = contract.methods[functionName](...functionArgs); - const result = await call.profile({ profileMode }); + const result = await call.profile({ profileMode, authWitnesses }); printProfileResult(result, log); if (debugOutputPath) { log(`Debug output written to ${debugOutputPath} (witnesses.msgpack and acir.msgpack)`); diff --git a/yarn-project/cli-wallet/src/cmds/send.ts b/yarn-project/cli-wallet/src/cmds/send.ts index 3752b07f9ba6..3dd598d92afa 100644 --- a/yarn-project/cli-wallet/src/cmds/send.ts +++ b/yarn-project/cli-wallet/src/cmds/send.ts @@ -1,4 +1,4 @@ -import { type AccountWalletWithSecretKey, type AztecAddress, Contract, Fr } from '@aztec/aztec.js'; +import { type AccountWalletWithSecretKey, AuthWitness, type AztecAddress, Contract, Fr } from '@aztec/aztec.js'; import { prepTx } from '@aztec/cli/utils'; import type { LogFn } from '@aztec/foundation/log'; import { GasSettings } from '@aztec/stdlib/gas'; @@ -14,6 +14,7 @@ export async function send( wait: boolean, cancellable: boolean, feeOpts: IFeeOpts, + authWitnesses: AuthWitness[], log: LogFn, ) { const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log); @@ -29,7 +30,7 @@ export async function send( } const nonce = Fr.random(); - const tx = call.send({ ...(await feeOpts.toSendOpts(wallet)), nonce, cancellable }); + const tx = call.send({ ...(await feeOpts.toSendOpts(wallet)), nonce, cancellable, authWitnesses }); const txHash = await tx.getTxHash(); log(`\nTransaction hash: ${txHash.toString()}`); if (wait) { diff --git a/yarn-project/cli-wallet/src/cmds/simulate.ts b/yarn-project/cli-wallet/src/cmds/simulate.ts index 589778bb500e..ed63f4415faf 100644 --- a/yarn-project/cli-wallet/src/cmds/simulate.ts +++ b/yarn-project/cli-wallet/src/cmds/simulate.ts @@ -1,4 +1,4 @@ -import { type AccountWalletWithSecretKey, type AztecAddress, Contract } from '@aztec/aztec.js'; +import { type AccountWalletWithSecretKey, AuthWitness, type AztecAddress, Contract } from '@aztec/aztec.js'; import { prepTx } from '@aztec/cli/utils'; import type { LogFn } from '@aztec/foundation/log'; @@ -10,13 +10,13 @@ export async function simulate( functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, + authWitnesses: AuthWitness[], log: LogFn, ) { const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log); const contract = await Contract.at(contractAddress, contractArtifact, wallet); const call = contract.methods[functionName](...functionArgs); - - const result = await call.simulate(); + const result = await call.simulate({ authWitnesses }); log(format('\nSimulation result: ', result, '\n')); } diff --git a/yarn-project/cli-wallet/src/utils/options/options.ts b/yarn-project/cli-wallet/src/utils/options/options.ts index b4a6b5a2a1a6..518b432744f5 100644 --- a/yarn-project/cli-wallet/src/utils/options/options.ts +++ b/yarn-project/cli-wallet/src/utils/options/options.ts @@ -79,6 +79,12 @@ export function createAccountOption(description: string, hide: boolean, db?: Wal .argParser(address => aliasedAddressParser('accounts', address, db)); } +export function createAuthwitnessOption(description: string, hide: boolean, db?: WalletDB) { + return new Option('-w, --auth-witness ', description) + .hideHelp(hide) + .argParser(witness => aliasedAuthWitParser(witness, db)); +} + export function createTypeOption(mandatory: boolean) { return new Option('-t, --type ', 'Type of account to create') .choices(AccountTypes) @@ -173,3 +179,8 @@ async function contractArtifactFromWorkspace(pkg?: string, contractName?: string } return `${cwd}/${TARGET_DIR}/${bestMatch[0]}`; } + +export function cleanupAuthWitnesses(authWitnesses: AuthWitness | AuthWitness[]): AuthWitness[] { + const authWitnessArray = Array.isArray(authWitnesses) ? authWitnesses : [authWitnesses]; + return authWitnessArray.filter(w => w !== undefined); +} From 53e364711f757d08399d4c139877deb1e8adf78f Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 08:41:55 +0000 Subject: [PATCH 38/48] fmt --- .../src/account_manager/deploy_account_method.ts | 2 +- yarn-project/cli-wallet/src/cmds/index.ts | 1 - yarn-project/entrypoints/src/payload.ts | 10 ++-------- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index abec2f985e06..ad7349dcd49e 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -1,4 +1,4 @@ -import { type AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; +import type { AuthWitnessProvider } from '@aztec/entrypoints/interfaces'; import { EncodedAppEntrypointPayload, EncodedFeeEntrypointPayload, diff --git a/yarn-project/cli-wallet/src/cmds/index.ts b/yarn-project/cli-wallet/src/cmds/index.ts index 40a231489c53..2025297ad09e 100644 --- a/yarn-project/cli-wallet/src/cmds/index.ts +++ b/yarn-project/cli-wallet/src/cmds/index.ts @@ -26,7 +26,6 @@ import { FeeOpts, FeeOptsWithFeePayer } from '../utils/options/fees.js'; import { ARTIFACT_DESCRIPTION, aliasedAddressParser, - aliasedAuthWitParser, aliasedSecretKeyParser, aliasedTxHashParser, artifactPathFromPromiseOrAlias, diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index 18b5428c4dcf..61497aee56a0 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -3,18 +3,12 @@ import { padArrayEnd } from '@aztec/foundation/collection'; import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import type { Tuple } from '@aztec/foundation/serialize'; -import { - type FunctionArtifact, - FunctionCall, - FunctionSelector, - FunctionType, - encodeArguments, -} from '@aztec/stdlib/abi'; +import { FunctionCall, FunctionType } from '@aztec/stdlib/abi'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { Capsule, HashedValues } from '@aztec/stdlib/tx'; -import type { AuthWitnessProvider, EncodedFunctionCall, FeeOptions } from './interfaces.js'; +import type { EncodedFunctionCall, FeeOptions } from './interfaces.js'; // These must match the values defined in: // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr From a6151d35937533d7652675d1f6a1cc843ddeb6ff Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 09:01:13 +0000 Subject: [PATCH 39/48] fmt --- yarn-project/cli-wallet/src/cmds/send.ts | 2 +- yarn-project/entrypoints/src/payload.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/cli-wallet/src/cmds/send.ts b/yarn-project/cli-wallet/src/cmds/send.ts index 3dd598d92afa..f5675411a1a1 100644 --- a/yarn-project/cli-wallet/src/cmds/send.ts +++ b/yarn-project/cli-wallet/src/cmds/send.ts @@ -22,7 +22,7 @@ export async function send( const contract = await Contract.at(contractAddress, contractArtifact, wallet); const call = contract.methods[functionName](...functionArgs); - const gasLimits = await call.estimateGas({ ...(await feeOpts.toSendOpts(wallet)) }); + const gasLimits = await call.estimateGas({ ...(await feeOpts.toSendOpts(wallet)), authWitnesses }); printGasEstimates(feeOpts, gasLimits, log); if (feeOpts.estimateOnly) { diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index 61497aee56a0..3bc0a0ceab34 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -25,7 +25,7 @@ export class ExecutionPayload { public authWitnesses: AuthWitness[], /** Data passed through an oracle for this execution. */ public capsules: Capsule[], - /* Extra hashed values to be injected in the execution cache */ + /** Extra hashed values to be injected in the execution cache */ public extraHashedValues: HashedValues[] = [], ) {} From 741d3bf2651dfa746fc59179c4fae99bbd027da4 Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 10:59:41 +0000 Subject: [PATCH 40/48] fixes --- .../src/account_manager/account_manager.ts | 235 +++++++++++++++++ .../aztec.js/src/account_manager/index.ts | 237 +----------------- .../src/contract/base_contract_interaction.ts | 10 +- .../aztec.js/src/contract/batch_call.ts | 2 +- .../contract/contract_function_interaction.ts | 5 +- .../aztec.js/src/contract/deploy_method.ts | 4 +- yarn-project/cli-wallet/src/cmds/send.ts | 23 +- .../cli-wallet/src/utils/options/options.ts | 2 +- .../test/flows/private_authwit_transfer.sh | 3 +- yarn-project/cli-wallet/test/flows/profile.sh | 3 +- .../end-to-end/src/guides/up_quick_start.sh | 3 +- 11 files changed, 271 insertions(+), 256 deletions(-) create mode 100644 yarn-project/aztec.js/src/account_manager/account_manager.ts diff --git a/yarn-project/aztec.js/src/account_manager/account_manager.ts b/yarn-project/aztec.js/src/account_manager/account_manager.ts new file mode 100644 index 000000000000..33cfb0b7a805 --- /dev/null +++ b/yarn-project/aztec.js/src/account_manager/account_manager.ts @@ -0,0 +1,235 @@ +import { Fr } from '@aztec/foundation/fields'; +import { CompleteAddress, type ContractInstanceWithAddress } from '@aztec/stdlib/contract'; +import { getContractInstanceFromDeployParams } from '@aztec/stdlib/contract'; +import type { PXE } from '@aztec/stdlib/interfaces/client'; +import { deriveKeys } from '@aztec/stdlib/keys'; + +import type { AccountContract } from '../account/account_contract.js'; +import type { Salt } from '../account/index.js'; +import type { AccountInterface } from '../account/interface.js'; +import { Contract } from '../contract/contract.js'; +import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; +import { DefaultWaitOpts, type WaitOpts } from '../contract/sent_tx.js'; +import { DefaultMultiCallEntrypoint } from '../entrypoint/default_multi_call_entrypoint.js'; +import { AccountWalletWithSecretKey, SignerlessWallet, type Wallet } from '../wallet/index.js'; +import { DeployAccountMethod } from './deploy_account_method.js'; +import { DeployAccountSentTx } from './deploy_account_sent_tx.js'; + +/** + * Options to deploy an account contract. + */ +export type DeployAccountOptions = Pick< + DeployOptions, + 'fee' | 'skipClassRegistration' | 'skipPublicDeployment' | 'skipInitialization' +> & { + /** + * Wallet used for deploying the account contract. Must be funded in order to pay for the fee. + */ + deployWallet?: Wallet; +}; + +/** + * Manages a user account. Provides methods for calculating the account's address, deploying the account contract, + * and creating and registering the user wallet in the PXE Service. + */ +export class AccountManager { + private constructor( + private pxe: PXE, + private secretKey: Fr, + private accountContract: AccountContract, + private instance: ContractInstanceWithAddress, + /** + * Deployment salt for the account contract + */ + public readonly salt: Salt, + ) {} + + static async create(pxe: PXE, secretKey: Fr, accountContract: AccountContract, salt?: Salt) { + const { publicKeys } = await deriveKeys(secretKey); + salt = salt !== undefined ? new Fr(salt) : Fr.random(); + + const { constructorName, constructorArgs } = (await accountContract.getDeploymentFunctionAndArgs()) ?? { + constructorName: undefined, + constructorArgs: undefined, + }; + + const artifact = await accountContract.getContractArtifact(); + const instance = await getContractInstanceFromDeployParams(artifact, { + constructorArtifact: constructorName, + constructorArgs, + salt: salt, + publicKeys, + }); + + return new AccountManager(pxe, secretKey, accountContract, instance, salt); + } + + protected getPublicKeys() { + return this.instance.publicKeys; + } + + protected getPublicKeysHash() { + return this.getPublicKeys().hash(); + } + + /** + * Returns the entrypoint for this account as defined by its account contract. + * @returns An entrypoint. + */ + public async getAccount(): Promise { + const nodeInfo = await this.pxe.getNodeInfo(); + const completeAddress = await this.getCompleteAddress(); + return this.accountContract.getInterface(completeAddress, nodeInfo); + } + + /** + * Gets the calculated complete address associated with this account. + * Does not require the account to be deployed or registered. + * @returns The address, partial address, and encryption public key. + */ + public getCompleteAddress(): Promise { + return CompleteAddress.fromSecretKeyAndInstance(this.secretKey, this.instance); + } + + /** + * Gets the address for this given account. + * Does not require the account to be deployed or registered. + * @returns The address. + */ + public getAddress() { + return this.instance.address; + } + + /** + * Returns the contract instance definition associated with this account. + * Does not require the account to be deployed or registered. + * @returns ContractInstance instance. + */ + public getInstance(): ContractInstanceWithAddress { + return this.instance; + } + + /** + * Returns a Wallet instance associated with this account. Use it to create Contract + * instances to be interacted with from this account. + * @returns A Wallet instance. + */ + public async getWallet(): Promise { + const entrypoint = await this.getAccount(); + return new AccountWalletWithSecretKey(this.pxe, entrypoint, this.secretKey, this.salt); + } + + /** + * Registers this account in the PXE Service and returns the associated wallet. Registering + * the account on the PXE Service is required for managing private state associated with it. + * Use the returned wallet to create Contract instances to be interacted with from this account. + * @param opts - Options to wait for the account to be synched. + * @returns A Wallet instance. + */ + public async register(): Promise { + await this.pxe.registerContract({ + artifact: await this.accountContract.getContractArtifact(), + instance: this.getInstance(), + }); + + await this.pxe.registerAccount(this.secretKey, (await this.getCompleteAddress()).partialAddress); + + return this.getWallet(); + } + + /** + * Returns the pre-populated deployment method to deploy the account contract that backs this account. + * Typically you will not need this method and can call `deploy` directly. Use this for having finer + * grained control on when to create, simulate, and send the deployment tx. + * @param deployWallet - Wallet used for deploying the account contract. + * @returns A DeployMethod instance that deploys this account contract. + */ + public async getDeployMethod(deployWallet?: Wallet) { + const artifact = await this.accountContract.getContractArtifact(); + + if (!(await this.isDeployable())) { + throw new Error(`Account contract ${artifact.name} does not require deployment.`); + } + + const completeAddress = await this.getCompleteAddress(); + + await this.pxe.registerAccount(this.secretKey, completeAddress.partialAddress); + + const { constructorName, constructorArgs } = (await this.accountContract.getDeploymentFunctionAndArgs()) ?? { + constructorName: undefined, + constructorArgs: undefined, + }; + + if (deployWallet) { + // If deploying using an existing wallet/account, treat it like regular contract deployment. + const thisWallet = await this.getWallet(); + return new DeployMethod( + this.getPublicKeys(), + deployWallet, + artifact, + address => Contract.at(address, artifact, thisWallet), + constructorArgs, + constructorName, + ); + } + + const { l1ChainId: chainId, protocolVersion } = await this.pxe.getNodeInfo(); + // We use a signerless wallet with the multi call entrypoint in order to make multiple calls in one go. + // If we used getWallet, the deployment would get routed via the account contract entrypoint + // and it can't be used unless the contract is initialized. + const wallet = new SignerlessWallet(this.pxe, new DefaultMultiCallEntrypoint(chainId, protocolVersion)); + + return new DeployAccountMethod( + this.accountContract.getAuthWitnessProvider(completeAddress), + this.getPublicKeys(), + wallet, + artifact, + constructorArgs, + constructorName, + 'entrypoint', + ); + } + + /** + * Deploys the account contract that backs this account. + * Does not register the associated class nor publicly deploy the instance by default. + * Uses the salt provided in the constructor or a randomly generated one. + * Registers the account in the PXE Service before deploying the contract. + * @param opts - Fee options to be used for the deployment. + * @returns A SentTx object that can be waited to get the associated Wallet. + */ + public deploy(opts?: DeployAccountOptions): DeployAccountSentTx { + const sentTx = this.getDeployMethod(opts?.deployWallet) + .then(deployMethod => + deployMethod.send({ + contractAddressSalt: new Fr(this.salt), + skipClassRegistration: opts?.skipClassRegistration ?? true, + skipPublicDeployment: opts?.skipPublicDeployment ?? true, + skipInitialization: opts?.skipInitialization ?? false, + universalDeploy: true, + fee: opts?.fee, + }), + ) + .then(tx => tx.getTxHash()); + return new DeployAccountSentTx(this.pxe, sentTx, this.getWallet()); + } + + /** + * Deploys the account contract that backs this account if needed and awaits the tx to be mined. + * Uses the salt provided in the constructor or a randomly generated one. If no initialization + * is required it skips the transaction, and only registers the account in the PXE Service. + * @param opts - Options to wait for the tx to be mined. + * @returns A Wallet instance. + */ + public async waitSetup(opts: DeployAccountOptions & WaitOpts = DefaultWaitOpts): Promise { + await ((await this.isDeployable()) ? this.deploy(opts).wait(opts) : this.register()); + return this.getWallet(); + } + + /** + * Returns whether this account contract has a constructor and needs deployment. + */ + public async isDeployable() { + return (await this.accountContract.getDeploymentFunctionAndArgs()) !== undefined; + } +} diff --git a/yarn-project/aztec.js/src/account_manager/index.ts b/yarn-project/aztec.js/src/account_manager/index.ts index 5b95eee56b2a..07441ad79fc9 100644 --- a/yarn-project/aztec.js/src/account_manager/index.ts +++ b/yarn-project/aztec.js/src/account_manager/index.ts @@ -1,238 +1,3 @@ -import { Fr } from '@aztec/foundation/fields'; -import { CompleteAddress, type ContractInstanceWithAddress } from '@aztec/stdlib/contract'; -import { getContractInstanceFromDeployParams } from '@aztec/stdlib/contract'; -import type { PXE } from '@aztec/stdlib/interfaces/client'; -import { deriveKeys } from '@aztec/stdlib/keys'; - -import type { AccountContract } from '../account/account_contract.js'; -import type { Salt } from '../account/index.js'; -import type { AccountInterface } from '../account/interface.js'; -import { Contract } from '../contract/contract.js'; -import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; -import { DefaultWaitOpts, type WaitOpts } from '../contract/sent_tx.js'; -import { DefaultMultiCallEntrypoint } from '../entrypoint/default_multi_call_entrypoint.js'; -import { AccountWalletWithSecretKey, SignerlessWallet, type Wallet } from '../wallet/index.js'; -import { DeployAccountMethod } from './deploy_account_method.js'; -import { DeployAccountSentTx } from './deploy_account_sent_tx.js'; - -/** - * Options to deploy an account contract. - */ -export type DeployAccountOptions = Pick< - DeployOptions, - 'fee' | 'skipClassRegistration' | 'skipPublicDeployment' | 'skipInitialization' -> & { - /** - * Wallet used for deploying the account contract. Must be funded in order to pay for the fee. - */ - deployWallet?: Wallet; -}; - -/** - * Manages a user account. Provides methods for calculating the account's address, deploying the account contract, - * and creating and registering the user wallet in the PXE Service. - */ -export class AccountManager { - private constructor( - private pxe: PXE, - private secretKey: Fr, - private accountContract: AccountContract, - private instance: ContractInstanceWithAddress, - /** - * Deployment salt for the account contract - */ - public readonly salt: Salt, - ) {} - - static async create(pxe: PXE, secretKey: Fr, accountContract: AccountContract, salt?: Salt) { - const { publicKeys } = await deriveKeys(secretKey); - salt = salt !== undefined ? new Fr(salt) : Fr.random(); - - const { constructorName, constructorArgs } = (await accountContract.getDeploymentFunctionAndArgs()) ?? { - constructorName: undefined, - constructorArgs: undefined, - }; - - const artifact = await accountContract.getContractArtifact(); - const instance = await getContractInstanceFromDeployParams(artifact, { - constructorArtifact: constructorName, - constructorArgs, - salt: salt, - publicKeys, - }); - - return new AccountManager(pxe, secretKey, accountContract, instance, salt); - } - - protected getPublicKeys() { - return this.instance.publicKeys; - } - - protected getPublicKeysHash() { - return this.getPublicKeys().hash(); - } - - /** - * Returns the entrypoint for this account as defined by its account contract. - * @returns An entrypoint. - */ - public async getAccount(): Promise { - const nodeInfo = await this.pxe.getNodeInfo(); - const completeAddress = await this.getCompleteAddress(); - return this.accountContract.getInterface(completeAddress, nodeInfo); - } - - /** - * Gets the calculated complete address associated with this account. - * Does not require the account to be deployed or registered. - * @returns The address, partial address, and encryption public key. - */ - public getCompleteAddress(): Promise { - return CompleteAddress.fromSecretKeyAndInstance(this.secretKey, this.instance); - } - - /** - * Gets the address for this given account. - * Does not require the account to be deployed or registered. - * @returns The address. - */ - public getAddress() { - return this.instance.address; - } - - /** - * Returns the contract instance definition associated with this account. - * Does not require the account to be deployed or registered. - * @returns ContractInstance instance. - */ - public getInstance(): ContractInstanceWithAddress { - return this.instance; - } - - /** - * Returns a Wallet instance associated with this account. Use it to create Contract - * instances to be interacted with from this account. - * @returns A Wallet instance. - */ - public async getWallet(): Promise { - const entrypoint = await this.getAccount(); - return new AccountWalletWithSecretKey(this.pxe, entrypoint, this.secretKey, this.salt); - } - - /** - * Registers this account in the PXE Service and returns the associated wallet. Registering - * the account on the PXE Service is required for managing private state associated with it. - * Use the returned wallet to create Contract instances to be interacted with from this account. - * @param opts - Options to wait for the account to be synched. - * @returns A Wallet instance. - */ - public async register(): Promise { - await this.pxe.registerContract({ - artifact: await this.accountContract.getContractArtifact(), - instance: this.getInstance(), - }); - - await this.pxe.registerAccount(this.secretKey, (await this.getCompleteAddress()).partialAddress); - - return this.getWallet(); - } - - /** - * Returns the pre-populated deployment method to deploy the account contract that backs this account. - * Typically you will not need this method and can call `deploy` directly. Use this for having finer - * grained control on when to create, simulate, and send the deployment tx. - * @param deployWallet - Wallet used for deploying the account contract. - * @returns A DeployMethod instance that deploys this account contract. - */ - public async getDeployMethod(deployWallet?: Wallet) { - const artifact = await this.accountContract.getContractArtifact(); - - if (!(await this.isDeployable())) { - throw new Error(`Account contract ${artifact.name} does not require deployment.`); - } - - const completeAddress = await this.getCompleteAddress(); - - await this.pxe.registerAccount(this.secretKey, completeAddress.partialAddress); - - const { constructorName, constructorArgs } = (await this.accountContract.getDeploymentFunctionAndArgs()) ?? { - constructorName: undefined, - constructorArgs: undefined, - }; - - if (deployWallet) { - // If deploying using an existing wallet/account, treat it like regular contract deployment. - const thisWallet = await this.getWallet(); - return new DeployMethod( - this.getPublicKeys(), - deployWallet, - artifact, - address => Contract.at(address, artifact, thisWallet), - constructorArgs, - constructorName, - ); - } - - const { l1ChainId: chainId, protocolVersion } = await this.pxe.getNodeInfo(); - // We use a signerless wallet with the multi call entrypoint in order to make multiple calls in one go. - // If we used getWallet, the deployment would get routed via the account contract entrypoint - // and it can't be used unless the contract is initialized. - const wallet = new SignerlessWallet(this.pxe, new DefaultMultiCallEntrypoint(chainId, protocolVersion)); - - return new DeployAccountMethod( - this.accountContract.getAuthWitnessProvider(completeAddress), - this.getPublicKeys(), - wallet, - artifact, - constructorArgs, - constructorName, - 'entrypoint', - ); - } - - /** - * Deploys the account contract that backs this account. - * Does not register the associated class nor publicly deploy the instance by default. - * Uses the salt provided in the constructor or a randomly generated one. - * Registers the account in the PXE Service before deploying the contract. - * @param opts - Fee options to be used for the deployment. - * @returns A SentTx object that can be waited to get the associated Wallet. - */ - public deploy(opts?: DeployAccountOptions): DeployAccountSentTx { - const sentTx = this.getDeployMethod(opts?.deployWallet) - .then(deployMethod => - deployMethod.send({ - contractAddressSalt: new Fr(this.salt), - skipClassRegistration: opts?.skipClassRegistration ?? true, - skipPublicDeployment: opts?.skipPublicDeployment ?? true, - skipInitialization: opts?.skipInitialization ?? false, - universalDeploy: true, - fee: opts?.fee, - }), - ) - .then(tx => tx.getTxHash()); - return new DeployAccountSentTx(this.pxe, sentTx, this.getWallet()); - } - - /** - * Deploys the account contract that backs this account if needed and awaits the tx to be mined. - * Uses the salt provided in the constructor or a randomly generated one. If no initialization - * is required it skips the transaction, and only registers the account in the PXE Service. - * @param opts - Options to wait for the tx to be mined. - * @returns A Wallet instance. - */ - public async waitSetup(opts: DeployAccountOptions & WaitOpts = DefaultWaitOpts): Promise { - await ((await this.isDeployable()) ? this.deploy(opts).wait(opts) : this.register()); - return this.getWallet(); - } - - /** - * Returns whether this account contract has a constructor and needs deployment. - */ - public async isDeployable() { - return (await this.accountContract.getDeploymentFunctionAndArgs()) !== undefined; - } -} - +export { AccountManager, type DeployAccountOptions } from './account_manager.js'; export { DeployAccountMethod } from './deploy_account_method.js'; export { type DeployAccountTxReceipt, DeployAccountSentTx } from './deploy_account_sent_tx.js'; diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 54bf522d4ad6..1b0a98253561 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -1,4 +1,4 @@ -import type { FeeOptions, UserFeeOptions } from '@aztec/entrypoints/interfaces'; +import type { FeeOptions, TxExecutionOptions, UserFeeOptions } from '@aztec/entrypoints/interfaces'; import type { ExecutionPayload } from '@aztec/entrypoints/payload'; import type { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; @@ -152,7 +152,11 @@ export abstract class BaseContractInteraction { * @param fee - User-provided fee options. * @returns Fee options for the actual transaction. */ - protected async getFeeOptions(executionPayload: ExecutionPayload, fee?: UserFeeOptions): Promise { + protected async getFeeOptions( + executionPayload: ExecutionPayload, + fee?: UserFeeOptions, + options?: TxExecutionOptions, + ): Promise { // docs:end:getFeeOptions const defaultFeeOptions = await this.getDefaultFeeOptions(fee); const paymentMethod = defaultFeeOptions.paymentMethod; @@ -162,7 +166,7 @@ export abstract class BaseContractInteraction { let gasSettings = defaultFeeOptions.gasSettings; if (fee?.estimateGas) { const feeForEstimation: FeeOptions = { paymentMethod, gasSettings }; - const txRequest = await this.wallet.createTxExecutionRequest(executionPayload, feeForEstimation, {}); + const txRequest = await this.wallet.createTxExecutionRequest(executionPayload, feeForEstimation, options ?? {}); const simulationResult = await this.wallet.simulateTx( txRequest, true /*simulatePublic*/, diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 4358724cd012..34835460cff1 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -23,7 +23,7 @@ export class BatchCall extends BaseContractInteraction { const requestWithoutFee = await this.request(options); const { fee: userFee, nonce, cancellable } = options; - const fee = await this.getFeeOptions(requestWithoutFee, userFee); + const fee = await this.getFeeOptions(requestWithoutFee, userFee, { nonce, cancellable }); return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable }); } diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index c63d29ea3c35..2f986eff8a34 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -78,9 +78,8 @@ export class ContractFunctionInteraction extends BaseContractInteraction { } const requestWithoutFee = await this.request(options); - const { fee: userFee } = options; - const { nonce, cancellable } = options; - const fee = await this.getFeeOptions(requestWithoutFee, userFee); + const { fee: userFee, nonce, cancellable } = options; + const fee = await this.getFeeOptions(requestWithoutFee, userFee, { nonce, cancellable }); return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable }); } diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index e650678d57a7..89e955a99fdd 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -77,8 +77,8 @@ export class DeployMethod extends Bas */ public async create(options: DeployOptions = {}): Promise { const requestWithoutFee = await this.request(options); - const { nonce, cancellable } = options; - const fee = await this.getFeeOptions(requestWithoutFee, options.fee); + const { fee: userFee, nonce, cancellable } = options; + const fee = await this.getFeeOptions(requestWithoutFee, userFee, { nonce, cancellable }); return this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable }); } diff --git a/yarn-project/cli-wallet/src/cmds/send.ts b/yarn-project/cli-wallet/src/cmds/send.ts index f5675411a1a1..f9905080e5d7 100644 --- a/yarn-project/cli-wallet/src/cmds/send.ts +++ b/yarn-project/cli-wallet/src/cmds/send.ts @@ -1,4 +1,11 @@ -import { type AccountWalletWithSecretKey, AuthWitness, type AztecAddress, Contract, Fr } from '@aztec/aztec.js'; +import { + type AccountWalletWithSecretKey, + AuthWitness, + type AztecAddress, + Contract, + Fr, + type SendMethodOptions, +} from '@aztec/aztec.js'; import { prepTx } from '@aztec/cli/utils'; import type { LogFn } from '@aztec/foundation/log'; import { GasSettings } from '@aztec/stdlib/gas'; @@ -22,15 +29,23 @@ export async function send( const contract = await Contract.at(contractAddress, contractArtifact, wallet); const call = contract.methods[functionName](...functionArgs); - const gasLimits = await call.estimateGas({ ...(await feeOpts.toSendOpts(wallet)), authWitnesses }); + const nonce = Fr.random(); + + const sendOptions: SendMethodOptions = { + ...(await feeOpts.toSendOpts(wallet)), + authWitnesses, + cancellable, + nonce, + }; + + const gasLimits = await call.estimateGas(sendOptions); printGasEstimates(feeOpts, gasLimits, log); if (feeOpts.estimateOnly) { return; } - const nonce = Fr.random(); - const tx = call.send({ ...(await feeOpts.toSendOpts(wallet)), nonce, cancellable, authWitnesses }); + const tx = call.send(sendOptions); const txHash = await tx.getTxHash(); log(`\nTransaction hash: ${txHash.toString()}`); if (wait) { diff --git a/yarn-project/cli-wallet/src/utils/options/options.ts b/yarn-project/cli-wallet/src/utils/options/options.ts index 518b432744f5..31fb538108f4 100644 --- a/yarn-project/cli-wallet/src/utils/options/options.ts +++ b/yarn-project/cli-wallet/src/utils/options/options.ts @@ -80,7 +80,7 @@ export function createAccountOption(description: string, hide: boolean, db?: Wal } export function createAuthwitnessOption(description: string, hide: boolean, db?: WalletDB) { - return new Option('-w, --auth-witness ', description) + return new Option('-aw, --auth-witness ', description) .hideHelp(hide) .argParser(witness => aliasedAuthWitParser(witness, db)); } diff --git a/yarn-project/cli-wallet/test/flows/private_authwit_transfer.sh b/yarn-project/cli-wallet/test/flows/private_authwit_transfer.sh index 0359cc38c19c..bdcbe34c80cb 100755 --- a/yarn-project/cli-wallet/test/flows/private_authwit_transfer.sh +++ b/yarn-project/cli-wallet/test/flows/private_authwit_transfer.sh @@ -14,8 +14,7 @@ source $flows/shared/create_funded_account.sh operator aztec-wallet create-secret -a auth_nonce aztec-wallet create-authwit transfer_in_private operator -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f main -aztec-wallet add-authwit authwits:last main -f operator -aztec-wallet send transfer_in_private -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f operator +aztec-wallet send transfer_in_private -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -aw authwits:last -f operator RESULT_MAIN=$(aztec-wallet simulate balance_of_private -ca token --args accounts:main -f main | grep "Simulation result:" | awk '{print $3}') RESULT_RECIPIENT=$(aztec-wallet simulate balance_of_private -ca token --args accounts:operator -f operator | grep "Simulation result:" | awk '{print $3}') diff --git a/yarn-project/cli-wallet/test/flows/profile.sh b/yarn-project/cli-wallet/test/flows/profile.sh index c0b706a7f453..f76115d69ae8 100755 --- a/yarn-project/cli-wallet/test/flows/profile.sh +++ b/yarn-project/cli-wallet/test/flows/profile.sh @@ -11,7 +11,6 @@ source $flows/shared/create_funded_account.sh operator # Create an authwit for the operator to transfer tokens from the main account to operator's own account. aztec-wallet create-secret -a auth_nonce aztec-wallet create-authwit transfer_in_private operator -ca token --args accounts:main accounts:operator 100 secrets:auth_nonce -f main -aztec-wallet add-authwit authwits:last main -f operator # Write out debug execution steps (used for debugging prover development). tmp=$(mktemp -d) @@ -19,7 +18,7 @@ function cleanup { rm -rf $tmp } trap cleanup EXIT SIGINT -aztec-wallet profile transfer_in_private --debug-execution-steps-dir $tmp -ca token --args accounts:main accounts:operator 100 secrets:auth_nonce -f operator +aztec-wallet profile transfer_in_private --debug-execution-steps-dir $tmp -ca token --args accounts:main accounts:operator 100 secrets:auth_nonce -aw authwits:last -f operator # Crude check, check that $tmp is over one megabyte, the validity of these files is checked more directly in the client ivc benches. size=$(du -sb $tmp | awk '{print $1}') if [ "$size" -lt 1000000 ]; then diff --git a/yarn-project/end-to-end/src/guides/up_quick_start.sh b/yarn-project/end-to-end/src/guides/up_quick_start.sh index 89bc070d8486..46d140da6d6e 100755 --- a/yarn-project/end-to-end/src/guides/up_quick_start.sh +++ b/yarn-project/end-to-end/src/guides/up_quick_start.sh @@ -45,9 +45,8 @@ fi TRANSFER_AMOUNT=42 aztec-wallet create-authwit transfer_in_private accounts:test0 -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -f alice -aztec-wallet add-authwit authwits:last alice -f test0 -aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -f test0 +aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -w authwits:last -f test0 # docs:end:transfer # Test end result From d9526d20ab3c970a731676ad826352d2c11d1595 Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 11:06:26 +0000 Subject: [PATCH 41/48] fmt --- .../aztec.js/src/contract/base_contract_interaction.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 1b0a98253561..3e4b13fe5b0d 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -146,10 +146,9 @@ export abstract class BaseContractInteraction { // docs:start:getFeeOptions /** * Return fee options based on the user opts, estimating tx gas if needed. - * @param request - Request to execute for this interaction. - * @param pad - Percentage to pad the suggested gas limits by, as decimal (e.g., 0.10 for 10%). * @param executionPayload - Execution payload to get the fee for * @param fee - User-provided fee options. + * @param options - Additional options for the transaction. They must faithfully represent the tx to get accurate fee estimates * @returns Fee options for the actual transaction. */ protected async getFeeOptions( From 5d82c74574c99819f82788c928100bf37630c74b Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 11:26:50 +0000 Subject: [PATCH 42/48] more test fixing --- yarn-project/aztec.js/src/contract/sent_tx.test.ts | 10 ---------- yarn-project/cli-wallet/test/flows/profile.sh | 2 +- yarn-project/end-to-end/src/guides/up_quick_start.sh | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.test.ts b/yarn-project/aztec.js/src/contract/sent_tx.test.ts index da4a220bdce6..20c18b4e2cb0 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.test.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.test.ts @@ -31,16 +31,6 @@ describe('SentTx', () => { pxe.getTxReceipt.mockResolvedValue({ ...txReceipt, status: TxStatus.DROPPED } as TxReceipt); await expect(sentTx.wait({ timeout: 1, interval: 0.4, ignoreDroppedReceiptsFor: 0 })).rejects.toThrow(/dropped/); }); - - it('waits for the tx to be proven', async () => { - const waitOpts = { timeout: 1, interval: 0.4, proven: true, provenTimeout: 2 }; - pxe.getProvenBlockNumber.mockResolvedValue(10); - await expect(sentTx.wait(waitOpts)).rejects.toThrow(/timeout/i); - - pxe.getProvenBlockNumber.mockResolvedValue(20); - const actual = await sentTx.wait(waitOpts); - expect(actual).toEqual(txReceipt); - }); }); describe('wait with node', () => { diff --git a/yarn-project/cli-wallet/test/flows/profile.sh b/yarn-project/cli-wallet/test/flows/profile.sh index f76115d69ae8..c145bb3c32e9 100755 --- a/yarn-project/cli-wallet/test/flows/profile.sh +++ b/yarn-project/cli-wallet/test/flows/profile.sh @@ -27,7 +27,7 @@ if [ "$size" -lt 1000000 ]; then fi # Profile gate counts for `transfer_in_private` -gate_count=$(aztec-wallet profile transfer_in_private -ca token --args accounts:main accounts:operator 100 secrets:auth_nonce -f operator | grep "Total gates:" | awk '{print $3}') +gate_count=$(aztec-wallet profile transfer_in_private -ca token --args accounts:main accounts:operator 100 secrets:auth_nonce -aw authwits:last -f operator | grep "Total gates:" | awk '{print $3}') echo "GATE_COUNT: $gate_count" diff --git a/yarn-project/end-to-end/src/guides/up_quick_start.sh b/yarn-project/end-to-end/src/guides/up_quick_start.sh index 46d140da6d6e..df8e5e3cbd8c 100755 --- a/yarn-project/end-to-end/src/guides/up_quick_start.sh +++ b/yarn-project/end-to-end/src/guides/up_quick_start.sh @@ -46,7 +46,7 @@ TRANSFER_AMOUNT=42 aztec-wallet create-authwit transfer_in_private accounts:test0 -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -f alice -aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -w authwits:last -f test0 +aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -aw authwits:last -f test0 # docs:end:transfer # Test end result From dfe95ca632532572b8e00e95db4b17bbd467d3dd Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 12:35:00 +0000 Subject: [PATCH 43/48] migration notes --- docs/docs/migration_notes.md | 89 +++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/docs/docs/migration_notes.md b/docs/docs/migration_notes.md index 665a741c42ef..4f5e35bf88ba 100644 --- a/docs/docs/migration_notes.md +++ b/docs/docs/migration_notes.md @@ -8,6 +8,93 @@ Aztec is in full-speed development. Literally every version breaks compatibility ## TBD +## [aztec.js] Wallet interface and Authwit management + +The `Wallet` interface in `aztec.js` is undergoing transformations, trying to be friendlier to wallet builders and reducing the surface of its API. This means `Wallet` no longer extends `PXE`, and instead just implements a subset of the methods of the former. This is NOT going to be its final form, but paves the way towards better interfaces and starts to clarify what the responsibilities of the wallet are: + +``` typescript +/** + * The wallet interface. + */ +export type Wallet = AccountInterface & + Pick< + PXE, + // Simulation + | 'simulateTx' + | 'simulateUnconstrained' + | 'profileTx' + // Sending + | 'sendTx' + // Contract management (will probably be collapsed in the future to avoid instance and class versions) + | 'getContractClassMetadata' + | 'getContractMetadata' + | 'registerContract' + | 'registerContractClass' + // Likely to be removed + | 'proveTx' + // Will probably be collapsed + | 'getNodeInfo' + | 'getPXEInfo' + // Fee info + | 'getCurrentBaseFees' + // Still undecided, kept for the time being + | 'updateContract' + // Sender management + | 'registerSender' + | 'getSenders' + | 'removeSender' + // Tx status + | 'getTxReceipt' + // Events. Kept since events are going to be reworked and changes will come when that's done + | 'getPrivateEvents' + | 'getPublicEvents' + > & { + createAuthWit(intent: IntentInnerHash | IntentAction): Promise; + }; +``` + +As a side effect, a few debug only features have been removed + +```diff +// Obtain tx effects +const { txHash, debugInfo } = await contract.methods + .set_constant(value) + .send() +-- .wait({ interval: 0.1, debug: true }); +++ .wait({ interval: 0.1 }) + +-- // check that 1 note hash was created +-- expect(debugInfo!.noteHashes.length).toBe(1); +++ const txEffect = await aztecNode.getTxEffect(txHash); +++ const noteHashes = txEffect?.data.noteHashes; +++ // check that 1 note hash was created +++ expect(noteHashes?.length).toBe(1); + +// Wait for a tx to be proven +-- tx.wait({ timeout: 300, interval: 10, proven: true, provenTimeout: 3000 }))); +++ const receipt = await tx.wait({ timeout: 300, interval: 10 }); +++ await waitForProven(aztecNode, receipt, { provenTimeout: 3000 }); +``` + +Authwit management has changed, and PXE no longet stores them. This is unnecesary because now they can be externally provided to simulations and transactions, making sure no stale authorizations are kept inside PXE's db. + +```diff +const witness = await wallet.createAuthWit({ caller, action }); +--await callerWallet.addAuthWitness(witness); +--await action.send().wait(); +++await action.send({ authWitnesses: [witness] }).wait(); +``` + +Another side effect of this is that the interface of the `lookupValidity` method has changed, and now the authwitness has to be provided: + +```diff +const witness = await wallet.createAuthWit({ caller, action }); +--await callerWallet.addAuthWitness(witness); +--await wallet.lookupValidity(wallet.getAddress(), { caller, action }); +++await wallet.lookupValidity(wallet.getAddress(), { caller, action }, witness); +``` + + ### [PXE] Concurrent contract function simulation disabled PXE is no longer be able to execute contract functions concurrently (e.g. by collecting calls to `simulateTx` and then using `await Promise.all`). They will instead be put in a job queue and executed sequentially in order of arrival. @@ -24,7 +111,7 @@ class BatchCall extends BaseContractInteraction { } ``` -The `request` method of `BaseContractInteraction` now returns `ExecutionRequestInit` without the fee (`Omit`). This object includes all the necessary data to execute one or more functions. `BatchCall` invokes this method on all interactions to aggregate the required information. It is also used internally in simulations for fee estimation. +The `request` method of `BaseContractInteraction` now returns `ExecutionPayload`. This object includes all the necessary data to execute one or more functions. `BatchCall` invokes this method on all interactions to aggregate the required information. It is also used internally in simulations for fee estimation. Declaring a `BatchCall`: From a37cf6699c4f5af97b710ef6f6d506e816a20786 Mon Sep 17 00:00:00 2001 From: Gregorio Juliana Date: Tue, 18 Mar 2025 18:48:19 +0100 Subject: [PATCH 44/48] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Beneš --- docs/docs/migration_notes.md | 2 +- yarn-project/aztec.js/src/contract/deploy_sent_tx.ts | 2 +- yarn-project/end-to-end/src/composed/e2e_persistence.test.ts | 4 ++-- yarn-project/end-to-end/src/e2e_authwit.test.ts | 4 ++-- .../blacklist_token_contract_test.ts | 4 ++-- .../end-to-end/src/e2e_crowdfunding_and_claim.test.ts | 2 +- .../end-to-end/src/e2e_offchain_note_delivery.test.ts | 1 - 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/docs/migration_notes.md b/docs/docs/migration_notes.md index 4f5e35bf88ba..f71ec322758b 100644 --- a/docs/docs/migration_notes.md +++ b/docs/docs/migration_notes.md @@ -76,7 +76,7 @@ const { txHash, debugInfo } = await contract.methods ++ await waitForProven(aztecNode, receipt, { provenTimeout: 3000 }); ``` -Authwit management has changed, and PXE no longet stores them. This is unnecesary because now they can be externally provided to simulations and transactions, making sure no stale authorizations are kept inside PXE's db. +Authwit management has changed, and PXE no longer stores them. This is unnecessary because now they can be externally provided to simulations and transactions, making sure no stale authorizations are kept inside PXE's db. ```diff const witness = await wallet.createAuthWit({ caller, action }); diff --git a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts index f0d647a44b79..c887c6723d99 100644 --- a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts @@ -29,7 +29,7 @@ export class DeploySentTx extends SentTx private log = createLogger('aztecjs:deploy_sent_tx'); constructor( - pxeOrWallet: Wallet, + wallet: Wallet, txHashPromise: Promise, private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise, /** A getter for the deployed contract instance */ diff --git a/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts b/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts index 44034b6d4a3e..80892d0dbc14 100644 --- a/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts +++ b/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts @@ -355,7 +355,7 @@ function toBoundedVec(arr: Fr[], maxLen: number) { async function addPendingShieldNoteToPXE( contract: TokenBlacklistContract, - address: AztecAddress, + recipient: AztecAddress, amount: bigint, secretHash: Fr, txHash: TxHash, @@ -371,7 +371,7 @@ async function addPendingShieldNoteToPXE( txHash.hash, toBoundedVec(txEffects!.data.noteHashes, MAX_NOTE_HASHES_PER_TX), txEffects!.data.nullifiers[0], - address, + recipient, ) .simulate(); // docs:end:offchain_delivery diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index 9cd9bb438694..c37b3099330d 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -39,8 +39,8 @@ describe('e2e_authwit_tests', () => { // 1. We compute an inner hash which is here just a hash of random data // 2. We then compute the message hash, which is binding it to a "consumer" (here the "auth" contract) // 3. We then create an authwit for this message hash. - // 5. We check that the authwit is valid in private for wallet[0] (check that it is signed by 0) - // 6. We check that the authwit is NOT valid in private for wallet[1] (check that it is not signed by 1) + // 4. We check that the authwit is valid in private for wallet[0] (check that it is signed by 0) + // 5. We check that the authwit is NOT valid in private for wallet[1] (check that it is not signed by 1) // docs:start:compute_inner_authwit_hash const innerHash = await computeInnerAuthWitHash([Fr.fromHexString('0xdead')]); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts index fe40445827b2..3651eff39c9f 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts @@ -168,7 +168,7 @@ export class BlacklistTokenContractTest { async addPendingShieldNoteToPXE( contract: TokenBlacklistContract, - address: AztecAddress, + recipient: AztecAddress, amount: bigint, secretHash: Fr, txHash: TxHash, @@ -182,7 +182,7 @@ export class BlacklistTokenContractTest { txHash.hash, this.#toBoundedVec(txEffects!.data.noteHashes, MAX_NOTE_HASHES_PER_TX), txEffects!.data.nullifiers[0], - address, + recipient, ) .simulate(); } diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index f08fa2ceec20..0232d37746df 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -188,7 +188,7 @@ describe('e2e_crowdfunding_and_claim', () => { .simulate(); expect(balanceDNTBeforeWithdrawal).toEqual(0n); - // 4) At last, we withdraw the raised funds from the crowdfunding contract to the operator's address + // 3) At last, we withdraw the raised funds from the crowdfunding contract to the operator's address await crowdfundingContract.methods.withdraw(donationAmount).send().wait(); const balanceDNTAfterWithdrawal = await donationToken.methods diff --git a/yarn-project/end-to-end/src/e2e_offchain_note_delivery.test.ts b/yarn-project/end-to-end/src/e2e_offchain_note_delivery.test.ts index bc810a306a07..756173f7847a 100644 --- a/yarn-project/end-to-end/src/e2e_offchain_note_delivery.test.ts +++ b/yarn-project/end-to-end/src/e2e_offchain_note_delivery.test.ts @@ -34,7 +34,6 @@ describe('e2e_offchain_note_delivery', () => { expect(noteHashes?.length).toBe(1); // The note was not broadcast, so we must manually deliver it to the contract via the custom mechanism to do so. - await contract.methods .deliver_note( contract.address, From 8cf030a9e0547e4f9d17d7c737509a8c705ff8df Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 18:30:08 +0000 Subject: [PATCH 45/48] bunch of comments --- yarn-project/aztec.js/src/contract/deploy_sent_tx.ts | 2 +- .../aztec.js/src/deployment/broadcast_function.ts | 10 ++++++---- .../src/fee/fee_juice_payment_method_with_claim.ts | 4 ++-- .../aztec.js/src/fee/private_fee_payment_method.ts | 8 ++++---- .../aztec.js/src/fee/public_fee_payment_method.ts | 8 ++++---- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts index c887c6723d99..87b436d5375f 100644 --- a/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/deploy_sent_tx.ts @@ -35,7 +35,7 @@ export class DeploySentTx extends SentTx /** A getter for the deployed contract instance */ public instanceGetter: () => Promise, ) { - super(pxeOrWallet, txHashPromise); + super(wallet, txHashPromise); } /** diff --git a/yarn-project/aztec.js/src/deployment/broadcast_function.ts b/yarn-project/aztec.js/src/deployment/broadcast_function.ts index 451ca4a93a7b..e37af7e96081 100644 --- a/yarn-project/aztec.js/src/deployment/broadcast_function.ts +++ b/yarn-project/aztec.js/src/deployment/broadcast_function.ts @@ -59,7 +59,7 @@ export async function broadcastPrivateFunction( const vkHash = await computeVerificationKeyHash(privateFunctionArtifact); const registerer = await getRegistererContract(wallet); - const functionArtifact = registerer.artifact.functions.find(f => f.name === 'broadcast_private_function')!; + const broadcastFunctionArtifact = registerer.artifact.functions.find(f => f.name === 'broadcast_private_function')!; const bytecode = bufferAsFields( privateFunctionArtifact.bytecode, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS, @@ -67,7 +67,7 @@ export async function broadcastPrivateFunction( const fn = new ContractFunctionInteraction( wallet, registerer.address, - functionArtifact!, + broadcastFunctionArtifact!, [ contractClass.id, artifactMetadataHash, @@ -128,7 +128,9 @@ export async function broadcastUnconstrainedFunction( } = await createUnconstrainedFunctionMembershipProof(selector, artifact); const registerer = await getRegistererContract(wallet); - const functionArtifact = registerer.artifact.functions.find(f => f.name === 'broadcast_unconstrained_function'); + const broadcastFunctionArtifact = registerer.artifact.functions.find( + f => f.name === 'broadcast_unconstrained_function', + ); const bytecode = bufferAsFields( unconstrainedFunctionArtifact.bytecode, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS, @@ -137,7 +139,7 @@ export async function broadcastUnconstrainedFunction( const fn = new ContractFunctionInteraction( wallet, registerer.address, - functionArtifact!, + broadcastFunctionArtifact!, [ contractClass.id, artifactMetadataHash, diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts index 516a67a6de2f..b079fefccf75 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts @@ -20,8 +20,8 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod { } /** - * Creates a function call to pay the fee in Fee Juice. - * @returns A function call + * Creates an execution payload to pay the fee in Fee Juice. + * @returns An execution payload that just contains the claim function call. */ override async getExecutionPayload(): Promise { const canonicalFeeJuice = await getFeeJuice(this.senderWallet); diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index 33a1a1b21c69..e6af6eae2521 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -38,7 +38,8 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { */ getAsset(): Promise { if (!this.assetPromise) { - // We use signer-less wallet because this function could be triggered before the associated account is deployed. + // We use the utility method to avoid a signature because this function could be triggered + // before the associated account is deployed. this.assetPromise = simulateWithoutSignature(this.wallet, this.paymentContract, { name: 'get_accepted_asset', functionType: FunctionType.PRIVATE, @@ -71,9 +72,8 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { } /** - * Creates a function call to pay the fee in the given asset. - * @param gasSettings - The gas settings. - * @returns The function call to pay the fee. + * Creates an execution payload to pay the fee using a private function through an FPC in the desired asset + * @returns An execution payload that contains the required function calls and auth witnesses. */ async getExecutionPayload(gasSettings: GasSettings): Promise { // We assume 1:1 exchange rate between fee juice and token. But in reality you would need to convert feeLimit diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index 89a23b75c193..c51bd4819198 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -31,7 +31,8 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { */ getAsset(): Promise { if (!this.assetPromise) { - // We use the utility method to avoid a signature because this function could be triggered before the associated account is deployed. + // We use the utility method to avoid a signature because this function could be triggered + // before the associated account is deployed. this.assetPromise = simulateWithoutSignature(this.wallet, this.paymentContract, { name: 'get_accepted_asset', functionType: FunctionType.PRIVATE, @@ -64,9 +65,8 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { } /** - * Creates a function call to pay the fee in the given asset. - * @param gasSettings - The gas settings. - * @returns The function call to pay the fee. + * Creates an execution payload to pay the fee using a public function through an FPC in the desired asset + * @returns An execution payload that contains the required function calls. */ async getExecutionPayload(gasSettings: GasSettings): Promise { const nonce = Fr.random(); From ed7dd5f3316d286a6a12892b6bf3bfbaf047e3a6 Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 18:45:30 +0000 Subject: [PATCH 46/48] more comments --- yarn-project/aztec.js/src/fee/utils.ts | 6 +++++- yarn-project/aztec.js/src/utils/authwit.ts | 15 +++++++++++++++ .../aztec.js/src/wallet/account_wallet.ts | 1 + yarn-project/end-to-end/src/e2e_fees/fees_test.ts | 4 ---- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/yarn-project/aztec.js/src/fee/utils.ts b/yarn-project/aztec.js/src/fee/utils.ts index e1a74e2929a0..9961ea56dc56 100644 --- a/yarn-project/aztec.js/src/fee/utils.ts +++ b/yarn-project/aztec.js/src/fee/utils.ts @@ -8,7 +8,11 @@ import type { Wallet } from '../wallet/wallet.js'; import { FeeJuicePaymentMethod } from './fee_juice_payment_method.js'; /** - * + * Use a wallet to simulate a function avoiding the wallet's entrypoint, as a SignerlessWallet would do + * @param wallet - The wallet to use for the simulation. + * @param contractAddress - The address of the contract to call. + * @param abi - The ABI of the function to simulate. + * @returns The return values of the function call. */ export async function simulateWithoutSignature(wallet: Wallet, contractAddress: AztecAddress, abi: FunctionAbi) { const interaction = new ContractFunctionInteraction(wallet, contractAddress, abi, []); diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index c95d69939cad..4b20a25e8796 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -72,6 +72,13 @@ export const computeAuthWitMessageHash = async (intent: IntentInnerHash | Intent }; // docs:end:authwit_computeAuthWitMessageHash +/** + * Computes the inner authwitness hash for a function call, for it to later be combined with the metadata + * required for the outer hash and eventually the full AuthWitness. + * @param caller - Who is going to be calling the function + * @param fnCall - The function call to compute the inner hash from + * @returns The inner hash for the function call + **/ export const computeInnerAuthWitHashFromFunctionCall = async (caller: AztecAddress, fnCall: FunctionCall) => { return computeInnerAuthWitHash([ caller.toField(), @@ -80,6 +87,14 @@ export const computeInnerAuthWitHashFromFunctionCall = async (caller: AztecAddre ]); }; +/** + * Computes the inner authwitness hash for an action, that can either be a ContractFunctionInteraction + * or an isolated FunctionCall. Since the former is just a wrapper around the latter, we can just extract + * the first (and only) call from the ContractFunctionInteraction and use it to compute the inner hash. + * @param caller - Who is going to be performing the action + * @param action - The ContractFunctionInteraction or FunctionCall to compute the inner hash for + * @returns The inner hash for the action + **/ export const computeInnerAuthWitHashFromAction = async ( caller: AztecAddress, action: FunctionCall | ContractFunctionInteraction, diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 75f37c02626c..5528294834cd 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -155,6 +155,7 @@ export class AccountWallet extends BaseWallet { consumer, innerHash, ]).simulate({ authWitnesses: [witness] })) as boolean; + // TODO: Narrow down the error to make sure simulation failed due to an invalid authwit // eslint-disable-next-line no-empty } catch {} diff --git a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts index aaf426eceefc..1ed0951d1fdc 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts @@ -179,10 +179,6 @@ export class FeesTest { const canonicalFeeJuice = await getCanonicalFeeJuice(); this.feeJuiceContract = await FeeJuiceContract.at(canonicalFeeJuice.address, this.aliceWallet); - // if (this.numberOfAccounts > 1) { - // const bobInstance = (await this.bobWallet.getContractMetadata(this.bobAddress)).contractInstance; - // await this.aliceWallet.registerAccount(deployedAccounts[1].secret, await computePartialAddress(bobInstance!)); - // } this.coinbase = EthAddress.random(); const { publicClient, walletClient } = createL1Clients(aztecNodeConfig.l1RpcUrls, MNEMONIC); From 4912ef3bcba0a859e35f857636e6660d300e894e Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 18:49:11 +0000 Subject: [PATCH 47/48] more comments --- .../src/fixtures/snapshot_manager.ts | 2 ++ yarn-project/entrypoints/src/payload.ts | 10 +++------- .../pxe/src/pxe_service/pxe_service.ts | 19 +------------------ 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index 08e323f00cfa..214c9eb4daa8 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -612,6 +612,8 @@ export const deployAccounts = * Use this when you need to make a public call to an account contract, such as for requesting a public authwit. * @param sender - Wallet to send the deployment tx. * @param accountsToDeploy - Which accounts to publicly deploy. + * @param waitUntilProven - Whether to wait for the tx to be proven. + * @param pxeOrNode - PXE or AztecNode to wait for proven. */ export async function publicDeployAccounts( sender: Wallet, diff --git a/yarn-project/entrypoints/src/payload.ts b/yarn-project/entrypoints/src/payload.ts index 3bc0a0ceab34..41e566c07690 100644 --- a/yarn-project/entrypoints/src/payload.ts +++ b/yarn-project/entrypoints/src/payload.ts @@ -33,9 +33,7 @@ export class ExecutionPayload { return new ExecutionPayload([], [], []); } - /** - * Encodes the payload for execution, following Noir's convention - */ + /** Encodes the payload for execution, following Noir's convention */ public async encode(): Promise { const hashedArguments: HashedValues[] = []; for (const call of this.calls) { @@ -62,9 +60,7 @@ export class ExecutionPayload { } } -/** - * Representation of the encoded payload for execution - */ +/** Representation of the encoded payload for execution */ export type EncodedExecutionPayload = Omit & { /** Function calls in the expected format (Noir's convention) */ encodedFunctionCalls: EncodedFunctionCall[]; @@ -78,7 +74,7 @@ export type EncodedExecutionPayload = Omit { const contract = await this.contractDataProvider.getContract(to); if (!contract) { @@ -424,6 +406,7 @@ export class PXEService implements PXE { * @param txExecutionRequest - The transaction request to be simulated and proved. * @param proofCreator - The proof creator to use for proving the execution. * @param privateExecutionResult - The result of the private execution + * @param config - The configuration for the kernel execution prover. * @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled. */ async #prove( From ea47021824b84d85e15d4e07f1163acef44578b7 Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 18 Mar 2025 19:03:06 +0000 Subject: [PATCH 48/48] fixed jsdoc --- yarn-project/aztec.js/src/fee/private_fee_payment_method.ts | 1 + yarn-project/aztec.js/src/fee/public_fee_payment_method.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index e6af6eae2521..871234648fd4 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -73,6 +73,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { /** * Creates an execution payload to pay the fee using a private function through an FPC in the desired asset + * @param gasSettings - The gas settings. * @returns An execution payload that contains the required function calls and auth witnesses. */ async getExecutionPayload(gasSettings: GasSettings): Promise { diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index c51bd4819198..8c7a5724dfd6 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -66,6 +66,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { /** * Creates an execution payload to pay the fee using a public function through an FPC in the desired asset + * @param gasSettings - The gas settings. * @returns An execution payload that contains the required function calls. */ async getExecutionPayload(gasSettings: GasSettings): Promise {