From 07daac4d0e4a8f66de48ec44b85eaff11bd8e648 Mon Sep 17 00:00:00 2001 From: Sambhav Jain <136801346+DarkLord017@users.noreply.github.com> Date: Thu, 29 Jan 2026 14:53:44 +0530 Subject: [PATCH 1/2] feat: add tool to get initialization counter and update that in contracts --- src/PDPVerifier.sol | 8 +++-- src/SimplePDPService.sol | 5 ++- test/ERC1967Proxy.t.sol | 6 ++-- test/PDPVerifier.t.sol | 33 ++++++++++--------- test/PDPVerifierProofTest.t.sol | 2 +- test/SimplePDPService.t.sol | 4 +-- tools/deploy-calibnet.sh | 3 +- tools/deploy-devnet.sh | 4 +-- tools/deploy-mainnet.sh | 3 +- tools/deploy-simple-pdp-service.sh | 4 ++- ...loy-transfer-ownership-upgrade-calibnet.sh | 11 +++++-- tools/get-initialized-counter.sh | 24 ++++++++++++++ tools/upgrade-contract.sh | 8 +++-- 13 files changed, 80 insertions(+), 35 deletions(-) create mode 100755 tools/get-initialized-counter.sh diff --git a/src/PDPVerifier.sol b/src/PDPVerifier.sol index 160f148..abe7a27 100644 --- a/src/PDPVerifier.sol +++ b/src/PDPVerifier.sol @@ -46,6 +46,9 @@ contract PDPVerifier is Initializable, UUPSUpgradeable, OwnableUpgradeable { uint256 public constant NO_CHALLENGE_SCHEDULED = 0; uint256 public constant NO_PROVEN_EPOCH = 0; + // Upgrade sequence number, used by Initializable.reinitializer + uint64 private immutable REINITIALIZER_VERSION; + // Events event DataSetCreated(uint256 indexed setId, address indexed storageProvider); event StorageProviderChanged( @@ -160,8 +163,9 @@ contract PDPVerifier is Initializable, UUPSUpgradeable, OwnableUpgradeable { // Methods /// @custom:oz-upgrades-unsafe-allow constructor - constructor() { + constructor(uint64 _initializerVersion) { _disableInitializers(); + REINITIALIZER_VERSION = _initializerVersion; } function initialize(uint256 _challengeFinality) public initializer { @@ -177,7 +181,7 @@ contract PDPVerifier is Initializable, UUPSUpgradeable, OwnableUpgradeable { event ContractUpgraded(string version, address implementation); event UpgradeAnnounced(PlannedUpgrade plannedUpgrade); - function migrate() external onlyProxy onlyOwner reinitializer(2) { + function migrate() external onlyProxy onlyOwner reinitializer(REINITIALIZER_VERSION) { emit ContractUpgraded(VERSION, ERC1967Utils.getImplementation()); } diff --git a/src/SimplePDPService.sol b/src/SimplePDPService.sol index 005c6aa..a3399e2 100644 --- a/src/SimplePDPService.sol +++ b/src/SimplePDPService.sol @@ -84,8 +84,11 @@ contract SimplePDPService is PDPListener, IPDPProvingSchedule, Initializable, UU mapping(uint256 => uint256) public provingDeadlines; mapping(uint256 => bool) public provenThisPeriod; + uint64 private immutable REINITIALIZER_VERSION; + /// @custom:oz-upgrades-unsafe-allow constructor - constructor() { + constructor(uint64 _reinitalizerVersion) { + REINITIALIZER_VERSION = _reinitalizerVersion; _disableInitializers(); } diff --git a/test/ERC1967Proxy.t.sol b/test/ERC1967Proxy.t.sol index b31b641..22e1fd9 100644 --- a/test/ERC1967Proxy.t.sol +++ b/test/ERC1967Proxy.t.sol @@ -15,7 +15,7 @@ contract ERC1967ProxyTest is Test { // Set owner for testing vm.startPrank(owner); // Deploy implementation contract - implementation = new PDPVerifier(); + implementation = new PDPVerifier(1); // Deploy proxy pointing to implementation bytes memory initData = abi.encodeWithSelector( @@ -43,7 +43,7 @@ contract ERC1967ProxyTest is Test { assertImplementationEquals(address(implementation)); // Deploy new implementation - PDPVerifier newImplementation = new PDPVerifier(); + PDPVerifier newImplementation = new PDPVerifier(2); // Announce upgrade first (required by new upgrade pattern) PDPVerifier.PlannedUpgrade memory plan; @@ -64,7 +64,7 @@ contract ERC1967ProxyTest is Test { } function testUpgradeFromNonOwnerNoGood() public { - PDPVerifier newImplementation = new PDPVerifier(); + PDPVerifier newImplementation = new PDPVerifier(2); // Announce upgrade first (as owner) PDPVerifier.PlannedUpgrade memory plan; diff --git a/test/PDPVerifier.t.sol b/test/PDPVerifier.t.sol index 8e132c1..48988a6 100644 --- a/test/PDPVerifier.t.sol +++ b/test/PDPVerifier.t.sol @@ -23,7 +23,7 @@ contract PDPVerifierDataSetCreateDeleteTest is MockFVMTest, PieceHelper { function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); uint256 challengeFinality = 2; bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, challengeFinality); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); @@ -240,7 +240,7 @@ contract PDPVerifierStorageProviderTest is MockFVMTest, PieceHelper { function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, 2); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); pdpVerifier = PDPVerifier(address(proxy)); @@ -340,7 +340,7 @@ contract PDPVerifierDataSetMutateTest is MockFVMTest, PieceHelper { function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, CHALLENGE_FINALITY_DELAY); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); pdpVerifier = PDPVerifier(address(proxy)); @@ -898,7 +898,7 @@ contract PDPVerifierPaginationTest is MockFVMTest, PieceHelper { function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); uint256 challengeFinality = 2; bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, challengeFinality); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); @@ -1182,7 +1182,8 @@ contract TestingRecordKeeperService is PDPListener, PDPRecordKeeper { } contract SumTreeInternalTestPDPVerifier is PDPVerifier { - constructor() {} + constructor() PDPVerifier(1) { + } function getTestHeightFromIndex(uint256 index) public pure returns (uint256) { return heightFromIndex(index); @@ -1626,9 +1627,9 @@ contract PDPListenerIntegrationTest is MockFVMTest, PieceHelper { uint256 constant CHALLENGE_FINALITY_DELAY = 2; bytes empty = new bytes(0); - function setUp() public override { + function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, CHALLENGE_FINALITY_DELAY); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); pdpVerifier = PDPVerifier(address(proxy)); @@ -1718,7 +1719,7 @@ contract PDPVerifierExtraDataTest is MockFVMTest, PieceHelper { function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, CHALLENGE_FINALITY_DELAY); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); pdpVerifier = PDPVerifier(address(proxy)); @@ -1774,7 +1775,7 @@ contract PDPVerifierE2ETest is MockFVMTest, ProofBuilderHelper, PieceHelper { function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, CHALLENGE_FINALITY_DELAY); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); pdpVerifier = PDPVerifier(address(proxy)); @@ -1915,8 +1916,8 @@ contract PDPVerifierMigrateTest is Test { function setUp() public { bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, 2); - implementation = new PDPVerifier(); - newImplementation = new PDPVerifier(); + implementation = new PDPVerifier(1); + newImplementation = new PDPVerifier(2); proxy = new MyERC1967Proxy(address(implementation), initializeData); pdpVerifier = PDPVerifier(address(proxy)); } @@ -1928,7 +1929,7 @@ contract PDPVerifierMigrateTest is Test { assertEq(afterEpoch, uint96(0)); // Deploy new implementation - PDPVerifier newImpl = new PDPVerifier(); + PDPVerifier newImpl = new PDPVerifier(2); // Announce upgrade PDPVerifier.PlannedUpgrade memory plan; @@ -1967,7 +1968,7 @@ contract PDPVerifierMigrateTest is Test { } function testAnnouncePlannedUpgradeOnlyOwner() public { - PDPVerifier newImpl = new PDPVerifier(); + PDPVerifier newImpl = new PDPVerifier(2); PDPVerifier.PlannedUpgrade memory plan; plan.nextImplementation = address(newImpl); plan.afterEpoch = uint96(vm.getBlockNumber()) + 2000; @@ -1988,7 +1989,7 @@ contract PDPVerifierMigrateTest is Test { } function testAnnouncePlannedUpgradeInvalidEpoch() public { - PDPVerifier newImpl = new PDPVerifier(); + PDPVerifier newImpl = new PDPVerifier(2); PDPVerifier.PlannedUpgrade memory plan; plan.nextImplementation = address(newImpl); plan.afterEpoch = uint96(vm.getBlockNumber()); // Must be in the future @@ -2033,7 +2034,7 @@ contract PDPVerifierFeeTest is MockFVMTest, PieceHelper, ProofBuilderHelper { function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, CHALLENGE_FINALITY_DELAY); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); pdpVerifier = PDPVerifier(address(proxy)); @@ -2173,7 +2174,7 @@ contract PDPVerifierStorageProviderListenerTest is MockFVMTest { function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, 2); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); pdpVerifier = PDPVerifier(address(proxy)); diff --git a/test/PDPVerifierProofTest.t.sol b/test/PDPVerifierProofTest.t.sol index c9df30d..20783ec 100644 --- a/test/PDPVerifierProofTest.t.sol +++ b/test/PDPVerifierProofTest.t.sol @@ -22,7 +22,7 @@ contract PDPVerifierProofTest is MockFVMTest, ProofBuilderHelper, PieceHelper { function setUp() public override { super.setUp(); - PDPVerifier pdpVerifierImpl = new PDPVerifier(); + PDPVerifier pdpVerifierImpl = new PDPVerifier(1); bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, CHALLENGE_FINALITY_DELAY); MyERC1967Proxy proxy = new MyERC1967Proxy(address(pdpVerifierImpl), initializeData); pdpVerifier = PDPVerifier(address(proxy)); diff --git a/test/SimplePDPService.t.sol b/test/SimplePDPService.t.sol index 94598f7..e4a3edc 100644 --- a/test/SimplePDPService.t.sol +++ b/test/SimplePDPService.t.sol @@ -16,7 +16,7 @@ contract SimplePDPServiceTest is Test { function setUp() public { pdpVerifierAddress = address(this); - SimplePDPService pdpServiceImpl = new SimplePDPService(); + SimplePDPService pdpServiceImpl = new SimplePDPService(1); bytes memory initializeData = abi.encodeWithSelector(SimplePDPService.initialize.selector, address(pdpVerifierAddress)); MyERC1967Proxy pdpServiceProxy = new MyERC1967Proxy(address(pdpServiceImpl), initializeData); @@ -113,7 +113,7 @@ contract SimplePDPServiceFaultsTest is Test { function setUp() public { pdpVerifierAddress = address(this); - SimplePDPService pdpServiceImpl = new SimplePDPService(); + SimplePDPService pdpServiceImpl = new SimplePDPService(1); bytes memory initializeData = abi.encodeWithSelector(SimplePDPService.initialize.selector, address(pdpVerifierAddress)); MyERC1967Proxy pdpServiceProxy = new MyERC1967Proxy(address(pdpServiceImpl), initializeData); diff --git a/tools/deploy-calibnet.sh b/tools/deploy-calibnet.sh index 48a1d22..d858f2f 100755 --- a/tools/deploy-calibnet.sh +++ b/tools/deploy-calibnet.sh @@ -19,13 +19,14 @@ fi # Calibration testnet uses 10 epochs (vs 150 on mainnet) CHALLENGE_FINALITY=10 +VERIFIER_INIT_COUNTER=1 ADDR=$(cast wallet address --keystore "$KEYSTORE" --password "$PASSWORD") echo "Deploying PDP verifier from address $ADDR" # Parse the output of forge create to extract the contract address NONCE="$(cast nonce --rpc-url "$RPC_URL" "$ADDR")" -VERIFIER_IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --broadcast --nonce $NONCE --chain-id 314159 src/PDPVerifier.sol:PDPVerifier | grep "Deployed to" | awk '{print $3}') +VERIFIER_IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --broadcast --nonce $NONCE --chain-id 314159 src/PDPVerifier.sol:PDPVerifier --constructor-args "$VERIFIER_INIT_COUNTER" | grep "Deployed to" | awk '{print $3}') if [ -z "$VERIFIER_IMPLEMENTATION_ADDRESS" ]; then echo "Error: Failed to extract PDP verifier contract address" exit 1 diff --git a/tools/deploy-devnet.sh b/tools/deploy-devnet.sh index 284d32a..131e383 100755 --- a/tools/deploy-devnet.sh +++ b/tools/deploy-devnet.sh @@ -25,10 +25,10 @@ lotus send $clientAddr 10000 sleep 5 ## Sleep for 5 seconds so fund are available and actor is registered NONCE="$(cast nonce --rpc-url "$RPC_URL" "$clientAddr")" - +VERIFIER_INIT_COUNTER=1 echo "Deploying PDP verifier" # Parse the output of forge create to extract the contract address -VERIFIER_IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --nonce $NONCE --broadcast src/PDPVerifier.sol:PDPVerifier | grep "Deployed to" | awk '{print $3}') +VERIFIER_IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --nonce $NONCE --broadcast src/PDPVerifier.sol:PDPVerifier --constructor-args $VERIFIER_INIT_COUNTER | grep "Deployed to" | awk '{print $3}') if [ -z "$VERIFIER_IMPLEMENTATION_ADDRESS" ]; then echo "Error: Failed to extract PDP verifier contract address" exit 1 diff --git a/tools/deploy-mainnet.sh b/tools/deploy-mainnet.sh index ea53d70..23d5f37 100755 --- a/tools/deploy-mainnet.sh +++ b/tools/deploy-mainnet.sh @@ -19,13 +19,14 @@ fi # Mainnet uses 150 epochs (vs 10 on Calibration testnet) CHALLENGE_FINALITY=150 +VERIFIER_INIT_COUNTER=1 ADDR=$(cast wallet address --keystore "$KEYSTORE" --password "$PASSWORD") echo "Deploying PDP verifier from address $ADDR" # Parse the output of forge create to extract the contract address NONCE="$(cast nonce --rpc-url "$RPC_URL" "$ADDR")" -VERIFIER_IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --broadcast --nonce $NONCE --chain-id 314 src/PDPVerifier.sol:PDPVerifier | grep "Deployed to" | awk '{print $3}') +VERIFIER_IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --broadcast --nonce $NONCE --chain-id 314 src/PDPVerifier.sol:PDPVerifier --constructor-args $VERIFIER_INIT_COUNTER | grep "Deployed to" | awk '{print $3}') if [ -z "$VERIFIER_IMPLEMENTATION_ADDRESS" ]; then echo "Error: Failed to extract PDP verifier contract address" exit 1 diff --git a/tools/deploy-simple-pdp-service.sh b/tools/deploy-simple-pdp-service.sh index eb81ae6..1eaebd5 100755 --- a/tools/deploy-simple-pdp-service.sh +++ b/tools/deploy-simple-pdp-service.sh @@ -68,8 +68,10 @@ echo "Using PDPVerifier at: $PDP_VERIFIER_ADDRESS" NONCE="$(cast nonce --rpc-url "$RPC_URL" "$ADDR")" +VERIFIER_INIT_COUNTER=1 + echo "Deploying SimplePDPService implementation..." -SERVICE_IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --broadcast --nonce $NONCE --chain-id $CHAIN_ID src/SimplePDPService.sol:SimplePDPService | grep "Deployed to" | awk '{print $3}') +SERVICE_IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --broadcast --nonce $NONCE --chain-id $CHAIN_ID src/SimplePDPService.sol:SimplePDPService --constructor-args $VERIFIER_INIT_COUNTER | grep "Deployed to" | awk '{print $3}') if [ -z "$SERVICE_IMPLEMENTATION_ADDRESS" ]; then echo "Error: Failed to extract SimplePDPService contract address" diff --git a/tools/deploy-transfer-ownership-upgrade-calibnet.sh b/tools/deploy-transfer-ownership-upgrade-calibnet.sh index 26cee5d..997f7ce 100755 --- a/tools/deploy-transfer-ownership-upgrade-calibnet.sh +++ b/tools/deploy-transfer-ownership-upgrade-calibnet.sh @@ -4,7 +4,7 @@ set -euo pipefail ##################################### # Environment variables & defaults # ##################################### - +SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" : "${FIL_CALIBNET_RPC_URL:?FIL_CALIBNET_RPC_URL not set. Please export it and rerun.}" : "${FIL_CALIBNET_PRIVATE_KEY:?FIL_CALIBNET_PRIVATE_KEY not set. Please export it and rerun.}" : "${NEW_OWNER:?NEW_OWNER not set. Please export it and rerun.}" @@ -34,6 +34,8 @@ echo # 2. Deploy PDPVerifier contract # ##################################### echo "Deploying PDPVerifier contract ..." +# initial verifier init counter (default 1) +VERIFIER_INIT_COUNTER=1 DEPLOY_OUTPUT_VERIFIER=$( forge create \ --rpc-url "$FIL_CALIBNET_RPC_URL" \ @@ -41,7 +43,8 @@ DEPLOY_OUTPUT_VERIFIER=$( --chain-id "$CHAIN_ID" \ --broadcast \ --nonce $NONCE \ - src/PDPVerifier.sol:PDPVerifier + src/PDPVerifier.sol:PDPVerifier \ + --constructor-args $VERIFIER_INIT_COUNTER ) NONCE=$(expr $NONCE + "1") @@ -116,7 +119,9 @@ echo "========================================" ##################################### echo "Deploying a new PDPVerifier contract ..." -DEPLOY_OUTPUT_VERIFIER_2=$(forge create --nonce $NONCE --broadcast --rpc-url "$FIL_CALIBNET_RPC_URL" --private-key "$FIL_CALIBNET_PRIVATE_KEY" --chain-id "$CHAIN_ID" src/PDPVerifier.sol:PDPVerifier) +# For the upgrade, compute next initializer counter from the proxy and pass it +UPGRADE_INIT_COUNTER=$(expr "$("$SCRIPT_DIR/get-initialized-counter.sh" "$PROXY_ADDRESS")" + 1) +DEPLOY_OUTPUT_VERIFIER_2=$(forge create --nonce $NONCE --broadcast --rpc-url "$FIL_CALIBNET_RPC_URL" --private-key "$FIL_CALIBNET_PRIVATE_KEY" --chain-id "$CHAIN_ID" src/PDPVerifier.sol:PDPVerifier --constructor-args $UPGRADE_INIT_COUNTER) NONCE=$(expr $NONCE + "1") PDP_VERIFIER_ADDRESS_2=$(echo "$DEPLOY_OUTPUT_VERIFIER_2" | grep "Deployed to" | awk '{print $3}') echo "PDPVerifier deployed at: $PDP_VERIFIER_ADDRESS_2" diff --git a/tools/get-initialized-counter.sh b/tools/get-initialized-counter.sh new file mode 100755 index 0000000..cae6af0 --- /dev/null +++ b/tools/get-initialized-counter.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Reads the current reinitializer counter from an OpenZeppelin +# Initializable proxy contract. +# +# The counter lives in the InitializableStorage struct at the +# ERC-7201 namespaced slot defined in: +# https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dde766bd542e4a1695fe8e4a07dc03b77305f367/contracts/proxy/utils/Initializable.sol#L76-L77 + +if [ -z "$RPC_URL" ]; then + echo "Error: RPC_URL is not set" + exit 1 +fi + +if [ -z "$1" ]; then + echo "Error: Must specify a contract address" + exit 1 +fi + +# keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff)) +INITIALIZABLE_STORAGE="0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00" +SLOT=$(cast storage --rpc-url "$RPC_URL" $1 $INITIALIZABLE_STORAGE) + +cast to-base $SLOT 10 \ No newline at end of file diff --git a/tools/upgrade-contract.sh b/tools/upgrade-contract.sh index df1b33d..d9a8acb 100755 --- a/tools/upgrade-contract.sh +++ b/tools/upgrade-contract.sh @@ -7,6 +7,7 @@ # # Set DRY_RUN=false to actually deploy and broadcast transactions (default is dry-run for safety) DRY_RUN=${DRY_RUN:-true} +SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" if [ "$DRY_RUN" = "true" ]; then echo "๐Ÿงช Running in DRY-RUN mode - simulation only, no actual deployment" @@ -49,9 +50,11 @@ if [ -z "$IMPLEMENTATION_PATH" ]; then exit 1 fi +UPGRADE_INIT_COUNTER=$(expr "$("$SCRIPT_DIR/get-initialized-counter.sh" "$PROXY_ADDRESS")" + 1) + if [ "$DRY_RUN" = "true" ]; then echo "๐Ÿ” Simulating deployment of new $IMPLEMENTATION_PATH implementation contract" - forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --compiler-version 0.8.23 --chain-id "$CHAIN_ID" "$IMPLEMENTATION_PATH" + forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --compiler-version 0.8.30 --chain-id "$CHAIN_ID" "$IMPLEMENTATION_PATH" --constructor-args $UPGRADE_INIT_COUNTER if [ $? -eq 0 ]; then echo "โœ… Contract compilation and simulation successful!" @@ -67,8 +70,9 @@ if [ "$DRY_RUN" = "true" ]; then fi else echo "๐Ÿš€ Deploying new $IMPLEMENTATION_PATH implementation contract" + # Parse the output of forge create to extract the contract address - IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --broadcast --compiler-version 0.8.23 --chain-id "$CHAIN_ID" "$IMPLEMENTATION_PATH" | grep "Deployed to" | awk '{print $3}') + IMPLEMENTATION_ADDRESS=$(forge create --rpc-url "$RPC_URL" --keystore "$KEYSTORE" --password "$PASSWORD" --broadcast --compiler-version 0.8.30 --chain-id "$CHAIN_ID" "$IMPLEMENTATION_PATH" --constructor-args $UPGRADE_INIT_COUNTER | grep "Deployed to" | awk '{print $3}') if [ -z "$IMPLEMENTATION_ADDRESS" ]; then echo "โŒ Error: Failed to extract PDP verifier contract address" From 9c1740042f721efeef69120f9c0f73197786d904 Mon Sep 17 00:00:00 2001 From: Sambhav Jain <136801346+DarkLord017@users.noreply.github.com> Date: Thu, 29 Jan 2026 14:57:57 +0530 Subject: [PATCH 2/2] feat: add tool to get initialization counter and update that in contracts --- test/PDPVerifier.t.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/PDPVerifier.t.sol b/test/PDPVerifier.t.sol index 48988a6..ef5fd14 100644 --- a/test/PDPVerifier.t.sol +++ b/test/PDPVerifier.t.sol @@ -1182,8 +1182,7 @@ contract TestingRecordKeeperService is PDPListener, PDPRecordKeeper { } contract SumTreeInternalTestPDPVerifier is PDPVerifier { - constructor() PDPVerifier(1) { - } + constructor() PDPVerifier(1) {} function getTestHeightFromIndex(uint256 index) public pure returns (uint256) { return heightFromIndex(index); @@ -1627,7 +1626,7 @@ contract PDPListenerIntegrationTest is MockFVMTest, PieceHelper { uint256 constant CHALLENGE_FINALITY_DELAY = 2; bytes empty = new bytes(0); - function setUp() public override { + function setUp() public override { super.setUp(); PDPVerifier pdpVerifierImpl = new PDPVerifier(1); bytes memory initializeData = abi.encodeWithSelector(PDPVerifier.initialize.selector, CHALLENGE_FINALITY_DELAY);