@inco/lightning 0.8.0-devnet-4 → 0.8.0-devnet-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +59 -1
  2. package/manifest.yaml +22 -0
  3. package/package.json +1 -1
  4. package/src/DeployUtils.sol +71 -25
  5. package/src/IncoLightning.sol +27 -7
  6. package/src/IncoVerifier.sol +18 -1
  7. package/src/Lib.alphanet.sol +390 -3
  8. package/src/Lib.demonet.sol +390 -3
  9. package/src/Lib.devnet.sol +391 -4
  10. package/src/Lib.sol +391 -4
  11. package/src/Lib.template.sol +387 -0
  12. package/src/Lib.testnet.sol +390 -3
  13. package/src/libs/incoLightning_alphanet_v0_297966649.sol +390 -3
  14. package/src/libs/incoLightning_alphanet_v1_725458969.sol +390 -3
  15. package/src/libs/incoLightning_alphanet_v2_976644394.sol +390 -3
  16. package/src/libs/incoLightning_demonet_v0_863421733.sol +390 -3
  17. package/src/libs/incoLightning_demonet_v2_467437523.sol +390 -3
  18. package/src/libs/incoLightning_devnet_v0_340846814.sol +390 -3
  19. package/src/libs/incoLightning_devnet_v1_904635675.sol +390 -3
  20. package/src/libs/incoLightning_devnet_v2_295237520.sol +390 -3
  21. package/src/libs/incoLightning_devnet_v3_976859633.sol +390 -3
  22. package/src/libs/incoLightning_devnet_v4_409204766.sol +921 -0
  23. package/src/libs/incoLightning_testnet_v0_183408998.sol +390 -3
  24. package/src/libs/incoLightning_testnet_v2_889158349.sol +390 -3
  25. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +65 -4
  26. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +71 -5
  27. package/src/lightning-parts/DecryptionAttester.sol +16 -3
  28. package/src/lightning-parts/EncryptedInput.sol +48 -2
  29. package/src/lightning-parts/EncryptedOperations.sol +134 -1
  30. package/src/lightning-parts/Fee.sol +29 -6
  31. package/src/lightning-parts/primitives/EventCounter.sol +36 -5
  32. package/src/lightning-parts/primitives/HandleGeneration.sol +38 -6
  33. package/src/lightning-parts/primitives/HandleMetadata.sol +28 -0
  34. package/src/lightning-parts/primitives/LightningAddressGetter.sol +10 -0
  35. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +10 -0
  36. package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +0 -2
  37. package/src/periphery/IncoUtils.sol +1 -0
  38. package/src/periphery/SessionVerifier.sol +35 -7
  39. package/src/test/TestFakeInfra.t.sol +536 -1
  40. package/src/version/IncoLightningConfig.sol +2 -2
package/README.md CHANGED
@@ -1,8 +1,66 @@
1
1
  # Inco Lightning
2
2
 
3
+ ![coverage](./coverage.svg)
4
+
3
5
  The core Inco Lightning smart contracts library for building confidential applications on EVM chains.
4
6
 
5
- ![coverage](./coverage.svg)
7
+ ## Architecture
8
+
9
+ The Inco Lightning protocol consists of two main contracts that work together:
10
+
11
+ - **IncoLightning**: The core encrypted operations contract - handles encrypted inputs, operations (arithmetic, bitwise, comparisons), trivial encryption, and access control
12
+ - **IncoVerifier**: The attestation contract - manages TEE lifecycle, decryption attestations, and advanced access control with signed vouchers
13
+
14
+ ```mermaid
15
+ flowchart TB
16
+ subgraph IncoLightning["IncoLightning (Operations)"]
17
+ EI[EncryptedInput]
18
+ EO[EncryptedOperations]
19
+ TE[TrivialEncryption]
20
+ ACL[BaseAccessControlList]
21
+ FEE[Fee Management]
22
+ end
23
+
24
+ subgraph IncoVerifier["IncoVerifier (Attestation)"]
25
+ AAC[AdvancedAccessControl]
26
+ DA[DecryptionAttester]
27
+ TEE[TEELifecycle]
28
+ SV[SignatureVerifier]
29
+ end
30
+
31
+ subgraph External["External"]
32
+ CLIENT[Client App]
33
+ COVAL[Covalidator TEE]
34
+ QV[Quote Verifier]
35
+ end
36
+
37
+ CLIENT -->|"encrypted input"| EI
38
+ CLIENT -->|"plaintext → encrypted"| TE
39
+ EI --> EO
40
+ TE --> EO
41
+ EO -->|"operations emit events"| COVAL
42
+ EO --> ACL
43
+ ACL -->|"verify access proofs"| AAC
44
+ COVAL -->|"decryption attestations"| DA
45
+ COVAL -->|"TEE quotes"| TEE
46
+ TEE --> QV
47
+ DA --> SV
48
+ TEE --> SV
49
+ ```
50
+
51
+ ### Key Components
52
+
53
+ | Contract | Module | Purpose |
54
+ | ------------- | --------------------- | ------------------------------------------------------- |
55
+ | IncoLightning | EncryptedInput | Accept client-encrypted values with replay protection |
56
+ | IncoLightning | EncryptedOperations | 29 operations (arithmetic, bitwise, comparison, random) |
57
+ | IncoLightning | TrivialEncryption | Create encrypted handles from plaintext constants |
58
+ | IncoLightning | BaseAccessControlList | Persistent + transient access permissions |
59
+ | IncoLightning | Fee Management | Collect fees for covalidator processing |
60
+ | IncoVerifier | AdvancedAccessControl | EIP-712 signed vouchers for access delegation |
61
+ | IncoVerifier | DecryptionAttester | Verify covalidator signatures on decryptions |
62
+ | IncoVerifier | TEELifecycle | Bootstrap, upgrade, and manage TEE nodes |
63
+ | IncoVerifier | SignatureVerifier | Multi-signature threshold verification |
6
64
 
7
65
  ## Install dependencies
8
66
 
package/manifest.yaml CHANGED
@@ -1,3 +1,25 @@
1
+ incoLightning_devnet_v4_409204766:
2
+ executor:
3
+ name: incoLightning_devnet_v4_409204766
4
+ majorVersion: 4
5
+ deployer: "0x8202D2D747784Cb7D48868E44C42C4bf162a70BC"
6
+ pepper: devnet
7
+ executorAddress: "0x4046b737B454b0430FBF29cea070e3337AdE95aD"
8
+ salt: "0x8202d2d747784cb7d48868e44c42c4bf162a70bc003b3f2c4caeb6f787dcce1e"
9
+ deployments:
10
+ - name: incoLightningPreview_4_0_0__409204766
11
+ chainId: "84532"
12
+ chainName: Base Sepolia
13
+ version:
14
+ major: 4
15
+ minor: 0
16
+ patch: 0
17
+ shortSalt: "409204766"
18
+ blockNumber: "36706685"
19
+ deployDate: 2026-01-23T15:20:59.956Z
20
+ commit: v0.8.0-devnet-4-1-g48f40565-dirty
21
+ active: true
22
+ includesPreviewFeatures: true
1
23
  incoLightning_devnet_v3_976859633:
2
24
  executor:
3
25
  name: incoLightning_devnet_v3_976859633
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inco/lightning",
3
- "version": "0.8.0-devnet-4",
3
+ "version": "0.8.0-devnet-5",
4
4
  "repository": "https://github.com/Inco-fhevm/inco-monorepo",
5
5
  "files": [
6
6
  "src/",
@@ -13,8 +13,9 @@ import {console} from "forge-std/console.sol";
13
13
  import {CreateXHelper} from "./CreateXHelper.sol";
14
14
  import {IQuoteVerifier} from "./interfaces/automata-interfaces/IQuoteVerifier.sol";
15
15
 
16
- // can be set to 0x01 so the inco address can exist on only one chain, we want the same contract at the same address
17
- // on all chains
16
+ /// @dev Flag controlling cross-chain deployment authorization.
17
+ /// Set to 0x00 to allow same contract at same address on all chains.
18
+ /// Set to 0x01 to restrict to single chain deployment.
18
19
  bytes1 constant CROSS_CHAIN_DEPLOY_AUTHORIZED_FLAG = 0x00;
19
20
 
20
21
  // GLOSSARY
@@ -25,10 +26,27 @@ bytes1 constant CROSS_CHAIN_DEPLOY_AUTHORIZED_FLAG = 0x00;
25
26
  // using the CROSS_CHAIN_DEPLOY_AUTHORIZED_FLAG, it prevents the contract from being deployed by someone other than
26
27
  // the deployer at the expected address
27
28
 
28
- /// @dev not a script in itself, use this contract in tests or scripts to get new instances of IncoLightning
29
+ /// @title DeployUtils
30
+ /// @notice Deployment utilities for IncoLightning and IncoVerifier contracts
31
+ /// @dev Provides deterministic cross-chain deployment using CreateX (CREATE3 pattern).
32
+ /// This contract is meant to be inherited by deployment scripts and test helpers.
33
+ ///
34
+ /// Deployment uses CREATE3 via CreateX to achieve:
35
+ /// - Deterministic addresses across all EVM chains
36
+ /// - Same address regardless of deployer nonce
37
+ /// - Address computed only from salt (derived from name, version, deployer, pepper)
38
+ ///
39
+ /// Typical deployment sequence:
40
+ /// 1. Compute salts from deployer address and pepper
41
+ /// 2. Deploy IncoLightning implementation and proxy
42
+ /// 3. Deploy IncoVerifier implementation and proxy
43
+ /// 4. Both contracts reference each other via computed addresses
29
44
  contract DeployUtils is Script {
30
45
 
31
- /// @dev CreateX is deployed on most chains, use this method for the testing environment
46
+ /// @notice Deploys CreateX contract for testing environments
47
+ /// @dev CreateX is pre-deployed on most production chains. Use this only in test environments
48
+ /// where CreateX is not available. Pranks as the CreateX deployer to get expected address.
49
+ /// @return createX The deployed CreateX instance at the canonical address
32
50
  function deployCreateX() public returns (CreateX createX) {
33
51
  vm.prank(CREATE_X_DEPLOYER);
34
52
  createX = new CreateX();
@@ -36,6 +54,16 @@ contract DeployUtils is Script {
36
54
  return createX;
37
55
  }
38
56
 
57
+ /// @notice Computes a deployment salt from contract metadata
58
+ /// @dev The salt incorporates:
59
+ /// - Deployer address (first 20 bytes)
60
+ /// - Cross-chain flag (1 byte)
61
+ /// - Hash of name, version, and pepper (last 11 bytes)
62
+ /// @param name The contract name (e.g., "IncoLightning")
63
+ /// @param majorVersionNumber The major version number
64
+ /// @param deployer The address that will deploy the contract
65
+ /// @param pepper Additional entropy to avoid address collisions
66
+ /// @return The 32-byte salt for CreateX deployment
39
67
  function getSalt(string memory name, uint8 majorVersionNumber, address deployer, string memory pepper)
40
68
  internal
41
69
  pure
@@ -50,19 +78,23 @@ contract DeployUtils is Script {
50
78
  );
51
79
  }
52
80
 
53
- /// @notice Computes the address of the contract using CreateX based on the deployer and pepper
54
- /// @dev not sure what the msg.sender influence is over the result
81
+ /// @notice Computes the address a contract will be deployed to using CreateX
82
+ /// @dev Uses CREATE3 address derivation. The address is deterministic based only on salt.
55
83
  /// @param salt The salt value that will be passed to CreateX
56
- /// @return The address of the deployed contract by CreateX
84
+ /// @return The address where the contract will be deployed
57
85
  function computeAddressFromSalt(bytes32 salt) public returns (address) {
58
86
  CreateXHelper createX = new CreateXHelper();
59
87
  return createX.computeCreate3DeployAddress({salt: salt});
60
88
  }
61
89
 
62
- /// @dev wrap in prank or broadcast depending on prod or testing environment
63
- /// @param deployer MUST be the signer of the transaction
64
- /// @param pepper a value used to avoid address collision on deploying the same contract twice with the same deployer
65
- /// @param quoteVerifier the address of the QuoteVerifier contract to use in the contract
90
+ /// @notice Full deployment of IncoLightning and IncoVerifier using configuration
91
+ /// @dev Computes salts from deployer and pepper, then deploys both contracts.
92
+ /// Should be wrapped in prank (testing) or broadcast (production).
93
+ /// @param deployer The address that will own both deployed proxies (MUST be tx signer)
94
+ /// @param pepper Entropy string to avoid address collision with previous deployments
95
+ /// @param quoteVerifier The Automata quote verifier for TEE attestation validation
96
+ /// @return lightningProxy The deployed IncoLightning proxy
97
+ /// @return verifierProxy The deployed IncoVerifier proxy
66
98
  function deployIncoLightningUsingConfig(address deployer, string memory pepper, IQuoteVerifier quoteVerifier)
67
99
  internal
68
100
  returns (IIncoLightning lightningProxy, IIncoVerifier verifierProxy)
@@ -78,6 +110,12 @@ contract DeployUtils is Script {
78
110
  );
79
111
  }
80
112
 
113
+ /// @notice Computes the standard salts for IncoLightning and IncoVerifier
114
+ /// @dev Uses the contract names and major version from IncoLightningConfig
115
+ /// @param deployer The deployer address
116
+ /// @param pepper The pepper string for salt generation
117
+ /// @return lightningSalt Salt for IncoLightning deployment
118
+ /// @return verifierSalt Salt for IncoVerifier deployment
81
119
  function getIncoSalts(address deployer, string memory pepper)
82
120
  internal
83
121
  pure
@@ -87,10 +125,13 @@ contract DeployUtils is Script {
87
125
  verifierSalt = getSalt(VERIFIER_NAME, MAJOR_VERSION, deployer, pepper);
88
126
  }
89
127
 
90
- /// @notice Deploys the IncoLightning contract
91
- /// @param lightningSalt The salt value that will be passed to CreateX
92
- /// @param verifierSalt The salt value that will be passed to CreateX
93
- /// @param deployer The address of the deployer
128
+ /// @notice Deploys the IncoLightning contract with proxy
129
+ /// @dev Creates both implementation and proxy contracts. The verifier address is
130
+ /// computed from salt since it may not be deployed yet.
131
+ /// @param lightningSalt The salt for CreateX deployment
132
+ /// @param verifierSalt The salt used to compute the verifier address
133
+ /// @param deployer The address that will own the proxy
134
+ /// @return lightningProxy The deployed proxy cast to IIncoLightning
94
135
  function deployLightning(bytes32 lightningSalt, bytes32 verifierSalt, address deployer)
95
136
  internal
96
137
  returns (IIncoLightning lightningProxy)
@@ -109,12 +150,14 @@ contract DeployUtils is Script {
109
150
  );
110
151
  }
111
152
 
112
- /// @notice Deploys the IncoVerifier contract
113
- /// @param verifierSalt The salt value that will be passed to CreateX
114
- /// @param lightning The previously deployed lightning contract
115
- /// @param deployer The address of the deployer
116
- /// @param quoteVerifier The address of the TEE lifecycle contract
117
- /// @dev lightning implem must already be deployed
153
+ /// @notice Deploys the IncoVerifier contract with proxy
154
+ /// @dev Creates both implementation and proxy. Lightning must already be deployed
155
+ /// so it can be referenced in the verifier.
156
+ /// @param verifierSalt The salt for CreateX deployment
157
+ /// @param lightning The previously deployed IncoLightning proxy
158
+ /// @param deployer The address that will own the proxy
159
+ /// @param quoteVerifier The Automata quote verifier for TEE attestation
160
+ /// @return verifierProxy The deployed proxy cast to IIncoVerifier
118
161
  function deployVerifier(
119
162
  bytes32 verifierSalt,
120
163
  IIncoLightning lightning,
@@ -137,13 +180,16 @@ contract DeployUtils is Script {
137
180
  );
138
181
  }
139
182
 
140
- /// @notice deploys a ERC1967Proxy contract using CreateX (create3 pattern), gives the deployer the ownership of
141
- /// the proxy
142
- /// @dev deployer is made the owner of the contract
183
+ /// @notice Deploys an ERC1967 proxy using CreateX (CREATE3 pattern)
184
+ /// @dev The proxy is initialized with the provided init call during deployment.
185
+ /// Uses CREATE3 for deterministic addressing.
186
+ /// @param salt The salt for CreateX deployment
187
+ /// @param implem The implementation contract address
188
+ /// @param initCall ABI-encoded initializer call (selector + arguments)
189
+ /// @return proxy The deployed proxy address
143
190
  function deployProxy(bytes32 salt, address implem, bytes memory initCall) internal returns (address proxy) {
144
191
  CreateX createX = CreateX(CREATE_X_ADDRESS);
145
192
  bytes memory bytecode = abi.encodePacked(type(ERC1967Proxy).creationCode, abi.encode(implem, initCall));
146
- // todo: check if we don't have a double delegatecall cost issue
147
193
  proxy = createX.deployCreate3(salt, bytecode);
148
194
  }
149
195
 
@@ -12,11 +12,16 @@ import {Version} from "./version/Version.sol";
12
12
  import {IIncoVerifier} from "./interfaces/IIncoVerifier.sol";
13
13
  import {VerifierAddressGetter} from "./lightning-parts/primitives/VerifierAddressGetter.sol";
14
14
 
15
- // todo add initialization of tee lifecycle
16
-
17
- /// @title Inco Lightning
18
- /// @notice Onchain singleton for Inco Lightning, TEE-based encrypted data and operations over shared state service
19
- /// @dev implicitly extends BaseAccessControlList, IncoVerifierGetter
15
+ /// @title IncoLightning
16
+ /// @notice Onchain singleton for Inco Lightning, TEE-based encrypted data and operations over shared state
17
+ /// @dev This is the main entry point contract for the Inco Lightning protocol. It combines:
18
+ /// - EncryptedOperations: Encrypted operations (eAdd, eSub, eMul, etc.)
19
+ /// - TrivialEncryption: Creating encrypted handles from plaintext values
20
+ /// - EncryptedInput: Processing client-encrypted inputs
21
+ /// - BaseAccessControlList: Managing access permissions (via inheritance)
22
+ ///
23
+ /// The contract is deployed as a UUPS upgradeable proxy and uses CreateX for deterministic deployment.
24
+ /// All encrypted values are represented as bytes32 handles that reference ciphertexts stored off-chain.
20
25
  contract IncoLightning is
21
26
  IIncoLightning,
22
27
  EncryptedOperations,
@@ -27,24 +32,39 @@ contract IncoLightning is
27
32
  Version
28
33
  {
29
34
 
30
- // salt embeds the deployer address, the contract name, the version and the pepper
35
+ /// @notice Initializes the IncoLightning contract with deployment configuration
36
+ /// @dev The salt embeds the deployer address, contract name, version, and pepper for deterministic deployment.
37
+ /// This constructor is called once during proxy implementation deployment.
38
+ /// @param salt Unique salt used for deterministic deployment via CreateX
39
+ /// @param _incoVerifier The verifier contract address for attestation validation
31
40
  constructor(bytes32 salt, IIncoVerifier _incoVerifier)
32
41
  Version(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, salt, CONTRACT_NAME)
33
42
  VerifierAddressGetter(address(_incoVerifier))
34
43
  {}
35
44
 
45
+ /// @notice Authorizes contract upgrades (restricted to owner only)
46
+ /// @dev Required by UUPSUpgradeable. Only the contract owner can authorize upgrades.
36
47
  function _authorizeUpgrade(address) internal view override {
37
48
  require(msg.sender == owner());
38
49
  }
39
50
 
51
+ /// @notice Initializes the proxy with an owner address
52
+ /// @dev Must be called immediately after proxy deployment. Can only be called once.
53
+ /// This sets up the Ownable state for the proxy instance.
54
+ /// @param owner The address that will own this contract and can authorize upgrades
40
55
  function initialize(address owner) public initializer {
41
56
  __Ownable_init(owner);
42
57
  }
43
58
 
59
+ /// @notice Withdraws accumulated protocol fees to the owner
60
+ /// @dev Only callable by the contract owner. Transfers all accumulated fees
61
+ /// from encrypted operations to the owner address.
44
62
  function withdrawFees() external onlyOwner {
45
63
  _withdrawFeesTo(owner());
46
64
  }
47
65
 
48
- fallback() external {} // must be included for createX deploy
66
+ /// @notice Required for CreateX deterministic deployment
67
+ /// @dev Empty fallback allows the contract to be deployed via CreateX's create2 mechanism
68
+ fallback() external {}
49
69
 
50
70
  }
@@ -9,16 +9,29 @@ import {TEELifecycle} from "./lightning-parts/TEELifecycle.sol";
9
9
  import {IIncoVerifier} from "./interfaces/IIncoVerifier.sol";
10
10
  import {LightningAddressGetter} from "./lightning-parts/primitives/LightningAddressGetter.sol";
11
11
 
12
- /// @dev implicitly extends OwnableUpgradeable, EIP712Upgradeable, SignatureVerifier, LightningAddressGetter
12
+ /// @title IncoVerifier
13
+ /// @notice Verifier contract for Inco Lightning TEE attestation and decryption authorization
13
14
  /// @dev NEVER deploy this contract on its own, always deploy as a joint process with IncoLightning
14
15
  contract IncoVerifier is IIncoVerifier, AdvancedAccessControl, DecryptionAttester, TEELifecycle, UUPSUpgradeable {
15
16
 
17
+ /// @notice Initializes the IncoVerifier contract with the IncoLightning address
18
+ /// @dev This constructor is called once during proxy implementation deployment.
19
+ /// @param _incoLightningAddress The address of the IncoLightning contract for attestation validation
16
20
  constructor(address _incoLightningAddress) LightningAddressGetter(_incoLightningAddress) {}
17
21
 
22
+ /// @notice Authorizes contract upgrades (restricted to owner only)
23
+ /// @dev Required by UUPSUpgradeable. Only the contract owner can authorize upgrades.
18
24
  function _authorizeUpgrade(address) internal view override {
19
25
  require(msg.sender == owner());
20
26
  }
21
27
 
28
+ /// @notice Initializes the proxy with an owner address and EIP712 parameters
29
+ /// @dev Must be called immediately after proxy deployment. Can only be called once.
30
+ /// This sets up the Ownable state for the proxy instance and initializes EIP712 and TEE lifecycle.
31
+ /// @param owner The address that will own this contract and can authorize upgrades
32
+ /// @param name The EIP712 domain name
33
+ /// @param version The EIP712 domain version
34
+ /// @param quoteVerifier The quote verifier contract for TEE attestation validation
22
35
  function initialize(address owner, string memory name, string memory version, IQuoteVerifier quoteVerifier)
23
36
  public
24
37
  initializer
@@ -28,11 +41,15 @@ contract IncoVerifier is IIncoVerifier, AdvancedAccessControl, DecryptionAtteste
28
41
  __TeeLifecycle_init(quoteVerifier);
29
42
  }
30
43
 
44
+ /// @notice Returns the EIP712 domain name
45
+ /// @dev Used in signing and verifying structured data
31
46
  // forge-lint: disable-next-line(mixed-case-function)
32
47
  function getEIP712Name() external view returns (string memory) {
33
48
  return _EIP712Name();
34
49
  }
35
50
 
51
+ /// @notice Returns the EIP712 domain version
52
+ /// @dev Used in signing and verifying structured data
36
53
  // forge-lint: disable-next-line(mixed-case-function)
37
54
  function getEIP712Version() external view returns (string memory) {
38
55
  return _EIP712Version();