@inco/lightning 0.5.3 → 0.6.0

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 (34) hide show
  1. package/manifest.yaml +14 -0
  2. package/package.json +1 -1
  3. package/src/Lib.alphanet.sol +12 -6
  4. package/src/Lib.demonet.sol +12 -6
  5. package/src/Lib.devnet.sol +12 -6
  6. package/src/Lib.sol +12 -6
  7. package/src/Lib.template.sol +12 -6
  8. package/src/Lib.testnet.sol +12 -6
  9. package/src/Types.sol +2 -1
  10. package/src/libs/incoLightning_alphanet_v0_297966649.sol +12 -6
  11. package/src/libs/incoLightning_demonet_v0_863421733.sol +12 -6
  12. package/src/libs/incoLightning_devnet_v0_340846814.sol +12 -6
  13. package/src/libs/incoLightning_devnet_v1_904635675.sol +12 -6
  14. package/src/libs/incoLightning_testnet_v0_183408998.sol +12 -6
  15. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +11 -3
  16. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +1 -0
  17. package/src/lightning-parts/EncryptedInput.sol +22 -6
  18. package/src/lightning-parts/EncryptedOperations.sol +6 -6
  19. package/src/lightning-parts/Fee.sol +41 -0
  20. package/src/lightning-parts/TEELifecycle.sol +138 -52
  21. package/src/lightning-parts/TEELifecycle.types.sol +9 -12
  22. package/src/lightning-parts/interfaces/IEncryptedInput.sol +3 -3
  23. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +48 -1
  24. package/src/lightning-parts/test/Fee.t.sol +101 -0
  25. package/src/lightning-parts/test/HandleMetadata.t.sol +4 -3
  26. package/src/lightning-parts/test/InputsFee.t.sol +65 -0
  27. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +1 -0
  28. package/src/test/AddTwo.sol +18 -6
  29. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +12 -0
  30. package/src/test/FakeIncoInfra/getOpForSelector.sol +3 -1
  31. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +2 -2
  32. package/src/test/TestAddTwo.t.sol +9 -1
  33. package/src/test/TestFakeInfra.t.sol +13 -3
  34. package/src/version/IncoLightningConfig.sol +1 -1
@@ -0,0 +1,65 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {Test} from "forge-std/Test.sol";
5
+ import {EncryptedInput} from "../EncryptedInput.sol";
6
+ import {VerifierAddressGetter} from "../primitives/VerifierAddressGetter.sol";
7
+ import {FEE, Fee} from "../Fee.sol";
8
+ import {IncoTest} from "../../test/IncoTest.sol";
9
+
10
+ contract InputsTester is EncryptedInput {
11
+ constructor() VerifierAddressGetter(address(0)) {}
12
+ }
13
+
14
+ contract TestInputsFee is IncoTest {
15
+ InputsTester inputsTester;
16
+
17
+ function setUp() public override {
18
+ inputsTester = new InputsTester();
19
+ }
20
+
21
+ function testPayOnInputs() public {
22
+ // should fail if no fee
23
+ vm.expectRevert(Fee.FeeNotPaid.selector);
24
+ inputsTester.newEuint256{value: 0}(
25
+ fakePrepareEuint256Ciphertext(12),
26
+ address(0)
27
+ );
28
+
29
+ // should fail if not enough fee
30
+ vm.expectRevert(Fee.FeeNotPaid.selector);
31
+ inputsTester.newEuint256{value: FEE - 1}(
32
+ fakePrepareEuint256Ciphertext(12),
33
+ address(0)
34
+ );
35
+
36
+ // should fail if too much fee
37
+ vm.expectRevert(Fee.FeeNotPaid.selector);
38
+ inputsTester.newEuint256{value: FEE + 1}(
39
+ fakePrepareEuint256Ciphertext(12),
40
+ address(0)
41
+ );
42
+
43
+ // should work with exact fee
44
+ inputsTester.newEuint256{value: FEE}(
45
+ fakePrepareEuint256Ciphertext(12),
46
+ address(0)
47
+ );
48
+ }
49
+
50
+ function testPayForNewEbool() public {
51
+ // should work with exact fee
52
+ inputsTester.newEbool{value: FEE}(
53
+ fakePrepareEboolCiphertext(true),
54
+ address(0)
55
+ );
56
+ }
57
+
58
+ function testPayForNewEaddress() public {
59
+ // should work with exact fee
60
+ inputsTester.newEaddress{value: FEE}(
61
+ fakePrepareEaddressCiphertext(address(this)),
62
+ address(0)
63
+ );
64
+ }
65
+ }
@@ -35,6 +35,7 @@ contract TestDecryptionAttestationInSynchronousFlow is IncoTest {
35
35
  AllowanceProof emptyProof; // no proof needed when requester has the handle in persisted allowed pairs
36
36
  function testSynchronousBurning() public {
37
37
  TokenBurnCurrentBalance token = new TokenBurnCurrentBalance();
38
+ vm.deal(address(token), 100 ether);
38
39
  token.confidentialTransfer(
39
40
  alice,
40
41
  fakePrepareEuint256Ciphertext(10 * GWEI),
@@ -1,14 +1,13 @@
1
1
  // SPDX-License-Identifier: No License
2
2
  pragma solidity ^0.8;
3
3
 
4
- import {euint256} from "../Types.sol";
4
+ import {euint256, ebool} from "../Types.sol";
5
5
  import {IncoLightning} from "../IncoLightning.sol";
6
-
7
- // import {console} from "forge-std/console.sol";
6
+ import {Fee} from "../lightning-parts/Fee.sol";
8
7
 
9
8
  // To implement such a contract, we would normally import e form Lib.sol. For test purposes, we take inco as
10
9
  // a constructor argument instead, so we can test it from other deployment addresses.
11
- contract AddTwo {
10
+ contract AddTwo is Fee {
12
11
  IncoLightning inco;
13
12
 
14
13
  constructor(IncoLightning _inco) {
@@ -31,8 +30,11 @@ contract AddTwo {
31
30
 
32
31
  function addTwoEOA(
33
32
  bytes memory uint256EInput
34
- ) external returns (euint256 result, euint256 resultRevealed) {
35
- euint256 value = inco.newEuint256(uint256EInput, msg.sender);
33
+ ) external payable refundUnspent returns (euint256 result, euint256 resultRevealed) {
34
+ euint256 value = inco.newEuint256{value: getFee()}(
35
+ uint256EInput,
36
+ msg.sender
37
+ );
36
38
  result = addTwo(value);
37
39
 
38
40
  inco.allow(euint256.unwrap(result), address(this));
@@ -43,4 +45,14 @@ contract AddTwo {
43
45
  resultRevealed = addTwoAlt(value);
44
46
  inco.reveal(euint256.unwrap(resultRevealed));
45
47
  }
48
+
49
+ function getTrue() external returns (ebool) {
50
+ ebool trueHandle = inco.asEbool(true);
51
+ inco.reveal(ebool.unwrap(trueHandle));
52
+ return trueHandle;
53
+ }
54
+
55
+ receive() external payable {
56
+ // Accept ETH payments
57
+ }
46
58
  }
@@ -47,6 +47,18 @@ contract FakeIncoInfraBase is TestUtils, KVStore {
47
47
  ciphertext = abi.encode(value);
48
48
  }
49
49
 
50
+ function fakePrepareEaddressCiphertext(
51
+ address value
52
+ ) internal pure returns (bytes memory ciphertext) {
53
+ ciphertext = abi.encode(value);
54
+ }
55
+
56
+ function fakeDecryptEaddressCiphertext(
57
+ bytes memory ciphertext
58
+ ) internal pure returns (address value) {
59
+ value = abi.decode(ciphertext, (address));
60
+ }
61
+
50
62
  function fakeDecryptEboolCiphertext(
51
63
  bytes memory ciphertext
52
64
  ) internal pure returns (bool value) {
@@ -63,8 +63,10 @@ function getOpForSelector(bytes32 opEventSelector) pure returns (EOps) {
63
63
  return EOps.Rand;
64
64
  } else if (opEventSelector == EncryptedOperations.ERandBounded.selector) {
65
65
  return EOps.RandBounded;
66
- } else if (opEventSelector == BaseAccessControlList.EAllow.selector) {
66
+ } else if (opEventSelector == BaseAccessControlList.Allow.selector) {
67
67
  return EOps.Allow;
68
+ } else if (opEventSelector == BaseAccessControlList.Reveal.selector) {
69
+ return EOps.Reveal;
68
70
  } else {
69
71
  revert("getOpForSelector: Unsupported selector");
70
72
  }
@@ -67,7 +67,7 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
67
67
  );
68
68
  vm.startPrank(this.owner());
69
69
  this.approveNewTEEVersion(mrAggregated);
70
- vm.expectRevert(TEELifecycle.InvalidBootstrapDataSignature.selector);
70
+ vm.expectRevert(TEELifecycle.InvalidEIP712Signature.selector);
71
71
  this.verifyBootstrapResult(bootstrapResult, quote, signatureInvalid);
72
72
  vm.stopPrank();
73
73
  }
@@ -117,7 +117,7 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
117
117
  (, address newCoval) = getLabeledKeyPair("newCoval");
118
118
  bytes memory quoteNew = createQuote(badMrtd, newCoval);
119
119
 
120
- vm.expectRevert(TEELifecycle.InvalidReportMrAggregated.selector);
120
+ vm.expectRevert(TEELifecycle.TEEVersionNotFound.selector);
121
121
  this.addNewCovalidator(quoteNew);
122
122
  vm.stopPrank();
123
123
  }
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8;
3
3
 
4
4
  import {inco} from "../Lib.sol";
5
- import {euint256} from "../Types.sol";
5
+ import {euint256, ebool} from "../Types.sol";
6
6
  import {IncoTest} from "./IncoTest.sol";
7
7
  import {AddTwo} from "./AddTwo.sol";
8
8
 
@@ -12,6 +12,7 @@ contract TestAddTwo is IncoTest {
12
12
  function setUp() public override {
13
13
  super.setUp();
14
14
  addTwo = new AddTwo(inco);
15
+ vm.deal(address(addTwo), 1 ether);
15
16
  vm.label(address(addTwo), "addTwo");
16
17
  }
17
18
 
@@ -33,4 +34,11 @@ contract TestAddTwo is IncoTest {
33
34
  assertFalse(inco.isAllowed(euint256.unwrap(result), bob));
34
35
  assertTrue(inco.isAllowed(euint256.unwrap(revealedResult), bob));
35
36
  }
37
+
38
+ function testTrueHandleReveal() public {
39
+ ebool trueVal = addTwo.getTrue();
40
+ processAllOperations();
41
+ assertEq(getBoolValue(trueVal), true);
42
+ assertTrue(inco.isAllowed(ebool.unwrap(trueVal), bob));
43
+ }
36
44
  }
@@ -270,6 +270,7 @@ contract TestFakeInfra is IncoTest, MockRemoteAttestation {
270
270
 
271
271
  function testEInput() public {
272
272
  TakesEInput inputContract = new TakesEInput();
273
+ vm.deal(address(inputContract), 1 ether);
273
274
  inputContract.setA(fakePrepareEuint256Ciphertext(12));
274
275
  inputContract.setB(fakePrepareEboolCiphertext(true));
275
276
  processAllOperations();
@@ -290,16 +291,25 @@ contract TestFakeInfra is IncoTest, MockRemoteAttestation {
290
291
  a.add(euint256.wrap(randomHandle));
291
292
  }
292
293
 
293
- function testCreateQuote() public {
294
+ function testCreateQuote() public view {
294
295
  bytes
295
296
  memory mrtd = hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
296
297
  address signer = address(0x1234567890123456789012345678901234567890);
297
298
  bytes memory quote = createQuote(mrtd, signer);
298
299
  TEELifecycle lifecycle = TEELifecycle(address(inco.incoVerifier()));
299
300
  TD10ReportBody memory tdReport = lifecycle.parseTD10ReportBody(quote);
300
- (address reportDataSigner, bytes32 reportMrAggregated) = lifecycle.parseReport(tdReport);
301
+ (address reportDataSigner, bytes32 reportMrAggregated) = lifecycle
302
+ .parseReport(tdReport);
301
303
  assertEq(reportDataSigner, signer);
302
- assertEq(reportMrAggregated, lifecycle.computeMrAggregated(tdReport.mrTd, tdReport.rtMr0, tdReport.rtMr1, tdReport.rtMr2));
304
+ assertEq(
305
+ reportMrAggregated,
306
+ lifecycle.computeMrAggregated(
307
+ tdReport.mrTd,
308
+ tdReport.rtMr0,
309
+ tdReport.rtMr1,
310
+ tdReport.rtMr2
311
+ )
312
+ );
303
313
  assertEq(quote.length, MINIMUM_QUOTE_LENGTH);
304
314
  }
305
315
  }
@@ -11,6 +11,6 @@ uint8 constant MAJOR_VERSION = 1;
11
11
  uint8 constant MINOR_VERSION = 0;
12
12
  // whenever a new major version is deployed, we need to pump this up
13
13
  // otherwise make test_upgrade will fail
14
- uint8 constant PATCH_VERSION = 1;
14
+ uint8 constant PATCH_VERSION = 2;
15
15
 
16
16
  string constant VERIFIER_NAME = "incoVerifier";