From 346ce2a128d7c949d5bdf531d6d72c25d4871481 Mon Sep 17 00:00:00 2001 From: The Dark Jester Date: Wed, 25 Sep 2024 08:29:46 -0700 Subject: [PATCH] Feat/94 emit version updated event (#98) * Emit LineaRollupVersionChanged on upgrade * make padded hex bytes generic --- contracts/contracts/LineaRollup.sol | 5 ++++- .../contracts/interfaces/l1/ILineaRollup.sol | 8 ++++++++ contracts/test/LineaRollup.ts | 20 +++++++++++-------- contracts/test/utils/helpers.ts | 12 +++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/contracts/contracts/LineaRollup.sol b/contracts/contracts/LineaRollup.sol index 4a3eb374c..b07977dee 100644 --- a/contracts/contracts/LineaRollup.sol +++ b/contracts/contracts/LineaRollup.sol @@ -125,7 +125,7 @@ contract LineaRollup is * @param _unpauseTypeRoles The list of unpause type roles. * @param _gatewayOperator The address of the gateway operator. */ - function reinitializePauseTypesAndPermissions( + function reinitializeLineaRollupV6( RoleAddress[] calldata _roleAddresses, PauseTypeRole[] calldata _pauseTypeRoles, PauseTypeRole[] calldata _unpauseTypeRoles, @@ -134,6 +134,9 @@ contract LineaRollup is __Permissions_init(_roleAddresses); __PauseManager_init(_pauseTypeRoles, _unpauseTypeRoles); gatewayOperator = _gatewayOperator; + + /// @dev using the constants requires string memory and more complex code. + emit LineaRollupVersionChanged(bytes8("5.0"), bytes8("6.0")); } /** diff --git a/contracts/contracts/interfaces/l1/ILineaRollup.sol b/contracts/contracts/interfaces/l1/ILineaRollup.sol index 1c002e9a3..1a2a0fe6d 100644 --- a/contracts/contracts/interfaces/l1/ILineaRollup.sol +++ b/contracts/contracts/interfaces/l1/ILineaRollup.sol @@ -131,6 +131,14 @@ interface ILineaRollup { bytes l2MessagingBlocksOffsets; } + /** + * @notice Emitted when the LineaRollup contract version has changed. + * @dev All bytes8 values are string based SemVer in the format M.m - e.g. "6.0"; + * @param previousVersion The previous version. + * @param newVersion The new version. + */ + event LineaRollupVersionChanged(bytes8 indexed previousVersion, bytes8 indexed newVersion); + /** * @notice Emitted when the gateway operator role is granted. * @param caller The address that granted the role. diff --git a/contracts/test/LineaRollup.ts b/contracts/test/LineaRollup.ts index 39112d82c..a6fed971e 100644 --- a/contracts/test/LineaRollup.ts +++ b/contracts/test/LineaRollup.ts @@ -64,6 +64,7 @@ import { generateBlobDataSubmission, generateBlobParentShnarfData, ShnarfDataGenerator, + convertStringToPaddedHexBytes, } from "./utils/helpers"; import { CalldataSubmissionData } from "./utils/types"; import aggregatedProof1To81 from "./testData/compressedData/multipleProofs/aggregatedProof-1-81.json"; @@ -2244,7 +2245,7 @@ describe("Linea Rollup contract", () => { const NewLineaRollupFactory = await ethers.getContractFactory("contracts/LineaRollup.sol:LineaRollup"); const newLineaRollup = await upgrades.upgradeProxy(lineaRollup, NewLineaRollupFactory); - await newLineaRollup.reinitializePauseTypesAndPermissions( + const upgradeCall = newLineaRollup.reinitializeLineaRollupV6( [ { addressWithRole: securityCouncil.address, role: DEFAULT_ADMIN_ROLE }, { addressWithRole: securityCouncil.address, role: VERIFIER_SETTER_ROLE }, @@ -2254,10 +2255,18 @@ describe("Linea Rollup contract", () => { multiCallAddress, ); + const expectedVersion5Bytes8 = convertStringToPaddedHexBytes("5.0", 8); + const expectedVersion6Bytes8 = convertStringToPaddedHexBytes("6.0", 8); + + await expectEvent(newLineaRollup, upgradeCall, "LineaRollupVersionChanged", [ + expectedVersion5Bytes8, + expectedVersion6Bytes8, + ]); + expect(await newLineaRollup.currentL2BlockNumber()).to.equal(0); }); - it("Should revert with ZeroAddressNotAllowed when addressWithRole is zero address in reinitializePauseTypesAndPermissions", async () => { + it("Should revert with ZeroAddressNotAllowed when addressWithRole is zero address in reinitializeLineaRollupV6", async () => { // Deploy new implementation const NewLineaRollupFactory = await ethers.getContractFactory("contracts/LineaRollup.sol:LineaRollup"); const newLineaRollup = await upgrades.upgradeProxy(lineaRollup, NewLineaRollupFactory); @@ -2270,12 +2279,7 @@ describe("Linea Rollup contract", () => { await expectRevertWithCustomError( newLineaRollup, - newLineaRollup.reinitializePauseTypesAndPermissions( - roleAddresses, - pauseTypeRoles, - unpauseTypeRoles, - multiCallAddress, - ), + newLineaRollup.reinitializeLineaRollupV6(roleAddresses, pauseTypeRoles, unpauseTypeRoles, multiCallAddress), "ZeroAddressNotAllowed", ); }); diff --git a/contracts/test/utils/helpers.ts b/contracts/test/utils/helpers.ts index 6e7ab616b..3e8a3e093 100644 --- a/contracts/test/utils/helpers.ts +++ b/contracts/test/utils/helpers.ts @@ -496,3 +496,15 @@ export async function expectEvent(contract: any, asyncCall: Promise, eventN .to.emit(contract, eventName) .withArgs(...eventArgs); } + +export function convertStringToPaddedHexBytes(strVal: string, paddedSize: number): string { + if (strVal.length > paddedSize) { + throw "Length is longer than padded size!"; + } + + const strBytes = ethers.toUtf8Bytes(strVal); + const bytes = ethers.zeroPadBytes(strBytes, paddedSize); + const bytes8Hex = ethers.hexlify(bytes); + + return bytes8Hex; +}