Skip to content

Commit 5eda611

Browse files
committed
ci(gateway-contracts): auto-detect contract upgrades via REINITIALIZER_VERSION
Apply the same auto-detection pattern from host-contracts to gateway: replace 7 hardcoded upgrade steps (all with `if: false`) with a single loop that compares REINITIALIZER_VERSION between the previous release and current code. - Add upgrade-manifest.json listing all 7 upgradeable gateway contracts - Extract PREVIOUS_RELEASE_TAG to env var (one place to bump per release) - Remove last actionlint exemption for constant `if: false` conditions Closes: zama-ai/fhevm-internal#379
1 parent dfa2030 commit 5eda611

File tree

3 files changed

+35
-87
lines changed

3 files changed

+35
-87
lines changed

.github/actionlint.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ paths:
2121
ignore:
2222
- SC2001 # https://www.shellcheck.net/wiki/SC2129
2323
- 'property "result" is not defined in object type.*'
24-
.github/workflows/gateway-contracts-upgrade-tests.yml:
25-
ignore:
26-
- 'constant expression "false" in condition' # https://github.com/zama-ai/fhevm-internal/issues/379

.github/workflows/gateway-contracts-upgrade-tests.yml

Lines changed: 34 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ concurrency:
1515
# - CHAIN_ID_GATEWAY: Should match the chain ID used in the anvil node in the docker-compose.yml file
1616
# - RPC_URL: The port should match the one used in the anvil node in the docker-compose.yml file
1717
env:
18+
PREVIOUS_RELEASE_TAG: v0.10.0
1819
DOTENV_CONFIG_PATH: .env.example
1920
HARDHAT_NETWORK: staging
2021
CHAIN_ID_GATEWAY: 54321
@@ -54,9 +55,7 @@ jobs:
5455
- name: Checkout previous release code
5556
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5657
with:
57-
# This version should be updated whenever we release new contract versions or
58-
# touch a contract upgrade path.
59-
ref: v0.10.0
58+
ref: ${{ env.PREVIOUS_RELEASE_TAG }}
6059
path: previous-fhevm
6160
persist-credentials: 'false'
6261

@@ -117,89 +116,40 @@ jobs:
117116
cp -r ../../previous-fhevm/gateway-contracts/contracts ./previous-contracts
118117
docker cp deploy-gateway-contracts:/app/addresses ./
119118
120-
# TODO: We should instead automatically detect if the contract needs to be upgraded
121-
# See https://github.com/zama-ai/fhevm-internal/issues/379
122-
- name: Upgrade GatewayConfig contract
119+
- name: Run contract upgrades
123120
working-directory: current-fhevm/gateway-contracts
124-
if: false
125121
run: |
126-
npx hardhat task:upgradeGatewayConfig \
127-
--current-implementation previous-contracts/GatewayConfig.sol:GatewayConfig \
128-
--new-implementation contracts/GatewayConfig.sol:GatewayConfig \
129-
--use-internal-proxy-address true \
130-
--verify-contract false
131-
132-
# TODO: We should instead automatically detect if the contract needs to be upgraded
133-
# See https://github.com/zama-ai/fhevm-internal/issues/379
134-
- name: Upgrade Decryption contract
135-
working-directory: current-fhevm/gateway-contracts
136-
if: false
137-
run: |
138-
npx hardhat task:upgradeDecryption \
139-
--current-implementation previous-contracts/Decryption.sol:Decryption \
140-
--new-implementation contracts/Decryption.sol:Decryption \
141-
--use-internal-proxy-address true \
142-
--verify-contract false
143-
144-
# TODO: We should instead automatically detect if the contract needs to be upgraded
145-
# See https://github.com/zama-ai/fhevm-internal/issues/379
146-
- name: Upgrade CiphertextCommits contract
147-
working-directory: current-fhevm/gateway-contracts
148-
if: false
149-
run: |
150-
npx hardhat task:upgradeCiphertextCommits \
151-
--current-implementation previous-contracts/CiphertextCommits.sol:CiphertextCommits \
152-
--new-implementation contracts/CiphertextCommits.sol:CiphertextCommits \
153-
--use-internal-proxy-address true \
154-
--verify-contract false
155-
156-
# TODO: We should instead automatically detect if the contract needs to be upgraded
157-
# See https://github.com/zama-ai/fhevm-internal/issues/379
158-
- name: Upgrade InputVerification contract
159-
working-directory: current-fhevm/gateway-contracts
160-
if: false
161-
run: |
162-
npx hardhat task:upgradeInputVerification \
163-
--current-implementation previous-contracts/InputVerification.sol:InputVerification \
164-
--new-implementation contracts/InputVerification.sol:InputVerification \
165-
--use-internal-proxy-address true \
166-
--verify-contract false
167-
168-
# TODO: We should instead automatically detect if the contract needs to be upgraded
169-
# See https://github.com/zama-ai/fhevm-internal/issues/379
170-
- name: Upgrade MultichainACL contract
171-
working-directory: current-fhevm/gateway-contracts
172-
if: false
173-
run: |
174-
npx hardhat task:upgradeMultichainACL \
175-
--current-implementation previous-contracts/MultichainACL.sol:MultichainACL \
176-
--new-implementation contracts/MultichainACL.sol:MultichainACL \
177-
--use-internal-proxy-address true \
178-
--verify-contract false
179-
180-
# TODO: We should instead automatically detect if the contract needs to be upgraded
181-
# See https://github.com/zama-ai/fhevm-internal/issues/379
182-
- name: Upgrade KMSGeneration contract
183-
working-directory: current-fhevm/gateway-contracts
184-
if: false
185-
run: |
186-
npx hardhat task:upgradeKMSGeneration \
187-
--current-implementation previous-contracts/KMSGeneration.sol:KMSGeneration \
188-
--new-implementation contracts/KMSGeneration.sol:KMSGeneration \
189-
--use-internal-proxy-address true \
190-
--verify-contract false
191-
192-
# TODO: We should instead automatically detect if the contract needs to be upgraded
193-
# See https://github.com/zama-ai/fhevm-internal/issues/379
194-
- name: Upgrade ProtocolPayment contract
195-
working-directory: current-fhevm/gateway-contracts
196-
if: false
197-
run: |
198-
npx hardhat task:upgradeProtocolPayment \
199-
--current-implementation previous-contracts/ProtocolPayment.sol:ProtocolPayment \
200-
--new-implementation contracts/ProtocolPayment.sol:ProtocolPayment \
201-
--use-internal-proxy-address true \
202-
--verify-contract false
122+
set -euo pipefail
123+
UPGRADED=0
124+
SKIPPED=0
125+
126+
for name in $(jq -r '.[]' upgrade-manifest.json); do
127+
old_ver=$(sed -n 's/.*REINITIALIZER_VERSION[[:space:]]*=[[:space:]]*\([0-9]*\).*/\1/p' \
128+
"previous-contracts/${name}.sol")
129+
new_ver=$(sed -n 's/.*REINITIALIZER_VERSION[[:space:]]*=[[:space:]]*\([0-9]*\).*/\1/p' \
130+
"contracts/${name}.sol")
131+
old_ver=${old_ver:-0}
132+
new_ver=${new_ver:-0}
133+
134+
if [ "$old_ver" != "$new_ver" ]; then
135+
echo "::group::Upgrading $name (reinitializer $old_ver → $new_ver)"
136+
npx hardhat "task:upgrade${name}" \
137+
--current-implementation "previous-contracts/${name}.sol:${name}" \
138+
--new-implementation "contracts/${name}.sol:${name}" \
139+
--use-internal-proxy-address true \
140+
--verify-contract false
141+
echo "::endgroup::"
142+
UPGRADED=$((UPGRADED + 1))
143+
else
144+
echo "Skipping $name (reinitializer unchanged: $old_ver)"
145+
SKIPPED=$((SKIPPED + 1))
146+
fi
147+
done
148+
149+
echo "::notice::Upgrade summary: $UPGRADED upgraded, $SKIPPED skipped"
150+
if [ "$UPGRADED" -eq 0 ]; then
151+
echo "::warning::No contracts needed upgrading — consider bumping PREVIOUS_RELEASE_TAG"
152+
fi
203153
204154
- name: Clean up
205155
working-directory: previous-fhevm/gateway-contracts
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["GatewayConfig", "Decryption", "CiphertextCommits", "InputVerification", "MultichainACL", "KMSGeneration", "ProtocolPayment"]

0 commit comments

Comments
 (0)