Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more up to date OZ library #128

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions ethereum/contracts/dev-contracts/test/MailboxFacetTest.sol
Expand Up @@ -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);
}
}
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions ethereum/package.json
Expand Up @@ -9,8 +9,8 @@
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-solpp": "^2.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@openzeppelin/contracts": "4.9.2",
"@openzeppelin/contracts-upgradeable": "4.9.2",
"@openzeppelin/contracts": "4.9.5",
"@openzeppelin/contracts-upgradeable": "4.9.5",
"@typechain/ethers-v5": "^2.0.0",
"@types/argparse": "^1.0.36",
"@types/chai": "^4.2.21",
Expand Down
73 changes: 44 additions & 29 deletions 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,
Expand Down Expand Up @@ -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<ethers.BigNumber>) {
async function testOnAllGasPrices(
testFunc: (price: ethers.BigNumber) => ethers.utils.Deferrable<ethers.BigNumber>
) {
for (const gasPrice of TEST_GAS_PRICES) {
expect(await testContract.getL2GasPrice(gasPrice)).to.eq(testFunc(gasPrice));
}
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
Expand All @@ -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()));
}
22 changes: 10 additions & 12 deletions ethereum/test/unit_tests/transaction_validator_test.spec.ts
Expand Up @@ -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");
});

Expand All @@ -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
);
});
});

Expand Down
18 changes: 9 additions & 9 deletions ethereum/yarn.lock
Expand Up @@ -866,15 +866,15 @@
"@types/sinon-chai" "^3.2.3"
"@types/web3" "1.0.19"

"@openzeppelin/contracts-upgradeable@4.9.2":
version "4.9.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.2.tgz#a817c75688f8daede420052fbcb34e52482e769e"
integrity sha512-siviV3PZV/fHfPaoIC51rf1Jb6iElkYWnNYZ0leO23/ukXuvOyoC/ahy8jqiV7g+++9Nuo3n/rk5ajSN/+d/Sg==

"@openzeppelin/contracts@4.9.2":
version "4.9.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.2.tgz#1cb2d5e4d3360141a17dbc45094a8cad6aac16c1"
integrity sha512-mO+y6JaqXjWeMh9glYVzVu8HYPGknAAnWyxTRhGeckOruyXQMNnlcW6w/Dx9ftLeIQk6N+ZJFuVmTwF7lEIFrg==
"@openzeppelin/contracts-upgradeable@4.9.5":
version "4.9.5"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.5.tgz#572b5da102fc9be1d73f34968e0ca56765969812"
integrity sha512-f7L1//4sLlflAN7fVzJLoRedrf5Na3Oal5PZfIq55NFcVZ90EpV1q5xOvL4lFvg3MNICSDr2hH0JUBxwlxcoPg==

"@openzeppelin/contracts@4.9.5":
version "4.9.5"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.5.tgz#1eed23d4844c861a1835b5d33507c1017fa98de8"
integrity sha512-ZK+W5mVhRppff9BE6YdR8CC52C8zAvsVAiWhEtQ5+oNxFE6h1WdeWo+FJSF8KKvtxxVYZ7MTP/5KoVpAU3aSWg==

"@pkgr/utils@^2.3.1":
version "2.4.2"
Expand Down
4 changes: 2 additions & 2 deletions zksync/package.json
Expand Up @@ -14,8 +14,8 @@
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@nomiclabs/hardhat-solpp": "^2.0.0",
"@openzeppelin/contracts": "4.9.2",
"@openzeppelin/contracts-upgradeable": "4.9.2",
"@openzeppelin/contracts": "4.9.5",
"@openzeppelin/contracts-upgradeable": "4.9.5",
"@typechain/ethers-v5": "^2.0.0",
"@types/chai": "^4.2.21",
"@types/chai-as-promised": "^7.1.4",
Expand Down
18 changes: 9 additions & 9 deletions zksync/yarn.lock
Expand Up @@ -857,15 +857,15 @@
fs-extra "^7.0.1"
solpp "^0.11.5"

"@openzeppelin/contracts-upgradeable@4.9.2":
version "4.9.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.2.tgz#a817c75688f8daede420052fbcb34e52482e769e"
integrity sha512-siviV3PZV/fHfPaoIC51rf1Jb6iElkYWnNYZ0leO23/ukXuvOyoC/ahy8jqiV7g+++9Nuo3n/rk5ajSN/+d/Sg==

"@openzeppelin/contracts@4.9.2":
version "4.9.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.2.tgz#1cb2d5e4d3360141a17dbc45094a8cad6aac16c1"
integrity sha512-mO+y6JaqXjWeMh9glYVzVu8HYPGknAAnWyxTRhGeckOruyXQMNnlcW6w/Dx9ftLeIQk6N+ZJFuVmTwF7lEIFrg==
"@openzeppelin/contracts-upgradeable@4.9.5":
version "4.9.5"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.5.tgz#572b5da102fc9be1d73f34968e0ca56765969812"
integrity sha512-f7L1//4sLlflAN7fVzJLoRedrf5Na3Oal5PZfIq55NFcVZ90EpV1q5xOvL4lFvg3MNICSDr2hH0JUBxwlxcoPg==

"@openzeppelin/contracts@4.9.5":
version "4.9.5"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.5.tgz#1eed23d4844c861a1835b5d33507c1017fa98de8"
integrity sha512-ZK+W5mVhRppff9BE6YdR8CC52C8zAvsVAiWhEtQ5+oNxFE6h1WdeWo+FJSF8KKvtxxVYZ7MTP/5KoVpAU3aSWg==

"@pkgr/utils@^2.3.1":
version "2.4.2"
Expand Down