Skip to content

Commit cb73f69

Browse files
authored
Merge pull request #21 from datachainlab/upgradeable
Add upgradeable LCP Client Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
2 parents afa453d + dee87dd commit cb73f69

File tree

10 files changed

+831
-65
lines changed

10 files changed

+831
-65
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,30 @@ jobs:
99
name: Test
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
with:
1414
submodules: recursive
1515

16-
- uses: actions/setup-node@v3
16+
- uses: actions/setup-node@v4
1717
with:
18-
node-version: '16'
18+
node-version: '20'
1919

2020
- name: Install Foundry
2121
uses: foundry-rs/foundry-toolchain@v1
2222
with:
2323
version: nightly
2424

25+
- name: Show forge version
26+
run: forge --version
27+
2528
- name: npm install
2629
run: npm install
2730

2831
- name: Build and Check sizes
29-
run: forge build --sizes --skip test --use solc:${{ env.SOLC_VERSION }}
32+
run: make SOLC_VERSION=${{ env.SOLC_VERSION }} build
3033

3134
- name: Run tests
32-
run: make SOLC_VERSION=${{ env.SOLC_VERSION }} test
35+
run: make SOLC_VERSION=${{ env.SOLC_VERSION }} TEST_UPGRADEABLE=true test
3336

3437
- name: Lint
3538
run: make lint

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "lib/forge-std"]
22
path = lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/openzeppelin-foundry-upgrades"]
5+
path = lib/openzeppelin-foundry-upgrades
6+
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades

Makefile

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
SOLC_VERSION ?= 0.8.20
2-
FORGE ?= forge
1+
SOLC_VERSION=0.8.20
2+
FORGE=forge
3+
TEST_UPGRADEABLE=false
34

4-
.PHONY: proto-sol
5-
proto-sol:
6-
ifndef SOLPB_DIR
7-
$(error SOLPB_DIR is not specified)
8-
else
9-
./solpb.sh
10-
endif
5+
.PHONY: build
6+
build:
7+
@FOUNDRY_PROFILE=ir $(FORGE) build --sizes --skip test --use solc:$(SOLC_VERSION)
8+
9+
.PHONY: clean
10+
clean:
11+
@$(FORGE) clean
1112

1213
.PHONY: test
1314
test:
14-
@$(FORGE) test -vvvv --gas-report --ffi --use solc:$(SOLC_VERSION)
15+
@TEST_UPGRADEABLE=$(TEST_UPGRADEABLE) $(FORGE) test -vvvv --gas-report --ffi --use solc:$(SOLC_VERSION)
16+
17+
.PHONY: coverage
18+
coverage:
19+
@$(FORGE) coverage --ffi --use solc:$(SOLC_VERSION)
1520

1621
.PHONY: fmt
1722
fmt:
@@ -27,3 +32,11 @@ check-fmt:
2732
lint:
2833
@npx solhint 'contracts/*.sol'
2934
@$(MAKE) FORGE_FMT_OPTS=--check fmt
35+
36+
.PHONY: proto-sol
37+
proto-sol:
38+
ifndef SOLPB_DIR
39+
$(error SOLPB_DIR is not specified)
40+
else
41+
./solpb.sh
42+
endif

contracts/LCPClientBase.sol

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,27 @@ abstract contract LCPClientBase is ILightClient, ILCPClientErrors {
4848

4949
// --------------------- Immutable fields ---------------------
5050

51+
/// @dev ibcHandler is the address of the IBC handler contract.
52+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
5153
address internal immutable ibcHandler;
52-
// if developmentMode is true, the client allows the remote attestation of IAS in development.
54+
/// @dev if developmentMode is true, the client allows the remote attestation of IAS in development.
55+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
5356
bool internal immutable developmentMode;
5457

5558
// --------------------- Storage fields ---------------------
5659

5760
mapping(string => ClientStorage) internal clientStorages;
5861

5962
// rootCA's public key parameters
60-
AVRValidator.RSAParams public verifiedRootCAParams;
63+
AVRValidator.RSAParams internal verifiedRootCAParams;
6164
// keccak256(signingCert) => RSAParams of signing public key
62-
mapping(bytes32 => AVRValidator.RSAParams) public verifiedSigningRSAParams;
65+
mapping(bytes32 => AVRValidator.RSAParams) internal verifiedSigningRSAParams;
6366

6467
// --------------------- Constructor ---------------------
6568

69+
/// @custom:oz-upgrades-unsafe-allow constructor
70+
/// @param ibcHandler_ the address of the IBC handler contract
71+
/// @param developmentMode_ if true, the client allows the enclave debug mode
6672
constructor(address ibcHandler_, bool developmentMode_) {
6773
ibcHandler = ibcHandler_;
6874
developmentMode = developmentMode_;
@@ -77,7 +83,7 @@ abstract contract LCPClientBase is ILightClient, ILCPClientErrors {
7783

7884
// --------------------- Public methods ---------------------
7985

80-
/// @dev isDevelopmentMode returns true if the client allows the remote attestation of IAS in development.
86+
/// @dev isDevelopmentMode returns true if the client allows the enclave debug mode.
8187
function isDevelopmentMode() public view returns (bool) {
8288
return developmentMode;
8389
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.12;
3+
4+
import {LCPClientBase} from "./LCPClientBase.sol";
5+
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
6+
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
7+
8+
/// @custom:oz-upgrades-unsafe-allow external-library-linking
9+
contract LCPClientOwnableUpgradeable is LCPClientBase, UUPSUpgradeable, OwnableUpgradeable {
10+
/// @custom:oz-upgrades-unsafe-allow constructor
11+
constructor(address ibcHandler, bool developmentMode) LCPClientBase(ibcHandler, developmentMode) {}
12+
13+
function initialize(bytes memory rootCACert) public initializer {
14+
initializeRootCACert(rootCACert);
15+
__UUPSUpgradeable_init();
16+
__Ownable_init(msg.sender);
17+
}
18+
19+
function _authorizeUpgrade(address newImplementation) internal virtual override onlyOwner {}
20+
}

foundry.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ out = 'out'
44
libs = ['lib', 'node_modules']
55
optimizer = true
66
optimizer_runs = 9_999_999
7+
via-ir = false
8+
ffi = true
9+
ast = true
10+
build_info = true
11+
extra_output = ["storageLayout"]
712
fs_permissions = [{ access = "read", path = "./"}]
13+
14+
[profile.ir]
15+
via-ir = true

lib/openzeppelin-foundry-upgrades

0 commit comments

Comments
 (0)