@aztec-labs/ethereum 6.0.0-rc.3 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dest/blob_tx.d.ts +24 -0
  2. package/dest/blob_tx.d.ts.map +1 -0
  3. package/dest/blob_tx.js +94 -0
  4. package/dest/bn254/hash_to_point.d.ts +32 -0
  5. package/dest/bn254/hash_to_point.d.ts.map +1 -0
  6. package/dest/bn254/hash_to_point.js +80 -0
  7. package/dest/bn254/index.d.ts +3 -0
  8. package/dest/bn254/index.d.ts.map +1 -0
  9. package/dest/bn254/index.js +2 -0
  10. package/dest/bn254/proof_of_possession_gas.d.ts +29 -0
  11. package/dest/bn254/proof_of_possession_gas.d.ts.map +1 -0
  12. package/dest/bn254/proof_of_possession_gas.js +24 -0
  13. package/dest/client.d.ts +1 -1
  14. package/dest/client.d.ts.map +1 -1
  15. package/dest/client.js +5 -3
  16. package/dest/contracts/errors.d.ts +10 -3
  17. package/dest/contracts/errors.d.ts.map +1 -1
  18. package/dest/contracts/errors.js +10 -4
  19. package/dest/contracts/inbox.d.ts +1 -1
  20. package/dest/contracts/inbox.d.ts.map +1 -1
  21. package/dest/contracts/inbox.js +2 -0
  22. package/dest/contracts/log.d.ts +7 -1
  23. package/dest/contracts/log.d.ts.map +1 -1
  24. package/dest/contracts/log.js +6 -0
  25. package/dest/contracts/rollup.d.ts +32 -4
  26. package/dest/contracts/rollup.d.ts.map +1 -1
  27. package/dest/contracts/rollup.js +63 -7
  28. package/dest/deploy_aztec_l1_contracts.d.ts +16 -1
  29. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  30. package/dest/deploy_aztec_l1_contracts.js +201 -65
  31. package/dest/foundry_binary.d.ts +1 -1
  32. package/dest/foundry_binary.d.ts.map +1 -1
  33. package/dest/foundry_binary.js +2 -1
  34. package/dest/l1_tx_utils/amsterdam.d.ts +1 -1
  35. package/dest/l1_tx_utils/amsterdam.d.ts.map +1 -1
  36. package/dest/l1_tx_utils/amsterdam.js +4 -1
  37. package/dest/l1_tx_utils/constants.d.ts +2 -1
  38. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  39. package/dest/l1_tx_utils/constants.js +3 -0
  40. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +1 -1
  41. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -1
  42. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +6 -1
  43. package/dest/l1_tx_utils/index.d.ts +2 -1
  44. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  45. package/dest/l1_tx_utils/index.js +1 -0
  46. package/dest/l1_tx_utils/l1_tx_utils.d.ts +21 -1
  47. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  48. package/dest/l1_tx_utils/l1_tx_utils.js +71 -5
  49. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +8 -1
  50. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  51. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +1 -1
  52. package/dest/l1_tx_utils/send_cost.d.ts +15 -0
  53. package/dest/l1_tx_utils/send_cost.d.ts.map +1 -0
  54. package/dest/l1_tx_utils/send_cost.js +10 -0
  55. package/dest/l1_tx_utils/signer.d.ts +2 -2
  56. package/dest/l1_tx_utils/signer.d.ts.map +1 -1
  57. package/dest/l1_tx_utils/signer.js +2 -2
  58. package/dest/l1_tx_utils/tx_delayer.d.ts +1 -1
  59. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -1
  60. package/dest/l1_tx_utils/tx_delayer.js +8 -26
  61. package/dest/publisher_manager.d.ts +127 -13
  62. package/dest/publisher_manager.d.ts.map +1 -1
  63. package/dest/publisher_manager.js +320 -79
  64. package/dest/test/anvil_hardfork.d.ts +42 -0
  65. package/dest/test/anvil_hardfork.d.ts.map +1 -0
  66. package/dest/test/anvil_hardfork.js +107 -0
  67. package/dest/test/eth_cheat_codes.d.ts +30 -5
  68. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  69. package/dest/test/eth_cheat_codes.js +283 -101
  70. package/dest/test/index.d.ts +3 -1
  71. package/dest/test/index.d.ts.map +1 -1
  72. package/dest/test/index.js +2 -0
  73. package/dest/test/l1_hardfork.d.ts +43 -0
  74. package/dest/test/l1_hardfork.d.ts.map +1 -0
  75. package/dest/test/l1_hardfork.js +51 -0
  76. package/dest/test/recording_rpc_server.d.ts +1 -1
  77. package/dest/test/recording_rpc_server.d.ts.map +1 -1
  78. package/dest/test/recording_rpc_server.js +1 -0
  79. package/dest/test/rollup_cheat_codes.d.ts +1 -1
  80. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  81. package/dest/test/rollup_cheat_codes.js +7 -7
  82. package/dest/test/start_anvil.d.ts +14 -2
  83. package/dest/test/start_anvil.d.ts.map +1 -1
  84. package/dest/test/start_anvil.js +28 -11
  85. package/package.json +13 -11
  86. package/src/blob_tx.ts +118 -0
  87. package/src/bn254/hash_to_point.ts +95 -0
  88. package/src/bn254/index.ts +2 -0
  89. package/src/bn254/proof_of_possession_gas.ts +54 -0
  90. package/src/client.ts +6 -3
  91. package/src/contracts/errors.ts +12 -4
  92. package/src/contracts/inbox.ts +4 -0
  93. package/src/contracts/log.ts +12 -0
  94. package/src/contracts/rollup.ts +63 -6
  95. package/src/deploy_aztec_l1_contracts.ts +238 -63
  96. package/src/foundry_binary.ts +2 -1
  97. package/src/l1_tx_utils/amsterdam.ts +4 -1
  98. package/src/l1_tx_utils/constants.ts +4 -0
  99. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +11 -1
  100. package/src/l1_tx_utils/index.ts +1 -0
  101. package/src/l1_tx_utils/l1_tx_utils.ts +72 -5
  102. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +1 -1
  103. package/src/l1_tx_utils/send_cost.ts +21 -0
  104. package/src/l1_tx_utils/signer.ts +3 -2
  105. package/src/l1_tx_utils/tx_delayer.ts +8 -37
  106. package/src/publisher_manager.ts +458 -83
  107. package/src/test/anvil_hardfork.ts +95 -0
  108. package/src/test/eth_cheat_codes.ts +306 -81
  109. package/src/test/fixtures/sepolia_blob_tx.json +10 -0
  110. package/src/test/index.ts +2 -0
  111. package/src/test/l1_hardfork.ts +71 -0
  112. package/src/test/recording_rpc_server.ts +1 -0
  113. package/src/test/rollup_cheat_codes.ts +9 -9
  114. package/src/test/start_anvil.ts +41 -13
@@ -0,0 +1,21 @@
1
+ import { GAS_PER_BLOB } from './constants.js';
2
+ import type { FeesPerGas } from './types.js';
3
+
4
+ /** Gas limit and blob count of an L1 send, used to bound the ETH a sender must hold to submit it. */
5
+ export type SendCostRequirement = {
6
+ /** Gas limit the tx will be sent with. */
7
+ gasLimit: bigint;
8
+ /** Number of blobs attached to the tx. */
9
+ blobCount: number;
10
+ };
11
+
12
+ /**
13
+ * Upper bound on the ETH a send needs up front: `gasLimit * maxFeePerGas + blobCount * GAS_PER_BLOB * maxFeePerBlobGas`.
14
+ * This is what the node checks against the sender balance before accepting the tx, so a sender holding less than this
15
+ * gets the tx rejected with an insufficient funds error.
16
+ */
17
+ export function computeSendCost(fees: FeesPerGas, req: SendCostRequirement): bigint {
18
+ const executionCost = req.gasLimit * fees.maxFeePerGas;
19
+ const blobCost = BigInt(req.blobCount) * GAS_PER_BLOB * (fees.maxFeePerBlobGas ?? 0n);
20
+ return executionCost + blobCost;
21
+ }
@@ -1,7 +1,8 @@
1
1
  import { EthAddress } from '@aztec-labs/foundation/eth-address';
2
2
  import type { ViemTransactionSignature } from '@aztec-labs/foundation/eth-signature';
3
- import { type TransactionSerializable, type WalletClient, parseTransaction } from 'viem';
3
+ import type { TransactionSerializable, WalletClient } from 'viem';
4
4
 
5
+ import { parseSignedTransaction } from '../blob_tx.js';
5
6
  import type { SigningCallback } from './types.js';
6
7
 
7
8
  export function createViemSigner(client: WalletClient) {
@@ -11,7 +12,7 @@ export function createViemSigner(client: WalletClient) {
11
12
  ): Promise<ViemTransactionSignature> => {
12
13
  const signedTx = await client.signTransaction(tx as any);
13
14
 
14
- const parsed = parseTransaction(signedTx);
15
+ const parsed = parseSignedTransaction(signedTx);
15
16
 
16
17
  if (!parsed.r || !parsed.s || (parsed.yParity !== 0 && parsed.yParity !== 1)) {
17
18
  throw new Error('Failed to extract signature from viem signed transaction');
@@ -1,22 +1,11 @@
1
1
  import { omit } from '@aztec-labs/foundation/collection';
2
+ import { inspect } from '@aztec-labs/foundation/inspect';
2
3
  import { type Logger, type LoggerBindings, createLogger } from '@aztec-labs/foundation/log';
3
4
  import { retryUntil } from '@aztec-labs/foundation/retry';
4
5
  import type { DateProvider } from '@aztec-labs/foundation/timer';
5
- import { inspect } from 'util';
6
- import {
7
- type Client,
8
- type Hex,
9
- type PublicClient,
10
- type TransactionSerializableEIP4844,
11
- type TransactionSerialized,
12
- keccak256,
13
- parseTransaction,
14
- publicActions,
15
- recoverTransactionAddress,
16
- serializeTransaction,
17
- walletActions,
18
- } from 'viem';
6
+ import { type Client, type Hex, type PublicClient, publicActions, walletActions } from 'viem';
19
7
 
8
+ import { computeSignedTransactionHash, parseSignedTransaction, recoverSignedTransactionAddress } from '../blob_tx.js';
20
9
  import type { ExtendedViemWalletClient, ViemClient } from '../types.js';
21
10
 
22
11
  const MAX_WAIT_TIME_SECONDS = 180;
@@ -152,9 +141,7 @@ export function createDelayer(
152
141
  /** Tries to recover the sender address from a serialized signed transaction. */
153
142
  async function tryRecoverSender(serializedTransaction: Hex): Promise<string | undefined> {
154
143
  try {
155
- return await recoverTransactionAddress({
156
- serializedTransaction: serializedTransaction as TransactionSerialized,
157
- });
144
+ return await recoverSignedTransactionAddress(serializedTransaction);
158
145
  } catch {
159
146
  return undefined;
160
147
  }
@@ -189,7 +176,7 @@ export function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer:
189
176
  delayer.nextWait = undefined;
190
177
 
191
178
  // Compute the tx hash manually so we emulate sendRawTransaction response
192
- txHash = computeTxHash(serializedTransaction);
179
+ txHash = computeSignedTransactionHash(serializedTransaction);
193
180
 
194
181
  // Cancel tx outright if instructed
195
182
  if ('indefinitely' in waitUntil && waitUntil.indefinitely) {
@@ -214,7 +201,7 @@ export function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer:
214
201
  logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`, {
215
202
  sender,
216
203
  argsLen: args.length,
217
- ...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
204
+ ...omit(parseSignedTransaction(serializedTransaction), 'data', 'sidecars'),
218
205
  });
219
206
  } else if (delayer.maxInclusionTimeIntoSlot !== undefined) {
220
207
  // Check if we need to delay txs sent too close to the end of the slot.
@@ -222,10 +209,10 @@ export function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer:
222
209
  const { timestamp: lastBlockTimestamp, number } = currentBlock;
223
210
  const now = delayer.dateProvider.now();
224
211
 
225
- txHash = computeTxHash(serializedTransaction);
212
+ txHash = computeSignedTransactionHash(serializedTransaction);
226
213
  const logData = {
227
214
  sender,
228
- ...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
215
+ ...omit(parseSignedTransaction(serializedTransaction), 'data', 'sidecars'),
229
216
  lastBlockTimestamp,
230
217
  now,
231
218
  maxInclusionTimeIntoSlot: delayer.maxInclusionTimeIntoSlot,
@@ -284,19 +271,3 @@ export function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer:
284
271
 
285
272
  return extended as T;
286
273
  }
287
-
288
- /**
289
- * Compute the tx hash given the serialized tx. Note that if this is a blob tx, we need to
290
- * exclude the blobs, commitments, and proofs from the hash.
291
- */
292
- function computeTxHash(serializedTransaction: Hex) {
293
- if (serializedTransaction.startsWith('0x03')) {
294
- const parsed = parseTransaction(serializedTransaction);
295
- if (parsed.blobs || parsed.sidecars) {
296
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
297
- const { blobs, sidecars, ...rest } = parsed;
298
- return keccak256(serializeTransaction({ type: 'eip4844', ...rest } as TransactionSerializableEIP4844));
299
- }
300
- }
301
- return keccak256(serializedTransaction);
302
- }