From b7f8ed33c8f9ab39ecaf606a69653cec5c9f5d6f Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Wed, 20 Dec 2023 23:46:51 +0100 Subject: [PATCH 1/3] decrease the fee because of increased number of transactions --- SystemConfig.json | 4 ++-- ethereum/contracts/zksync/Config.sol | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SystemConfig.json b/SystemConfig.json index 9b11b9636..22fd1f84d 100644 --- a/SystemConfig.json +++ b/SystemConfig.json @@ -6,8 +6,8 @@ "L1_GAS_PER_PUBDATA_BYTE": 17, "BATCH_OVERHEAD_L2_GAS": 1200000, "BATCH_OVERHEAD_L1_GAS": 1000000, - "MAX_TRANSACTIONS_IN_BATCH": 1024, - "BOOTLOADER_TX_ENCODING_SPACE": 8740224, + "MAX_TRANSACTIONS_IN_BATCH": 10000, + "BOOTLOADER_TX_ENCODING_SPACE": 9090400, "L1_TX_INTRINSIC_L2_GAS": 167157, "L1_TX_INTRINSIC_PUBDATA": 88, "L1_TX_MIN_L2_GAS_BASE": 173484, diff --git a/ethereum/contracts/zksync/Config.sol b/ethereum/contracts/zksync/Config.sol index 01a7a8f8e..8f0f33851 100644 --- a/ethereum/contracts/zksync/Config.sol +++ b/ethereum/contracts/zksync/Config.sol @@ -107,7 +107,7 @@ uint256 constant PACKED_L2_BLOCK_TIMESTAMP_MASK = 0xffffffffffffffffffffffffffff /// need to pay to compensate for the batch being closed. /// @dev It is expected that the L1 contracts will enforce that the L2 gas price will be high enough to compensate /// the operator in case the batch is closed because of tx slots filling up. -uint256 constant TX_SLOT_OVERHEAD_L2_GAS = 80000; +uint256 constant TX_SLOT_OVERHEAD_L2_GAS = 10000; /// @dev The overhead for each byte of the bootloader memory that the encoding of the transaction. /// It is roughly equal to 80kk/BOOTLOADER_MEMORY_FOR_TXS, i.e. how many gas would an L1->L2 transaction From c1bf18703ecf7c68f1b600dea7dced9c5acdd5fc Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Thu, 21 Dec 2023 10:52:01 +0100 Subject: [PATCH 2/3] make lint pass --- .../dev-contracts/test/MailboxFacetTest.sol | 4 +- .../test/TransactionValidatorTest.sol | 4 +- ethereum/test/unit_tests/mailbox_test.spec.ts | 73 +++++++++++-------- .../transaction_validator_test.spec.ts | 22 +++--- 4 files changed, 56 insertions(+), 47 deletions(-) diff --git a/ethereum/contracts/dev-contracts/test/MailboxFacetTest.sol b/ethereum/contracts/dev-contracts/test/MailboxFacetTest.sol index 9ea1b36a4..95d88dbfd 100644 --- a/ethereum/contracts/dev-contracts/test/MailboxFacetTest.sol +++ b/ethereum/contracts/dev-contracts/test/MailboxFacetTest.sol @@ -14,9 +14,7 @@ contract MailboxFacetTest is MailboxFacet { s.feeParams = _feeParams; } - function getL2GasPrice( - uint256 _l1GasPrice - ) external view returns (uint256) { + function getL2GasPrice(uint256 _l1GasPrice) external view returns (uint256) { return _deriveL2GasPrice(_l1GasPrice, REQUIRED_L2_GAS_PRICE_PER_PUBDATA); } } diff --git a/ethereum/contracts/dev-contracts/test/TransactionValidatorTest.sol b/ethereum/contracts/dev-contracts/test/TransactionValidatorTest.sol index 47548880f..ba5d4f0e5 100644 --- a/ethereum/contracts/dev-contracts/test/TransactionValidatorTest.sol +++ b/ethereum/contracts/dev-contracts/test/TransactionValidatorTest.sol @@ -23,9 +23,7 @@ contract TransactionValidatorTest { TransactionValidator.validateUpgradeTransaction(_transaction); } - function getOverheadForTransaction( - uint256 _encodingLength - ) external pure returns (uint256) { + function getOverheadForTransaction(uint256 _encodingLength) external pure returns (uint256) { return TransactionValidator.getOverheadForTransaction(_encodingLength); } } diff --git a/ethereum/test/unit_tests/mailbox_test.spec.ts b/ethereum/test/unit_tests/mailbox_test.spec.ts index 6314af01f..3b10fa383 100644 --- a/ethereum/test/unit_tests/mailbox_test.spec.ts +++ b/ethereum/test/unit_tests/mailbox_test.spec.ts @@ -1,8 +1,14 @@ import { expect } from "chai"; import * as hardhat from "hardhat"; import { Action, facetCut, diamondCut } from "../../src.ts/diamondCut"; -import { MailboxFacet, MockExecutorFacet, Forwarder, MailboxFacetTestFactory, MailboxFacetTest } from "../../typechain"; -import { MailboxFacetFactory, MockExecutorFacetFactory, DiamondInitFactory, ForwarderFactory } from "../../typechain"; +import type { MailboxFacet, MockExecutorFacet, Forwarder, MailboxFacetTest } from "../../typechain"; +import { + MailboxFacetTestFactory, + MailboxFacetFactory, + MockExecutorFacetFactory, + DiamondInitFactory, + ForwarderFactory, +} from "../../typechain"; import { DEFAULT_REVERT_REASON, getCallRevertReason, @@ -210,7 +216,9 @@ describe("Mailbox tests", function () { let testContract: MailboxFacetTest; const TEST_GAS_PRICES = []; - async function testOnAllGasPrices(testFunc: (price: ethers.BigNumber) => ethers.utils.Deferrable) { + async function testOnAllGasPrices( + testFunc: (price: ethers.BigNumber) => ethers.utils.Deferrable + ) { for (const gasPrice of TEST_GAS_PRICES) { expect(await testContract.getL2GasPrice(gasPrice)).to.eq(testFunc(gasPrice)); } @@ -223,43 +231,49 @@ describe("Mailbox tests", function () { // Generating 10 more gas prices for test suit let priceGwei = 0.001; - while(priceGwei < 10000) { + while (priceGwei < 10000) { priceGwei *= 2; - const priceWei = ethers.utils.parseUnits(priceGwei.toString(), 'gwei'); + const priceWei = ethers.utils.parseUnits(priceGwei.toString(), "gwei"); TEST_GAS_PRICES.push(priceWei); } }); it("Should allow simulating old behaviour", async () => { // Simulating old L2 gas price calculations might be helpful for migration between the systems - await (await testContract.setFeeParams({ - ...defaultFeeParams(), - pubdataPricingMode: PubdataPricingMode.Rollup, - batchOverheadL1Gas: 0, - minimalL2GasPrice: 500_000_000, - })).wait(); + await ( + await testContract.setFeeParams({ + ...defaultFeeParams(), + pubdataPricingMode: PubdataPricingMode.Rollup, + batchOverheadL1Gas: 0, + minimalL2GasPrice: 500_000_000, + }) + ).wait(); // Testing the logic under low / medium / high L1 gas price testOnAllGasPrices(expectedLegacyL2GasPrice); }); it("Should allow free pubdata", async () => { - await (await testContract.setFeeParams({ - ...defaultFeeParams(), - pubdataPricingMode: PubdataPricingMode.Validium, - batchOverheadL1Gas: 0 - })).wait(); - + await ( + await testContract.setFeeParams({ + ...defaultFeeParams(), + pubdataPricingMode: PubdataPricingMode.Validium, + batchOverheadL1Gas: 0, + }) + ).wait(); + // The gas price per pubdata is still constant, however, the L2 gas price is always equal to the minimalL2GasPrice testOnAllGasPrices(() => { return ethers.BigNumber.from(defaultFeeParams().minimalL2GasPrice); - }) + }); }); - + it("Should work fine in general case", async () => { - await (await testContract.setFeeParams({ - ...defaultFeeParams(), - })).wait(); + await ( + await testContract.setFeeParams({ + ...defaultFeeParams(), + }) + ).wait(); testOnAllGasPrices(calculateL2GasPrice); }); @@ -363,7 +377,7 @@ function calculateL2GasPrice(l1GasPrice: ethers.BigNumber) { let pubdataPriceETH = ethers.BigNumber.from(0); if (feeParams.pubdataPricingMode === PubdataPricingMode.Rollup) { - pubdataPriceETH = l1GasPrice.mul(17); + pubdataPriceETH = l1GasPrice.mul(17); } const batchOverheadETH = l1GasPrice.mul(feeParams.batchOverheadL1Gas); @@ -379,19 +393,20 @@ function calculateL2GasPrice(l1GasPrice: ethers.BigNumber) { return minL2GasPriceETH; } - function expectedLegacyL2GasPrice(l1GasPrice: ethers.BigNumberish) { // In the previous release the following code was used to calculate the L2 gas price for L1->L2 transactions: - // + // // uint256 pubdataPriceETH = L1_GAS_PER_PUBDATA_BYTE * _l1GasPrice; // uint256 minL2GasPriceETH = (pubdataPriceETH + _gasPricePerPubdata - 1) / _gasPricePerPubdata; // return Math.max(FAIR_L2_GAS_PRICE, minL2GasPriceETH); - // + // const pubdataPriceETH = ethers.BigNumber.from(l1GasPrice).mul(17); - const gasPricePerPubdata = ethers.BigNumber.from(REQUIRED_L2_GAS_PRICE_PER_PUBDATA); + const gasPricePerPubdata = ethers.BigNumber.from(REQUIRED_L2_GAS_PRICE_PER_PUBDATA); const FAIR_L2_GAS_PRICE = 500_000_000; // 0.5 gwei - const minL2GasPirceETH = ethers.BigNumber.from(pubdataPriceETH.add(gasPricePerPubdata).sub(1)).div(gasPricePerPubdata); + const minL2GasPirceETH = ethers.BigNumber.from(pubdataPriceETH.add(gasPricePerPubdata).sub(1)).div( + gasPricePerPubdata + ); - return ethers.BigNumber.from(Math.max(FAIR_L2_GAS_PRICE, minL2GasPirceETH.toNumber())) + return ethers.BigNumber.from(Math.max(FAIR_L2_GAS_PRICE, minL2GasPirceETH.toNumber())); } diff --git a/ethereum/test/unit_tests/transaction_validator_test.spec.ts b/ethereum/test/unit_tests/transaction_validator_test.spec.ts index 8f83bb569..7d5483d52 100644 --- a/ethereum/test/unit_tests/transaction_validator_test.spec.ts +++ b/ethereum/test/unit_tests/transaction_validator_test.spec.ts @@ -48,13 +48,7 @@ describe("TransactionValidator tests", function () { ); expect(result).equal("uk"); - const result = await getCallRevertReason( - tester.validateL1ToL2Transaction( - createTestTransaction({}), - 500000, - 1 - ) - ); + const result = await getCallRevertReason(tester.validateL1ToL2Transaction(createTestTransaction({}), 500000, 1)); expect(result).equal("uk"); }); @@ -72,12 +66,16 @@ describe("TransactionValidator tests", function () { }); it("Should allow large transactions if the caller is fine with it", async () => { - // This transaction could publish 2B bytes of pubdata & has 2B gas, which is more than would be typically + // This transaction could publish 2B bytes of pubdata & has 2B gas, which is more than would be typically // allowed in the production system - await tester.validateL1ToL2Transaction(createTestTransaction({ - gasPergasPerPubdataByteLimit: 1, - gasLimit: 2_000_000_000, - }), 2_000_000_000, 2_000_000_000); + await tester.validateL1ToL2Transaction( + createTestTransaction({ + gasPergasPerPubdataByteLimit: 1, + gasLimit: 2_000_000_000, + }), + 2_000_000_000, + 2_000_000_000 + ); }); }); From 4f5f1a24b9723f4c0718ec21b3ff38f467d7e749 Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Thu, 21 Dec 2023 11:15:59 +0100 Subject: [PATCH 3/3] fix unit tests --- ethereum/test/unit_tests/transaction_validator_test.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/test/unit_tests/transaction_validator_test.spec.ts b/ethereum/test/unit_tests/transaction_validator_test.spec.ts index 7d5483d52..928623d75 100644 --- a/ethereum/test/unit_tests/transaction_validator_test.spec.ts +++ b/ethereum/test/unit_tests/transaction_validator_test.spec.ts @@ -243,7 +243,7 @@ function createTestTransaction(overrides) { function getCorrectOverheadForTransaction(len: number) { const MEMORY_BYTE_OVERHEAD = 10; - const TX_SLOT_OVERHEAD = 80000; + const TX_SLOT_OVERHEAD = 10000; return Math.max(len * MEMORY_BYTE_OVERHEAD, TX_SLOT_OVERHEAD); }