arr00-testing-oz-contracts 0.0.0 → 5.8.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 (507) hide show
  1. package/README.md +121 -0
  2. package/access/AccessControl.sol +206 -0
  3. package/access/IAccessControl.sol +98 -0
  4. package/access/Ownable.sol +100 -0
  5. package/access/Ownable2Step.sol +67 -0
  6. package/access/extensions/AccessControlDefaultAdminRules.sol +372 -0
  7. package/access/extensions/AccessControlEnumerable.sol +81 -0
  8. package/access/extensions/IAccessControlDefaultAdminRules.sol +192 -0
  9. package/access/extensions/IAccessControlEnumerable.sol +31 -0
  10. package/access/manager/AccessManaged.sol +118 -0
  11. package/access/manager/AccessManager.sol +781 -0
  12. package/access/manager/AuthorityUtils.sol +36 -0
  13. package/access/manager/IAccessManaged.sol +32 -0
  14. package/access/manager/IAccessManager.sol +410 -0
  15. package/access/manager/IAuthority.sol +14 -0
  16. package/account/Account.sol +151 -0
  17. package/account/extensions/draft-AccountERC7579.sol +430 -0
  18. package/account/extensions/draft-AccountERC7579Hooked.sol +113 -0
  19. package/account/extensions/draft-ERC7821.sol +70 -0
  20. package/account/paymaster/Paymaster.sol +170 -0
  21. package/account/paymaster/extensions/PaymasterERC20.sol +394 -0
  22. package/account/paymaster/extensions/PaymasterERC20Guarantor.sol +190 -0
  23. package/account/paymaster/extensions/PaymasterERC721Owner.sol +54 -0
  24. package/account/paymaster/extensions/PaymasterSigner.sol +125 -0
  25. package/account/utils/EIP7702Utils.sol +25 -0
  26. package/account/utils/ERC4337Utils.sol +317 -0
  27. package/account/utils/draft-ERC7579Utils.sol +314 -0
  28. package/build/contracts/AbstractSigner.json +13 -0
  29. package/build/contracts/AccessControl.json +239 -0
  30. package/build/contracts/AccessControlDefaultAdminRules.json +467 -0
  31. package/build/contracts/AccessControlEnumerable.json +301 -0
  32. package/build/contracts/AccessManaged.json +104 -0
  33. package/build/contracts/AccessManager.json +1189 -0
  34. package/build/contracts/Account.json +150 -0
  35. package/build/contracts/AccountERC7579.json +515 -0
  36. package/build/contracts/AccountERC7579Hooked.json +539 -0
  37. package/build/contracts/Accumulators.json +13 -0
  38. package/build/contracts/Address.json +25 -0
  39. package/build/contracts/Arrays.json +13 -0
  40. package/build/contracts/AuthorityUtils.json +13 -0
  41. package/build/contracts/Base58.json +25 -0
  42. package/build/contracts/Base64.json +25 -0
  43. package/build/contracts/BeaconProxy.json +97 -0
  44. package/build/contracts/BitMaps.json +13 -0
  45. package/build/contracts/BlockHeader.json +25 -0
  46. package/build/contracts/Blockhash.json +13 -0
  47. package/build/contracts/BridgeERC1155.json +508 -0
  48. package/build/contracts/BridgeERC20.json +260 -0
  49. package/build/contracts/BridgeERC721.json +270 -0
  50. package/build/contracts/BridgeERC7802.json +249 -0
  51. package/build/contracts/BridgeFungible.json +236 -0
  52. package/build/contracts/BridgeMultiToken.json +236 -0
  53. package/build/contracts/BridgeNonFungible.json +212 -0
  54. package/build/contracts/Bytes.json +13 -0
  55. package/build/contracts/CAIP10.json +13 -0
  56. package/build/contracts/CAIP2.json +13 -0
  57. package/build/contracts/Calldata.json +13 -0
  58. package/build/contracts/Checkpoints.json +19 -0
  59. package/build/contracts/CircularBuffer.json +19 -0
  60. package/build/contracts/Clones.json +19 -0
  61. package/build/contracts/Comparators.json +13 -0
  62. package/build/contracts/Context.json +13 -0
  63. package/build/contracts/Create2.json +19 -0
  64. package/build/contracts/Create3.json +19 -0
  65. package/build/contracts/CrosschainLinked.json +145 -0
  66. package/build/contracts/CrosschainRemoteExecutor.json +199 -0
  67. package/build/contracts/DoubleEndedQueue.json +13 -0
  68. package/build/contracts/ECDSA.json +41 -0
  69. package/build/contracts/EIP712.json +79 -0
  70. package/build/contracts/EIP7702Utils.json +13 -0
  71. package/build/contracts/ERC1155.json +428 -0
  72. package/build/contracts/ERC1155Burnable.json +474 -0
  73. package/build/contracts/ERC1155Crosschain.json +796 -0
  74. package/build/contracts/ERC1155Holder.json +111 -0
  75. package/build/contracts/ERC1155Pausable.json +477 -0
  76. package/build/contracts/ERC1155Supply.json +479 -0
  77. package/build/contracts/ERC1155URIStorage.json +428 -0
  78. package/build/contracts/ERC1155Utils.json +13 -0
  79. package/build/contracts/ERC1363.json +585 -0
  80. package/build/contracts/ERC1363Utils.json +36 -0
  81. package/build/contracts/ERC165.json +33 -0
  82. package/build/contracts/ERC165Checker.json +13 -0
  83. package/build/contracts/ERC1967Clones.json +13 -0
  84. package/build/contracts/ERC1967Proxy.json +84 -0
  85. package/build/contracts/ERC1967Utils.json +52 -0
  86. package/build/contracts/ERC20.json +322 -0
  87. package/build/contracts/ERC20Bridgeable.json +427 -0
  88. package/build/contracts/ERC20Burnable.json +353 -0
  89. package/build/contracts/ERC20Capped.json +362 -0
  90. package/build/contracts/ERC20Crosschain.json +573 -0
  91. package/build/contracts/ERC20FlashMint.json +432 -0
  92. package/build/contracts/ERC20Pausable.json +371 -0
  93. package/build/contracts/ERC20Permit.json +532 -0
  94. package/build/contracts/ERC20TemporaryApproval.json +346 -0
  95. package/build/contracts/ERC20TransferAuthorization.json +836 -0
  96. package/build/contracts/ERC20Votes.json +781 -0
  97. package/build/contracts/ERC20Wrapper.json +405 -0
  98. package/build/contracts/ERC2771Context.json +46 -0
  99. package/build/contracts/ERC2771Forwarder.json +439 -0
  100. package/build/contracts/ERC2981.json +126 -0
  101. package/build/contracts/ERC3009.json +668 -0
  102. package/build/contracts/ERC4337Utils.json +13 -0
  103. package/build/contracts/ERC4626.json +807 -0
  104. package/build/contracts/ERC6372Utils.json +19 -0
  105. package/build/contracts/ERC6909.json +415 -0
  106. package/build/contracts/ERC6909ContentURI.json +472 -0
  107. package/build/contracts/ERC6909Metadata.json +529 -0
  108. package/build/contracts/ERC6909TokenSupply.json +434 -0
  109. package/build/contracts/ERC721.json +447 -0
  110. package/build/contracts/ERC721Burnable.json +460 -0
  111. package/build/contracts/ERC721Consecutive.json +509 -0
  112. package/build/contracts/ERC721Crosschain.json +674 -0
  113. package/build/contracts/ERC721Enumerable.json +524 -0
  114. package/build/contracts/ERC721Holder.json +48 -0
  115. package/build/contracts/ERC721Pausable.json +496 -0
  116. package/build/contracts/ERC721Royalty.json +540 -0
  117. package/build/contracts/ERC721URIStorage.json +479 -0
  118. package/build/contracts/ERC721Utils.json +13 -0
  119. package/build/contracts/ERC721Votes.json +835 -0
  120. package/build/contracts/ERC721Wrapper.json +553 -0
  121. package/build/contracts/ERC7579Utils.json +119 -0
  122. package/build/contracts/ERC7739.json +103 -0
  123. package/build/contracts/ERC7739Utils.json +13 -0
  124. package/build/contracts/ERC7786Recipient.json +59 -0
  125. package/build/contracts/ERC7821.json +112 -0
  126. package/build/contracts/ERC7913P256Verifier.json +43 -0
  127. package/build/contracts/ERC7913RSAVerifier.json +43 -0
  128. package/build/contracts/ERC7913WebAuthnVerifier.json +43 -0
  129. package/build/contracts/EnumerableMap.json +36 -0
  130. package/build/contracts/EnumerableSet.json +13 -0
  131. package/build/contracts/Errors.json +51 -0
  132. package/build/contracts/Governor.json +1381 -0
  133. package/build/contracts/GovernorCountingFractional.json +1455 -0
  134. package/build/contracts/GovernorCountingOverridable.json +1612 -0
  135. package/build/contracts/GovernorCountingSimple.json +1410 -0
  136. package/build/contracts/GovernorCrosschain.json +1409 -0
  137. package/build/contracts/GovernorNoncesKeyed.json +1405 -0
  138. package/build/contracts/GovernorPreventLateQuorum.json +1461 -0
  139. package/build/contracts/GovernorProposalGuardian.json +1426 -0
  140. package/build/contracts/GovernorSequentialProposalId.json +1399 -0
  141. package/build/contracts/GovernorSettings.json +1477 -0
  142. package/build/contracts/GovernorStorage.json +1506 -0
  143. package/build/contracts/GovernorSuperQuorum.json +1429 -0
  144. package/build/contracts/GovernorTimelockAccess.json +1582 -0
  145. package/build/contracts/GovernorTimelockCompound.json +1449 -0
  146. package/build/contracts/GovernorTimelockControl.json +1426 -0
  147. package/build/contracts/GovernorVotes.json +1399 -0
  148. package/build/contracts/GovernorVotesQuorumFraction.json +1497 -0
  149. package/build/contracts/GovernorVotesSuperQuorumFraction.json +1657 -0
  150. package/build/contracts/Hashes.json +13 -0
  151. package/build/contracts/Heap.json +13 -0
  152. package/build/contracts/IAccessControl.json +207 -0
  153. package/build/contracts/IAccessControlDefaultAdminRules.json +406 -0
  154. package/build/contracts/IAccessControlEnumerable.json +250 -0
  155. package/build/contracts/IAccessManaged.json +104 -0
  156. package/build/contracts/IAccessManager.json +1085 -0
  157. package/build/contracts/IAccount.json +90 -0
  158. package/build/contracts/IAccountExecute.json +79 -0
  159. package/build/contracts/IAggregator.json +211 -0
  160. package/build/contracts/IAuthority.json +43 -0
  161. package/build/contracts/IBeacon.json +27 -0
  162. package/build/contracts/ICompoundTimelock.json +427 -0
  163. package/build/contracts/IERC1155.json +307 -0
  164. package/build/contracts/IERC1155Errors.json +116 -0
  165. package/build/contracts/IERC1155MetadataURI.json +326 -0
  166. package/build/contracts/IERC1155Receiver.json +111 -0
  167. package/build/contracts/IERC1271.json +38 -0
  168. package/build/contracts/IERC1363.json +385 -0
  169. package/build/contracts/IERC1363Receiver.json +48 -0
  170. package/build/contracts/IERC1363Spender.json +43 -0
  171. package/build/contracts/IERC165.json +33 -0
  172. package/build/contracts/IERC1820Implementer.json +38 -0
  173. package/build/contracts/IERC1820Registry.json +227 -0
  174. package/build/contracts/IERC1822Proxiable.json +27 -0
  175. package/build/contracts/IERC1967.json +59 -0
  176. package/build/contracts/IERC20.json +197 -0
  177. package/build/contracts/IERC20Errors.json +100 -0
  178. package/build/contracts/IERC20Metadata.json +236 -0
  179. package/build/contracts/IERC20Permit.json +89 -0
  180. package/build/contracts/IERC2309.json +45 -0
  181. package/build/contracts/IERC2612.json +89 -0
  182. package/build/contracts/IERC2981.json +62 -0
  183. package/build/contracts/IERC3009.json +163 -0
  184. package/build/contracts/IERC3009Cancel.json +66 -0
  185. package/build/contracts/IERC3156FlashBorrower.json +53 -0
  186. package/build/contracts/IERC3156FlashLender.json +91 -0
  187. package/build/contracts/IERC4626.json +626 -0
  188. package/build/contracts/IERC4906.json +331 -0
  189. package/build/contracts/IERC5267.json +63 -0
  190. package/build/contracts/IERC5313.json +27 -0
  191. package/build/contracts/IERC5805.json +233 -0
  192. package/build/contracts/IERC6372.json +40 -0
  193. package/build/contracts/IERC6909.json +319 -0
  194. package/build/contracts/IERC6909ContentURI.json +351 -0
  195. package/build/contracts/IERC6909Metadata.json +376 -0
  196. package/build/contracts/IERC6909TokenSupply.json +338 -0
  197. package/build/contracts/IERC721.json +299 -0
  198. package/build/contracts/IERC721Enumerable.json +355 -0
  199. package/build/contracts/IERC721Errors.json +117 -0
  200. package/build/contracts/IERC721Metadata.json +344 -0
  201. package/build/contracts/IERC721Receiver.json +48 -0
  202. package/build/contracts/IERC7579AccountConfig.json +65 -0
  203. package/build/contracts/IERC7579Execution.json +56 -0
  204. package/build/contracts/IERC7579Hook.json +101 -0
  205. package/build/contracts/IERC7579Module.json +59 -0
  206. package/build/contracts/IERC7579ModuleConfig.json +127 -0
  207. package/build/contracts/IERC7579Validator.json +159 -0
  208. package/build/contracts/IERC7674.json +221 -0
  209. package/build/contracts/IERC7751.json +40 -0
  210. package/build/contracts/IERC777.json +405 -0
  211. package/build/contracts/IERC777Recipient.json +52 -0
  212. package/build/contracts/IERC777Sender.json +52 -0
  213. package/build/contracts/IERC7786GatewaySource.json +116 -0
  214. package/build/contracts/IERC7786Recipient.json +43 -0
  215. package/build/contracts/IERC7802.json +119 -0
  216. package/build/contracts/IERC7821.json +51 -0
  217. package/build/contracts/IERC7913SignatureVerifier.json +43 -0
  218. package/build/contracts/IEntryPoint.json +305 -0
  219. package/build/contracts/IEntryPointExtra.json +80 -0
  220. package/build/contracts/IEntryPointNonces.json +38 -0
  221. package/build/contracts/IEntryPointStake.json +97 -0
  222. package/build/contracts/IGovernor.json +1095 -0
  223. package/build/contracts/IPaymaster.json +123 -0
  224. package/build/contracts/ITransparentUpgradeableProxy.json +77 -0
  225. package/build/contracts/IVotes.json +207 -0
  226. package/build/contracts/Initializable.json +37 -0
  227. package/build/contracts/InteroperableAddress.json +30 -0
  228. package/build/contracts/LowLevelCall.json +13 -0
  229. package/build/contracts/Math.json +13 -0
  230. package/build/contracts/Memory.json +13 -0
  231. package/build/contracts/MerkleProof.json +19 -0
  232. package/build/contracts/MerkleTree.json +35 -0
  233. package/build/contracts/MessageHashUtils.json +19 -0
  234. package/build/contracts/MultiSignerERC7913.json +176 -0
  235. package/build/contracts/MultiSignerERC7913Weighted.json +264 -0
  236. package/build/contracts/Multicall.json +49 -0
  237. package/build/contracts/Nonces.json +49 -0
  238. package/build/contracts/NoncesKeyed.json +73 -0
  239. package/build/contracts/Ownable.json +88 -0
  240. package/build/contracts/Ownable2Step.json +127 -0
  241. package/build/contracts/P256.json +13 -0
  242. package/build/contracts/Packing.json +19 -0
  243. package/build/contracts/Panic.json +13 -0
  244. package/build/contracts/Pausable.json +63 -0
  245. package/build/contracts/Paymaster.json +147 -0
  246. package/build/contracts/PaymasterERC20.json +209 -0
  247. package/build/contracts/PaymasterERC20Guarantor.json +234 -0
  248. package/build/contracts/PaymasterERC721Owner.json +160 -0
  249. package/build/contracts/PaymasterSigner.json +212 -0
  250. package/build/contracts/Proxy.json +18 -0
  251. package/build/contracts/ProxyAdmin.json +135 -0
  252. package/build/contracts/RLP.json +19 -0
  253. package/build/contracts/RSA.json +13 -0
  254. package/build/contracts/RateLimiter.json +19 -0
  255. package/build/contracts/ReentrancyGuard.json +19 -0
  256. package/build/contracts/ReentrancyGuardTransient.json +19 -0
  257. package/build/contracts/RelayedCall.json +13 -0
  258. package/build/contracts/SafeCast.json +68 -0
  259. package/build/contracts/SafeERC20.json +46 -0
  260. package/build/contracts/ShortStrings.json +30 -0
  261. package/build/contracts/SignatureChecker.json +13 -0
  262. package/build/contracts/SignedMath.json +13 -0
  263. package/build/contracts/SignerECDSA.json +27 -0
  264. package/build/contracts/SignerEIP7702.json +13 -0
  265. package/build/contracts/SignerERC7913.json +27 -0
  266. package/build/contracts/SignerP256.json +48 -0
  267. package/build/contracts/SignerRSA.json +32 -0
  268. package/build/contracts/SignerWebAuthn.json +48 -0
  269. package/build/contracts/SimulateCall.json +13 -0
  270. package/build/contracts/SlotDerivation.json +13 -0
  271. package/build/contracts/StorageSlot.json +13 -0
  272. package/build/contracts/Strings.json +40 -0
  273. package/build/contracts/Time.json +13 -0
  274. package/build/contracts/TimelockController.json +1010 -0
  275. package/build/contracts/TransientSlot.json +13 -0
  276. package/build/contracts/TransparentUpgradeableProxy.json +131 -0
  277. package/build/contracts/TrieProof.json +25 -0
  278. package/build/contracts/UUPSUpgradeable.json +119 -0
  279. package/build/contracts/UpgradeableBeacon.json +154 -0
  280. package/build/contracts/VestingWallet.json +364 -0
  281. package/build/contracts/VestingWalletCliff.json +367 -0
  282. package/build/contracts/Votes.json +402 -0
  283. package/build/contracts/VotesExtended.json +450 -0
  284. package/build/contracts/WebAuthn.json +13 -0
  285. package/crosschain/CrosschainLinked.sol +114 -0
  286. package/crosschain/CrosschainRemoteExecutor.sol +99 -0
  287. package/crosschain/ERC7786Recipient.sol +66 -0
  288. package/crosschain/bridges/BridgeERC1155.sol +131 -0
  289. package/crosschain/bridges/BridgeERC20.sol +42 -0
  290. package/crosschain/bridges/BridgeERC721.sol +62 -0
  291. package/crosschain/bridges/BridgeERC7802.sol +34 -0
  292. package/crosschain/bridges/abstract/BridgeFungible.sol +86 -0
  293. package/crosschain/bridges/abstract/BridgeMultiToken.sol +99 -0
  294. package/crosschain/bridges/abstract/BridgeNonFungible.sol +79 -0
  295. package/finance/VestingWallet.sol +160 -0
  296. package/finance/VestingWalletCliff.sol +55 -0
  297. package/governance/Governor.sol +825 -0
  298. package/governance/IGovernor.sol +454 -0
  299. package/governance/TimelockController.sol +470 -0
  300. package/governance/extensions/GovernorCountingFractional.sol +190 -0
  301. package/governance/extensions/GovernorCountingOverridable.sol +226 -0
  302. package/governance/extensions/GovernorCountingSimple.sol +96 -0
  303. package/governance/extensions/GovernorCrosschain.sol +31 -0
  304. package/governance/extensions/GovernorNoncesKeyed.sol +91 -0
  305. package/governance/extensions/GovernorPreventLateQuorum.sol +119 -0
  306. package/governance/extensions/GovernorProposalGuardian.sol +59 -0
  307. package/governance/extensions/GovernorSequentialProposalId.sol +75 -0
  308. package/governance/extensions/GovernorSettings.sol +106 -0
  309. package/governance/extensions/GovernorStorage.sol +134 -0
  310. package/governance/extensions/GovernorSuperQuorum.sol +59 -0
  311. package/governance/extensions/GovernorTimelockAccess.sol +346 -0
  312. package/governance/extensions/GovernorTimelockCompound.sol +162 -0
  313. package/governance/extensions/GovernorTimelockControl.sol +167 -0
  314. package/governance/extensions/GovernorVotes.sol +64 -0
  315. package/governance/extensions/GovernorVotesQuorumFraction.sol +113 -0
  316. package/governance/extensions/GovernorVotesSuperQuorumFraction.sol +135 -0
  317. package/governance/utils/IVotes.sol +60 -0
  318. package/governance/utils/Votes.sol +245 -0
  319. package/governance/utils/VotesExtended.sol +85 -0
  320. package/interfaces/IERC1155.sol +6 -0
  321. package/interfaces/IERC1155MetadataURI.sol +6 -0
  322. package/interfaces/IERC1155Receiver.sol +6 -0
  323. package/interfaces/IERC1271.sol +17 -0
  324. package/interfaces/IERC1363.sol +86 -0
  325. package/interfaces/IERC1363Receiver.sol +32 -0
  326. package/interfaces/IERC1363Spender.sol +26 -0
  327. package/interfaces/IERC165.sol +6 -0
  328. package/interfaces/IERC1820Implementer.sol +20 -0
  329. package/interfaces/IERC1820Registry.sol +112 -0
  330. package/interfaces/IERC1967.sol +24 -0
  331. package/interfaces/IERC20.sol +6 -0
  332. package/interfaces/IERC20Metadata.sol +6 -0
  333. package/interfaces/IERC2309.sol +19 -0
  334. package/interfaces/IERC2612.sol +8 -0
  335. package/interfaces/IERC2981.sol +26 -0
  336. package/interfaces/IERC3156.sol +7 -0
  337. package/interfaces/IERC3156FlashBorrower.sol +27 -0
  338. package/interfaces/IERC3156FlashLender.sol +41 -0
  339. package/interfaces/IERC4337.sol +255 -0
  340. package/interfaces/IERC4626.sol +230 -0
  341. package/interfaces/IERC4906.sol +20 -0
  342. package/interfaces/IERC5267.sol +28 -0
  343. package/interfaces/IERC5313.sol +16 -0
  344. package/interfaces/IERC5805.sol +9 -0
  345. package/interfaces/IERC6093.sol +162 -0
  346. package/interfaces/IERC6372.sol +19 -0
  347. package/interfaces/IERC6909.sol +131 -0
  348. package/interfaces/IERC721.sol +6 -0
  349. package/interfaces/IERC721Enumerable.sol +6 -0
  350. package/interfaces/IERC721Metadata.sol +6 -0
  351. package/interfaces/IERC721Receiver.sol +6 -0
  352. package/interfaces/IERC7751.sol +12 -0
  353. package/interfaces/IERC777.sol +200 -0
  354. package/interfaces/IERC777Recipient.sol +35 -0
  355. package/interfaces/IERC777Sender.sol +35 -0
  356. package/interfaces/IERC7786.sol +64 -0
  357. package/interfaces/IERC7913.sol +18 -0
  358. package/interfaces/draft-IERC1822.sol +20 -0
  359. package/interfaces/draft-IERC3009.sol +87 -0
  360. package/interfaces/draft-IERC7579.sol +227 -0
  361. package/interfaces/draft-IERC7674.sol +17 -0
  362. package/interfaces/draft-IERC7802.sol +32 -0
  363. package/interfaces/draft-IERC7821.sol +44 -0
  364. package/metatx/ERC2771Context.sol +90 -0
  365. package/metatx/ERC2771Forwarder.sol +376 -0
  366. package/package.json +29 -1
  367. package/proxy/Clones.sol +294 -0
  368. package/proxy/ERC1967/ERC1967Clones.sol +219 -0
  369. package/proxy/ERC1967/ERC1967Proxy.sol +62 -0
  370. package/proxy/ERC1967/ERC1967Utils.sol +177 -0
  371. package/proxy/Proxy.sol +69 -0
  372. package/proxy/beacon/BeaconProxy.sol +57 -0
  373. package/proxy/beacon/IBeacon.sol +16 -0
  374. package/proxy/beacon/UpgradeableBeacon.sol +70 -0
  375. package/proxy/transparent/ProxyAdmin.sol +45 -0
  376. package/proxy/transparent/TransparentUpgradeableProxy.sol +118 -0
  377. package/proxy/utils/Initializable.sol +238 -0
  378. package/proxy/utils/UUPSUpgradeable.sol +148 -0
  379. package/token/ERC1155/ERC1155.sol +417 -0
  380. package/token/ERC1155/IERC1155.sol +123 -0
  381. package/token/ERC1155/IERC1155Receiver.sol +59 -0
  382. package/token/ERC1155/extensions/ERC1155Burnable.sol +22 -0
  383. package/token/ERC1155/extensions/ERC1155Crosschain.sol +87 -0
  384. package/token/ERC1155/extensions/ERC1155Pausable.sol +38 -0
  385. package/token/ERC1155/extensions/ERC1155Supply.sol +88 -0
  386. package/token/ERC1155/extensions/ERC1155URIStorage.sol +58 -0
  387. package/token/ERC1155/extensions/IERC1155MetadataURI.sol +20 -0
  388. package/token/ERC1155/utils/ERC1155Holder.sol +42 -0
  389. package/token/ERC1155/utils/ERC1155Utils.sol +88 -0
  390. package/token/ERC20/ERC20.sol +305 -0
  391. package/token/ERC20/IERC20.sol +79 -0
  392. package/token/ERC20/extensions/ERC1363.sol +135 -0
  393. package/token/ERC20/extensions/ERC20Burnable.sol +38 -0
  394. package/token/ERC20/extensions/ERC20Capped.sol +54 -0
  395. package/token/ERC20/extensions/ERC20Crosschain.sol +39 -0
  396. package/token/ERC20/extensions/ERC20FlashMint.sol +130 -0
  397. package/token/ERC20/extensions/ERC20Pausable.sol +33 -0
  398. package/token/ERC20/extensions/ERC20Permit.sol +77 -0
  399. package/token/ERC20/extensions/ERC20TransferAuthorization.sol +91 -0
  400. package/token/ERC20/extensions/ERC20Votes.sol +83 -0
  401. package/token/ERC20/extensions/ERC20Wrapper.sol +93 -0
  402. package/token/ERC20/extensions/ERC4626.sol +304 -0
  403. package/token/ERC20/extensions/IERC20Metadata.sol +26 -0
  404. package/token/ERC20/extensions/IERC20Permit.sol +90 -0
  405. package/token/ERC20/extensions/draft-ERC20Bridgeable.sol +51 -0
  406. package/token/ERC20/extensions/draft-ERC20TemporaryApproval.sol +119 -0
  407. package/token/ERC20/extensions/draft-ERC3009.sol +152 -0
  408. package/token/ERC20/utils/ERC1363Utils.sol +95 -0
  409. package/token/ERC20/utils/SafeERC20.sol +292 -0
  410. package/token/ERC6909/ERC6909.sol +224 -0
  411. package/token/ERC6909/extensions/ERC6909ContentURI.sol +59 -0
  412. package/token/ERC6909/extensions/ERC6909Metadata.sol +83 -0
  413. package/token/ERC6909/extensions/ERC6909TokenSupply.sol +41 -0
  414. package/token/ERC721/ERC721.sol +433 -0
  415. package/token/ERC721/IERC721.sol +135 -0
  416. package/token/ERC721/IERC721Receiver.sol +28 -0
  417. package/token/ERC721/extensions/ERC721Burnable.sol +26 -0
  418. package/token/ERC721/extensions/ERC721Consecutive.sol +176 -0
  419. package/token/ERC721/extensions/ERC721Crosschain.sol +38 -0
  420. package/token/ERC721/extensions/ERC721Enumerable.sol +165 -0
  421. package/token/ERC721/extensions/ERC721Pausable.sol +37 -0
  422. package/token/ERC721/extensions/ERC721Royalty.sol +26 -0
  423. package/token/ERC721/extensions/ERC721URIStorage.sol +62 -0
  424. package/token/ERC721/extensions/ERC721Votes.sol +47 -0
  425. package/token/ERC721/extensions/ERC721Wrapper.sol +102 -0
  426. package/token/ERC721/extensions/IERC721Enumerable.sol +29 -0
  427. package/token/ERC721/extensions/IERC721Metadata.sol +27 -0
  428. package/token/ERC721/utils/ERC721Holder.sol +26 -0
  429. package/token/ERC721/utils/ERC721Utils.sol +50 -0
  430. package/token/common/ERC2981.sol +140 -0
  431. package/utils/Address.sol +167 -0
  432. package/utils/Arrays.sol +905 -0
  433. package/utils/Base58.sol +240 -0
  434. package/utils/Base64.sol +234 -0
  435. package/utils/BlockHeader.sol +312 -0
  436. package/utils/Blockhash.sol +54 -0
  437. package/utils/Bytes.sol +329 -0
  438. package/utils/CAIP10.sol +54 -0
  439. package/utils/CAIP2.sol +51 -0
  440. package/utils/Calldata.sol +25 -0
  441. package/utils/Comparators.sol +19 -0
  442. package/utils/Context.sol +28 -0
  443. package/utils/Create2.sol +91 -0
  444. package/utils/Create3.sol +133 -0
  445. package/utils/ERC6372Utils.sol +53 -0
  446. package/utils/Errors.sol +34 -0
  447. package/utils/LowLevelCall.sol +127 -0
  448. package/utils/Memory.sol +151 -0
  449. package/utils/Multicall.sol +37 -0
  450. package/utils/Nonces.sol +47 -0
  451. package/utils/NoncesKeyed.sol +75 -0
  452. package/utils/Packing.sol +1656 -0
  453. package/utils/Panic.sol +57 -0
  454. package/utils/Pausable.sol +112 -0
  455. package/utils/RLP.sol +487 -0
  456. package/utils/RateLimiter.sol +310 -0
  457. package/utils/ReentrancyGuard.sol +119 -0
  458. package/utils/ReentrancyGuardTransient.sol +84 -0
  459. package/utils/RelayedCall.sol +145 -0
  460. package/utils/ShortStrings.sol +122 -0
  461. package/utils/SimulateCall.sol +114 -0
  462. package/utils/SlotDerivation.sol +155 -0
  463. package/utils/StorageSlot.sol +143 -0
  464. package/utils/Strings.sol +532 -0
  465. package/utils/TransientSlot.sol +183 -0
  466. package/utils/cryptography/ECDSA.sol +284 -0
  467. package/utils/cryptography/EIP712.sol +168 -0
  468. package/utils/cryptography/Hashes.sol +31 -0
  469. package/utils/cryptography/MerkleProof.sol +510 -0
  470. package/utils/cryptography/MessageHashUtils.sol +228 -0
  471. package/utils/cryptography/P256.sol +409 -0
  472. package/utils/cryptography/RSA.sol +159 -0
  473. package/utils/cryptography/SignatureChecker.sol +199 -0
  474. package/utils/cryptography/TrieProof.sol +256 -0
  475. package/utils/cryptography/WebAuthn.sol +269 -0
  476. package/utils/cryptography/draft-ERC7739Utils.sol +215 -0
  477. package/utils/cryptography/signers/AbstractSigner.sol +23 -0
  478. package/utils/cryptography/signers/MultiSignerERC7913.sol +336 -0
  479. package/utils/cryptography/signers/MultiSignerERC7913Weighted.sol +208 -0
  480. package/utils/cryptography/signers/SignerECDSA.sol +56 -0
  481. package/utils/cryptography/signers/SignerEIP7702.sol +25 -0
  482. package/utils/cryptography/signers/SignerERC7913.sol +63 -0
  483. package/utils/cryptography/signers/SignerP256.sol +64 -0
  484. package/utils/cryptography/signers/SignerRSA.sol +65 -0
  485. package/utils/cryptography/signers/SignerWebAuthn.sol +45 -0
  486. package/utils/cryptography/signers/draft-ERC7739.sol +99 -0
  487. package/utils/cryptography/verifiers/ERC7913P256Verifier.sol +29 -0
  488. package/utils/cryptography/verifiers/ERC7913RSAVerifier.sol +23 -0
  489. package/utils/cryptography/verifiers/ERC7913WebAuthnVerifier.sol +45 -0
  490. package/utils/draft-InteroperableAddress.sol +245 -0
  491. package/utils/introspection/ERC165.sol +25 -0
  492. package/utils/introspection/ERC165Checker.sol +142 -0
  493. package/utils/introspection/IERC165.sol +25 -0
  494. package/utils/math/Math.sol +763 -0
  495. package/utils/math/SafeCast.sol +1162 -0
  496. package/utils/math/SignedMath.sol +68 -0
  497. package/utils/structs/Accumulators.sol +135 -0
  498. package/utils/structs/BitMaps.sol +61 -0
  499. package/utils/structs/Checkpoints.sol +881 -0
  500. package/utils/structs/CircularBuffer.sol +152 -0
  501. package/utils/structs/DoubleEndedQueue.sol +280 -0
  502. package/utils/structs/EnumerableMap.sol +1870 -0
  503. package/utils/structs/EnumerableSet.sol +1177 -0
  504. package/utils/structs/Heap.sol +259 -0
  505. package/utils/structs/MerkleTree.sol +267 -0
  506. package/utils/types/Time.sol +133 -0
  507. package/vendor/compound/ICompoundTimelock.sol +86 -0
@@ -0,0 +1,228 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.6.0) (utils/cryptography/MessageHashUtils.sol)
3
+
4
+ pragma solidity ^0.8.24;
5
+
6
+ import {Strings} from "../Strings.sol";
7
+
8
+ /**
9
+ * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
10
+ *
11
+ * The library provides methods for generating a hash of a message that conforms to the
12
+ * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
13
+ * specifications.
14
+ */
15
+ library MessageHashUtils {
16
+ error ERC5267ExtensionsNotSupported();
17
+
18
+ /**
19
+ * @dev Returns the keccak256 digest of an ERC-191 signed data with version
20
+ * `0x45` (`personal_sign` messages).
21
+ *
22
+ * The digest is calculated by prefixing a bytes32 `messageHash` with
23
+ * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
24
+ * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
25
+ *
26
+ * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
27
+ * keccak256, although any bytes32 value can be safely used because the final digest will
28
+ * be re-hashed.
29
+ *
30
+ * See {ECDSA-recover}.
31
+ */
32
+ function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
33
+ assembly ("memory-safe") {
34
+ mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
35
+ mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
36
+ digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
37
+ }
38
+ }
39
+
40
+ /**
41
+ * @dev Returns the keccak256 digest of an ERC-191 signed data with version
42
+ * `0x45` (`personal_sign` messages).
43
+ *
44
+ * The digest is calculated by prefixing an arbitrary `message` with
45
+ * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
46
+ * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
47
+ *
48
+ * See {ECDSA-recover}.
49
+ */
50
+ function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
51
+ return
52
+ keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
53
+ }
54
+
55
+ /**
56
+ * @dev Returns the keccak256 digest of an ERC-191 signed data with version
57
+ * `0x00` (data with intended validator).
58
+ *
59
+ * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
60
+ * `validator` address. Then hashing the result.
61
+ *
62
+ * See {ECDSA-recover}.
63
+ */
64
+ function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
65
+ return keccak256(abi.encodePacked(hex"19_00", validator, data));
66
+ }
67
+
68
+ /**
69
+ * @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.
70
+ */
71
+ function toDataWithIntendedValidatorHash(
72
+ address validator,
73
+ bytes32 messageHash
74
+ ) internal pure returns (bytes32 digest) {
75
+ assembly ("memory-safe") {
76
+ mstore(0x00, hex"19_00")
77
+ mstore(0x02, shl(96, validator))
78
+ mstore(0x16, messageHash)
79
+ digest := keccak256(0x00, 0x36)
80
+ }
81
+ }
82
+
83
+ /**
84
+ * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).
85
+ *
86
+ * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
87
+ * `\x19\x01` and hashing the result. It corresponds to the hash signed by the
88
+ * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
89
+ *
90
+ * See {ECDSA-recover}.
91
+ */
92
+ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
93
+ assembly ("memory-safe") {
94
+ let ptr := mload(0x40)
95
+ mstore(ptr, hex"19_01")
96
+ mstore(add(ptr, 0x02), domainSeparator)
97
+ mstore(add(ptr, 0x22), structHash)
98
+ digest := keccak256(ptr, 0x42)
99
+ }
100
+ }
101
+
102
+ /**
103
+ * @dev Returns the EIP-712 domain separator constructed from an `eip712Domain`. See {IERC5267-eip712Domain}
104
+ *
105
+ * This function dynamically constructs the domain separator based on which fields are present in the
106
+ * `fields` parameter. It contains flags that indicate which domain fields are present:
107
+ *
108
+ * * Bit 0 (0x01): name
109
+ * * Bit 1 (0x02): version
110
+ * * Bit 2 (0x04): chainId
111
+ * * Bit 3 (0x08): verifyingContract
112
+ * * Bit 4 (0x10): salt
113
+ *
114
+ * Arguments that correspond to fields which are not present in `fields` are ignored. For example, if `fields` is
115
+ * `0x0f` (`0b01111`), then the `salt` parameter is ignored.
116
+ */
117
+ function toDomainSeparator(
118
+ bytes1 fields,
119
+ string memory name,
120
+ string memory version,
121
+ uint256 chainId,
122
+ address verifyingContract,
123
+ bytes32 salt
124
+ ) internal pure returns (bytes32 hash) {
125
+ return
126
+ toDomainSeparator(
127
+ fields,
128
+ keccak256(bytes(name)),
129
+ keccak256(bytes(version)),
130
+ chainId,
131
+ verifyingContract,
132
+ salt
133
+ );
134
+ }
135
+
136
+ /// @dev Variant of {toDomainSeparator-bytes1-string-string-uint256-address-bytes32} that uses hashed name and version.
137
+ function toDomainSeparator(
138
+ bytes1 fields,
139
+ bytes32 nameHash,
140
+ bytes32 versionHash,
141
+ uint256 chainId,
142
+ address verifyingContract,
143
+ bytes32 salt
144
+ ) internal pure returns (bytes32 hash) {
145
+ bytes32 domainTypeHash = toDomainTypeHash(fields);
146
+
147
+ assembly ("memory-safe") {
148
+ // align fields to the right for easy processing
149
+ fields := shr(248, fields)
150
+
151
+ // FMP used as scratch space
152
+ let fmp := mload(0x40)
153
+ mstore(fmp, domainTypeHash)
154
+
155
+ let ptr := add(fmp, 0x20)
156
+ if and(fields, 0x01) {
157
+ mstore(ptr, nameHash)
158
+ ptr := add(ptr, 0x20)
159
+ }
160
+ if and(fields, 0x02) {
161
+ mstore(ptr, versionHash)
162
+ ptr := add(ptr, 0x20)
163
+ }
164
+ if and(fields, 0x04) {
165
+ mstore(ptr, chainId)
166
+ ptr := add(ptr, 0x20)
167
+ }
168
+ if and(fields, 0x08) {
169
+ mstore(ptr, verifyingContract)
170
+ ptr := add(ptr, 0x20)
171
+ }
172
+ if and(fields, 0x10) {
173
+ mstore(ptr, salt)
174
+ ptr := add(ptr, 0x20)
175
+ }
176
+
177
+ hash := keccak256(fmp, sub(ptr, fmp))
178
+ }
179
+ }
180
+
181
+ /// @dev Builds an EIP-712 domain type hash depending on the `fields` provided, following https://eips.ethereum.org/EIPS/eip-5267[ERC-5267]
182
+ function toDomainTypeHash(bytes1 fields) internal pure returns (bytes32 hash) {
183
+ if (fields & 0x20 == 0x20) revert ERC5267ExtensionsNotSupported();
184
+
185
+ assembly ("memory-safe") {
186
+ // align fields to the right for easy processing
187
+ fields := shr(248, fields)
188
+
189
+ // FMP used as scratch space
190
+ let fmp := mload(0x40)
191
+ mstore(fmp, "EIP712Domain(")
192
+
193
+ let ptr := add(fmp, 0x0d)
194
+ // name field
195
+ if and(fields, 0x01) {
196
+ mstore(ptr, "string name,")
197
+ ptr := add(ptr, 0x0c)
198
+ }
199
+ // version field
200
+ if and(fields, 0x02) {
201
+ mstore(ptr, "string version,")
202
+ ptr := add(ptr, 0x0f)
203
+ }
204
+ // chainId field
205
+ if and(fields, 0x04) {
206
+ mstore(ptr, "uint256 chainId,")
207
+ ptr := add(ptr, 0x10)
208
+ }
209
+ // verifyingContract field
210
+ if and(fields, 0x08) {
211
+ mstore(ptr, "address verifyingContract,")
212
+ ptr := add(ptr, 0x1a)
213
+ }
214
+ // salt field
215
+ if and(fields, 0x10) {
216
+ mstore(ptr, "bytes32 salt,")
217
+ ptr := add(ptr, 0x0d)
218
+ }
219
+ // if any field is enabled, remove the trailing comma
220
+ ptr := sub(ptr, iszero(iszero(and(fields, 0x1f))))
221
+ // add the closing brace
222
+ mstore8(ptr, 0x29) // add closing brace
223
+ ptr := add(ptr, 1)
224
+
225
+ hash := keccak256(fmp, sub(ptr, fmp))
226
+ }
227
+ }
228
+ }
@@ -0,0 +1,409 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Contracts (last updated v5.8.0) (utils/cryptography/P256.sol)
3
+
4
+ pragma solidity ^0.8.20;
5
+
6
+ import {Errors} from "../Errors.sol";
7
+ import {Math} from "../math/Math.sol";
8
+
9
+ /**
10
+ * @dev Implementation of secp256r1 verification and recovery functions.
11
+ *
12
+ * The secp256r1 curve (also known as P256) is a NIST standard curve with wide support in modern devices
13
+ * and cryptographic standards. Some notable examples include Apple's Secure Enclave and Android's Keystore
14
+ * as well as authentication protocols like FIDO2.
15
+ *
16
+ * Based on the original https://github.com/itsobvioustech/aa-passkeys-wallet/blob/d3d423f28a4d8dfcb203c7fa0c47f42592a7378e/src/Secp256r1.sol[implementation of itsobvioustech] (GNU General Public License v3.0).
17
+ * Heavily inspired in https://github.com/maxrobot/elliptic-solidity/blob/c4bb1b6e8ae89534d8db3a6b3a6b52219100520f/contracts/Secp256r1.sol[maxrobot] and
18
+ * https://github.com/tdrerup/elliptic-curve-solidity/blob/59a9c25957d4d190eff53b6610731d81a077a15e/contracts/curves/EllipticCurve.sol[tdrerup] implementations.
19
+ *
20
+ * _Available since v5.1._
21
+ */
22
+ library P256 {
23
+ struct JPoint {
24
+ uint256 x;
25
+ uint256 y;
26
+ uint256 z;
27
+ }
28
+
29
+ /// @dev Generator (x component)
30
+ uint256 internal constant GX = 0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296;
31
+ /// @dev Generator (y component)
32
+ uint256 internal constant GY = 0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5;
33
+ /// @dev P (size of the field)
34
+ uint256 internal constant P = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF;
35
+ /// @dev N (order of G)
36
+ uint256 internal constant N = 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551;
37
+ /// @dev A parameter of the weierstrass equation
38
+ uint256 internal constant A = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC;
39
+ /// @dev B parameter of the weierstrass equation
40
+ uint256 internal constant B = 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B;
41
+
42
+ /// @dev (P + 1) / 4. Useful to compute sqrt
43
+ uint256 private constant P1DIV4 = 0x3fffffffc0000000400000000000000000000000400000000000000000000000;
44
+
45
+ /// @dev N/2 for excluding higher order `s` values
46
+ uint256 private constant HALF_N = 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5617e3192a8;
47
+
48
+ /**
49
+ * @dev Verifies a secp256r1 signature using the RIP-7212 precompile and falls back to the Solidity implementation
50
+ * if the precompile is not available. This version should work on all chains, but requires the deployment of more
51
+ * bytecode.
52
+ *
53
+ * @param h - hashed message
54
+ * @param r - signature half R
55
+ * @param s - signature half S
56
+ * @param qx - public key coordinate X
57
+ * @param qy - public key coordinate Y
58
+ *
59
+ * IMPORTANT: This function disallows signatures where the `s` value is above `N/2` to prevent malleability.
60
+ * To flip the `s` value, compute `s = N - s`.
61
+ */
62
+ function verify(bytes32 h, bytes32 r, bytes32 s, bytes32 qx, bytes32 qy) internal view returns (bool) {
63
+ (bool valid, bool supported) = _tryVerifyNative(h, r, s, qx, qy);
64
+ return supported ? valid : verifySolidity(h, r, s, qx, qy);
65
+ }
66
+
67
+ /**
68
+ * @dev Same as {verify}, but it will revert if the required precompile is not available.
69
+ *
70
+ * Make sure any logic (code or precompile) deployed at that address is the expected one,
71
+ * otherwise the returned value may be misinterpreted as a positive boolean.
72
+ */
73
+ function verifyNative(bytes32 h, bytes32 r, bytes32 s, bytes32 qx, bytes32 qy) internal view returns (bool) {
74
+ (bool valid, bool supported) = _tryVerifyNative(h, r, s, qx, qy);
75
+ if (supported) {
76
+ return valid;
77
+ } else {
78
+ revert Errors.MissingPrecompile(address(0x100));
79
+ }
80
+ }
81
+
82
+ /**
83
+ * @dev Same as {verify}, but it will return false if the required precompile is not available.
84
+ */
85
+ function _tryVerifyNative(
86
+ bytes32 h,
87
+ bytes32 r,
88
+ bytes32 s,
89
+ bytes32 qx,
90
+ bytes32 qy
91
+ ) private view returns (bool valid, bool supported) {
92
+ if (!_isProperSignature(r, s) || !isValidPublicKey(qx, qy)) {
93
+ return (false, true); // signature is invalid, and it's not because the precompile is missing
94
+ } else if (_rip7212(h, r, s, qx, qy)) {
95
+ return (true, true); // precompile is present, signature is valid
96
+ } else if (
97
+ // Given precompiles have no bytecode (i.e. `address(0x100).code.length == 0`), we use
98
+ // a valid signature with small `r` and `s` values to check if the precompile is present. Taken from
99
+ // https://github.com/C2SP/wycheproof/blob/4672ff74d68766e7785c2cac4c597effccef2c5c/testvectors/ecdsa_secp256r1_sha256_p1363_test.json#L1173-L1204
100
+ _rip7212(
101
+ 0xbb5a52f42f9c9261ed4361f59422a1e30036e7c32b270c8807a419feca605023, // sha256("123400")
102
+ 0x0000000000000000000000000000000000000000000000000000000000000005,
103
+ 0x0000000000000000000000000000000000000000000000000000000000000001,
104
+ 0xa71af64de5126a4a4e02b7922d66ce9415ce88a4c9d25514d91082c8725ac957,
105
+ 0x5d47723c8fbe580bb369fec9c2665d8e30a435b9932645482e7c9f11e872296b
106
+ )
107
+ ) {
108
+ return (false, true); // precompile is present, signature is invalid
109
+ } else {
110
+ return (false, false); // precompile is absent
111
+ }
112
+ }
113
+
114
+ /**
115
+ * @dev Low level helper for {_tryVerifyNative}. Calls the precompile and checks if there is a return value.
116
+ */
117
+ function _rip7212(bytes32 h, bytes32 r, bytes32 s, bytes32 qx, bytes32 qy) private view returns (bool isValid) {
118
+ assembly ("memory-safe") {
119
+ // Use the free memory pointer without updating it at the end of the function
120
+ let ptr := mload(0x40)
121
+ mstore(ptr, h)
122
+ mstore(add(ptr, 0x20), r)
123
+ mstore(add(ptr, 0x40), s)
124
+ mstore(add(ptr, 0x60), qx)
125
+ mstore(add(ptr, 0x80), qy)
126
+ // RIP-7212 precompiles return empty bytes when an invalid signature is passed, making it impossible
127
+ // to distinguish the presence of the precompile. Custom precompile implementations may decide to
128
+ // return `bytes32(0)` (i.e. false) without developers noticing, so we decide to evaluate the return value
129
+ // without expanding memory using scratch space.
130
+ mstore(0x00, 0) // zero out scratch space in case the precompile doesn't return anything
131
+ if iszero(staticcall(gas(), 0x100, ptr, 0xa0, 0x00, 0x20)) {
132
+ invalid()
133
+ }
134
+ isValid := mload(0x00)
135
+ }
136
+ }
137
+
138
+ /**
139
+ * @dev Same as {verify}, but only the Solidity implementation is used.
140
+ */
141
+ function verifySolidity(bytes32 h, bytes32 r, bytes32 s, bytes32 qx, bytes32 qy) internal view returns (bool) {
142
+ if (!_isProperSignature(r, s) || !isValidPublicKey(qx, qy)) {
143
+ return false;
144
+ }
145
+
146
+ JPoint[16] memory points = _preComputeJacobianPoints(uint256(qx), uint256(qy));
147
+ uint256 w = Math.invModPrime(uint256(s), N);
148
+ uint256 u1 = mulmod(uint256(h), w, N);
149
+ uint256 u2 = mulmod(uint256(r), w, N);
150
+ (uint256 x, ) = _jMultShamir(points, u1, u2);
151
+ return ((x % N) == uint256(r));
152
+ }
153
+
154
+ /**
155
+ * @dev Public key recovery
156
+ *
157
+ * @param h - hashed message
158
+ * @param v - signature recovery param
159
+ * @param r - signature half R
160
+ * @param s - signature half S
161
+ *
162
+ * IMPORTANT: This function disallows signatures where the `s` value is above `N/2` to prevent malleability.
163
+ * To flip the `s` value, compute `s = N - s` and `v = 1 - v` if (`v = 0 | 1`).
164
+ */
165
+ function recovery(bytes32 h, uint8 v, bytes32 r, bytes32 s) internal view returns (bytes32 x, bytes32 y) {
166
+ if (!_isProperSignature(r, s) || v > 1) {
167
+ return (0, 0);
168
+ }
169
+
170
+ uint256 p = P; // cache P on the stack
171
+ uint256 rx = uint256(r);
172
+ uint256 ry2 = addmod(mulmod(addmod(mulmod(rx, rx, p), A, p), rx, p), B, p); // weierstrass equation y² = x³ + a.x + b
173
+ uint256 ry = Math.modExp(ry2, P1DIV4, p); // This formula for sqrt work because P ≡ 3 (mod 4)
174
+ if (mulmod(ry, ry, p) != ry2) return (0, 0); // Sanity check
175
+ if (ry % 2 != v) ry = p - ry;
176
+
177
+ JPoint[16] memory points = _preComputeJacobianPoints(rx, ry);
178
+ uint256 w = Math.invModPrime(uint256(r), N);
179
+ uint256 u1 = mulmod(N - (uint256(h) % N), w, N);
180
+ uint256 u2 = mulmod(uint256(s), w, N);
181
+ (uint256 xU, uint256 yU) = _jMultShamir(points, u1, u2);
182
+ return (bytes32(xU), bytes32(yU));
183
+ }
184
+
185
+ /**
186
+ * @dev Checks if (x, y) are valid coordinates of a point on the curve.
187
+ * In particular this function checks that x < P and y < P.
188
+ */
189
+ function isValidPublicKey(bytes32 x, bytes32 y) internal pure returns (bool result) {
190
+ assembly ("memory-safe") {
191
+ let p := P
192
+ let lhs := mulmod(y, y, p) // y^2
193
+ let rhs := addmod(mulmod(addmod(mulmod(x, x, p), A, p), x, p), B, p) // ((x^2 + a) * x) + b = x^3 + ax + b
194
+ result := and(and(lt(x, p), lt(y, p)), eq(lhs, rhs)) // Should conform with the Weierstrass equation
195
+ }
196
+ }
197
+
198
+ /**
199
+ * @dev Checks if (r, s) is a proper signature.
200
+ * In particular, this checks that `s` is in the "lower-range", making the signature non-malleable.
201
+ */
202
+ function _isProperSignature(bytes32 r, bytes32 s) private pure returns (bool) {
203
+ return uint256(r) > 0 && uint256(r) < N && uint256(s) > 0 && uint256(s) <= HALF_N;
204
+ }
205
+
206
+ /**
207
+ * @dev Reduce from jacobian to affine coordinates
208
+ * @param jx - jacobian coordinate x
209
+ * @param jy - jacobian coordinate y
210
+ * @param jz - jacobian coordinate z
211
+ * @return ax - affine coordinate x
212
+ * @return ay - affine coordinate y
213
+ */
214
+ function _affineFromJacobian(uint256 jx, uint256 jy, uint256 jz) private view returns (uint256 ax, uint256 ay) {
215
+ if (jz == 0) return (0, 0);
216
+ uint256 p = P; // cache P on the stack
217
+ uint256 zinv = Math.invModPrime(jz, p);
218
+ assembly ("memory-safe") {
219
+ let zzinv := mulmod(zinv, zinv, p)
220
+ ax := mulmod(jx, zzinv, p)
221
+ ay := mulmod(jy, mulmod(zzinv, zinv, p), p)
222
+ }
223
+ }
224
+
225
+ /**
226
+ * @dev Point addition on the jacobian coordinates
227
+ * Reference: https://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian.html#addition-add-1998-cmo-2
228
+ *
229
+ * Note that:
230
+ *
231
+ * - `addition-add-1998-cmo-2` doesn't support identical input points. This version is modified to use
232
+ * the `h` and `r` values computed by `addition-add-1998-cmo-2` to detect identical inputs, and fallback to
233
+ * `doubling-dbl-1998-cmo-2` if needed.
234
+ * - if one of the points is at infinity (i.e. `z=0`), the result is undefined.
235
+ */
236
+ function _jAdd(
237
+ JPoint memory p1,
238
+ uint256 x2,
239
+ uint256 y2,
240
+ uint256 z2
241
+ ) private pure returns (uint256 rx, uint256 ry, uint256 rz) {
242
+ assembly ("memory-safe") {
243
+ let p := P
244
+ let z1 := mload(add(p1, 0x40))
245
+ let zz1 := mulmod(z1, z1, p) // zz1 = z1²
246
+ let s1 := mulmod(mload(add(p1, 0x20)), mulmod(mulmod(z2, z2, p), z2, p), p) // s1 = y1*z2³
247
+ let r := addmod(mulmod(y2, mulmod(zz1, z1, p), p), sub(p, s1), p) // r = s2-s1 = y2*z1³-s1 = y2*z1³-y1*z2³
248
+ let u1 := mulmod(mload(p1), mulmod(z2, z2, p), p) // u1 = x1*z2²
249
+ let h := addmod(mulmod(x2, zz1, p), sub(p, u1), p) // h = u2-u1 = x2*z1²-u1 = x2*z1²-x1*z2²
250
+
251
+ // detect edge cases where inputs are identical
252
+ switch and(iszero(r), iszero(h))
253
+ // case 0: points are different
254
+ case 0 {
255
+ let hh := mulmod(h, h, p) // h²
256
+
257
+ // x' = r²-h³-2*u1*h²
258
+ rx := addmod(
259
+ addmod(mulmod(r, r, p), sub(p, mulmod(h, hh, p)), p),
260
+ sub(p, mulmod(2, mulmod(u1, hh, p), p)),
261
+ p
262
+ )
263
+ // y' = r*(u1*h²-x')-s1*h³
264
+ ry := addmod(
265
+ mulmod(r, addmod(mulmod(u1, hh, p), sub(p, rx), p), p),
266
+ sub(p, mulmod(s1, mulmod(h, hh, p), p)),
267
+ p
268
+ )
269
+ // z' = h*z1*z2
270
+ rz := mulmod(h, mulmod(z1, z2, p), p)
271
+ }
272
+ // case 1: points are equal
273
+ case 1 {
274
+ let x := x2
275
+ let y := y2
276
+ let z := z2
277
+ let yy := mulmod(y, y, p)
278
+ let zz := mulmod(z, z, p)
279
+ let m := addmod(mulmod(3, mulmod(x, x, p), p), mulmod(A, mulmod(zz, zz, p), p), p) // m = 3*x²+a*z⁴
280
+ let s := mulmod(4, mulmod(x, yy, p), p) // s = 4*x*y²
281
+
282
+ // x' = t = m²-2*s
283
+ rx := addmod(mulmod(m, m, p), sub(p, mulmod(2, s, p)), p)
284
+
285
+ // y' = m*(s-t)-8*y⁴ = m*(s-x')-8*y⁴
286
+ // cut the computation to avoid stack too deep
287
+ let rytmp1 := sub(p, mulmod(8, mulmod(yy, yy, p), p)) // -8*y⁴
288
+ let rytmp2 := addmod(s, sub(p, rx), p) // s-x'
289
+ ry := addmod(mulmod(m, rytmp2, p), rytmp1, p) // m*(s-x')-8*y⁴
290
+
291
+ // z' = 2*y*z
292
+ rz := mulmod(2, mulmod(y, z, p), p)
293
+ }
294
+ }
295
+ }
296
+
297
+ /**
298
+ * @dev Point doubling on the jacobian coordinates
299
+ * Reference: https://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian.html#doubling-dbl-1998-cmo-2
300
+ */
301
+ function _jDouble(uint256 x, uint256 y, uint256 z) private pure returns (uint256 rx, uint256 ry, uint256 rz) {
302
+ assembly ("memory-safe") {
303
+ let p := P
304
+ let yy := mulmod(y, y, p)
305
+ let zz := mulmod(z, z, p)
306
+ let m := addmod(mulmod(3, mulmod(x, x, p), p), mulmod(A, mulmod(zz, zz, p), p), p) // m = 3*x²+a*z⁴
307
+ let s := mulmod(4, mulmod(x, yy, p), p) // s = 4*x*y²
308
+
309
+ // x' = t = m²-2*s
310
+ rx := addmod(mulmod(m, m, p), sub(p, mulmod(2, s, p)), p)
311
+ // y' = m*(s-t)-8*y⁴ = m*(s-x')-8*y⁴
312
+ ry := addmod(mulmod(m, addmod(s, sub(p, rx), p), p), sub(p, mulmod(8, mulmod(yy, yy, p), p)), p)
313
+ // z' = 2*y*z
314
+ rz := mulmod(2, mulmod(y, z, p), p)
315
+ }
316
+ }
317
+
318
+ /**
319
+ * @dev Compute G·u1 + P·u2 using the precomputed points for G and P (see {_preComputeJacobianPoints}).
320
+ *
321
+ * Uses Strauss Shamir trick for EC multiplication
322
+ * https://stackoverflow.com/questions/50993471/ec-scalar-multiplication-with-strauss-shamir-method
323
+ *
324
+ * We optimize this for 2 bits at a time rather than a single bit. The individual points for a single pass are
325
+ * precomputed. Overall this reduces the number of additions while keeping the same number of
326
+ * doublings
327
+ */
328
+ function _jMultShamir(
329
+ JPoint[16] memory points,
330
+ uint256 u1,
331
+ uint256 u2
332
+ ) private view returns (uint256 rx, uint256 ry) {
333
+ uint256 x = 0;
334
+ uint256 y = 0;
335
+ uint256 z = 0;
336
+ unchecked {
337
+ for (uint256 i = 0; i < 128; ++i) {
338
+ if (z > 0) {
339
+ (x, y, z) = _jDouble(x, y, z);
340
+ (x, y, z) = _jDouble(x, y, z);
341
+ }
342
+ // Read 2 bits of u1, and 2 bits of u2. Combining the two gives the lookup index in the table.
343
+ uint256 pos = ((u1 >> 252) & 0xc) | ((u2 >> 254) & 0x3);
344
+ // Points that have z = 0 are points at infinity. They are the additive 0 of the group
345
+ // - if the lookup point is a 0, we can skip it
346
+ // - otherwise:
347
+ // - if the current point (x, y, z) is 0, we use the lookup point as our new value (0+P=P)
348
+ // - if the current point (x, y, z) is not 0, both points are valid and we can use `_jAdd`
349
+ if (points[pos].z != 0) {
350
+ if (z == 0) {
351
+ (x, y, z) = (points[pos].x, points[pos].y, points[pos].z);
352
+ } else {
353
+ (x, y, z) = _jAdd(points[pos], x, y, z);
354
+ }
355
+ }
356
+ u1 <<= 2;
357
+ u2 <<= 2;
358
+ }
359
+ }
360
+ return _affineFromJacobian(x, y, z);
361
+ }
362
+
363
+ /**
364
+ * @dev Precompute a matrice of useful jacobian points associated with a given P. This can be seen as a 4x4 matrix
365
+ * that contains combination of P and G (generator) up to 3 times each. See the table below:
366
+ *
367
+ * ┌────┬─────────────────────┐
368
+ * │ i │ 0 1 2 3 │
369
+ * ├────┼─────────────────────┤
370
+ * │ 0 │ 0 p 2p 3p │
371
+ * │ 4 │ g g+p g+2p g+3p │
372
+ * │ 8 │ 2g 2g+p 2g+2p 2g+3p │
373
+ * │ 12 │ 3g 3g+p 3g+2p 3g+3p │
374
+ * └────┴─────────────────────┘
375
+ *
376
+ * Note that `_jAdd` (and thus `_jAddPoint`) does not handle the case where one of the inputs is a point at
377
+ * infinity (z = 0). However, we know that since `N ≡ 1 mod 2` and `N ≡ 1 mod 3`, there is no point P such that
378
+ * 2P = 0 or 3P = 0. This guarantees that g, 2g, 3g, p, 2p, 3p are all non-zero, and that all `_jAddPoint` calls
379
+ * have valid inputs.
380
+ */
381
+ function _preComputeJacobianPoints(uint256 px, uint256 py) private pure returns (JPoint[16] memory points) {
382
+ points[0x00] = JPoint(0, 0, 0); // 0,0
383
+ points[0x01] = JPoint(px, py, 1); // 1,0 (p)
384
+ points[0x04] = JPoint(GX, GY, 1); // 0,1 (g)
385
+ points[0x02] = _jDoublePoint(points[0x01]); // 2,0 (2p)
386
+ points[0x08] = _jDoublePoint(points[0x04]); // 0,2 (2g)
387
+ points[0x03] = _jAddPoint(points[0x01], points[0x02]); // 3,0 (p+2p = 3p)
388
+ points[0x05] = _jAddPoint(points[0x01], points[0x04]); // 1,1 (p+g)
389
+ points[0x06] = _jAddPoint(points[0x02], points[0x04]); // 2,1 (2p+g)
390
+ points[0x07] = _jAddPoint(points[0x03], points[0x04]); // 3,1 (3p+g)
391
+ points[0x09] = _jAddPoint(points[0x01], points[0x08]); // 1,2 (p+2g)
392
+ points[0x0a] = _jAddPoint(points[0x02], points[0x08]); // 2,2 (2p+2g)
393
+ points[0x0b] = _jAddPoint(points[0x03], points[0x08]); // 3,2 (3p+2g)
394
+ points[0x0c] = _jAddPoint(points[0x04], points[0x08]); // 0,3 (g+2g = 3g)
395
+ points[0x0d] = _jAddPoint(points[0x01], points[0x0c]); // 1,3 (p+3g)
396
+ points[0x0e] = _jAddPoint(points[0x02], points[0x0c]); // 2,3 (2p+3g)
397
+ points[0x0f] = _jAddPoint(points[0x03], points[0x0c]); // 3,3 (3p+3g)
398
+ }
399
+
400
+ function _jAddPoint(JPoint memory p1, JPoint memory p2) private pure returns (JPoint memory) {
401
+ (uint256 x, uint256 y, uint256 z) = _jAdd(p1, p2.x, p2.y, p2.z);
402
+ return JPoint(x, y, z);
403
+ }
404
+
405
+ function _jDoublePoint(JPoint memory p) private pure returns (JPoint memory) {
406
+ (uint256 x, uint256 y, uint256 z) = _jDouble(p.x, p.y, p.z);
407
+ return JPoint(x, y, z);
408
+ }
409
+ }