|
| 1 | +import { EcdsaKAccountContract } from '@aztec/accounts/ecdsa'; |
| 2 | +import { SchnorrAccountContract } from '@aztec/accounts/schnorr'; |
| 3 | +import { NO_FROM } from '@aztec/aztec.js/account'; |
1 | 4 | import { AztecAddress } from '@aztec/aztec.js/addresses'; |
2 | 5 | import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization'; |
3 | 6 | import { Fr } from '@aztec/aztec.js/fields'; |
4 | 7 | import type { Logger } from '@aztec/aztec.js/log'; |
5 | 8 | import type { AztecNode } from '@aztec/aztec.js/node'; |
| 9 | +import { randomBytes } from '@aztec/foundation/crypto/random'; |
| 10 | +import { Fq } from '@aztec/foundation/curves/bn254'; |
6 | 11 | import { AMMContract } from '@aztec/noir-contracts.js/AMM'; |
7 | 12 | import { type TokenContract, TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; |
8 | 13 | import { AuthWitTestContract, AuthWitTestContractArtifact } from '@aztec/noir-test-contracts.js/AuthWitTest'; |
@@ -420,4 +425,60 @@ describe('Kernelless simulation', () => { |
420 | 425 | noteHashMembershipWitnessSpy.mockRestore(); |
421 | 426 | }); |
422 | 427 | }); |
| 428 | + |
| 429 | + describe('account contract deployment', () => { |
| 430 | + it('simulates Schnorr account deployment and gas matches with-kernels counterpart', async () => { |
| 431 | + const signingKey = Fq.random(); |
| 432 | + const accountManager = await wallet.createAccount({ |
| 433 | + secret: Fr.random(), |
| 434 | + salt: Fr.random(), |
| 435 | + contract: new SchnorrAccountContract(signingKey), |
| 436 | + type: 'schnorr', |
| 437 | + }); |
| 438 | + const deployMethod = await accountManager.getDeployMethod(); |
| 439 | + const deployOptions = { from: NO_FROM, skipClassPublication: true }; |
| 440 | + |
| 441 | + wallet.setSimulationMode('kernelless-override'); |
| 442 | + const kernellessResult = await deployMethod.simulate(deployOptions); |
| 443 | + const kernellessGas = kernellessResult.estimatedGas!; |
| 444 | + |
| 445 | + wallet.setSimulationMode('full'); |
| 446 | + const withKernelsResult = await deployMethod.simulate(deployOptions); |
| 447 | + const withKernelsGas = withKernelsResult.estimatedGas!; |
| 448 | + |
| 449 | + logger.info(`Schnorr kernelless gas: L2=${kernellessGas.gasLimits.l2Gas} DA=${kernellessGas.gasLimits.daGas}`); |
| 450 | + logger.info( |
| 451 | + `Schnorr with kernels gas: L2=${withKernelsGas.gasLimits.l2Gas} DA=${withKernelsGas.gasLimits.daGas}`, |
| 452 | + ); |
| 453 | + |
| 454 | + expect(kernellessGas.gasLimits.daGas).toEqual(withKernelsGas.gasLimits.daGas); |
| 455 | + expect(kernellessGas.gasLimits.l2Gas).toEqual(withKernelsGas.gasLimits.l2Gas); |
| 456 | + }); |
| 457 | + |
| 458 | + it('simulates ECDSA account deployment and gas matches with-kernels counterpart', async () => { |
| 459 | + const signingKey = randomBytes(32); |
| 460 | + const accountManager = await wallet.createAccount({ |
| 461 | + secret: Fr.random(), |
| 462 | + salt: Fr.random(), |
| 463 | + contract: new EcdsaKAccountContract(signingKey), |
| 464 | + type: 'ecdsasecp256k1', |
| 465 | + }); |
| 466 | + const deployMethod = await accountManager.getDeployMethod(); |
| 467 | + const deployOptions = { from: NO_FROM, skipClassPublication: true }; |
| 468 | + |
| 469 | + wallet.setSimulationMode('kernelless-override'); |
| 470 | + const kernellessResult = await deployMethod.simulate(deployOptions); |
| 471 | + const kernellessGas = kernellessResult.estimatedGas!; |
| 472 | + |
| 473 | + wallet.setSimulationMode('full'); |
| 474 | + const withKernelsResult = await deployMethod.simulate(deployOptions); |
| 475 | + const withKernelsGas = withKernelsResult.estimatedGas!; |
| 476 | + |
| 477 | + logger.info(`ECDSA kernelless gas: L2=${kernellessGas.gasLimits.l2Gas} DA=${kernellessGas.gasLimits.daGas}`); |
| 478 | + logger.info(`ECDSA with kernels gas: L2=${withKernelsGas.gasLimits.l2Gas} DA=${withKernelsGas.gasLimits.daGas}`); |
| 479 | + |
| 480 | + expect(kernellessGas.gasLimits.daGas).toEqual(withKernelsGas.gasLimits.daGas); |
| 481 | + expect(kernellessGas.gasLimits.l2Gas).toEqual(withKernelsGas.gasLimits.l2Gas); |
| 482 | + }); |
| 483 | + }); |
423 | 484 | }); |
0 commit comments