Skip to content

Commit

Permalink
Updates aggchinECDSA to look like FEPV·
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Feb 25, 2025
1 parent ae01976 commit bd809aa
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 73 deletions.
67 changes: 30 additions & 37 deletions contracts/v2/aggchains/AggchainECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ contract AggchainECDSA is AggchainBase, IAggchain {
*/
event OnVerifyPessimistic(bytes32 newStateRoot);

////////////////////////////////////////////////////////////
// Errors //
////////////////////////////////////////////////////////////
/// @notice Thrown when trying to initialize the wrong initialize function.
error InvalidInitializer();

////////////////////////////////////////////////////////////
// Modifiers //
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -88,8 +94,8 @@ contract AggchainECDSA is AggchainBase, IAggchain {
(
// aggchainBase params
bool _useDefaultGateway,
bytes32[] memory _ownedAggchainVKeys,
bytes4[] memory _aggchainVKeySelectors,
bytes32 _initOwnedAggchainVKey,
bytes2 _initAggchainVKeySelector,
address _vKeyManager,
// PolygonConsensusBase params
address _admin,
Expand All @@ -101,8 +107,8 @@ contract AggchainECDSA is AggchainBase, IAggchain {
initializeBytesAggchain,
(
bool,
bytes32[],
bytes4[],
bytes32,
bytes2,
address,
address,
address,
Expand All @@ -112,12 +118,8 @@ contract AggchainECDSA is AggchainBase, IAggchain {
)
);
// Set aggchainBase variables
_initializeAggchainBase(
_useDefaultGateway,
_ownedAggchainVKeys,
_aggchainVKeySelectors,
_vKeyManager
);
_initializeAggchainBase(_useDefaultGateway, _initOwnedAggchainVKey, _initAggchainVKeySelector, _vKeyManager);

// init polygonConsensusBase params
_initializePolygonConsensusBase(
_admin,
Expand All @@ -131,18 +133,18 @@ contract AggchainECDSA is AggchainBase, IAggchain {
// aggchainBase params
(
bool _useDefaultGateway,
bytes32[] memory _ownedAggchainVKeys,
bytes4[] memory _aggchainVKeySelectors,
bytes32 _initOwnedAggchainVKey,
bytes2 _initAggchainVKeySelector,
address _vKeyManager
) = abi.decode(
initializeBytesAggchain,
(bool, bytes32[], bytes4[], address)
(bool, bytes32, bytes2, address)
);
// Set aggchainBase variables
_initializeAggchainBase(
_useDefaultGateway,
_ownedAggchainVKeys,
_aggchainVKeySelectors,
_initOwnedAggchainVKey,
_initAggchainVKeySelector,
_vKeyManager
);
} else {
Expand All @@ -151,31 +153,22 @@ contract AggchainECDSA is AggchainBase, IAggchain {
}
}

/// @notice Initializer AggchainBase storage
/// @param _useDefaultGateway Flag to setup initial values for the owned gateway
/// @param _initOwnedAggchainVKey Initial owned aggchain verification key
/// @param _initAggchainVKeySelector Initial aggchain selector
/// @param _vKeyManager Initial vKeyManager
function _initializeAggchainBase(
bool _useDefaultGateway,
bytes32[] memory _initOwnedAggchainVKey,
bytes4[] memory _initAggchainVKeySelector,
address _vKeyManager
) internal {
useDefaultGateway = _useDefaultGateway;
/**
* @notice Initializer AggchainBase storage
* @param _useOwnedGateway Flag to setup initial values for the owned gateway
* @param _initOwnedAggchainVKey Initial owned aggchain verification key
* @param _initAggchainVKeySelector Initial aggchain selector
* @param _vKeyManager Initial vKeyManager
*/
function _initializeAggchainBase(bool _useOwnedGateway, bytes32 _initOwnedAggchainVKey, bytes2 _initAggchainVKeySelector, address _vKeyManager) internal {
useDefaultGateway = _useOwnedGateway;
// set the initial aggchain keys
ownedAggchainVKeys[getFinalAggchainVKeySelectorFromType(_initAggchainVKeySelector, AGGCHAIN_TYPE_SELECTOR)] = _initOwnedAggchainVKey;
// set initial vKeyManager
vKeyManager = _vKeyManager;
// set the owned verification keys
if (_initOwnedAggchainVKey.length != _initAggchainVKeySelector.length) {
revert OwnedAggchainVKeyLengthMismatch();
}

for (uint256 i = 0; i < _initOwnedAggchainVKey.length; i++) {
ownedAggchainVKeys[
_initAggchainVKeySelector[i]
] = _initOwnedAggchainVKey[i];
}
}


/**
* @notice Initializer PolygonConsensusBase storage
* @param _admin Admin address
Expand Down
6 changes: 6 additions & 0 deletions contracts/v2/aggchains/AggchainFEP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ contract AggchainFEP is AggchainBase, IAggchain {
uint128 initL2BlockNumber
);

////////////////////////////////////////////////////////////
// Errors //
////////////////////////////////////////////////////////////
/// @notice Thrown when trying to initialize the wrong initialize function.
error InvalidInitializer();

////////////////////////////////////////////////////////////
// Modifiers //
////////////////////////////////////////////////////////////
Expand Down
9 changes: 4 additions & 5 deletions contracts/v2/interfaces/IAggchainBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,18 @@ interface IAggchainBaseErrors {
error InvalidInitializeFunction();
/// @notice Thrown when trying to enable or disable the default gateway when it is already set.
error UseDefaultGatewayAlreadySet();
/// @notice Thrown when trying to initialize the wrong initialize function.
error InvalidInitializer();
/// @notice Thrown when trying to call a function that only the VKeyManager can call.
error OnlyVKeyManager();
/// @notice Thrown when trying to call a function that only the pending VKeyManager can call.
error OnlyPendingVKeyManager();
/// @notice Thrown when trying to retrieve an aggchain verification key from the mapping that doesn't exists.
error AggchainVKeyNotFound();
/// @notice owned vKeys and selectors length mismatch.
error OwnedAggchainVKeyLengthMismatch();
}
/**
* @title IAggchainBase
* @notice Shared interface for native aggchain implementations.
*/
interface IAggchainBase is IAggchainBaseErrors, IAggchainBaseEvents {}
interface IAggchainBase is IAggchainBaseErrors, IAggchainBaseEvents {
/// @notice Returns the unique aggchain type selector identifier.
function AGGCHAIN_TYPE_SELECTOR() external view returns (bytes2);
}
12 changes: 6 additions & 6 deletions src/utils-aggchain-ECDSA.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const AGGCHAIN_TYPE_SELECTOR_ECDSA = '0x0000';
function encodeInitializeBytesAggchainECDSAv0(
useDefaultGateway,
ownedAggchainVKey,
aggchainVKeySelectors,
aggchainVKeySelector,
vKeyManager,
admin,
trustedSequencer,
Expand All @@ -38,11 +38,11 @@ function encodeInitializeBytesAggchainECDSAv0(
networkName,
) {
return ethers.AbiCoder.defaultAbiCoder().encode(
['bool', 'bytes32[]', 'bytes4[]', 'address', 'address', 'address', 'address', 'string', 'string'],
['bool', 'bytes32', 'bytes2', 'address', 'address', 'address', 'address', 'string', 'string'],
[
useDefaultGateway,
ownedAggchainVKey,
aggchainVKeySelectors,
aggchainVKeySelector,
vKeyManager,
admin,
trustedSequencer,
Expand All @@ -64,15 +64,15 @@ function encodeInitializeBytesAggchainECDSAv0(
function encodeInitializeBytesAggchainECDSAv1(
useDefaultGateway,
ownedAggchainVKey,
aggchainVKeySelectors,
aggchainVKeySelector,
vKeyManager,
) {
return ethers.AbiCoder.defaultAbiCoder().encode(
['bool', 'bytes32[]', 'bytes4[]', 'address'],
['bool', 'bytes32', 'bytes2', 'address'],
[
useDefaultGateway,
ownedAggchainVKey,
aggchainVKeySelectors,
aggchainVKeySelector,
vKeyManager,
],
);
Expand Down
30 changes: 13 additions & 17 deletions test/contractsv2/AggchainECDSA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ describe("AggchainECDSA", () => {
// aggchain variables
let initializeBytesAggchain: string;
let initializeBytesAggchainError: string;
const AGGCHAIN_TYPE_SELECTOR = "0x00";
const AGGCHAIN_TYPE_SELECTOR = "0x0000";
const AGGCHAIN_TYPE = 1;
const aggchainSelector = "0x22222222";
const newAggChainVKey = "0x2222222222222222222222222222222222222222222222222222222222222222";
const aggchainSelector2 = "0x11111111";
const newAggChainVKey2 = "0x1111111111111111111111111111111111111111111111111111111111111111";
const aggchainVkeySelector = "0x1234";
const aggchainVkeySelector = "0x1235";
const newStateRoot = "0x1122334455667788990011223344556677889900112233445566778899001122";

const useDefaultGateway = true;
const aggchainSelectors = ["0x12345678"];
const ownedAggchainVKeys = ["0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"];
const aggchainSelector3 = "0x1234";
const ownedAggchainVKey = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";

beforeEach("Deploy contract", async () => {
upgrades.silenceWarnings();
Expand All @@ -65,8 +65,8 @@ describe("AggchainECDSA", () => {

initializeBytesAggchain = utilsECDSA.encodeInitializeBytesAggchainECDSAv0(
useDefaultGateway,
ownedAggchainVKeys,
aggchainSelectors,
ownedAggchainVKey,
aggchainSelector3,
vKeyManager.address,
admin.address,
trustedSequencer.address,
Expand Down Expand Up @@ -132,7 +132,7 @@ describe("AggchainECDSA", () => {
await aggchainECDSAcontract.waitForDeployment();
});

it("should check the initalized parameters", async () => {
it("should check the initialized parameters", async () => {
// initialize zkEVM using non admin address
await expect(aggchainECDSAcontract.initialize(initializeBytesAggchain)).to.be.revertedWithCustomError(
aggchainECDSAcontract,
Expand All @@ -150,7 +150,7 @@ describe("AggchainECDSA", () => {
expect(await aggchainECDSAcontract.trustedSequencerURL()).to.be.equal(urlSequencer);
expect(await aggchainECDSAcontract.networkName()).to.be.equal(networkName);
expect(await aggchainECDSAcontract.gasTokenAddress()).to.be.equal(gasTokenAddress);
expect(await aggchainECDSAcontract.ownedAggchainVKeys(aggchainSelectors[0])).to.be.equal(ownedAggchainVKeys[0]);
expect(await aggchainECDSAcontract.ownedAggchainVKeys(`${aggchainSelector3}${AGGCHAIN_TYPE_SELECTOR.slice(2)}`)).to.be.equal(ownedAggchainVKey);

// initialize again
await expect(
Expand Down Expand Up @@ -396,22 +396,18 @@ describe("AggchainECDSA", () => {

initializeBytesAggchain = utilsECDSA.encodeInitializeBytesAggchainECDSAv1(
useDefaultGateway,
ownedAggchainVKeys,
aggchainSelectors,
ownedAggchainVKey,
aggchainSelector3,
vKeyManager.address
);

initializeBytesAggchainError = utilsECDSA.encodeInitializeBytesAggchainECDSAv1(
useDefaultGateway,
ownedAggchainVKeys,
[],
ownedAggchainVKey,
"0x0000",
vKeyManager.address
);

await expect(
ppConsensusContract.connect(rollupManagerSigner).initialize(initializeBytesAggchainError, {gasPrice: 0})
).to.be.revertedWithCustomError(aggchainECDSAcontract, "OwnedAggchainVKeyLengthMismatch");

await ppConsensusContract.connect(rollupManagerSigner).initialize(initializeBytesAggchain, {gasPrice: 0});

// check initializeBytesAggchain
Expand All @@ -421,6 +417,6 @@ describe("AggchainECDSA", () => {
expect(await ppConsensusContract.trustedSequencerURL()).to.be.equal(urlSequencer);
expect(await ppConsensusContract.networkName()).to.be.equal(networkName);
expect(await ppConsensusContract.gasTokenAddress()).to.be.equal(gasTokenAddress);
expect(await ppConsensusContract.ownedAggchainVKeys(aggchainSelectors[0])).to.be.equal(ownedAggchainVKeys[0]);
expect(await ppConsensusContract.ownedAggchainVKeys(`${aggchainSelector3}${AGGCHAIN_TYPE_SELECTOR.slice(2)}`)).to.be.equal(ownedAggchainVKey);
});
});
8 changes: 4 additions & 4 deletions test/contractsv2/PolygonRollupManagerAL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ describe("Polygon rollup manager aggregation layer v3", () => {
const aggchainECDSAFactory = await ethers.getContractFactory("AggchainECDSA");
const initializeBytesCustomChain = encodeInitializeBytesAggchainECDSAv1(
true, //useDefaultGateway
[], //ownedAggchainVKeys
[], // aggchainVkeySelector
ethers.ZeroHash, //ownedAggchainVKey
"0x0000", // aggchainVkeySelector
vKeyManager.address
);
const upgradeData = aggchainECDSAFactory.interface.encodeFunctionData("initialize(bytes)", [
Expand Down Expand Up @@ -715,8 +715,8 @@ describe("Polygon rollup manager aggregation layer v3", () => {
async function createECDSARollup(rollupTypeIdECDSA: number) {
const initializeBytesCustomChain = encodeInitializeBytesAggchainECDSAv0(
true, // useDefaultGateway
[], // ownedAggchainVKeys
[], //aggchainVKeysSelectors
ethers.ZeroHash, // ownedAggchainVKeys
"0x0000", //aggchainVKeysSelectors
vKeyManager.address,
admin.address,
trustedSequencer.address,
Expand Down
8 changes: 4 additions & 4 deletions test/contractsv2/PolygonRollupManagerALUpgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ describe("Polygon rollup manager aggregation layer v3 UPGRADED", () => {
const aggchainECDSAFactory = await ethers.getContractFactory("AggchainECDSA");
const initializeBytesCustomChain = encodeInitializeBytesAggchainECDSAv1(
true, //useDefaultGateway
[], //ownedAggchainVKeys
[], // aggchainVkeySelector
ethers.ZeroHash, //ownedAggchainVKeys
"0x0000", // aggchainVkeySelector
vKeyManager.address
);
const upgradeData = aggchainECDSAFactory.interface.encodeFunctionData("initialize(bytes)", [
Expand Down Expand Up @@ -709,8 +709,8 @@ describe("Polygon rollup manager aggregation layer v3 UPGRADED", () => {
async function createECDSARollup(rollupTypeIdECDSA: number) {
const initializeBytesCustomChain = encodeInitializeBytesAggchainECDSAv0(
true, // useDefaultGateway
[], // ownedAggchainVKeys
[], //aggchainVKeysSelectors
ethers.ZeroHash, // ownedAggchainVKeys
"0x0000", //aggchainVKeysSelectors
vKeyManager.address,
admin.address,
trustedSequencer.address,
Expand Down

0 comments on commit bd809aa

Please sign in to comment.