Skip to content

Commit a2bc58e

Browse files
committed
fix upgrade to upgrade multiple clients
also, disable the 'dead code' detector temporarily due to a false positive Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent 03752d0 commit a2bc58e

File tree

3 files changed

+411
-35
lines changed

3 files changed

+411
-35
lines changed

contracts/toki/TokiLCPClientZKDCAP.sol

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
1313
contract 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) {

slither.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"detectors_to_run": "arbitrary-send-erc20,array-by-reference,incorrect-shift,name-reused,rtlo,suicidal,uninitialized-storage,arbitrary-send-erc20-permit,controlled-array-length,controlled-delegatecall,delegatecall-loop,msg-value-loop,reentrancy-eth,unchecked-transfer,weak-prng,domain-separator-collision,erc20-interface,erc721-interface,locked-ether,mapping-deletion,shadowing-abstract,tautology,write-after-write,boolean-cst,reentrancy-no-eth,reused-constructor,tx-origin,unchecked-lowlevel,unchecked-send,variable-scope,void-cst,events-access,events-maths,incorrect-unary,boolean-equal,deprecated-standards,erc20-indexed,function-init-state,pragma,reentrancy-unlimited-gas,immutable-states,var-read-using-this,dead-code",
2+
"detectors_to_run": "arbitrary-send-erc20,array-by-reference,incorrect-shift,name-reused,rtlo,suicidal,uninitialized-storage,arbitrary-send-erc20-permit,controlled-array-length,controlled-delegatecall,delegatecall-loop,msg-value-loop,reentrancy-eth,unchecked-transfer,weak-prng,domain-separator-collision,erc20-interface,erc721-interface,locked-ether,mapping-deletion,shadowing-abstract,tautology,write-after-write,boolean-cst,reentrancy-no-eth,reused-constructor,tx-origin,unchecked-lowlevel,unchecked-send,variable-scope,void-cst,events-access,events-maths,incorrect-unary,boolean-equal,deprecated-standards,erc20-indexed,function-init-state,pragma,reentrancy-unlimited-gas,immutable-states,var-read-using-this",
33
"filter_paths": "(test/|node_modules/|lib/|contracts/proto/)"
44
}

0 commit comments

Comments
 (0)