@inco/lightning 0.6.8 → 0.7.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 (87) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +29 -2
  3. package/manifest.yaml +35 -42
  4. package/package.json +5 -2
  5. package/src/CreateXHelper.sol +3 -1
  6. package/src/DeployUtils.sol +36 -71
  7. package/src/Errors.sol +1 -1
  8. package/src/IIncoLightning.sol +2 -0
  9. package/src/IncoLightning.sol +5 -17
  10. package/src/IncoVerifier.sol +12 -18
  11. package/src/Lib.alphanet.sol +1 -1
  12. package/src/Lib.sol +1 -1
  13. package/src/Lib.template.sol +35 -153
  14. package/src/Types.sol +231 -97
  15. package/src/interfaces/IIncoLightning.sol +2 -0
  16. package/src/interfaces/IIncoVerifier.sol +6 -12
  17. package/src/interfaces/automata-interfaces/BELE.sol +2 -0
  18. package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +9 -11
  19. package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +3 -3
  20. package/src/interfaces/automata-interfaces/IPCCSRouter.sol +13 -47
  21. package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +2 -0
  22. package/src/interfaces/automata-interfaces/IPcsDao.sol +6 -11
  23. package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +4 -7
  24. package/src/interfaces/automata-interfaces/Types.sol +7 -6
  25. package/src/libs/incoLightning_alphanet_v2_976644394.sol +478 -0
  26. package/src/libs/incoLightning_devnet_v1_887305889.sol +5 -3
  27. package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
  28. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +39 -72
  29. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +31 -62
  30. package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +8 -15
  31. package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +5 -12
  32. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +44 -84
  33. package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +2 -0
  34. package/src/lightning-parts/DecryptionAttester.sol +14 -28
  35. package/src/lightning-parts/EncryptedInput.sol +23 -52
  36. package/src/lightning-parts/EncryptedOperations.sol +96 -438
  37. package/src/lightning-parts/Fee.sol +3 -1
  38. package/src/lightning-parts/TEELifecycle.sol +94 -223
  39. package/src/lightning-parts/TEELifecycle.types.sol +4 -3
  40. package/src/lightning-parts/TrivialEncryption.sol +6 -20
  41. package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -2
  42. package/src/lightning-parts/interfaces/IEncryptedInput.sol +5 -12
  43. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +17 -61
  44. package/src/lightning-parts/interfaces/ITEELifecycle.sol +7 -11
  45. package/src/lightning-parts/interfaces/ITrivialEncryption.sol +2 -0
  46. package/src/lightning-parts/primitives/EventCounter.sol +7 -8
  47. package/src/lightning-parts/primitives/HandleGeneration.sol +20 -32
  48. package/src/lightning-parts/primitives/HandleMetadata.sol +7 -17
  49. package/src/lightning-parts/primitives/LightningAddressGetter.sol +3 -0
  50. package/src/lightning-parts/primitives/SignatureVerifier.sol +91 -27
  51. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +3 -0
  52. package/src/lightning-parts/primitives/interfaces/IEventCounter.sol +2 -0
  53. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +10 -2
  54. package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +4 -2
  55. package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +2 -0
  56. package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +838 -0
  57. package/src/lightning-parts/test/Fee.t.sol +6 -6
  58. package/src/lightning-parts/test/HandleMetadata.t.sol +21 -76
  59. package/src/lightning-parts/test/InputsFee.t.sol +7 -28
  60. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +16 -48
  61. package/src/pasted-dependencies/CreateX.sol +154 -455
  62. package/src/pasted-dependencies/ICreateX.sol +55 -102
  63. package/src/periphery/SessionVerifier.sol +10 -8
  64. package/src/shared/IOwnable.sol +3 -0
  65. package/src/shared/IUUPSUpgradable.sol +5 -1
  66. package/src/shared/JsonUtils.sol +3 -5
  67. package/src/shared/TestUtils.sol +15 -13
  68. package/src/test/AddTwo.sol +9 -7
  69. package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
  70. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -119
  71. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +31 -48
  72. package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +4 -7
  73. package/src/test/FakeIncoInfra/KVStore.sol +2 -0
  74. package/src/test/FakeIncoInfra/MockOpHandler.sol +9 -31
  75. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +50 -21
  76. package/src/test/IncoTest.sol +22 -9
  77. package/src/test/OpsTest.sol +438 -0
  78. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +57 -104
  79. package/src/test/TestAddTwo.t.sol +4 -3
  80. package/src/test/TestDeploy.t.sol +5 -6
  81. package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -9
  82. package/src/test/TestFakeInfra.t.sol +15 -38
  83. package/src/test/TestUpgrade.t.sol +40 -135
  84. package/src/test/TestVersion.t.sol +6 -5
  85. package/src/version/IncoLightningConfig.sol +2 -2
  86. package/src/version/Version.sol +46 -48
  87. package/src/version/interfaces/IVersion.sol +6 -0
@@ -7,6 +7,7 @@ pragma solidity ^0.8.4;
7
7
  * @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)
8
8
  */
9
9
  interface ICreateX {
10
+
10
11
  /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
11
12
  /* TYPES */
12
13
  /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
@@ -22,10 +23,7 @@ interface ICreateX {
22
23
 
23
24
  event ContractCreation(address indexed newContract, bytes32 indexed salt);
24
25
  event ContractCreation(address indexed newContract);
25
- event Create3ProxyContractCreation(
26
- address indexed newContract,
27
- bytes32 indexed salt
28
- );
26
+ event Create3ProxyContractCreation(address indexed newContract, bytes32 indexed salt);
29
27
 
30
28
  /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
31
29
  /* CUSTOM ERRORS */
@@ -41,49 +39,31 @@ interface ICreateX {
41
39
  /* CREATE */
42
40
  /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
43
41
 
44
- function deployCreate(
45
- bytes memory initCode
46
- ) external payable returns (address newContract);
42
+ function deployCreate(bytes memory initCode) external payable returns (address newContract);
47
43
 
48
- function deployCreateAndInit(
49
- bytes memory initCode,
50
- bytes memory data,
51
- Values memory values,
52
- address refundAddress
53
- ) external payable returns (address newContract);
44
+ function deployCreateAndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
45
+ external
46
+ payable
47
+ returns (address newContract);
54
48
 
55
- function deployCreateAndInit(
56
- bytes memory initCode,
57
- bytes memory data,
58
- Values memory values
59
- ) external payable returns (address newContract);
49
+ function deployCreateAndInit(bytes memory initCode, bytes memory data, Values memory values)
50
+ external
51
+ payable
52
+ returns (address newContract);
60
53
 
61
- function deployCreateClone(
62
- address implementation,
63
- bytes memory data
64
- ) external payable returns (address proxy);
54
+ function deployCreateClone(address implementation, bytes memory data) external payable returns (address proxy);
65
55
 
66
- function computeCreateAddress(
67
- address deployer,
68
- uint256 nonce
69
- ) external view returns (address computedAddress);
56
+ function computeCreateAddress(address deployer, uint256 nonce) external view returns (address computedAddress);
70
57
 
71
- function computeCreateAddress(
72
- uint256 nonce
73
- ) external view returns (address computedAddress);
58
+ function computeCreateAddress(uint256 nonce) external view returns (address computedAddress);
74
59
 
75
60
  /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
76
61
  /* CREATE2 */
77
62
  /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
78
63
 
79
- function deployCreate2(
80
- bytes32 salt,
81
- bytes memory initCode
82
- ) external payable returns (address newContract);
64
+ function deployCreate2(bytes32 salt, bytes memory initCode) external payable returns (address newContract);
83
65
 
84
- function deployCreate2(
85
- bytes memory initCode
86
- ) external payable returns (address newContract);
66
+ function deployCreate2(bytes memory initCode) external payable returns (address newContract);
87
67
 
88
68
  function deployCreate2AndInit(
89
69
  bytes32 salt,
@@ -93,60 +73,42 @@ interface ICreateX {
93
73
  address refundAddress
94
74
  ) external payable returns (address newContract);
95
75
 
96
- function deployCreate2AndInit(
97
- bytes32 salt,
98
- bytes memory initCode,
99
- bytes memory data,
100
- Values memory values
101
- ) external payable returns (address newContract);
76
+ function deployCreate2AndInit(bytes32 salt, bytes memory initCode, bytes memory data, Values memory values)
77
+ external
78
+ payable
79
+ returns (address newContract);
102
80
 
103
- function deployCreate2AndInit(
104
- bytes memory initCode,
105
- bytes memory data,
106
- Values memory values,
107
- address refundAddress
108
- ) external payable returns (address newContract);
81
+ function deployCreate2AndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
82
+ external
83
+ payable
84
+ returns (address newContract);
109
85
 
110
- function deployCreate2AndInit(
111
- bytes memory initCode,
112
- bytes memory data,
113
- Values memory values
114
- ) external payable returns (address newContract);
86
+ function deployCreate2AndInit(bytes memory initCode, bytes memory data, Values memory values)
87
+ external
88
+ payable
89
+ returns (address newContract);
115
90
 
116
- function deployCreate2Clone(
117
- bytes32 salt,
118
- address implementation,
119
- bytes memory data
120
- ) external payable returns (address proxy);
91
+ function deployCreate2Clone(bytes32 salt, address implementation, bytes memory data)
92
+ external
93
+ payable
94
+ returns (address proxy);
121
95
 
122
- function deployCreate2Clone(
123
- address implementation,
124
- bytes memory data
125
- ) external payable returns (address proxy);
96
+ function deployCreate2Clone(address implementation, bytes memory data) external payable returns (address proxy);
126
97
 
127
- function computeCreate2Address(
128
- bytes32 salt,
129
- bytes32 initCodeHash,
130
- address deployer
131
- ) external pure returns (address computedAddress);
98
+ function computeCreate2Address(bytes32 salt, bytes32 initCodeHash, address deployer)
99
+ external
100
+ pure
101
+ returns (address computedAddress);
132
102
 
133
- function computeCreate2Address(
134
- bytes32 salt,
135
- bytes32 initCodeHash
136
- ) external view returns (address computedAddress);
103
+ function computeCreate2Address(bytes32 salt, bytes32 initCodeHash) external view returns (address computedAddress);
137
104
 
138
105
  /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
139
106
  /* CREATE3 */
140
107
  /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
141
108
 
142
- function deployCreate3(
143
- bytes32 salt,
144
- bytes memory initCode
145
- ) external payable returns (address newContract);
109
+ function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);
146
110
 
147
- function deployCreate3(
148
- bytes memory initCode
149
- ) external payable returns (address newContract);
111
+ function deployCreate3(bytes memory initCode) external payable returns (address newContract);
150
112
 
151
113
  function deployCreate3AndInit(
152
114
  bytes32 salt,
@@ -156,32 +118,23 @@ interface ICreateX {
156
118
  address refundAddress
157
119
  ) external payable returns (address newContract);
158
120
 
159
- function deployCreate3AndInit(
160
- bytes32 salt,
161
- bytes memory initCode,
162
- bytes memory data,
163
- Values memory values
164
- ) external payable returns (address newContract);
121
+ function deployCreate3AndInit(bytes32 salt, bytes memory initCode, bytes memory data, Values memory values)
122
+ external
123
+ payable
124
+ returns (address newContract);
165
125
 
166
- function deployCreate3AndInit(
167
- bytes memory initCode,
168
- bytes memory data,
169
- Values memory values,
170
- address refundAddress
171
- ) external payable returns (address newContract);
126
+ function deployCreate3AndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
127
+ external
128
+ payable
129
+ returns (address newContract);
172
130
 
173
- function deployCreate3AndInit(
174
- bytes memory initCode,
175
- bytes memory data,
176
- Values memory values
177
- ) external payable returns (address newContract);
131
+ function deployCreate3AndInit(bytes memory initCode, bytes memory data, Values memory values)
132
+ external
133
+ payable
134
+ returns (address newContract);
178
135
 
179
- function computeCreate3Address(
180
- bytes32 salt,
181
- address deployer
182
- ) external pure returns (address computedAddress);
136
+ function computeCreate3Address(bytes32 salt, address deployer) external pure returns (address computedAddress);
137
+
138
+ function computeCreate3Address(bytes32 salt) external view returns (address computedAddress);
183
139
 
184
- function computeCreate3Address(
185
- bytes32 salt
186
- ) external view returns (address computedAddress);
187
140
  }
@@ -23,9 +23,8 @@ struct Session {
23
23
  /// the sharer to one decrypter for a limited time.
24
24
  /// @dev define the selector of canUseSession in the voucher to use this verifier
25
25
  contract SessionVerifier is UUPSUpgradeable, OwnableUpgradeable, Version {
26
- constructor(
27
- bytes32 salt
28
- )
26
+
27
+ constructor(bytes32 salt)
29
28
  Version(
30
29
  SESSION_VERIFIER_MAJOR_VERSION,
31
30
  SESSION_VERIFIER_MINOR_VERSION,
@@ -37,15 +36,17 @@ contract SessionVerifier is UUPSUpgradeable, OwnableUpgradeable, Version {
37
36
 
38
37
  // todo add text mention of what is being signed
39
38
  function canUseSession(
40
- bytes32 /* handle */,
39
+ bytes32, /* handle */
41
40
  address account,
42
41
  bytes memory sharerArgData,
43
42
  bytes memory /* requesterArgData */
44
- ) external view returns (bytes32) {
43
+ )
44
+ external
45
+ view
46
+ returns (bytes32)
47
+ {
45
48
  Session memory session = abi.decode(sharerArgData, (Session));
46
- if (
47
- session.expiresAt >= block.timestamp && session.decrypter == account
48
- ) {
49
+ if (session.expiresAt >= block.timestamp && session.decrypter == account) {
49
50
  return ALLOWANCE_GRANTED_MAGIC_VALUE;
50
51
  }
51
52
  return bytes32(0);
@@ -60,4 +61,5 @@ contract SessionVerifier is UUPSUpgradeable, OwnableUpgradeable, Version {
60
61
  }
61
62
 
62
63
  fallback() external {} // must be included for createX deploy
64
+
63
65
  }
@@ -4,7 +4,10 @@ pragma solidity ^0.8.0;
4
4
  // OpenZeppelin doesn't export any interfaces for ownable so we define our own
5
5
 
6
6
  interface IOwnable {
7
+
7
8
  function owner() external view returns (address);
8
9
  function transferOwnership(address newOwner) external;
10
+
9
11
  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
12
+
10
13
  }
@@ -4,7 +4,11 @@ pragma solidity ^0.8.0;
4
4
  // OpenZeppelin doesn't export any interfaces for uupsUpgradeable so we define our own
5
5
 
6
6
  interface IUUPSUpgradable {
7
+
8
+ // forge-lint: disable-next-line(mixed-case-function)
7
9
  function proxiableUUID() external view returns (bytes32);
10
+ // forge-lint: disable-next-line(mixed-case-function)
8
11
  function UPGRADE_INTERFACE_VERSION() external view returns (string memory);
9
12
  function upgradeToAndCall(address newImplementation, bytes memory data) external payable;
10
- }
13
+
14
+ }
@@ -4,13 +4,11 @@ pragma solidity ^0.8;
4
4
  import {Script} from "forge-std/Script.sol";
5
5
 
6
6
  contract JsonUtils is Script {
7
- function writeAddressToJson(
8
- address toWrite,
9
- string memory addressName,
10
- string memory destFile
11
- ) public {
7
+
8
+ function writeAddressToJson(address toWrite, string memory addressName, string memory destFile) public {
12
9
  string memory jsonObj = "";
13
10
  jsonObj = vm.serializeAddress(jsonObj, addressName, toWrite);
14
11
  vm.writeJson(jsonObj, destFile);
15
12
  }
13
+
16
14
  }
@@ -4,6 +4,11 @@ pragma solidity ^0.8;
4
4
  import {Test} from "forge-std/Test.sol";
5
5
 
6
6
  contract TestUtils is Test {
7
+
8
+ address private constant ANVIL_ZEROTH_ADDRESS = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
9
+ uint256 private constant ANVIL_ZEROTH_PRIVATE_KEY =
10
+ 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;
11
+
7
12
  uint256 internal alicePrivKey;
8
13
  address internal immutable alice;
9
14
  uint256 internal bobPrivKey;
@@ -15,36 +20,33 @@ contract TestUtils is Test {
15
20
  uint256 internal evePrivKey;
16
21
  address internal immutable eve;
17
22
 
23
+ // it is convenient for e2e tests to use these well-known addresses for the TEE
24
+ address internal teeEOA = ANVIL_ZEROTH_ADDRESS;
25
+ uint256 internal teePrivKey = ANVIL_ZEROTH_PRIVATE_KEY;
26
+
18
27
  constructor() {
19
28
  (alicePrivKey, alice) = getLabeledKeyPair("alice");
20
29
  (bobPrivKey, bob) = getLabeledKeyPair("bob");
21
30
  (carolPrivKey, carol) = getLabeledKeyPair("carol");
22
31
  (davePrivKey, dave) = getLabeledKeyPair("dave");
23
32
  (evePrivKey, eve) = getLabeledKeyPair("eve");
33
+ vm.label(teeEOA, "tee");
24
34
  }
25
35
 
26
- function getLabeledAddress(
27
- string memory input
28
- ) internal returns (address hashGenerated) {
29
- hashGenerated = address(
30
- uint160(uint256(keccak256(abi.encodePacked(input))))
31
- );
36
+ function getLabeledAddress(string memory input) internal returns (address hashGenerated) {
37
+ hashGenerated = address(uint160(uint256(keccak256(abi.encodePacked(input)))));
32
38
  vm.label(hashGenerated, input);
33
39
  }
34
40
 
35
- function getLabeledKeyPair(
36
- string memory input
37
- ) internal returns (uint256 privKey, address accountAddress) {
41
+ function getLabeledKeyPair(string memory input) internal returns (uint256 privKey, address accountAddress) {
38
42
  privKey = uint256(keccak256(abi.encodePacked(input)));
39
43
  accountAddress = vm.addr(privKey);
40
44
  vm.label(accountAddress, input);
41
45
  }
42
46
 
43
- function getSignatureForDigest(
44
- bytes32 digest,
45
- uint256 privKey
46
- ) internal pure returns (bytes memory signature) {
47
+ function getSignatureForDigest(bytes32 digest, uint256 privKey) internal pure returns (bytes memory signature) {
47
48
  (uint8 v, bytes32 r, bytes32 s) = vm.sign(privKey, digest);
48
49
  signature = bytes.concat(r, s, bytes1(v));
49
50
  }
51
+
50
52
  }
@@ -8,6 +8,7 @@ import {Fee} from "../lightning-parts/Fee.sol";
8
8
  // To implement such a contract, we would normally import e form Lib.sol. For test purposes, we take inco as
9
9
  // a constructor argument instead, so we can test it from other deployment addresses.
10
10
  contract AddTwo is Fee {
11
+
11
12
  IncoLightning inco;
12
13
 
13
14
  constructor(IncoLightning _inco) {
@@ -28,13 +29,13 @@ contract AddTwo is Fee {
28
29
  return inco.eAdd(a, inco.eAdd(one, one));
29
30
  }
30
31
 
31
- function addTwoEOA(
32
- bytes memory uint256EInput
33
- ) external payable refundUnspent returns (euint256 result, euint256 resultRevealed) {
34
- euint256 value = inco.newEuint256{value: getFee()}(
35
- uint256EInput,
36
- msg.sender
37
- );
32
+ function addTwoEoa(bytes memory uint256EInput)
33
+ external
34
+ payable
35
+ refundUnspent
36
+ returns (euint256 result, euint256 resultRevealed)
37
+ {
38
+ euint256 value = inco.newEuint256{value: getFee()}(uint256EInput, msg.sender);
38
39
  result = addTwo(value);
39
40
 
40
41
  inco.allow(euint256.unwrap(result), address(this));
@@ -55,4 +56,5 @@ contract AddTwo is Fee {
55
56
  receive() external payable {
56
57
  // Accept ETH payments
57
58
  }
59
+
58
60
  }
@@ -5,11 +5,8 @@ import {EOps, ETypes} from "../../Types.sol";
5
5
  import {asBytes32} from "../../shared/TypeUtils.sol";
6
6
 
7
7
  contract FakeComputeServer {
8
- function computeBinaryUintOp(
9
- uint256 lhs,
10
- uint256 rhs,
11
- EOps op
12
- ) internal pure returns (uint256) {
8
+
9
+ function computeBinaryUintOp(uint256 lhs, uint256 rhs, EOps op) internal pure returns (uint256) {
13
10
  if (op == EOps.Add) {
14
11
  return lhs + rhs;
15
12
  } else if (op == EOps.Sub) {
@@ -43,11 +40,7 @@ contract FakeComputeServer {
43
40
  }
44
41
  }
45
42
 
46
- function computeBinaryUintToBoolOp(
47
- uint256 lhs,
48
- uint256 rhs,
49
- EOps op
50
- ) internal pure returns (bool) {
43
+ function computeBinaryUintToBoolOp(uint256 lhs, uint256 rhs, EOps op) internal pure returns (bool) {
51
44
  if (op == EOps.Eq) {
52
45
  return lhs == rhs;
53
46
  } else if (op == EOps.Ne) {
@@ -66,31 +59,13 @@ contract FakeComputeServer {
66
59
  }
67
60
 
68
61
  function isBinaryUintToUintOp(EOps op) internal pure returns (bool) {
69
- return
70
- op == EOps.Add ||
71
- op == EOps.Sub ||
72
- op == EOps.Mul ||
73
- op == EOps.Div ||
74
- op == EOps.Rem ||
75
- op == EOps.Min ||
76
- op == EOps.Max ||
77
- op == EOps.BitAnd ||
78
- op == EOps.BitOr ||
79
- op == EOps.BitXor ||
80
- op == EOps.Shl ||
81
- op == EOps.Shr ||
82
- op == EOps.Rotl ||
83
- op == EOps.Rotr;
62
+ return op == EOps.Add || op == EOps.Sub || op == EOps.Mul || op == EOps.Div || op == EOps.Rem || op == EOps.Min
63
+ || op == EOps.Max || op == EOps.BitAnd || op == EOps.BitOr || op == EOps.BitXor || op == EOps.Shl
64
+ || op == EOps.Shr || op == EOps.Rotl || op == EOps.Rotr;
84
65
  }
85
66
 
86
67
  function isBinaryUintToBoolOp(EOps op) internal pure returns (bool) {
87
- return
88
- op == EOps.Eq ||
89
- op == EOps.Ne ||
90
- op == EOps.Ge ||
91
- op == EOps.Gt ||
92
- op == EOps.Le ||
93
- op == EOps.Lt;
68
+ return op == EOps.Eq || op == EOps.Ne || op == EOps.Ge || op == EOps.Gt || op == EOps.Le || op == EOps.Lt;
94
69
  }
95
70
 
96
71
  function opToResultType(EOps op) internal pure returns (ETypes) {
@@ -107,31 +82,14 @@ contract FakeComputeServer {
107
82
  return isBinaryUintToUintOp(op) || isBinaryUintToBoolOp(op);
108
83
  }
109
84
 
110
- function computeBinaryOp(
111
- bytes32 encodedLhs,
112
- bytes32 encodedRhs,
113
- EOps op
114
- ) internal pure returns (bytes32) {
85
+ function computeBinaryOp(bytes32 encodedLhs, bytes32 encodedRhs, EOps op) internal pure returns (bytes32) {
115
86
  if (isBinaryUintToUintOp(op)) {
116
- return
117
- bytes32(
118
- computeBinaryUintOp(
119
- uint256(encodedLhs),
120
- uint256(encodedRhs),
121
- op
122
- )
123
- );
87
+ return bytes32(computeBinaryUintOp(uint256(encodedLhs), uint256(encodedRhs), op));
124
88
  } else if (isBinaryUintToBoolOp(op)) {
125
- return
126
- asBytes32(
127
- computeBinaryUintToBoolOp(
128
- uint256(encodedLhs),
129
- uint256(encodedRhs),
130
- op
131
- )
132
- );
89
+ return asBytes32(computeBinaryUintToBoolOp(uint256(encodedLhs), uint256(encodedRhs), op));
133
90
  } else {
134
91
  revert("computeBinaryOp Invalid binary op");
135
92
  }
136
93
  }
94
+
137
95
  }