Skip to content

Commit

Permalink
last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
invocamanman committed Jun 30, 2023
1 parent dd2d061 commit 710f820
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 59 deletions.
4 changes: 2 additions & 2 deletions compiled-contracts/PolygonZkEVM.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions compiled-contracts/PolygonZkEVMMock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions compiled-contracts/PolygonZkEVMTimelock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/PolygonZkEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ contract PolygonZkEVM is
bytes32 newLocalExitRoot,
bytes32 newStateRoot,
bytes32[24] calldata proof
) internal {
) internal virtual {
bytes32 oldStateRoot;
uint64 currentLastVerifiedBatch = getLastVerifiedBatch();

Expand Down
31 changes: 31 additions & 0 deletions contracts/mainnetUpgraded/PolygonZkEVMUpgraded.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,35 @@ contract PolygonZkEVMUpgraded is PolygonZkEVM {
proof
);
}

/**
* @notice Verify and reward batches internal function
* @param pendingStateNum Init pending state, 0 if consolidated state is used
* @param initNumBatch Batch which the aggregator starts the verification
* @param finalNewBatch Last batch aggregator intends to verify
* @param newLocalExitRoot New local exit root once the batch is processed
* @param newStateRoot New State root once the batch is processed
* @param proof fflonk proof
*/
function _verifyAndRewardBatches(
uint64 pendingStateNum,
uint64 initNumBatch,
uint64 finalNewBatch,
bytes32 newLocalExitRoot,
bytes32 newStateRoot,
bytes32[24] calldata proof
) internal override {
if (initNumBatch < lastVerifiedBatchBeforeUpgrade) {
revert InitBatchMustMatchCurrentForkID();
}

super._verifyAndRewardBatches(
pendingStateNum,
initNumBatch,
finalNewBatch,
newLocalExitRoot,
newStateRoot,
proof
);
}
}
24 changes: 24 additions & 0 deletions docs/mainnetUpgraded/PolygonZkEVMUpgraded.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,27 @@ Internal function that proves a different state root given the same batches to v
|`newStateRoot` | bytes32 | New State root once the batch is processed
|`proof` | bytes32[24] | fflonk proof

### _verifyAndRewardBatches
```solidity
function _verifyAndRewardBatches(
uint64 pendingStateNum,
uint64 initNumBatch,
uint64 finalNewBatch,
bytes32 newLocalExitRoot,
bytes32 newStateRoot,
bytes32[24] proof
) internal
```
Verify and reward batches internal function


#### Parameters:
| Name | Type | Description |
| :--- | :--- | :------------------------------------------------------------------- |
|`pendingStateNum` | uint64 | Init pending state, 0 if consolidated state is used
|`initNumBatch` | uint64 | Batch which the aggregator starts the verification
|`finalNewBatch` | uint64 | Last batch aggregator intends to verify
|`newLocalExitRoot` | bytes32 | New local exit root once the batch is processed
|`newStateRoot` | bytes32 | New State root once the batch is processed
|`proof` | bytes32[24] | fflonk proof

90 changes: 49 additions & 41 deletions gas_report.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions test/contracts/polygonZkEVMUpgraded.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,5 +647,16 @@ describe('PolygonZkEVMUpgraded', () => {
zkProofFFlonk,
),
).to.be.revertedWith('InitBatchMustMatchCurrentForkID');

await expect(
polygonZkEVMContract.connect(trustedAggregator).verifyBatchesTrustedAggregator(
0,
updatedBatch - 1,
newBatch,
newLocalExitRoot,
newStateRoot2,
zkProofFFlonk,
),
).to.be.revertedWith('InitBatchMustMatchCurrentForkID');
});
});
23 changes: 12 additions & 11 deletions upgrade/timeLockUpgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const fs = require('fs');

const upgradeParameters = require('./upgrade_parameters.json');

const pathOutputJson = path.join(__dirname, `./upgrade_output_${new Date().getTime() / 1000}.json`);

async function main() {
// Set multiplier Gas
let currentProvider = ethers.provider;
if (upgradeParameters.multiplierGas) {
if (process.env.HARDHAT_NETWORK !== 'hardhat') {
const multiplierGas = upgradeParameters.multiplierGas;
const { multiplierGas } = upgradeParameters;
currentProvider = new ethers.providers.JsonRpcProvider(`https://${process.env.HARDHAT_NETWORK}.infura.io/v3/${process.env.INFURA_PROJECT_ID}`);
async function overrideFeeData() {
const feedata = await ethers.provider.getFeeData();
Expand All @@ -36,7 +37,7 @@ async function main() {
deployer = new ethers.Wallet(upgradeParameters.deployerPvtKey, currentProvider);
} else if (process.env.MNEMONIC) {
deployer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, 'm/44\'/60\'/0\'/0/0').connect(currentProvider);
console.log("using mnemonic", deployer.address)
console.log('using mnemonic', deployer.address);
} else {
[deployer] = (await ethers.getSigners());
}
Expand All @@ -54,22 +55,24 @@ async function main() {
let newImplPolygonAddress;

if (upgrade.constructorArgs) {
newImplPolygonAddress = await upgrades.prepareUpgrade(proxyPolygonAddress, polygonZkEVMFactory,
newImplPolygonAddress = await upgrades.prepareUpgrade(
proxyPolygonAddress,
polygonZkEVMFactory,
{
constructorArgs: upgrade.constructorArgs,
unsafeAllow: ['constructor', 'state-variable-immutable'],
},
);

console.log({ newImplPolygonAddress });
console.log("you can verify the new impl address with:")
console.log('you can verify the new impl address with:');
console.log(`npx hardhat verify --constructor-args upgrade/arguments.js ${newImplPolygonAddress} --network ${process.env.HARDHAT_NETWORK}\n`);
console.log("Copy the following constructor arguments on: upgrade/arguments.js \n", upgrade.constructorArgs)
console.log('Copy the following constructor arguments on: upgrade/arguments.js \n', upgrade.constructorArgs);
} else {
newImplPolygonAddress = await upgrades.prepareUpgrade(proxyPolygonAddress, polygonZkEVMFactory);

console.log({ newImplPolygonAddress });
console.log("you can verify the new impl address with:")
console.log('you can verify the new impl address with:');
console.log(`npx hardhat verify ${newImplPolygonAddress} --network ${process.env.HARDHAT_NETWORK}`);
}

Expand All @@ -89,14 +92,12 @@ async function main() {
polygonZkEVMFactory.interface.encodeFunctionData(
upgrade.callAfterUpgrade.functionName,
upgrade.callAfterUpgrade.arguments,
)
),
],
),
ethers.constants.HashZero, // predecesoor
salt, // salt
);


} else {
operation = genOperation(
proxyAdmin.address,
Expand Down Expand Up @@ -144,8 +145,8 @@ async function main() {
output.push({
contractName: upgrade.contractName,
scheduleData,
executeData
})
executeData,
});
}

fs.writeFileSync(pathOutputJson, JSON.stringify(output, null, 1));
Expand Down

0 comments on commit 710f820

Please sign in to comment.