chai-link 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (322) hide show
  1. package/README.md +5 -0
  2. package/contracts/Aggregator.sol +420 -0
  3. package/contracts/AggregatorProxy.sol +99 -0
  4. package/contracts/Chainlink.sol +125 -0
  5. package/contracts/ChainlinkClient.sol +262 -0
  6. package/contracts/Chainlinked.sol +141 -0
  7. package/contracts/Migrations.sol +23 -0
  8. package/contracts/Oracle.sol +320 -0
  9. package/contracts/Pointer.sol +9 -0
  10. package/contracts/interfaces/AggregatorInterface.sol +12 -0
  11. package/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
  12. package/contracts/interfaces/ENSInterface.sol +26 -0
  13. package/contracts/interfaces/LinkTokenInterface.sol +16 -0
  14. package/contracts/interfaces/OracleInterface.sol +16 -0
  15. package/contracts/interfaces/PointerInterface.sol +5 -0
  16. package/contracts/tests/BasicConsumer.sol +13 -0
  17. package/contracts/tests/ConcreteChainlink.sol +76 -0
  18. package/contracts/tests/ConcreteChainlinked.sol +100 -0
  19. package/contracts/tests/ConcreteSignedSafeMath.sol +16 -0
  20. package/contracts/tests/Consumer.sol +47 -0
  21. package/contracts/tests/EmptyOracle.sol +19 -0
  22. package/contracts/tests/GetterSetter.sol +45 -0
  23. package/contracts/tests/MaliciousChainlink.sol +76 -0
  24. package/contracts/tests/MaliciousChainlinked.sol +109 -0
  25. package/contracts/tests/MaliciousConsumer.sol +54 -0
  26. package/contracts/tests/MaliciousRequester.sol +52 -0
  27. package/contracts/tests/UpdatableConsumer.sol +24 -0
  28. package/contracts/vendor/Buffer.sol +301 -0
  29. package/contracts/vendor/CBOR.sol +71 -0
  30. package/contracts/vendor/ENS.sol +26 -0
  31. package/contracts/vendor/ENSRegistry.sol +99 -0
  32. package/contracts/vendor/ENSResolver.sol +5 -0
  33. package/contracts/vendor/Ownable.sol +64 -0
  34. package/contracts/vendor/PublicResolver.sol +238 -0
  35. package/contracts/vendor/SafeMath.sol +52 -0
  36. package/contracts/vendor/SignedSafeMath.sol +21 -0
  37. package/dist/artifacts/Aggregator.json +580 -0
  38. package/dist/artifacts/AggregatorInterface.json +172 -0
  39. package/dist/artifacts/AggregatorProxy.json +294 -0
  40. package/dist/artifacts/BasicConsumer.json +250 -0
  41. package/dist/artifacts/Buffer.json +52 -0
  42. package/dist/artifacts/CBOR.json +56 -0
  43. package/dist/artifacts/Chainlink.json +60 -0
  44. package/dist/artifacts/ChainlinkClient.json +125 -0
  45. package/dist/artifacts/ChainlinkRequestInterface.json +121 -0
  46. package/dist/artifacts/Chainlinked.json +129 -0
  47. package/dist/artifacts/ConcreteChainlink.json +190 -0
  48. package/dist/artifacts/ConcreteChainlinked.json +387 -0
  49. package/dist/artifacts/ConcreteSignedSafeMath.json +80 -0
  50. package/dist/artifacts/Consumer.json +227 -0
  51. package/dist/artifacts/ENS.json +259 -0
  52. package/dist/artifacts/ENSInterface.json +259 -0
  53. package/dist/artifacts/ENSRegistry.json +269 -0
  54. package/dist/artifacts/ENSResolver.json +72 -0
  55. package/dist/artifacts/EmptyOracle.json +259 -0
  56. package/dist/artifacts/GetterSetter.json +278 -0
  57. package/dist/artifacts/LinkTokenInterface.json +292 -0
  58. package/dist/artifacts/MaliciousChainlink.json +60 -0
  59. package/dist/artifacts/MaliciousChainlinked.json +137 -0
  60. package/dist/artifacts/MaliciousConsumer.json +288 -0
  61. package/dist/artifacts/MaliciousRequester.json +266 -0
  62. package/dist/artifacts/Migrations.json +115 -0
  63. package/dist/artifacts/Oracle.json +426 -0
  64. package/dist/artifacts/OracleInterface.json +161 -0
  65. package/dist/artifacts/Ownable.json +125 -0
  66. package/dist/artifacts/Pointer.json +78 -0
  67. package/dist/artifacts/PointerInterface.json +67 -0
  68. package/dist/artifacts/PublicResolver.json +503 -0
  69. package/dist/artifacts/SafeMath.json +52 -0
  70. package/dist/artifacts/SignedSafeMath.json +52 -0
  71. package/dist/artifacts/UpdatableConsumer.json +287 -0
  72. package/dist/src/LinkToken.d.ts +40 -0
  73. package/dist/src/LinkToken.json +164 -0
  74. package/dist/src/contract.d.ts +13 -0
  75. package/dist/src/contract.js +3 -0
  76. package/dist/src/contract.js.map +1 -0
  77. package/dist/src/debug.d.ts +8 -0
  78. package/dist/src/debug.js +17 -0
  79. package/dist/src/debug.js.map +1 -0
  80. package/dist/src/generated/Aggregator.d.ts +372 -0
  81. package/dist/src/generated/AggregatorFactory.d.ts +13 -0
  82. package/dist/src/generated/AggregatorFactory.js +505 -0
  83. package/dist/src/generated/AggregatorFactory.js.map +1 -0
  84. package/dist/src/generated/AggregatorInterface.d.ts +110 -0
  85. package/dist/src/generated/AggregatorInterfaceFactory.d.ts +6 -0
  86. package/dist/src/generated/AggregatorInterfaceFactory.js +133 -0
  87. package/dist/src/generated/AggregatorInterfaceFactory.js.map +1 -0
  88. package/dist/src/generated/AggregatorProxy.d.ts +196 -0
  89. package/dist/src/generated/AggregatorProxyFactory.d.ts +12 -0
  90. package/dist/src/generated/AggregatorProxyFactory.js +263 -0
  91. package/dist/src/generated/AggregatorProxyFactory.js.map +1 -0
  92. package/dist/src/generated/BasicConsumer.d.ts +154 -0
  93. package/dist/src/generated/BasicConsumerFactory.d.ts +13 -0
  94. package/dist/src/generated/BasicConsumerFactory.js +183 -0
  95. package/dist/src/generated/BasicConsumerFactory.js.map +1 -0
  96. package/dist/src/generated/ChainlinkClient.d.ts +58 -0
  97. package/dist/src/generated/ChainlinkClientFactory.d.ts +12 -0
  98. package/dist/src/generated/ChainlinkClientFactory.js +66 -0
  99. package/dist/src/generated/ChainlinkClientFactory.js.map +1 -0
  100. package/dist/src/generated/ChainlinkRequestInterface.d.ts +139 -0
  101. package/dist/src/generated/ChainlinkRequestInterfaceFactory.d.ts +6 -0
  102. package/dist/src/generated/ChainlinkRequestInterfaceFactory.js +82 -0
  103. package/dist/src/generated/ChainlinkRequestInterfaceFactory.js.map +1 -0
  104. package/dist/src/generated/Chainlinked.d.ts +55 -0
  105. package/dist/src/generated/ChainlinkedFactory.d.ts +12 -0
  106. package/dist/src/generated/ChainlinkedFactory.js +66 -0
  107. package/dist/src/generated/ChainlinkedFactory.js.map +1 -0
  108. package/dist/src/generated/ConcreteChainlink.d.ts +158 -0
  109. package/dist/src/generated/ConcreteChainlinkFactory.d.ts +12 -0
  110. package/dist/src/generated/ConcreteChainlinkFactory.js +155 -0
  111. package/dist/src/generated/ConcreteChainlinkFactory.js.map +1 -0
  112. package/dist/src/generated/ConcreteChainlinked.d.ts +300 -0
  113. package/dist/src/generated/ConcreteChainlinkedFactory.d.ts +12 -0
  114. package/dist/src/generated/ConcreteChainlinkedFactory.js +320 -0
  115. package/dist/src/generated/ConcreteChainlinkedFactory.js.map +1 -0
  116. package/dist/src/generated/ConcreteSignedSafeMath.d.ts +50 -0
  117. package/dist/src/generated/ConcreteSignedSafeMathFactory.d.ts +12 -0
  118. package/dist/src/generated/ConcreteSignedSafeMathFactory.js +53 -0
  119. package/dist/src/generated/ConcreteSignedSafeMathFactory.js.map +1 -0
  120. package/dist/src/generated/Consumer.d.ts +151 -0
  121. package/dist/src/generated/ConsumerFactory.d.ts +12 -0
  122. package/dist/src/generated/ConsumerFactory.js +164 -0
  123. package/dist/src/generated/ConsumerFactory.js.map +1 -0
  124. package/dist/src/generated/ENS.d.ts +171 -0
  125. package/dist/src/generated/ENSFactory.d.ts +6 -0
  126. package/dist/src/generated/ENSFactory.js +220 -0
  127. package/dist/src/generated/ENSFactory.js.map +1 -0
  128. package/dist/src/generated/ENSInterface.d.ts +174 -0
  129. package/dist/src/generated/ENSInterfaceFactory.d.ts +6 -0
  130. package/dist/src/generated/ENSInterfaceFactory.js +220 -0
  131. package/dist/src/generated/ENSInterfaceFactory.js.map +1 -0
  132. package/dist/src/generated/ENSRegistry.d.ts +171 -0
  133. package/dist/src/generated/ENSRegistryFactory.d.ts +12 -0
  134. package/dist/src/generated/ENSRegistryFactory.js +242 -0
  135. package/dist/src/generated/ENSRegistryFactory.js.map +1 -0
  136. package/dist/src/generated/ENSResolver.d.ts +45 -0
  137. package/dist/src/generated/ENSResolverFactory.d.ts +6 -0
  138. package/dist/src/generated/ENSResolverFactory.js +33 -0
  139. package/dist/src/generated/ENSResolverFactory.js.map +1 -0
  140. package/dist/src/generated/EmptyOracle.d.ts +228 -0
  141. package/dist/src/generated/EmptyOracleFactory.d.ts +12 -0
  142. package/dist/src/generated/EmptyOracleFactory.js +228 -0
  143. package/dist/src/generated/EmptyOracleFactory.js.map +1 -0
  144. package/dist/src/generated/GetterSetter.d.ts +207 -0
  145. package/dist/src/generated/GetterSetterFactory.d.ts +12 -0
  146. package/dist/src/generated/GetterSetterFactory.js +255 -0
  147. package/dist/src/generated/GetterSetterFactory.js.map +1 -0
  148. package/dist/src/generated/LinkToken.d.ts +243 -0
  149. package/dist/src/generated/LinkTokenFactory.d.ts +12 -0
  150. package/dist/src/generated/LinkTokenFactory.js +329 -0
  151. package/dist/src/generated/LinkTokenFactory.js.map +1 -0
  152. package/dist/src/generated/LinkTokenInterface.d.ts +230 -0
  153. package/dist/src/generated/LinkTokenInterfaceFactory.d.ts +6 -0
  154. package/dist/src/generated/LinkTokenInterfaceFactory.js +253 -0
  155. package/dist/src/generated/LinkTokenInterfaceFactory.js.map +1 -0
  156. package/dist/src/generated/MaliciousChainlinked.d.ts +58 -0
  157. package/dist/src/generated/MaliciousChainlinkedFactory.d.ts +12 -0
  158. package/dist/src/generated/MaliciousChainlinkedFactory.js +66 -0
  159. package/dist/src/generated/MaliciousChainlinkedFactory.js.map +1 -0
  160. package/dist/src/generated/MaliciousConsumer.d.ts +179 -0
  161. package/dist/src/generated/MaliciousConsumerFactory.d.ts +12 -0
  162. package/dist/src/generated/MaliciousConsumerFactory.js +221 -0
  163. package/dist/src/generated/MaliciousConsumerFactory.js.map +1 -0
  164. package/dist/src/generated/MaliciousRequester.d.ts +161 -0
  165. package/dist/src/generated/MaliciousRequesterFactory.d.ts +12 -0
  166. package/dist/src/generated/MaliciousRequesterFactory.js +191 -0
  167. package/dist/src/generated/MaliciousRequesterFactory.js.map +1 -0
  168. package/dist/src/generated/Migrations.d.ts +87 -0
  169. package/dist/src/generated/MigrationsFactory.d.ts +12 -0
  170. package/dist/src/generated/MigrationsFactory.js +92 -0
  171. package/dist/src/generated/MigrationsFactory.js.map +1 -0
  172. package/dist/src/generated/Oracle.d.ts +362 -0
  173. package/dist/src/generated/OracleFactory.d.ts +12 -0
  174. package/dist/src/generated/OracleFactory.js +383 -0
  175. package/dist/src/generated/OracleFactory.js.map +1 -0
  176. package/dist/src/generated/OracleInterface.d.ts +144 -0
  177. package/dist/src/generated/OracleInterfaceFactory.d.ts +6 -0
  178. package/dist/src/generated/OracleInterfaceFactory.js +122 -0
  179. package/dist/src/generated/OracleInterfaceFactory.js.map +1 -0
  180. package/dist/src/generated/Ownable.d.ts +91 -0
  181. package/dist/src/generated/OwnableFactory.d.ts +12 -0
  182. package/dist/src/generated/OwnableFactory.js +102 -0
  183. package/dist/src/generated/OwnableFactory.js.map +1 -0
  184. package/dist/src/generated/Pointer.d.ts +45 -0
  185. package/dist/src/generated/PointerFactory.d.ts +12 -0
  186. package/dist/src/generated/PointerFactory.js +55 -0
  187. package/dist/src/generated/PointerFactory.js.map +1 -0
  188. package/dist/src/generated/PointerInterface.d.ts +48 -0
  189. package/dist/src/generated/PointerInterfaceFactory.d.ts +6 -0
  190. package/dist/src/generated/PointerInterfaceFactory.js +28 -0
  191. package/dist/src/generated/PointerInterfaceFactory.js.map +1 -0
  192. package/dist/src/generated/PublicResolver.d.ts +336 -0
  193. package/dist/src/generated/PublicResolverFactory.d.ts +12 -0
  194. package/dist/src/generated/PublicResolverFactory.js +476 -0
  195. package/dist/src/generated/PublicResolverFactory.js.map +1 -0
  196. package/dist/src/generated/UpdatableConsumer.d.ts +180 -0
  197. package/dist/src/generated/UpdatableConsumerFactory.d.ts +13 -0
  198. package/dist/src/generated/UpdatableConsumerFactory.js +220 -0
  199. package/dist/src/generated/UpdatableConsumerFactory.js.map +1 -0
  200. package/dist/src/generated/index.d.ts +44 -0
  201. package/dist/src/generated/index.js +41 -0
  202. package/dist/src/generated/index.js.map +1 -0
  203. package/dist/src/helpers.d.ts +144 -0
  204. package/dist/src/helpers.js +358 -0
  205. package/dist/src/helpers.js.map +1 -0
  206. package/dist/src/helpers.test.d.ts +1 -0
  207. package/dist/src/helpers.test.js +21 -0
  208. package/dist/src/helpers.test.js.map +1 -0
  209. package/dist/src/index.d.ts +8 -0
  210. package/dist/src/index.js +27 -0
  211. package/dist/src/index.js.map +1 -0
  212. package/dist/src/matchers.d.ts +2 -0
  213. package/dist/src/matchers.js +7 -0
  214. package/dist/src/matchers.js.map +1 -0
  215. package/dist/src/provider.d.ts +5 -0
  216. package/dist/src/provider.js +15 -0
  217. package/dist/src/provider.js.map +1 -0
  218. package/dist/src/wallet.d.ts +35 -0
  219. package/dist/src/wallet.js +64 -0
  220. package/dist/src/wallet.js.map +1 -0
  221. package/dist/test/Aggregator.test.d.ts +1 -0
  222. package/dist/test/Aggregator.test.js +581 -0
  223. package/dist/test/Aggregator.test.js.map +1 -0
  224. package/dist/test/AggregatorProxy.test.d.ts +1 -0
  225. package/dist/test/AggregatorProxy.test.js +179 -0
  226. package/dist/test/AggregatorProxy.test.js.map +1 -0
  227. package/dist/test/BasicConsumer.test.d.ts +1 -0
  228. package/dist/test/BasicConsumer.test.js +180 -0
  229. package/dist/test/BasicConsumer.test.js.map +1 -0
  230. package/dist/test/Chainlinked.test.d.ts +1 -0
  231. package/dist/test/Chainlinked.test.js +11 -0
  232. package/dist/test/Chainlinked.test.js.map +1 -0
  233. package/dist/test/ConcreteChainlink.test.d.ts +1 -0
  234. package/dist/test/ConcreteChainlink.test.js +163 -0
  235. package/dist/test/ConcreteChainlink.test.js.map +1 -0
  236. package/dist/test/ConcreteChainlinked.test.d.ts +1 -0
  237. package/dist/test/ConcreteChainlinked.test.js +182 -0
  238. package/dist/test/ConcreteChainlinked.test.js.map +1 -0
  239. package/dist/test/GetterSetter.test.d.ts +1 -0
  240. package/dist/test/GetterSetter.test.js +76 -0
  241. package/dist/test/GetterSetter.test.js.map +1 -0
  242. package/dist/test/Oracle.test.d.ts +1 -0
  243. package/dist/test/Oracle.test.js +669 -0
  244. package/dist/test/Oracle.test.js.map +1 -0
  245. package/dist/test/Pointer.test.d.ts +1 -0
  246. package/dist/test/Pointer.test.js +35 -0
  247. package/dist/test/Pointer.test.js.map +1 -0
  248. package/dist/test/SignedSafeMath.test.d.ts +1 -0
  249. package/dist/test/SignedSafeMath.test.js +75 -0
  250. package/dist/test/SignedSafeMath.test.js.map +1 -0
  251. package/dist/test/UpdatableConsumer.test.d.ts +1 -0
  252. package/dist/test/UpdatableConsumer.test.js +144 -0
  253. package/dist/test/UpdatableConsumer.test.js.map +1 -0
  254. package/dist/tsconfig.tsbuildinfo +7737 -0
  255. package/package.json +50 -0
  256. package/r1z9aogk.cjs +1 -0
  257. package/v0.5/contracts/Chainlink.sol +125 -0
  258. package/v0.5/contracts/ChainlinkClient.sol +263 -0
  259. package/v0.5/contracts/LinkTokenReceiver.sol +70 -0
  260. package/v0.5/contracts/Median.sol +108 -0
  261. package/v0.5/contracts/Migrations.sol +23 -0
  262. package/v0.5/contracts/Oracle.sol +273 -0
  263. package/v0.5/contracts/PreCoordinator.sol +305 -0
  264. package/v0.5/contracts/dev/AggregatorInterface.sol +12 -0
  265. package/v0.5/contracts/dev/Coordinator.sol +411 -0
  266. package/v0.5/contracts/dev/CoordinatorInterface.sol +14 -0
  267. package/v0.5/contracts/dev/OracleSignaturesDecoder.sol +24 -0
  268. package/v0.5/contracts/dev/Owned.sol +61 -0
  269. package/v0.5/contracts/dev/PrepaidAggregator.sol +621 -0
  270. package/v0.5/contracts/dev/SafeMath128.sol +110 -0
  271. package/v0.5/contracts/dev/SafeMath32.sol +110 -0
  272. package/v0.5/contracts/dev/SafeMath64.sol +110 -0
  273. package/v0.5/contracts/dev/SchnorrSECP256K1.sol +147 -0
  274. package/v0.5/contracts/dev/ServiceAgreementDecoder.sol +59 -0
  275. package/v0.5/contracts/dev/VRF.sol +382 -0
  276. package/v0.5/contracts/dev/Whitelisted.sol +41 -0
  277. package/v0.5/contracts/dev/WhitelistedAggregator.sol +80 -0
  278. package/v0.5/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
  279. package/v0.5/contracts/interfaces/ENSInterface.sol +26 -0
  280. package/v0.5/contracts/interfaces/LinkTokenInterface.sol +16 -0
  281. package/v0.5/contracts/interfaces/OracleInterface.sol +16 -0
  282. package/v0.5/contracts/interfaces/PointerInterface.sol +5 -0
  283. package/v0.5/contracts/interfaces/WithdrawalInterface.sol +16 -0
  284. package/v0.5/contracts/tests/BasicConsumer.sol +13 -0
  285. package/v0.5/contracts/tests/ChainlinkTestHelper.sol +75 -0
  286. package/v0.5/contracts/tests/Consumer.sol +55 -0
  287. package/v0.5/contracts/tests/EmptyAggregator.sol +34 -0
  288. package/v0.5/contracts/tests/GetterSetter.sol +45 -0
  289. package/v0.5/contracts/tests/MaliciousChainlink.sol +75 -0
  290. package/v0.5/contracts/tests/MaliciousChainlinkClient.sol +109 -0
  291. package/v0.5/contracts/tests/MaliciousConsumer.sol +54 -0
  292. package/v0.5/contracts/tests/MaliciousRequester.sol +52 -0
  293. package/v0.5/contracts/tests/MeanAggregator.sol +75 -0
  294. package/v0.5/contracts/tests/MedianTestHelper.sol +15 -0
  295. package/v0.5/contracts/tests/OwnedTestHelper.sol +16 -0
  296. package/v0.5/contracts/tests/ServiceAgreementConsumer.sol +30 -0
  297. package/v0.5/contracts/vendor/Buffer.sol +301 -0
  298. package/v0.5/contracts/vendor/CBOR.sol +71 -0
  299. package/v0.5/contracts/vendor/ENSResolver.sol +5 -0
  300. package/v0.5/contracts/vendor/Ownable.sol +65 -0
  301. package/v0.5/contracts/vendor/SafeMath.sol +107 -0
  302. package/v0.5/contracts/vendor/SignedSafeMath.sol +22 -0
  303. package/v0.6/contracts/Chainlink.sol +125 -0
  304. package/v0.6/contracts/ChainlinkClient.sol +263 -0
  305. package/v0.6/contracts/LinkTokenReceiver.sol +70 -0
  306. package/v0.6/contracts/Oracle.sol +276 -0
  307. package/v0.6/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
  308. package/v0.6/contracts/interfaces/ENSInterface.sol +26 -0
  309. package/v0.6/contracts/interfaces/LinkTokenInterface.sol +16 -0
  310. package/v0.6/contracts/interfaces/OracleInterface.sol +16 -0
  311. package/v0.6/contracts/interfaces/PointerInterface.sol +5 -0
  312. package/v0.6/contracts/interfaces/WithdrawalInterface.sol +16 -0
  313. package/v0.6/contracts/tests/BasicConsumer.sol +13 -0
  314. package/v0.6/contracts/tests/Consumer.sol +55 -0
  315. package/v0.6/contracts/vendor/Buffer.sol +301 -0
  316. package/v0.6/contracts/vendor/CBOR.sol +71 -0
  317. package/v0.6/contracts/vendor/ENSResolver.sol +5 -0
  318. package/v0.6/contracts/vendor/Ownable.sol +65 -0
  319. package/v0.6/contracts/vendor/SafeMath.sol +107 -0
  320. package/zos.json +8 -0
  321. package/zos.rinkeby.json +104 -0
  322. package/zos.ropsten.json +104 -0
@@ -0,0 +1,110 @@
1
+ pragma solidity ^0.5.0;
2
+
3
+ /**
4
+ * @dev Wrappers over Solidity's arithmetic operations with added overflow
5
+ * checks.
6
+ *
7
+ * Arithmetic operations in Solidity wrap on overflow. This can easily result
8
+ * in bugs, because programmers usually assume that an overflow raises an
9
+ * error, which is the standard behavior in high level programming languages.
10
+ * `SafeMath` restores this intuition by reverting the transaction when an
11
+ * operation overflows.
12
+ *
13
+ * Using this library instead of the unchecked operations eliminates an entire
14
+ * class of bugs, so it's recommended to use it always.
15
+ *
16
+ * This library is a version of Open Zeppelin's SafeMath, modified to support
17
+ * unsigned 128 bit integers.
18
+ */
19
+ library SafeMath128 {
20
+ /**
21
+ * @dev Returns the addition of two unsigned integers, reverting on
22
+ * overflow.
23
+ *
24
+ * Counterpart to Solidity's `+` operator.
25
+ *
26
+ * Requirements:
27
+ * - Addition cannot overflow.
28
+ */
29
+ function add(uint128 a, uint128 b) internal pure returns (uint128) {
30
+ uint128 c = a + b;
31
+ require(c >= a, "SafeMath: addition overflow");
32
+
33
+ return c;
34
+ }
35
+
36
+ /**
37
+ * @dev Returns the subtraction of two unsigned integers, reverting on
38
+ * overflow (when the result is negative).
39
+ *
40
+ * Counterpart to Solidity's `-` operator.
41
+ *
42
+ * Requirements:
43
+ * - Subtraction cannot overflow.
44
+ */
45
+ function sub(uint128 a, uint128 b) internal pure returns (uint128) {
46
+ require(b <= a, "SafeMath: subtraction overflow");
47
+ uint128 c = a - b;
48
+
49
+ return c;
50
+ }
51
+
52
+ /**
53
+ * @dev Returns the multiplication of two unsigned integers, reverting on
54
+ * overflow.
55
+ *
56
+ * Counterpart to Solidity's `*` operator.
57
+ *
58
+ * Requirements:
59
+ * - Multiplication cannot overflow.
60
+ */
61
+ function mul(uint128 a, uint128 b) internal pure returns (uint128) {
62
+ // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
63
+ // benefit is lost if 'b' is also tested.
64
+ // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
65
+ if (a == 0) {
66
+ return 0;
67
+ }
68
+
69
+ uint128 c = a * b;
70
+ require(c / a == b, "SafeMath: multiplication overflow");
71
+
72
+ return c;
73
+ }
74
+
75
+ /**
76
+ * @dev Returns the integer division of two unsigned integers. Reverts on
77
+ * division by zero. The result is rounded towards zero.
78
+ *
79
+ * Counterpart to Solidity's `/` operator. Note: this function uses a
80
+ * `revert` opcode (which leaves remaining gas untouched) while Solidity
81
+ * uses an invalid opcode to revert (consuming all remaining gas).
82
+ *
83
+ * Requirements:
84
+ * - The divisor cannot be zero.
85
+ */
86
+ function div(uint128 a, uint128 b) internal pure returns (uint128) {
87
+ // Solidity only automatically asserts when dividing by 0
88
+ require(b > 0, "SafeMath: division by zero");
89
+ uint128 c = a / b;
90
+ // assert(a == b * c + a % b); // There is no case in which this doesn't hold
91
+
92
+ return c;
93
+ }
94
+
95
+ /**
96
+ * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
97
+ * Reverts when dividing by zero.
98
+ *
99
+ * Counterpart to Solidity's `%` operator. This function uses a `revert`
100
+ * opcode (which leaves remaining gas untouched) while Solidity uses an
101
+ * invalid opcode to revert (consuming all remaining gas).
102
+ *
103
+ * Requirements:
104
+ * - The divisor cannot be zero.
105
+ */
106
+ function mod(uint128 a, uint128 b) internal pure returns (uint128) {
107
+ require(b != 0, "SafeMath: modulo by zero");
108
+ return a % b;
109
+ }
110
+ }
@@ -0,0 +1,110 @@
1
+ pragma solidity ^0.5.0;
2
+
3
+ /**
4
+ * @dev Wrappers over Solidity's arithmetic operations with added overflow
5
+ * checks.
6
+ *
7
+ * Arithmetic operations in Solidity wrap on overflow. This can easily result
8
+ * in bugs, because programmers usually assume that an overflow raises an
9
+ * error, which is the standard behavior in high level programming languages.
10
+ * `SafeMath` restores this intuition by reverting the transaction when an
11
+ * operation overflows.
12
+ *
13
+ * Using this library instead of the unchecked operations eliminates an entire
14
+ * class of bugs, so it's recommended to use it always.
15
+ *
16
+ * This library is a version of Open Zeppelin's SafeMath, modified to support
17
+ * unsigned 32 bit integers.
18
+ */
19
+ library SafeMath32 {
20
+ /**
21
+ * @dev Returns the addition of two unsigned integers, reverting on
22
+ * overflow.
23
+ *
24
+ * Counterpart to Solidity's `+` operator.
25
+ *
26
+ * Requirements:
27
+ * - Addition cannot overflow.
28
+ */
29
+ function add(uint32 a, uint32 b) internal pure returns (uint32) {
30
+ uint32 c = a + b;
31
+ require(c >= a, "SafeMath: addition overflow");
32
+
33
+ return c;
34
+ }
35
+
36
+ /**
37
+ * @dev Returns the subtraction of two unsigned integers, reverting on
38
+ * overflow (when the result is negative).
39
+ *
40
+ * Counterpart to Solidity's `-` operator.
41
+ *
42
+ * Requirements:
43
+ * - Subtraction cannot overflow.
44
+ */
45
+ function sub(uint32 a, uint32 b) internal pure returns (uint32) {
46
+ require(b <= a, "SafeMath: subtraction overflow");
47
+ uint32 c = a - b;
48
+
49
+ return c;
50
+ }
51
+
52
+ /**
53
+ * @dev Returns the multiplication of two unsigned integers, reverting on
54
+ * overflow.
55
+ *
56
+ * Counterpart to Solidity's `*` operator.
57
+ *
58
+ * Requirements:
59
+ * - Multiplication cannot overflow.
60
+ */
61
+ function mul(uint32 a, uint32 b) internal pure returns (uint32) {
62
+ // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
63
+ // benefit is lost if 'b' is also tested.
64
+ // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
65
+ if (a == 0) {
66
+ return 0;
67
+ }
68
+
69
+ uint32 c = a * b;
70
+ require(c / a == b, "SafeMath: multiplication overflow");
71
+
72
+ return c;
73
+ }
74
+
75
+ /**
76
+ * @dev Returns the integer division of two unsigned integers. Reverts on
77
+ * division by zero. The result is rounded towards zero.
78
+ *
79
+ * Counterpart to Solidity's `/` operator. Note: this function uses a
80
+ * `revert` opcode (which leaves remaining gas untouched) while Solidity
81
+ * uses an invalid opcode to revert (consuming all remaining gas).
82
+ *
83
+ * Requirements:
84
+ * - The divisor cannot be zero.
85
+ */
86
+ function div(uint32 a, uint32 b) internal pure returns (uint32) {
87
+ // Solidity only automatically asserts when dividing by 0
88
+ require(b > 0, "SafeMath: division by zero");
89
+ uint32 c = a / b;
90
+ // assert(a == b * c + a % b); // There is no case in which this doesn't hold
91
+
92
+ return c;
93
+ }
94
+
95
+ /**
96
+ * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
97
+ * Reverts when dividing by zero.
98
+ *
99
+ * Counterpart to Solidity's `%` operator. This function uses a `revert`
100
+ * opcode (which leaves remaining gas untouched) while Solidity uses an
101
+ * invalid opcode to revert (consuming all remaining gas).
102
+ *
103
+ * Requirements:
104
+ * - The divisor cannot be zero.
105
+ */
106
+ function mod(uint32 a, uint32 b) internal pure returns (uint32) {
107
+ require(b != 0, "SafeMath: modulo by zero");
108
+ return a % b;
109
+ }
110
+ }
@@ -0,0 +1,110 @@
1
+ pragma solidity ^0.5.0;
2
+
3
+ /**
4
+ * @dev Wrappers over Solidity's arithmetic operations with added overflow
5
+ * checks.
6
+ *
7
+ * Arithmetic operations in Solidity wrap on overflow. This can easily result
8
+ * in bugs, because programmers usually assume that an overflow raises an
9
+ * error, which is the standard behavior in high level programming languages.
10
+ * `SafeMath` restores this intuition by reverting the transaction when an
11
+ * operation overflows.
12
+ *
13
+ * Using this library instead of the unchecked operations eliminates an entire
14
+ * class of bugs, so it's recommended to use it always.
15
+ *
16
+ * This library is a version of Open Zeppelin's SafeMath, modified to support
17
+ * unsigned 64 bit integers.
18
+ */
19
+ library SafeMath64 {
20
+ /**
21
+ * @dev Returns the addition of two unsigned integers, reverting on
22
+ * overflow.
23
+ *
24
+ * Counterpart to Solidity's `+` operator.
25
+ *
26
+ * Requirements:
27
+ * - Addition cannot overflow.
28
+ */
29
+ function add(uint64 a, uint64 b) internal pure returns (uint64) {
30
+ uint64 c = a + b;
31
+ require(c >= a, "SafeMath: addition overflow");
32
+
33
+ return c;
34
+ }
35
+
36
+ /**
37
+ * @dev Returns the subtraction of two unsigned integers, reverting on
38
+ * overflow (when the result is negative).
39
+ *
40
+ * Counterpart to Solidity's `-` operator.
41
+ *
42
+ * Requirements:
43
+ * - Subtraction cannot overflow.
44
+ */
45
+ function sub(uint64 a, uint64 b) internal pure returns (uint64) {
46
+ require(b <= a, "SafeMath: subtraction overflow");
47
+ uint64 c = a - b;
48
+
49
+ return c;
50
+ }
51
+
52
+ /**
53
+ * @dev Returns the multiplication of two unsigned integers, reverting on
54
+ * overflow.
55
+ *
56
+ * Counterpart to Solidity's `*` operator.
57
+ *
58
+ * Requirements:
59
+ * - Multiplication cannot overflow.
60
+ */
61
+ function mul(uint64 a, uint64 b) internal pure returns (uint64) {
62
+ // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
63
+ // benefit is lost if 'b' is also tested.
64
+ // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
65
+ if (a == 0) {
66
+ return 0;
67
+ }
68
+
69
+ uint64 c = a * b;
70
+ require(c / a == b, "SafeMath: multiplication overflow");
71
+
72
+ return c;
73
+ }
74
+
75
+ /**
76
+ * @dev Returns the integer division of two unsigned integers. Reverts on
77
+ * division by zero. The result is rounded towards zero.
78
+ *
79
+ * Counterpart to Solidity's `/` operator. Note: this function uses a
80
+ * `revert` opcode (which leaves remaining gas untouched) while Solidity
81
+ * uses an invalid opcode to revert (consuming all remaining gas).
82
+ *
83
+ * Requirements:
84
+ * - The divisor cannot be zero.
85
+ */
86
+ function div(uint64 a, uint64 b) internal pure returns (uint64) {
87
+ // Solidity only automatically asserts when dividing by 0
88
+ require(b > 0, "SafeMath: division by zero");
89
+ uint64 c = a / b;
90
+ // assert(a == b * c + a % b); // There is no case in which this doesn't hold
91
+
92
+ return c;
93
+ }
94
+
95
+ /**
96
+ * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
97
+ * Reverts when dividing by zero.
98
+ *
99
+ * Counterpart to Solidity's `%` operator. This function uses a `revert`
100
+ * opcode (which leaves remaining gas untouched) while Solidity uses an
101
+ * invalid opcode to revert (consuming all remaining gas).
102
+ *
103
+ * Requirements:
104
+ * - The divisor cannot be zero.
105
+ */
106
+ function mod(uint64 a, uint64 b) internal pure returns (uint64) {
107
+ require(b != 0, "SafeMath: modulo by zero");
108
+ return a % b;
109
+ }
110
+ }
@@ -0,0 +1,147 @@
1
+ pragma solidity ^0.5.0;
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // XXX: Do not use in production until this code has been audited.
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+ contract SchnorrSECP256K1 {
8
+ // See https://en.bitcoin.it/wiki/Secp256k1 for this constant.
9
+ uint256 constant public Q = // Group order of secp256k1
10
+ // solium-disable-next-line indentation
11
+ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141;
12
+ // solium-disable-next-line zeppelin/no-arithmetic-operations
13
+ uint256 constant public HALF_Q = (Q >> 1) + 1;
14
+
15
+ /** **************************************************************************
16
+ @notice verifySignature returns true iff passed a valid Schnorr signature.
17
+
18
+ @dev See https://en.wikipedia.org/wiki/Schnorr_signature for reference.
19
+
20
+ @dev In what follows, let d be your secret key, PK be your public key,
21
+ PKx be the x ordinate of your public key, and PKyp be the parity bit for
22
+ the y ordinate (i.e., 0 if PKy is even, 1 if odd.)
23
+ **************************************************************************
24
+ @dev TO CREATE A VALID SIGNATURE FOR THIS METHOD
25
+
26
+ @dev First PKx must be less than HALF_Q. Then follow these instructions
27
+ (see evm/test/schnorr_test.js, for an example of carrying them out):
28
+ @dev 1. Hash the target message to a uint256, called msgHash here, using
29
+ keccak256
30
+
31
+ @dev 2. Pick k uniformly and cryptographically securely randomly from
32
+ {0,...,Q-1}. It is critical that k remains confidential, as your
33
+ private key can be reconstructed from k and the signature.
34
+
35
+ @dev 3. Compute k*g in the secp256k1 group, where g is the group
36
+ generator. (This is the same as computing the public key from the
37
+ secret key k. But it's OK if k*g's x ordinate is greater than
38
+ HALF_Q.)
39
+
40
+ @dev 4. Compute the ethereum address for k*g. This is the lower 160 bits
41
+ of the keccak hash of the concatenated affine coordinates of k*g,
42
+ as 32-byte big-endians. (For instance, you could pass k to
43
+ ethereumjs-utils's privateToAddress to compute this, though that
44
+ should be strictly a development convenience, not for handling
45
+ live secrets, unless you've locked your javascript environment
46
+ down very carefully.) Call this address
47
+ nonceTimesGeneratorAddress.
48
+
49
+ @dev 5. Compute e=uint256(keccak256(PKx as a 32-byte big-endian
50
+ ‖ PKyp as a single byte
51
+ ‖ msgHash
52
+ ‖ nonceTimesGeneratorAddress))
53
+ This value e is called "msgChallenge" in verifySignature's source
54
+ code below. Here "‖" means concatenation of the listed byte
55
+ arrays.
56
+
57
+ @dev 6. Let x be your secret key. Compute s = (k - d * e) % Q. Add Q to
58
+ it, if it's negative. This is your signature. (d is your secret
59
+ key.)
60
+ **************************************************************************
61
+ @dev TO VERIFY A SIGNATURE
62
+
63
+ @dev Given a signature (s, e) of msgHash, constructed as above, compute
64
+ S=e*PK+s*generator in the secp256k1 group law, and then the ethereum
65
+ address of S, as described in step 4. Call that
66
+ nonceTimesGeneratorAddress. Then call the verifySignature method as:
67
+
68
+ @dev verifySignature(PKx, PKyp, s, msgHash,
69
+ nonceTimesGeneratorAddress)
70
+ **************************************************************************
71
+ @dev This signging scheme deviates slightly from the classical Schnorr
72
+ signature, in that the address of k*g is used in place of k*g itself,
73
+ both when calculating e and when verifying sum S as described in the
74
+ verification paragraph above. This reduces the difficulty of
75
+ brute-forcing a signature by trying random secp256k1 points in place of
76
+ k*g in the signature verification process from 256 bits to 160 bits.
77
+ However, the difficulty of cracking the public key using "baby-step,
78
+ giant-step" is only 128 bits, so this weakening constitutes no compromise
79
+ in the security of the signatures or the key.
80
+
81
+ @dev The constraint signingPubKeyX < HALF_Q comes from Eq. (281), p. 24
82
+ of Yellow Paper version 78d7b9a. ecrecover only accepts "s" inputs less
83
+ than HALF_Q, to protect against a signature- malleability vulnerability in
84
+ ECDSA. Schnorr does not have this vulnerability, but we must account for
85
+ ecrecover's defense anyway. And since we are abusing ecrecover by putting
86
+ signingPubKeyX in ecrecover's "s" argument the constraint applies to
87
+ signingPubKeyX, even though it represents a value in the base field, and
88
+ has no natural relationship to the order of the curve's cyclic group.
89
+ **************************************************************************
90
+ @param signingPubKeyX is the x ordinate of the public key. This must be
91
+ less than HALF_Q.
92
+ @param pubKeyYParity is 0 if the y ordinate of the public key is even, 1
93
+ if it's odd.
94
+ @param signature is the actual signature, described as s in the above
95
+ instructions.
96
+ @param msgHash is a 256-bit hash of the message being signed.
97
+ @param nonceTimesGeneratorAddress is the ethereum address of k*g in the
98
+ above instructions
99
+ **************************************************************************
100
+ @return True if passed a valid signature, false otherwise. */
101
+ function verifySignature(
102
+ uint256 signingPubKeyX,
103
+ uint8 pubKeyYParity,
104
+ uint256 signature,
105
+ uint256 msgHash,
106
+ address nonceTimesGeneratorAddress) external pure returns (bool) {
107
+ require(signingPubKeyX < HALF_Q, "Public-key x >= HALF_Q");
108
+ // Avoid signature malleability from multiple representations for ℤ/Qℤ elts
109
+ require(signature < Q, "signature must be reduced modulo Q");
110
+
111
+ // Forbid trivial inputs, to avoid ecrecover edge cases. The main thing to
112
+ // avoid is something which causes ecrecover to return 0x0: then trivial
113
+ // signatures could be constructed with the nonceTimesGeneratorAddress input
114
+ // set to 0x0.
115
+ //
116
+ // solium-disable-next-line indentation
117
+ require(nonceTimesGeneratorAddress != address(0) && signingPubKeyX > 0 &&
118
+ signature > 0 && msgHash > 0, "no zero inputs allowed");
119
+
120
+ // solium-disable-next-line indentation
121
+ uint256 msgChallenge = // "e"
122
+ // solium-disable-next-line indentation
123
+ uint256(keccak256(abi.encodePacked(signingPubKeyX, pubKeyYParity,
124
+ msgHash, nonceTimesGeneratorAddress))
125
+ );
126
+
127
+ // Verify msgChallenge * signingPubKey + signature * generator ==
128
+ // nonce * generator
129
+ //
130
+ // https://ethresear.ch/t/you-can-kinda-abuse-ecrecover-to-do-ecmul-in-secp256k1-today/2384/9
131
+ // The point corresponding to the address returned by
132
+ // ecrecover(-s*r,v,r,e*r) is (r⁻¹ mod Q)*(e*r*R-(-s)*r*g)=e*R+s*g, where R
133
+ // is the (v,r) point. See https://crypto.stackexchange.com/a/18106
134
+ //
135
+ // solium-disable-next-line indentation
136
+ address recoveredAddress = ecrecover(
137
+ // solium-disable-next-line zeppelin/no-arithmetic-operations
138
+ bytes32(Q - mulmod(signingPubKeyX, signature, Q)),
139
+ // https://ethereum.github.io/yellowpaper/paper.pdf p. 24, "The
140
+ // value 27 represents an even y value and 28 represents an odd
141
+ // y value."
142
+ (pubKeyYParity == 0) ? 27 : 28,
143
+ bytes32(signingPubKeyX),
144
+ bytes32(mulmod(msgChallenge, signingPubKeyX, Q)));
145
+ return nonceTimesGeneratorAddress == recoveredAddress;
146
+ }
147
+ }
@@ -0,0 +1,59 @@
1
+ pragma solidity 0.5.0;
2
+
3
+ contract ServiceAgreementDecoder {
4
+
5
+ struct ServiceAgreement {
6
+ uint256 payment;
7
+ uint256 expiration;
8
+ uint256 endAt;
9
+ address[] oracles;
10
+ // This effectively functions as an ID tag for the off-chain job of the
11
+ // service agreement. It is calculated as the keccak256 hash of the
12
+ // normalized JSON request to create the ServiceAgreement, but that identity
13
+ // is unused, and its value is essentially arbitrary.
14
+ bytes32 requestDigest;
15
+ // Specification of aggregator interface. See ../tests/MeanAggregator.sol
16
+ // for example
17
+ address aggregator;
18
+ // Selectors for the interface methods must be specified, because their
19
+ // arguments can vary from aggregator to aggregator.
20
+ //
21
+ // Function selector for aggregator initiateJob method
22
+ bytes4 aggInitiateJobSelector;
23
+ // Function selector for aggregator fulfill method
24
+ bytes4 aggFulfillSelector;
25
+ }
26
+
27
+ function decodeServiceAgreement(
28
+ bytes memory _serviceAgreementData
29
+ )
30
+ internal
31
+ pure
32
+ returns(ServiceAgreement memory)
33
+ {
34
+ // solhint-disable indent
35
+ ServiceAgreement memory agreement;
36
+
37
+ ( agreement.payment,
38
+ agreement.expiration,
39
+ agreement.endAt,
40
+ agreement.oracles,
41
+ agreement.requestDigest,
42
+ agreement.aggregator,
43
+ agreement.aggInitiateJobSelector,
44
+ agreement.aggFulfillSelector) =
45
+ abi.decode(
46
+ _serviceAgreementData,
47
+ ( uint256,
48
+ uint256,
49
+ uint256,
50
+ address[],
51
+ bytes32,
52
+ address,
53
+ bytes4,
54
+ bytes4 )
55
+ );
56
+
57
+ return agreement;
58
+ }
59
+ }