@inco/lightning 0.6.7 → 0.6.9

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 (83) hide show
  1. package/README.md +29 -2
  2. package/manifest.yaml +0 -42
  3. package/package.json +5 -2
  4. package/src/CreateXHelper.sol +3 -1
  5. package/src/DeployUtils.sol +36 -71
  6. package/src/Errors.sol +1 -1
  7. package/src/IIncoLightning.sol +2 -0
  8. package/src/IncoLightning.sol +5 -17
  9. package/src/IncoVerifier.sol +12 -18
  10. package/src/Lib.template.sol +40 -159
  11. package/src/Types.sol +233 -97
  12. package/src/interfaces/IIncoLightning.sol +2 -0
  13. package/src/interfaces/IIncoVerifier.sol +7 -12
  14. package/src/interfaces/automata-interfaces/BELE.sol +2 -0
  15. package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +9 -11
  16. package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +3 -3
  17. package/src/interfaces/automata-interfaces/IPCCSRouter.sol +13 -47
  18. package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +2 -0
  19. package/src/interfaces/automata-interfaces/IPcsDao.sol +6 -11
  20. package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +4 -7
  21. package/src/interfaces/automata-interfaces/Types.sol +7 -6
  22. package/src/libs/incoLightning_devnet_v1_887305889.sol +5 -3
  23. package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
  24. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +41 -75
  25. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +31 -62
  26. package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +8 -15
  27. package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +5 -12
  28. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +42 -83
  29. package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +2 -0
  30. package/src/lightning-parts/DecryptionAttester.sol +14 -28
  31. package/src/lightning-parts/EncryptedInput.sol +23 -52
  32. package/src/lightning-parts/EncryptedOperations.sol +93 -440
  33. package/src/lightning-parts/Fee.sol +3 -1
  34. package/src/lightning-parts/TEELifecycle.sol +95 -225
  35. package/src/lightning-parts/TEELifecycle.types.sol +4 -3
  36. package/src/lightning-parts/TrivialEncryption.sol +6 -20
  37. package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -2
  38. package/src/lightning-parts/interfaces/IEncryptedInput.sol +5 -12
  39. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +17 -61
  40. package/src/lightning-parts/interfaces/ITEELifecycle.sol +7 -11
  41. package/src/lightning-parts/interfaces/ITrivialEncryption.sol +2 -0
  42. package/src/lightning-parts/primitives/EventCounter.sol +7 -8
  43. package/src/lightning-parts/primitives/HandleGeneration.sol +20 -32
  44. package/src/lightning-parts/primitives/HandleMetadata.sol +7 -17
  45. package/src/lightning-parts/primitives/LightningAddressGetter.sol +3 -0
  46. package/src/lightning-parts/primitives/SignatureVerifier.sol +91 -27
  47. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +3 -0
  48. package/src/lightning-parts/primitives/interfaces/IEventCounter.sol +2 -0
  49. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +10 -2
  50. package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +4 -2
  51. package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +2 -0
  52. package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +838 -0
  53. package/src/lightning-parts/test/Fee.t.sol +6 -6
  54. package/src/lightning-parts/test/HandleMetadata.t.sol +21 -76
  55. package/src/lightning-parts/test/InputsFee.t.sol +7 -28
  56. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +16 -48
  57. package/src/pasted-dependencies/CreateX.sol +146 -419
  58. package/src/pasted-dependencies/ICreateX.sol +58 -102
  59. package/src/periphery/SessionVerifier.sol +5 -7
  60. package/src/shared/IOwnable.sol +3 -0
  61. package/src/shared/IUUPSUpgradable.sol +5 -1
  62. package/src/shared/JsonUtils.sol +3 -5
  63. package/src/shared/TestUtils.sol +14 -13
  64. package/src/test/AddTwo.sol +9 -7
  65. package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
  66. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -118
  67. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +31 -48
  68. package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +4 -7
  69. package/src/test/FakeIncoInfra/KVStore.sol +2 -0
  70. package/src/test/FakeIncoInfra/MockOpHandler.sol +9 -31
  71. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +44 -21
  72. package/src/test/IncoTest.sol +15 -9
  73. package/src/test/OpsTest.sol +429 -0
  74. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +58 -104
  75. package/src/test/TestAddTwo.t.sol +4 -3
  76. package/src/test/TestDeploy.t.sol +5 -6
  77. package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -14
  78. package/src/test/TestFakeInfra.t.sol +15 -38
  79. package/src/test/TestUpgrade.t.sol +40 -135
  80. package/src/test/TestVersion.t.sol +6 -5
  81. package/src/version/IncoLightningConfig.sol +1 -1
  82. package/src/version/Version.sol +48 -51
  83. package/src/version/interfaces/IVersion.sol +6 -0
@@ -5,22 +5,23 @@ import {Test} from "forge-std/Test.sol";
5
5
  import {Fee, FEE} from "../Fee.sol";
6
6
 
7
7
  contract FeeTester is Fee {
8
+
8
9
  function costOneFee() public payable paying {
9
10
  // do nothing
10
11
  }
11
12
 
12
- function costMultipleVariableFees(
13
- uint256 nbOfFees
14
- ) public payable payingMultiple(nbOfFees) {
13
+ function costMultipleVariableFees(uint256 nbOfFees) public payable payingMultiple(nbOfFees) {
15
14
  // do nothing
16
15
  }
17
16
 
18
17
  function costMultipleFixedFees() public payable payingMultiple(3) {
19
18
  // do nothing
20
19
  }
20
+
21
21
  }
22
22
 
23
23
  contract TestFee is Test {
24
+
24
25
  FeeTester feeTester;
25
26
 
26
27
  function setUp() public {
@@ -89,13 +90,12 @@ contract TestFee is Test {
89
90
  // should fail if not enough fee (unless expectedValue is 0)
90
91
  if (expectedValue > 0) {
91
92
  vm.expectRevert(Fee.FeeNotPaid.selector);
92
- feeTester.costMultipleVariableFees{value: expectedValue - 1}(
93
- nbOfFees
94
- );
93
+ feeTester.costMultipleVariableFees{value: expectedValue - 1}(nbOfFees);
95
94
  }
96
95
 
97
96
  // should fail if too much fee
98
97
  vm.expectRevert(Fee.FeeNotPaid.selector);
99
98
  feeTester.costMultipleVariableFees{value: expectedValue + 1}(nbOfFees);
100
99
  }
100
+
101
101
  }
@@ -7,13 +7,7 @@ import {TrivialEncryption} from "../TrivialEncryption.sol";
7
7
  import {EncryptedOperations} from "../EncryptedOperations.sol";
8
8
  import {EncryptedInput} from "../EncryptedInput.sol";
9
9
  import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
10
- import {
11
- ETypes,
12
- ebool,
13
- euint256,
14
- eaddress,
15
- typeToBitMask
16
- } from "../../Types.sol";
10
+ import {ETypes, ebool, euint256, eaddress, typeToBitMask} from "../../Types.sol";
17
11
  import {VerifierAddressGetter} from "../primitives/VerifierAddressGetter.sol";
18
12
  import {FEE} from "../Fee.sol";
19
13
 
@@ -25,25 +19,16 @@ contract TestHandleMetadata is
25
19
  EncryptedOperations,
26
20
  EncryptedInput
27
21
  {
22
+
28
23
  constructor() EIP712("", "") VerifierAddressGetter(address(0)) {}
29
24
 
30
25
  function testTypeAssignment() public pure {
31
26
  bytes32 someHandle = bytes32(keccak256("someHandle"));
27
+ assert(typeOf(embedIndexTypeVersion(someHandle, ETypes.Bool)) == ETypes.Bool);
28
+ assert(typeOf(embedIndexTypeVersion(someHandle, ETypes.Uint256)) == ETypes.Uint256);
32
29
  assert(
33
- typeOf(embedIndexTypeVersion(someHandle, ETypes.Bool)) ==
34
- ETypes.Bool
35
- );
36
- assert(
37
- typeOf(embedIndexTypeVersion(someHandle, ETypes.Uint256)) ==
38
- ETypes.Uint256
39
- );
40
- assert(
41
- typeOf(
42
- embedIndexTypeVersion(
43
- someHandle,
44
- ETypes.AddressOrUint160OrBytes20
45
- )
46
- ) == ETypes.AddressOrUint160OrBytes20
30
+ typeOf(embedIndexTypeVersion(someHandle, ETypes.AddressOrUint160OrBytes20))
31
+ == ETypes.AddressOrUint160OrBytes20
47
32
  );
48
33
  }
49
34
 
@@ -52,9 +37,7 @@ contract TestHandleMetadata is
52
37
  assert(typeOf(boolHandle) == ETypes.Bool);
53
38
  bytes32 uintHandle = euint256.unwrap(this.asEuint256(42));
54
39
  assert(typeOf(uintHandle) == ETypes.Uint256);
55
- bytes32 addressHandle = eaddress.unwrap(
56
- this.asEaddress(address(0xdeadbeef))
57
- );
40
+ bytes32 addressHandle = eaddress.unwrap(this.asEaddress(address(0xdeadbeef)));
58
41
  assert(typeOf(addressHandle) == ETypes.AddressOrUint160OrBytes20);
59
42
  }
60
43
 
@@ -70,27 +53,9 @@ contract TestHandleMetadata is
70
53
  assert(typeOf(euint256.unwrap(this.eAdd(a, b))) == ETypes.Uint256);
71
54
  assert(typeOf(euint256.unwrap(this.eSub(a, b))) == ETypes.Uint256);
72
55
  assert(typeOf(ebool.unwrap(this.eGe(a, b))) == ETypes.Bool);
73
- assert(
74
- typeOf(
75
- this.eIfThenElse(
76
- control,
77
- euint256.unwrap(a),
78
- euint256.unwrap(b)
79
- )
80
- ) == ETypes.Uint256
81
- );
82
- assert(
83
- typeOf(
84
- this.eIfThenElse(control, ebool.unwrap(c), ebool.unwrap(d))
85
- ) == ETypes.Bool
86
- );
87
- assert(
88
- typeOf(
89
- ebool.unwrap(
90
- this.eEq(eaddress.unwrap(addr1), eaddress.unwrap(addr2))
91
- )
92
- ) == ETypes.Bool
93
- );
56
+ assert(typeOf(this.eIfThenElse(control, euint256.unwrap(a), euint256.unwrap(b))) == ETypes.Uint256);
57
+ assert(typeOf(this.eIfThenElse(control, ebool.unwrap(c), ebool.unwrap(d))) == ETypes.Bool);
58
+ assert(typeOf(ebool.unwrap(this.eEq(eaddress.unwrap(addr1), eaddress.unwrap(addr2)))) == ETypes.Bool);
94
59
  }
95
60
 
96
61
  function testEIfThenElseChecksTypeCoherence() public {
@@ -99,9 +64,7 @@ contract TestHandleMetadata is
99
64
  ebool b = this.asEbool(true);
100
65
  vm.expectRevert(
101
66
  abi.encodeWithSelector(
102
- EncryptedOperations.UnexpectedType.selector,
103
- ETypes.Bool,
104
- typeToBitMask(ETypes.Uint256)
67
+ EncryptedOperations.UnexpectedType.selector, ETypes.Bool, typeToBitMask(ETypes.Uint256)
105
68
  )
106
69
  );
107
70
  this.eIfThenElse(control, euint256.unwrap(a), ebool.unwrap(b));
@@ -110,24 +73,12 @@ contract TestHandleMetadata is
110
73
  function testEncryptedInputHandleType() public {
111
74
  address self = address(this);
112
75
  bytes32 ciphertext = keccak256(abi.encodePacked("ciphertext"));
113
- euint256 a = this.newEuint256{value: FEE}(
114
- getCiphertextInput(ciphertext, self, self, ETypes.Uint256),
115
- self
116
- );
76
+ euint256 a = this.newEuint256{value: FEE}(getCiphertextInput(ciphertext, self, self, ETypes.Uint256), self);
117
77
  assert(typeOf(euint256.unwrap(a)) == ETypes.Uint256);
118
- ebool b = this.newEbool{value: FEE}(
119
- getCiphertextInput(ciphertext, self, self, ETypes.Bool),
120
- address(this)
121
- );
78
+ ebool b = this.newEbool{value: FEE}(getCiphertextInput(ciphertext, self, self, ETypes.Bool), address(this));
122
79
  assert(typeOf(ebool.unwrap(b)) == ETypes.Bool);
123
80
  eaddress c = this.newEaddress{value: FEE}(
124
- getCiphertextInput(
125
- ciphertext,
126
- self,
127
- self,
128
- ETypes.AddressOrUint160OrBytes20
129
- ),
130
- address(this)
81
+ getCiphertextInput(ciphertext, self, self, ETypes.AddressOrUint160OrBytes20), address(this)
131
82
  );
132
83
  assert(typeOf(eaddress.unwrap(c)) == ETypes.AddressOrUint160OrBytes20);
133
84
  }
@@ -135,21 +86,15 @@ contract TestHandleMetadata is
135
86
  /// @notice Helper to create an input with a handle prepended to the ciphertext.
136
87
  /// @param word A single word to be used as the ciphertext.
137
88
  /// @param user The user address associated with the input.
138
- function getCiphertextInput(
139
- bytes32 word,
140
- address user,
141
- address contractAddress,
142
- ETypes inputType
143
- ) public view returns (bytes memory input) {
89
+ function getCiphertextInput(bytes32 word, address user, address contractAddress, ETypes inputType)
90
+ public
91
+ view
92
+ returns (bytes memory input)
93
+ {
144
94
  // We need a single word here to get correct encoding
145
95
  bytes memory ciphertext = abi.encode(word);
146
- bytes32 handle = getInputHandle(
147
- ciphertext,
148
- address(this),
149
- user,
150
- contractAddress,
151
- inputType
152
- );
96
+ bytes32 handle = getInputHandle(ciphertext, address(this), user, contractAddress, inputType);
153
97
  input = abi.encode(handle, ciphertext);
154
98
  }
99
+
155
100
  }
@@ -1,12 +1,8 @@
1
1
  // SPDX-License-Identifier: No License
2
2
  pragma solidity ^0.8;
3
3
 
4
- import {Test} from "forge-std/Test.sol";
5
- import {EncryptedInput} from "../EncryptedInput.sol";
6
- import {VerifierAddressGetter} from "../primitives/VerifierAddressGetter.sol";
7
4
  import {FEE, Fee} from "../Fee.sol";
8
5
  import {IncoTest} from "../../test/IncoTest.sol";
9
- import {console} from "forge-std/console.sol";
10
6
  import {inco} from "../../Lib.sol";
11
7
 
12
8
  contract TestInputsFee is IncoTest {
@@ -14,45 +10,28 @@ contract TestInputsFee is IncoTest {
14
10
  function testPayOnInputs() public {
15
11
  // should fail if no fee
16
12
  vm.expectRevert(Fee.FeeNotPaid.selector);
17
- inco.newEuint256{value: 0}(
18
- fakePrepareEuint256Ciphertext(12, address(0), address(this)),
19
- address(0)
20
- );
13
+ inco.newEuint256{value: 0}(fakePrepareEuint256Ciphertext(12, address(0), address(this)), address(0));
21
14
 
22
15
  // should fail if not enough fee
23
16
  vm.expectRevert(Fee.FeeNotPaid.selector);
24
- inco.newEuint256{value: FEE - 1}(
25
- fakePrepareEuint256Ciphertext(12, address(0), address(this)),
26
- address(0)
27
- );
17
+ inco.newEuint256{value: FEE - 1}(fakePrepareEuint256Ciphertext(12, address(0), address(this)), address(0));
28
18
 
29
19
  // should fail if too much fee
30
20
  vm.expectRevert(Fee.FeeNotPaid.selector);
31
- inco.newEuint256{value: FEE + 1}(
32
- fakePrepareEuint256Ciphertext(12, address(0), address(this)),
33
- address(0)
34
- );
21
+ inco.newEuint256{value: FEE + 1}(fakePrepareEuint256Ciphertext(12, address(0), address(this)), address(0));
35
22
 
36
23
  // should work with exact fee
37
- inco.newEuint256{value: FEE}(
38
- fakePrepareEuint256Ciphertext(12, address(0), address(this)),
39
- address(0)
40
- );
24
+ inco.newEuint256{value: FEE}(fakePrepareEuint256Ciphertext(12, address(0), address(this)), address(0));
41
25
  }
42
26
 
43
27
  function testPayForNewEbool() public {
44
28
  // should work with exact fee
45
- inco.newEbool{value: FEE}(
46
- fakePrepareEboolCiphertext(true, address(0), address(this)),
47
- address(0)
48
- );
29
+ inco.newEbool{value: FEE}(fakePrepareEboolCiphertext(true, address(0), address(this)), address(0));
49
30
  }
50
31
 
51
32
  function testPayForNewEaddress() public {
52
33
  // should work with exact fee
53
- inco.newEaddress{value: FEE}(
54
- fakePrepareEaddressCiphertext(address(0), address(0), address(this)),
55
- address(0)
56
- );
34
+ inco.newEaddress{value: FEE}(fakePrepareEaddressCiphertext(address(0), address(0), address(this)), address(0));
57
35
  }
36
+
58
37
  }
@@ -11,73 +11,41 @@ import {inco} from "../../Lib.sol";
11
11
  import {euint256 as remappedEuint256} from "@inco/lightning/src/Lib.sol";
12
12
 
13
13
  contract TokenBurnCurrentBalance is DemoToken {
14
- function burnFullCurrentBalance(
15
- DecryptionAttestation memory decryption,
16
- bytes memory signature
17
- ) public {
14
+
15
+ function burnFullCurrentBalance(DecryptionAttestation memory decryption, bytes[] memory signatures) public {
18
16
  euint256 currentBalance = confidentialBalanceOf(msg.sender);
19
- require(
20
- inco.incoVerifier().isValidDecryptionAttestation(
21
- decryption,
22
- signature
23
- ),
24
- "Invalid Signature"
25
- );
26
- require(
27
- euint256.unwrap(currentBalance) == decryption.handle,
28
- "Handle mismatch"
29
- );
17
+ require(inco.incoVerifier().isValidDecryptionAttestation(decryption, signatures), "Invalid Signature");
18
+ require(euint256.unwrap(currentBalance) == decryption.handle, "Handle mismatch");
30
19
  publicBurn(msg.sender, uint256(decryption.value));
31
20
  }
21
+
32
22
  }
33
23
 
34
24
  contract TestDecryptionAttestationInSynchronousFlow is IncoTest {
25
+
35
26
  AllowanceProof emptyProof; // no proof needed when requester has the handle in persisted allowed pairs
27
+
36
28
  function testSynchronousBurning() public {
37
29
  TokenBurnCurrentBalance token = new TokenBurnCurrentBalance();
38
30
  vm.deal(address(token), 100 ether);
39
- token.confidentialTransfer(
40
- alice,
41
- fakePrepareEuint256Ciphertext(
42
- 10 * GWEI,
43
- address(this),
44
- address(token)
45
- ),
46
- ""
47
- );
31
+ token.confidentialTransfer(alice, fakePrepareEuint256Ciphertext(10 * GWEI, address(this), address(token)), "");
48
32
  processAllOperations(); // saves Alice's balance
49
- bytes32 aliceCurrentBalanceHandle = euint256.unwrap(
50
- token.confidentialBalanceOf(alice)
51
- );
33
+ bytes32 aliceCurrentBalanceHandle = euint256.unwrap(token.confidentialBalanceOf(alice));
52
34
  // simulates Alice requesting for a decryption attestation of Ge op on her balance and the amount
53
35
  // she intends to burn, therefore proving to the token contract that the operation will succeed
54
- (
55
- DecryptionAttestation memory decryption,
56
- bytes memory signature
57
- ) = getDecryptionAttestation(
58
- alice,
59
- HandleWithProof({
60
- handle: aliceCurrentBalanceHandle,
61
- proof: emptyProof
62
- })
63
- );
36
+ (DecryptionAttestation memory decryption, bytes[] memory signatures) =
37
+ getDecryptionAttestation(alice, HandleWithProof({handle: aliceCurrentBalanceHandle, proof: emptyProof}));
64
38
  vm.prank(alice);
65
39
 
66
40
  // the decryption attestation is passed to the token burn method
67
- token.burnFullCurrentBalance(decryption, signature);
41
+ token.burnFullCurrentBalance(decryption, signatures);
68
42
 
69
43
  processAllOperations();
70
44
 
71
- remappedEuint256 remappedFinalAliceBalance = token
72
- .confidentialBalanceOf(alice);
73
- bytes32 finalAliceBalance = remappedEuint256.unwrap(
74
- remappedFinalAliceBalance
75
- ); // compilation trick
45
+ remappedEuint256 remappedFinalAliceBalance = token.confidentialBalanceOf(alice);
46
+ bytes32 finalAliceBalance = remappedEuint256.unwrap(remappedFinalAliceBalance); // compilation trick
76
47
 
77
- assertEq(
78
- uint256(get(finalAliceBalance)),
79
- 0,
80
- "Alice should have burned all her tokens"
81
- );
48
+ assertEq(uint256(get(finalAliceBalance)), 0, "Alice should have burned all her tokens");
82
49
  }
50
+
83
51
  }