@inco/lightning 0.6.0 → 0.6.4

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 (46) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/manifest.yaml +23 -0
  3. package/package.json +1 -1
  4. package/src/DeployUtils.sol +1 -1
  5. package/src/Errors.sol +1 -1
  6. package/src/Lib.alphanet.sol +25 -4
  7. package/src/Lib.demonet.sol +24 -3
  8. package/src/Lib.devnet.sol +24 -3
  9. package/src/Lib.sol +25 -4
  10. package/src/Lib.template.sol +97 -20
  11. package/src/Lib.testnet.sol +24 -3
  12. package/src/libs/incoLightning_alphanet_v0_297966649.sol +24 -3
  13. package/src/libs/incoLightning_alphanet_v1_725458969.sol +478 -0
  14. package/src/libs/incoLightning_demonet_v0_863421733.sol +24 -3
  15. package/src/libs/incoLightning_devnet_v0_340846814.sol +24 -3
  16. package/src/libs/incoLightning_devnet_v1_904635675.sol +24 -3
  17. package/src/libs/incoLightning_testnet_v0_183408998.sol +24 -3
  18. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +1 -1
  19. package/src/lightning-parts/EncryptedInput.sol +52 -16
  20. package/src/lightning-parts/EncryptedOperations.sol +86 -90
  21. package/src/lightning-parts/TEELifecycle.sol +153 -66
  22. package/src/lightning-parts/TEELifecycle.types.sol +7 -0
  23. package/src/lightning-parts/interfaces/ITEELifecycle.sol +13 -2
  24. package/src/lightning-parts/primitives/HandleGeneration.sol +23 -57
  25. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +3 -34
  26. package/src/lightning-parts/test/HandleMetadata.t.sol +41 -4
  27. package/src/lightning-parts/test/InputsFee.t.sol +14 -21
  28. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +6 -2
  29. package/src/shared/IOwnable.sol +10 -0
  30. package/src/shared/IUUPSUpgradable.sol +10 -0
  31. package/src/shared/JsonUtils.sol +16 -0
  32. package/src/shared/TestUtils.sol +50 -0
  33. package/src/shared/TypeUtils.sol +12 -0
  34. package/src/test/FakeIncoInfra/FakeComputeServer.sol +1 -1
  35. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +36 -34
  36. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +33 -18
  37. package/src/test/FakeIncoInfra/KVStore.sol +1 -1
  38. package/src/test/FakeIncoInfra/MockOpHandler.sol +5 -5
  39. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +1 -1
  40. package/src/test/IncoTest.sol +3 -3
  41. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +73 -20
  42. package/src/test/TestAddTwo.t.sol +1 -1
  43. package/src/test/TestFakeInfra.t.sol +13 -3
  44. package/src/version/IncoLightningConfig.sol +4 -2
  45. package/src/version/Version.sol +4 -0
  46. package/src/version/interfaces/IVersion.sol +1 -0
@@ -4,7 +4,7 @@ pragma solidity ^0.8;
4
4
  import {IncoTest} from "../../test/IncoTest.sol";
5
5
  import {DemoToken} from "@inco/confidential-token-demo/src/DemoToken.sol";
6
6
  import {DecryptionAttestation} from "../DecryptionAttester.types.sol";
7
- import {GWEI} from "@inco/shared/src/TypeUtils.sol";
7
+ import {GWEI} from "../../shared/TypeUtils.sol";
8
8
  import {euint256} from "@inco/lightning/src/Lib.sol"; // import via remapping or compiler fails
9
9
  import {AllowanceProof} from "../AccessControl/AdvancedAccessControl.sol";
10
10
  import {inco} from "../../Lib.sol";
@@ -38,7 +38,11 @@ contract TestDecryptionAttestationInSynchronousFlow is IncoTest {
38
38
  vm.deal(address(token), 100 ether);
39
39
  token.confidentialTransfer(
40
40
  alice,
41
- fakePrepareEuint256Ciphertext(10 * GWEI),
41
+ fakePrepareEuint256Ciphertext(
42
+ 10 * GWEI,
43
+ address(this),
44
+ address(token)
45
+ ),
42
46
  ""
43
47
  );
44
48
  processAllOperations(); // saves Alice's balance
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ // OpenZeppelin doesn't export any interfaces for ownable so we define our own
5
+
6
+ interface IOwnable {
7
+ function owner() external view returns (address);
8
+ function transferOwnership(address newOwner) external;
9
+ event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
10
+ }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ // OpenZeppelin doesn't export any interfaces for uupsUpgradeable so we define our own
5
+
6
+ interface IUUPSUpgradable {
7
+ function proxiableUUID() external view returns (bytes32);
8
+ function UPGRADE_INTERFACE_VERSION() external view returns (string memory);
9
+ function upgradeToAndCall(address newImplementation, bytes memory data) external payable;
10
+ }
@@ -0,0 +1,16 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {Script} from "forge-std/Script.sol";
5
+
6
+ contract JsonUtils is Script {
7
+ function writeAddressToJson(
8
+ address toWrite,
9
+ string memory addressName,
10
+ string memory destFile
11
+ ) public {
12
+ string memory jsonObj = "";
13
+ jsonObj = vm.serializeAddress(jsonObj, addressName, toWrite);
14
+ vm.writeJson(jsonObj, destFile);
15
+ }
16
+ }
@@ -0,0 +1,50 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {Test} from "forge-std/Test.sol";
5
+
6
+ contract TestUtils is Test {
7
+ uint256 internal alicePrivKey;
8
+ address internal immutable alice;
9
+ uint256 internal bobPrivKey;
10
+ address internal immutable bob;
11
+ uint256 internal carolPrivKey;
12
+ address internal immutable carol;
13
+ uint256 internal davePrivKey;
14
+ address internal immutable dave;
15
+ uint256 internal evePrivKey;
16
+ address internal immutable eve;
17
+
18
+ constructor() {
19
+ (alicePrivKey, alice) = getLabeledKeyPair("alice");
20
+ (bobPrivKey, bob) = getLabeledKeyPair("bob");
21
+ (carolPrivKey, carol) = getLabeledKeyPair("carol");
22
+ (davePrivKey, dave) = getLabeledKeyPair("dave");
23
+ (evePrivKey, eve) = getLabeledKeyPair("eve");
24
+ }
25
+
26
+ function getLabeledAddress(
27
+ string memory input
28
+ ) internal returns (address hashGenerated) {
29
+ hashGenerated = address(
30
+ uint160(uint256(keccak256(abi.encodePacked(input))))
31
+ );
32
+ vm.label(hashGenerated, input);
33
+ }
34
+
35
+ function getLabeledKeyPair(
36
+ string memory input
37
+ ) internal returns (uint256 privKey, address accountAddress) {
38
+ privKey = uint256(keccak256(abi.encodePacked(input)));
39
+ accountAddress = vm.addr(privKey);
40
+ vm.label(accountAddress, input);
41
+ }
42
+
43
+ function getSignatureForDigest(
44
+ bytes32 digest,
45
+ uint256 privKey
46
+ ) internal pure returns (bytes memory signature) {
47
+ (uint8 v, bytes32 r, bytes32 s) = vm.sign(privKey, digest);
48
+ signature = bytes.concat(r, s, bytes1(v));
49
+ }
50
+ }
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ function asBool(bytes32 encodedBool) pure returns (bool) {
5
+ return encodedBool != bytes32(0);
6
+ }
7
+
8
+ function asBytes32(bool value) pure returns (bytes32) {
9
+ return value ? bytes32(uint256(1)) : bytes32(uint256(0));
10
+ }
11
+
12
+ uint256 constant GWEI = 1e9;
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8;
3
3
 
4
4
  import {EOps, ETypes} from "../../Types.sol";
5
- import {asBytes32} from "@inco/shared/src/TypeUtils.sol";
5
+ import {asBytes32} from "../../shared/TypeUtils.sol";
6
6
 
7
7
  contract FakeComputeServer {
8
8
  function computeBinaryUintOp(
@@ -27,11 +27,11 @@ contract FakeDecryptionAttester is FakeIncoInfraBase, FakeComputeServer {
27
27
  address requester,
28
28
  HandleWithProof memory handle
29
29
  )
30
- internal
31
- returns (
32
- DecryptionAttestation memory decryption,
33
- bytes memory signature
34
- )
30
+ internal
31
+ returns (
32
+ DecryptionAttestation memory decryption,
33
+ bytes memory signature
34
+ )
35
35
  {
36
36
  checkAccessControl(requester, handle);
37
37
  (decryption, signature) = _getDecryptionAttestation(
@@ -50,11 +50,11 @@ contract FakeDecryptionAttester is FakeIncoInfraBase, FakeComputeServer {
50
50
  HandleWithProof memory rhs,
51
51
  EOps op
52
52
  )
53
- internal
54
- returns (
55
- DecryptionAttestation memory decryption,
56
- bytes memory signature
57
- )
53
+ internal
54
+ returns (
55
+ DecryptionAttestation memory decryption,
56
+ bytes memory signature
57
+ )
58
58
  {
59
59
  checkAccessControl(requester, lhs);
60
60
  checkAccessControl(requester, rhs);
@@ -74,11 +74,11 @@ contract FakeDecryptionAttester is FakeIncoInfraBase, FakeComputeServer {
74
74
  HandleWithProof memory rhs,
75
75
  EOps op
76
76
  )
77
- internal
78
- returns (
79
- DecryptionAttestation memory decryption,
80
- bytes memory signature
81
- )
77
+ internal
78
+ returns (
79
+ DecryptionAttestation memory decryption,
80
+ bytes memory signature
81
+ )
82
82
  {
83
83
  checkAccessControl(requester, rhs);
84
84
  bytes32 lhsHandle = inco.getTrivialEncryptHandle(
@@ -101,11 +101,11 @@ contract FakeDecryptionAttester is FakeIncoInfraBase, FakeComputeServer {
101
101
  uint256 rhs,
102
102
  EOps op
103
103
  )
104
- internal
105
- returns (
106
- DecryptionAttestation memory decryption,
107
- bytes memory signature
108
- )
104
+ internal
105
+ returns (
106
+ DecryptionAttestation memory decryption,
107
+ bytes memory signature
108
+ )
109
109
  {
110
110
  checkAccessControl(requester, lhs);
111
111
  bytes32 rhsHandle = inco.getTrivialEncryptHandle(
@@ -149,12 +149,12 @@ contract FakeDecryptionAttester is FakeIncoInfraBase, FakeComputeServer {
149
149
  bytes32 handle,
150
150
  bytes32 value
151
151
  )
152
- private
153
- view
154
- returns (
155
- DecryptionAttestation memory decryption,
156
- bytes memory signature
157
- )
152
+ private
153
+ view
154
+ returns (
155
+ DecryptionAttestation memory decryption,
156
+ bytes memory signature
157
+ )
158
158
  {
159
159
  decryption = DecryptionAttestation({handle: handle, value: value});
160
160
  signature = signDecryption(decryption);
@@ -176,20 +176,22 @@ contract FakeDecryptionAttester is FakeIncoInfraBase, FakeComputeServer {
176
176
  bytes32 encodedResult,
177
177
  EOps op
178
178
  )
179
- private
180
- view
181
- returns (
182
- DecryptionAttestation memory decryption,
183
- bytes memory signature
184
- )
179
+ private
180
+ view
181
+ returns (
182
+ DecryptionAttestation memory decryption,
183
+ bytes memory signature
184
+ )
185
185
  {
186
186
  ETypes resultType = opToResultType(op);
187
187
  decryption = DecryptionAttestation({
188
188
  handle: inco.getOpResultHandle(
189
189
  op,
190
190
  resultType,
191
- lhsHandle,
192
- rhsHandle
191
+ abi.encodePacked(
192
+ lhsHandle,
193
+ rhsHandle
194
+ )
193
195
  ),
194
196
  value: encodedResult
195
197
  });
@@ -3,11 +3,12 @@ pragma solidity ^0.8;
3
3
 
4
4
  import {ebool, euint256, ETypes} from "../../Types.sol";
5
5
  import {inco} from "../../Lib.sol";
6
- import {TestUtils} from "@inco/shared/src/TestUtils.sol";
6
+ import {TestUtils} from "../../shared/TestUtils.sol";
7
7
  import {KVStore} from "./KVStore.sol";
8
+ import {HandleGeneration} from "../../lightning-parts/primitives/HandleGeneration.sol";
8
9
 
9
10
  /// @notice simulates what inco does offchain but over plaintexts
10
- contract FakeIncoInfraBase is TestUtils, KVStore {
11
+ contract FakeIncoInfraBase is TestUtils, KVStore, HandleGeneration {
11
12
  error UnsupportedTypeInput(ETypes inputType);
12
13
 
13
14
  address immutable teePubkeyAddress;
@@ -17,22 +18,31 @@ contract FakeIncoInfraBase is TestUtils, KVStore {
17
18
  (teePrivKey, teePubkeyAddress) = getLabeledKeyPair("tee");
18
19
  }
19
20
 
21
+ function getCiphertextInput(
22
+ bytes32 word,
23
+ address user,
24
+ address contractAddress,
25
+ ETypes inputType
26
+ ) public view returns (bytes memory input) {
27
+ // We need a single word here to get correct encoding
28
+ bytes memory ciphertext = abi.encode(word);
29
+ bytes32 handle = getInputHandle(ciphertext, address(inco), user, contractAddress, inputType);
30
+ input = abi.encode(handle, ciphertext);
31
+ }
32
+
20
33
  function fakePrepareEuint256Ciphertext(
21
- uint256 value
22
- ) internal pure returns (bytes memory ciphertext) {
23
- ciphertext = abi.encode(value);
34
+ uint256 value,
35
+ address userAddress,
36
+ address contractAddress
37
+ ) internal view returns (bytes memory ciphertext) {
38
+ ciphertext = getCiphertextInput(bytes32(value), userAddress, contractAddress, ETypes.Uint256);
24
39
  }
25
40
 
41
+
26
42
  function fakeDecryptEuint256Ciphertext(
27
43
  bytes memory ciphertext
28
44
  ) internal pure returns (uint256 value) {
29
- value = abi.decode(ciphertext, (uint256));
30
- }
31
-
32
- function fakePrepareEuint160Ciphertext(
33
- uint160 value
34
- ) internal pure returns (bytes memory ciphertext) {
35
- ciphertext = abi.encode(value);
45
+ (value) = abi.decode(ciphertext, (uint256));
36
46
  }
37
47
 
38
48
  function fakeDecryptEuint160Ciphertext(
@@ -42,15 +52,20 @@ contract FakeIncoInfraBase is TestUtils, KVStore {
42
52
  }
43
53
 
44
54
  function fakePrepareEboolCiphertext(
45
- bool value
46
- ) internal pure returns (bytes memory ciphertext) {
47
- ciphertext = abi.encode(value);
55
+ bool value,
56
+ address userAddress,
57
+ address contractAddress
58
+ ) internal view returns (bytes memory ciphertext) {
59
+ bytes32 b = bytes32(uint256(value ? 1 : 0));
60
+ ciphertext = getCiphertextInput(b, userAddress, contractAddress, ETypes.Bool);
48
61
  }
49
62
 
50
63
  function fakePrepareEaddressCiphertext(
51
- address value
52
- ) internal pure returns (bytes memory ciphertext) {
53
- ciphertext = abi.encode(value);
64
+ address value,
65
+ address userAddress,
66
+ address contractAddress
67
+ ) internal view returns (bytes memory ciphertext) {
68
+ ciphertext = getCiphertextInput(bytes32(uint256(uint160(value))), userAddress, contractAddress, ETypes.AddressOrUint160OrBytes20);
54
69
  }
55
70
 
56
71
  function fakeDecryptEaddressCiphertext(
@@ -3,7 +3,7 @@ pragma solidity ^0.8;
3
3
 
4
4
  import {HandleMetadata} from "../../lightning-parts/primitives/HandleMetadata.sol";
5
5
  import {ETypes, euint256, ebool, eaddress} from "../../Types.sol";
6
- import {asBool} from "@inco/shared/src/TypeUtils.sol";
6
+ import {asBool} from "../..//shared/TypeUtils.sol";
7
7
 
8
8
  /// @notice key-value store, knows the value behind each handle
9
9
  contract KVStore is HandleMetadata {
@@ -6,7 +6,7 @@ import {inco} from "../../Lib.sol";
6
6
  import {ebool, euint256, ETypes, EOps} from "../../Types.sol";
7
7
  import {FakeComputeServer} from "./FakeComputeServer.sol";
8
8
  import {FakeIncoInfraBase} from "./FakeIncoInfraBase.sol";
9
- import {asBytes32} from "@inco/shared/src/TypeUtils.sol";
9
+ import {asBytes32} from "../../shared/TypeUtils.sol";
10
10
  import {getOpForSelector} from "./getOpForSelector.sol";
11
11
 
12
12
  contract MockOpHandler is FakeIncoInfraBase, FakeComputeServer {
@@ -65,19 +65,19 @@ contract MockOpHandler is FakeIncoInfraBase, FakeComputeServer {
65
65
  } else if (op == EOps.NewInput) {
66
66
  bytes32 result = log.topics[1];
67
67
  // contractAddress and user topics are ignored
68
- (ETypes inputType, bytes memory ciphertext, ) = abi.decode(
68
+ (bytes memory ciphertext, ) = abi.decode(
69
69
  log.data,
70
- (ETypes, bytes, uint256)
70
+ (bytes, uint256)
71
71
  );
72
- handleEInput(result, inputType, ciphertext);
72
+ handleEInput(result, ciphertext);
73
73
  }
74
74
  }
75
75
 
76
76
  function handleEInput(
77
77
  bytes32 result,
78
- ETypes inputType,
79
78
  bytes memory ciphertext
80
79
  ) private {
80
+ ETypes inputType = typeOf(result);
81
81
  if (inputType == ETypes.Uint256) {
82
82
  set(result, bytes32(fakeDecryptEuint256Ciphertext(ciphertext)));
83
83
  } else if (inputType == ETypes.Bool) {
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: No License
2
2
  pragma solidity ^0.8;
3
3
 
4
- import {TestUtils} from "@inco/shared/src/TestUtils.sol";
4
+ import {TestUtils} from "../../shared/TestUtils.sol";
5
5
  import {
6
6
  HEADER_LENGTH,
7
7
  MINIMUM_QUOTE_LENGTH,
@@ -9,7 +9,7 @@ import {deployedBy} from "../Lib.sol";
9
9
  import {FakeDecryptionAttester} from "./FakeIncoInfra/FakeDecryptionAttester.sol";
10
10
  import {console} from "forge-std/console.sol";
11
11
  import {FakeQuoteVerifier} from "./FakeIncoInfra/FakeQuoteVerifier.sol";
12
- import {IOwnable} from "@inco/shared/src/IOwnable.sol";
12
+ import {IOwnable} from "../../src/shared/IOwnable.sol";
13
13
 
14
14
  contract IncoTest is MockOpHandler, DeployUtils, FakeDecryptionAttester {
15
15
  address immutable owner;
@@ -32,8 +32,8 @@ contract IncoTest is MockOpHandler, DeployUtils, FakeDecryptionAttester {
32
32
  (IIncoLightning proxy, ) = deployIncoLightningUsingConfig({
33
33
  deployer: testDeployer,
34
34
  // The highest precedent deployment
35
- // We select the pepper that will be used that will be generated in the lib.sol (usually "testnet"), but currently "devnet" has higher major version
36
- pepper: "devnet",
35
+ // We select the pepper that will be used that will be generated in the lib.sol (usually "testnet"), but currently "alphanet" has higher major version
36
+ pepper: "alphanet",
37
37
  quoteVerifier: new FakeQuoteVerifier()
38
38
  });
39
39
  IOwnable(address(proxy)).transferOwnership(owner);
@@ -2,14 +2,22 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  import {TEELifecycle} from "../../lightning-parts/TEELifecycle.sol";
5
- import {BootstrapResult} from "../../lightning-parts/TEELifecycle.types.sol";
5
+ import {BootstrapResult, AddNodeResult} from "../../lightning-parts/TEELifecycle.types.sol";
6
6
  import {MockRemoteAttestation} from "../FakeIncoInfra/MockRemoteAttestation.sol";
7
7
  import {FakeQuoteVerifier} from "../FakeIncoInfra/FakeQuoteVerifier.sol";
8
8
  import {Test} from "forge-std/Test.sol";
9
9
 
10
10
  contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
11
+ // Constants for testing
12
+ bytes testNetworkPubkey = hex"04ff5c6dd72ad7583288b84ee2598e081fe0bc6ef543c342e925a5dfcff9afb2444d25454d7d5dcfadc9ed99477c245efa93caf58d7f58143300d81cc948e7bdf5";
13
+ // See DEFAULT_MRTD in attestation/src/remote_attestation.rs
14
+ bytes testMrtd = hex"010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
15
+ // See DEFAULT_MR_AGGREGATED in attestation/src/remote_attestation.rs to
16
+ // see the calculation of the default value.
17
+ bytes32 testMrAggregated = hex"c3a67bac251d4946d7b17481d39631676042fe3afab06e70c22105ad8383c19f";
18
+
11
19
  function setUp() public {
12
- quoteVerifier = new FakeQuoteVerifier();
20
+ getTEELifecycleStorage().quoteVerifier = new FakeQuoteVerifier();
13
21
  }
14
22
 
15
23
  function testSuccessfulBootstrap() public {
@@ -89,18 +97,18 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
89
97
  vm.stopPrank();
90
98
  }
91
99
 
92
- function testBootstrapNotCompleteNewCoval() public {
100
+ function testAddNodeBootstrapNotComplete() public {
93
101
  bytes
94
- memory mrAggregated = hex"2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525";
102
+ memory mrtd = hex"2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525";
95
103
  (, address newCoval) = getLabeledKeyPair("newCoval");
96
- bytes memory quote = createQuote(mrAggregated, newCoval);
104
+ bytes memory quote = createQuote(mrtd, newCoval);
97
105
  vm.startPrank(this.owner());
98
106
  vm.expectRevert(TEELifecycle.BootstrapNotComplete.selector);
99
- this.addNewCovalidator(quote);
107
+ this.verifyAddNodeResult(testMrAggregated, AddNodeResult({network_pubkey: hex"00"}), quote, hex"");
100
108
  vm.stopPrank();
101
109
  }
102
110
 
103
- function testInvalidMrtdNewCoval() public {
111
+ function testAddNodeInvalidMrtd() public {
104
112
  (
105
113
  BootstrapResult memory bootstrapResult,
106
114
  ,
@@ -115,10 +123,52 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
115
123
  bytes
116
124
  memory badMrtd = hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
117
125
  (, address newCoval) = getLabeledKeyPair("newCoval");
118
- bytes memory quoteNew = createQuote(badMrtd, newCoval);
126
+ bytes memory badQuote = createQuote(badMrtd, newCoval);
127
+ vm.expectRevert(TEELifecycle.InvalidReportMrAggregated.selector);
128
+ this.verifyAddNodeResult(mrAggregated, AddNodeResult({network_pubkey: testNetworkPubkey}), badQuote, signature);
129
+ vm.stopPrank();
130
+ }
131
+
132
+ function testAddNodeInvalidNetworkPubkey() public {
133
+ (
134
+ BootstrapResult memory bootstrapResult,
135
+ ,
136
+ ,
137
+ bytes memory quote,
138
+ bytes memory signature,
139
+ bytes32 mrAggregated
140
+ ) = successfulBootstrapResult();
141
+ vm.startPrank(this.owner());
142
+ this.approveNewTEEVersion(mrAggregated);
143
+ this.verifyBootstrapResult(bootstrapResult, quote, signature);
144
+ vm.expectRevert(TEELifecycle.InvalidNetworkPubkey.selector);
145
+ this.verifyAddNodeResult(testMrAggregated, AddNodeResult({network_pubkey: hex"00"}), quote, signature);
146
+ vm.stopPrank();
147
+ }
148
+
149
+ function testAddNodeInvalidSignature() public {
150
+ (
151
+ BootstrapResult memory bootstrapResult,
152
+ ,
153
+ ,
154
+ bytes memory quote,
155
+ bytes memory signature,
156
+ bytes32 mrAggregated
157
+ ) = successfulBootstrapResult();
158
+ vm.startPrank(this.owner());
159
+ this.approveNewTEEVersion(mrAggregated);
160
+ this.verifyBootstrapResult(bootstrapResult, quote, signature);
119
161
 
120
- vm.expectRevert(TEELifecycle.TEEVersionNotFound.selector);
121
- this.addNewCovalidator(quoteNew);
162
+ (uint256 maliciousNewNodePrivkey,) = getLabeledKeyPair(
163
+ "maliciousNewNode"
164
+ );
165
+ bytes memory badSignature = signAddNodeResult(
166
+ AddNodeResult({network_pubkey: testNetworkPubkey}),
167
+ maliciousNewNodePrivkey
168
+ );
169
+
170
+ vm.expectRevert(TEELifecycle.InvalidEIP712Signature.selector);
171
+ this.verifyAddNodeResult(testMrAggregated, AddNodeResult({network_pubkey: testNetworkPubkey}), quote, badSignature);
122
172
  vm.stopPrank();
123
173
  }
124
174
 
@@ -137,16 +187,10 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
137
187
  (bootstrapPartyPrivkey, bootstrapPartyAddress) = getLabeledKeyPair(
138
188
  "bootstrapParty"
139
189
  );
140
- bytes
141
- memory eciesPubkey = hex"04ff5c6dd72ad7583288b84ee2598e081fe0bc6ef543c342e925a5dfcff9afb2444d25454d7d5dcfadc9ed99477c245efa93caf58d7f58143300d81cc948e7bdf5";
142
- // See DEFAULT_MRTD in attestation/src/remote_attestation.rs
143
- bytes memory mrtd = hex"010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
144
- // See DEFAULT_MR_AGGREGATED in attestation/src/remote_attestation.rs to
145
- // see the calculation of the default value.
146
- mrAggregated = hex"c3a67bac251d4946d7b17481d39631676042fe3afab06e70c22105ad8383c19f";
147
- bootstrapResult = BootstrapResult({ecies_pubkey: eciesPubkey});
148
-
149
- quote = createQuote(mrtd, bootstrapPartyAddress);
190
+ mrAggregated = testMrAggregated;
191
+ bootstrapResult = BootstrapResult({ecies_pubkey: testNetworkPubkey});
192
+
193
+ quote = createQuote(testMrtd, bootstrapPartyAddress);
150
194
  signature = signBootstrapResult(bootstrapResult, bootstrapPartyPrivkey);
151
195
  }
152
196
 
@@ -158,4 +202,13 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
158
202
  bytes32 bootstrapResultDigest = bootstrapResultDigest(bootstrapResult);
159
203
  return getSignatureForDigest(bootstrapResultDigest, privateKey);
160
204
  }
205
+
206
+ // Helper function to sign the add node result
207
+ function signAddNodeResult(
208
+ AddNodeResult memory addNodeResult,
209
+ uint256 privateKey
210
+ ) internal view returns (bytes memory) {
211
+ bytes32 addNodeResultDigest = addNodeResultDigest(addNodeResult);
212
+ return getSignatureForDigest(addNodeResultDigest, privateKey);
213
+ }
161
214
  }
@@ -26,7 +26,7 @@ contract TestAddTwo is IncoTest {
26
26
 
27
27
  function testAddTwoEoaAndPublicReveal() public {
28
28
  (euint256 result, euint256 revealedResult) = addTwo.addTwoEOA(
29
- fakePrepareEuint256Ciphertext(3)
29
+ fakePrepareEuint256Ciphertext(3, address(this), address(addTwo))
30
30
  );
31
31
  processAllOperations();
32
32
  assertEq(getUint256Value(result), 5);
@@ -11,7 +11,7 @@ import {
11
11
  MINIMUM_QUOTE_LENGTH
12
12
  } from "../interfaces/automata-interfaces/Types.sol";
13
13
 
14
- contract TakesEInput {
14
+ contract TakesEInput is IncoTest {
15
15
  using e for bytes;
16
16
  using e for euint256;
17
17
 
@@ -271,8 +271,18 @@ contract TestFakeInfra is IncoTest, MockRemoteAttestation {
271
271
  function testEInput() public {
272
272
  TakesEInput inputContract = new TakesEInput();
273
273
  vm.deal(address(inputContract), 1 ether);
274
- inputContract.setA(fakePrepareEuint256Ciphertext(12));
275
- inputContract.setB(fakePrepareEboolCiphertext(true));
274
+ address self = address(this);
275
+ bytes memory ciphertext = fakePrepareEuint256Ciphertext(
276
+ 12,
277
+ self,
278
+ address(inputContract)
279
+ );
280
+ inputContract.setA(ciphertext);
281
+ inputContract.setB(
282
+ fakePrepareEboolCiphertext(true,
283
+ self,
284
+ address(inputContract)
285
+ ));
276
286
  processAllOperations();
277
287
  assertEq(getUint256Value(inputContract.a()), 12);
278
288
  assertEq(getBoolValue(inputContract.b()), true);
@@ -9,8 +9,10 @@ pragma solidity ^0.8;
9
9
  string constant CONTRACT_NAME = "incoLightning";
10
10
  uint8 constant MAJOR_VERSION = 1;
11
11
  uint8 constant MINOR_VERSION = 0;
12
- // whenever a new major version is deployed, we need to pump this up
12
+ // whenever a new version is deployed, we need to pump this up
13
13
  // otherwise make test_upgrade will fail
14
- uint8 constant PATCH_VERSION = 2;
14
+ // consequently, when we do a patch release, we don't need to pump it as it's already pumped
15
+ // when the previous release was done
16
+ uint8 constant PATCH_VERSION = 3;
15
17
 
16
18
  string constant VERIFIER_NAME = "incoVerifier";
@@ -71,4 +71,8 @@ contract Version is IVersion {
71
71
  function getName() public view virtual returns (string memory) {
72
72
  return name.toString();
73
73
  }
74
+
75
+ function getMajorVersion() public view virtual returns (string memory) {
76
+ return Strings.toString(majorVersion);
77
+ }
74
78
  }
@@ -5,4 +5,5 @@ interface IVersion {
5
5
  function getVersionedName() external view returns (string memory);
6
6
  function getVersion() external view returns (string memory);
7
7
  function getName() external view returns (string memory);
8
+ function getMajorVersion() external view returns (string memory);
8
9
  }