@@ -11,6 +11,8 @@ import {IIBCClient} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/02-c
1111/// @notice TokiLCPClientZKDCAP is LCPClientZKDCAPOwnableUpgradeable with state recovery functionality for TOKI operations.
1212/// @custom:oz-upgrades-unsafe-allow external-library-linking
1313contract TokiLCPClientZKDCAP is LCPClientZKDCAPOwnableUpgradeable {
14+ // --------------------- Data structures ---------------------
15+
1416 struct NewClientState {
1517 string clientId;
1618 bytes mrenclave;
@@ -25,11 +27,15 @@ contract TokiLCPClientZKDCAP is LCPClientZKDCAPOwnableUpgradeable {
2527 ConsensusState consensusState;
2628 }
2729
30+ // --------------------- Immutable fields ---------------------
31+
2832 // A unique version is assigned to the implementation contract.
2933 // To ensure the initialization process is only allowed once, it is checked by the reinitializer modifier.
3034 /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
3135 uint64 public immutable RECOVERED_VERSION;
3236
37+ // --------------------- Constructor ---------------------
38+
3339 /// @custom:oz-upgrades-unsafe-allow constructor
3440 constructor (
3541 address ibcHandler ,
@@ -41,25 +47,42 @@ contract TokiLCPClientZKDCAP is LCPClientZKDCAPOwnableUpgradeable {
4147 RECOVERED_VERSION = recoveredVersion;
4248 }
4349
50+ // --------------------- Public methods ---------------------
51+
4452 /**
45- * @dev `upgrade` should only be called once through UUPSUpgradeable.upgradeToAndCall.
46- * This function is used in the following situations:
47- * - When a critical security vulnerability is discovered in the LCP enclave or zkDCAP quote verifier, requiring an urgent upgrade.
48- * - When a newly issued security advisory of SGX, which is not critical to LCP security or operations, needs to be permitted.
49- * - When an ELC corresponding to the client state's `mrenclave` needs to be upgraded due to a hard fork.
50- * @param newClientState New client state to upgrade.
51- * @param newConsensusState New consensus state to upgrade.
52- */
53- function upgrade (NewClientState memory newClientState , NewConsensusState memory newConsensusState )
53+ * @dev `upgrade` should only be called once through UUPSUpgradeable.upgradeToAndCall.
54+ * This function is used in the following situations:
55+ * - When a critical security vulnerability is discovered in the LCP enclave or zkDCAP quote verifier, requiring an urgent upgrade.
56+ * - When a newly issued security advisory of SGX, which is not critical to LCP security or operations, needs to be permitted.
57+ * - When an ELC corresponding to the client state's `mrenclave` needs to be upgraded due to a hard fork.
58+ * @param newClientStates New client states to upgrade. The order of the client states should be the same as the order of the consensus states.
59+ * @param newConsensusStates New consensus states to upgrade. The order of the consensus states should be the same as the order of the client states.
60+ * The consensus state with height zero is ignored.
61+ */
62+ function upgrade (NewClientState[] memory newClientStates , NewConsensusState[] memory newConsensusStates )
5463 external
5564 reinitializer (RECOVERED_VERSION)
5665 onlyOwner
5766 {
58- return _upgrade (newClientState, newConsensusState);
67+ _upgrade (newClientStates, newConsensusStates);
68+ }
69+
70+ // --------------------- Internal methods ---------------------
71+
72+ function _upgrade (NewClientState[] memory newClientStates , NewConsensusState[] memory newConsensusStates )
73+ internal
74+ {
75+ require (newClientStates.length == newConsensusStates.length );
76+ for (uint256 i = 0 ; i < newClientStates.length ; i++ ) {
77+ _upgradeState (newClientStates[i], newConsensusStates[i]);
78+ }
5979 }
6080
61- function _upgrade (NewClientState memory newClientState , NewConsensusState memory newConsensusState ) internal {
81+ function _upgradeState (NewClientState memory newClientState , NewConsensusState memory newConsensusState ) internal {
6282 ClientStorage storage clientStorage = clientStorages[newClientState.clientId];
83+ if (clientStorage.zkDCAPRisc0ImageId == bytes32 (0 )) {
84+ revert LCPClientZKDCAPRisc0ImageIdNotSet ();
85+ }
6386 IbcLightclientsLcpV1ClientState.Data storage clientState = clientStorage.clientState;
6487
6588 if (clientState.frozen) {
0 commit comments