applyHarness.patch 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. diff -ruN .gitignore .gitignore
  2. --- .gitignore 1969-12-31 16:00:00.000000000 -0800
  3. +++ .gitignore 2022-08-11 21:28:36.000000000 -0700
  4. @@ -0,0 +1,2 @@
  5. +*
  6. +!.gitignore
  7. diff -ruN access/AccessControl.sol access/AccessControl.sol
  8. --- access/AccessControl.sol 2022-08-11 21:28:00.000000000 -0700
  9. +++ access/AccessControl.sol 2022-08-11 21:28:36.000000000 -0700
  10. @@ -93,7 +93,7 @@
  11. *
  12. * _Available since v4.6._
  13. */
  14. - function _checkRole(bytes32 role) internal view virtual {
  15. + function _checkRole(bytes32 role) public view virtual { // HARNESS: internal -> public
  16. _checkRole(role, _msgSender());
  17. }
  18. diff -ruN access/Ownable.sol access/Ownable.sol
  19. --- access/Ownable.sol 2022-08-11 21:28:00.000000000 -0700
  20. +++ access/Ownable.sol 2022-08-11 21:28:36.000000000 -0700
  21. @@ -30,14 +30,6 @@
  22. }
  23. /**
  24. - * @dev Throws if called by any account other than the owner.
  25. - */
  26. - modifier onlyOwner() {
  27. - _checkOwner();
  28. - _;
  29. - }
  30. -
  31. - /**
  32. * @dev Returns the address of the current owner.
  33. */
  34. function owner() public view virtual returns (address) {
  35. @@ -45,10 +37,11 @@
  36. }
  37. /**
  38. - * @dev Throws if the sender is not the owner.
  39. + * @dev Throws if called by any account other than the owner.
  40. */
  41. - function _checkOwner() internal view virtual {
  42. + modifier onlyOwner() {
  43. require(owner() == _msgSender(), "Ownable: caller is not the owner");
  44. + _;
  45. }
  46. /**
  47. diff -ruN governance/Governor.sol governance/Governor.sol
  48. --- governance/Governor.sol 2022-08-11 21:28:00.000000000 -0700
  49. +++ governance/Governor.sol 2022-08-11 21:28:36.000000000 -0700
  50. @@ -44,7 +44,7 @@
  51. string private _name;
  52. - mapping(uint256 => ProposalCore) private _proposals;
  53. + mapping(uint256 => ProposalCore) internal _proposals;
  54. // This queue keeps track of the governor operating on itself. Calls to functions protected by the
  55. // {onlyGovernance} modifier needs to be whitelisted in this queue. Whitelisting is set in {_beforeExecute},
  56. diff -ruN governance/TimelockController.sol governance/TimelockController.sol
  57. --- governance/TimelockController.sol 2022-08-11 21:28:00.000000000 -0700
  58. +++ governance/TimelockController.sol 2022-08-11 21:28:36.000000000 -0700
  59. @@ -28,10 +28,10 @@
  60. bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
  61. bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
  62. bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");
  63. - uint256 internal constant _DONE_TIMESTAMP = uint256(1);
  64. + uint256 public constant _DONE_TIMESTAMP = uint256(1);
  65. mapping(bytes32 => uint256) private _timestamps;
  66. - uint256 private _minDelay;
  67. + uint256 public _minDelay;
  68. /**
  69. * @dev Emitted when a call is scheduled as part of operation `id`.
  70. diff -ruN governance/extensions/GovernorCountingSimple.sol governance/extensions/GovernorCountingSimple.sol
  71. --- governance/extensions/GovernorCountingSimple.sol 2022-08-11 21:28:00.000000000 -0700
  72. +++ governance/extensions/GovernorCountingSimple.sol 2022-08-11 21:28:36.000000000 -0700
  73. @@ -27,7 +27,7 @@
  74. mapping(address => bool) hasVoted;
  75. }
  76. - mapping(uint256 => ProposalVote) private _proposalVotes;
  77. + mapping(uint256 => ProposalVote) internal _proposalVotes;
  78. /**
  79. * @dev See {IGovernor-COUNTING_MODE}.
  80. diff -ruN governance/extensions/GovernorPreventLateQuorum.sol governance/extensions/GovernorPreventLateQuorum.sol
  81. --- governance/extensions/GovernorPreventLateQuorum.sol 2022-08-11 21:28:00.000000000 -0700
  82. +++ governance/extensions/GovernorPreventLateQuorum.sol 2022-08-11 21:28:36.000000000 -0700
  83. @@ -21,8 +21,8 @@
  84. using SafeCast for uint256;
  85. using Timers for Timers.BlockNumber;
  86. - uint64 private _voteExtension;
  87. - mapping(uint256 => Timers.BlockNumber) private _extendedDeadlines;
  88. + uint64 internal _voteExtension; // PRIVATE => INTERNAL
  89. + mapping(uint256 => Timers.BlockNumber) internal _extendedDeadlines; // PRIVATE => INTERNAL
  90. /// @dev Emitted when a proposal deadline is pushed back due to reaching quorum late in its voting period.
  91. event ProposalExtended(uint256 indexed proposalId, uint64 extendedDeadline);
  92. diff -ruN governance/utils/Votes.sol governance/utils/Votes.sol
  93. --- governance/utils/Votes.sol 2022-08-11 21:28:00.000000000 -0700
  94. +++ governance/utils/Votes.sol 2022-08-11 21:28:36.000000000 -0700
  95. @@ -35,7 +35,25 @@
  96. bytes32 private constant _DELEGATION_TYPEHASH =
  97. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  98. - mapping(address => address) private _delegation;
  99. + // HARNESS : Hooks cannot access any information from Checkpoints yet, so I am also updating votes and fromBlock in this struct
  100. + struct Ckpt {
  101. + uint32 fromBlock;
  102. + uint224 votes;
  103. + }
  104. + mapping(address => Ckpt) public _checkpoints;
  105. +
  106. + // HARNESSED getters
  107. + function numCheckpoints(address account) public view returns (uint32) {
  108. + return SafeCast.toUint32(_delegateCheckpoints[account]._checkpoints.length);
  109. + }
  110. + function ckptFromBlock(address account, uint32 pos) public view returns (uint32) {
  111. + return _delegateCheckpoints[account]._checkpoints[pos]._blockNumber;
  112. + }
  113. + function ckptVotes(address account, uint32 pos) public view returns (uint224) {
  114. + return _delegateCheckpoints[account]._checkpoints[pos]._value;
  115. + }
  116. +
  117. + mapping(address => address) public _delegation;
  118. mapping(address => Checkpoints.History) private _delegateCheckpoints;
  119. Checkpoints.History private _totalCheckpoints;
  120. @@ -124,7 +142,7 @@
  121. *
  122. * Emits events {DelegateChanged} and {DelegateVotesChanged}.
  123. */
  124. - function _delegate(address account, address delegatee) internal virtual {
  125. + function _delegate(address account, address delegatee) public virtual {
  126. address oldDelegate = delegates(account);
  127. _delegation[account] = delegatee;
  128. @@ -142,10 +160,10 @@
  129. uint256 amount
  130. ) internal virtual {
  131. if (from == address(0)) {
  132. - _totalCheckpoints.push(_add, amount);
  133. + _totalCheckpoints.push(_totalCheckpoints.latest() + amount); // Harnessed to remove function pointers
  134. }
  135. if (to == address(0)) {
  136. - _totalCheckpoints.push(_subtract, amount);
  137. + _totalCheckpoints.push(_totalCheckpoints.latest() - amount); // Harnessed to remove function pointers
  138. }
  139. _moveDelegateVotes(delegates(from), delegates(to), amount);
  140. }
  141. @@ -160,11 +178,13 @@
  142. ) private {
  143. if (from != to && amount > 0) {
  144. if (from != address(0)) {
  145. - (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[from].push(_subtract, amount);
  146. + (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[from].push(_delegateCheckpoints[from].latest() - amount); // HARNESSED TO REMOVE FUNCTION POINTERS
  147. + _checkpoints[from] = Ckpt({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newValue)}); // HARNESS
  148. emit DelegateVotesChanged(from, oldValue, newValue);
  149. }
  150. if (to != address(0)) {
  151. - (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[to].push(_add, amount);
  152. + (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[to].push(_delegateCheckpoints[to].latest() + amount); // HARNESSED TO REMOVE FUNCTION POINTERS
  153. + _checkpoints[to] = Ckpt({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newValue)}); // HARNESS
  154. emit DelegateVotesChanged(to, oldValue, newValue);
  155. }
  156. }
  157. @@ -207,5 +227,5 @@
  158. /**
  159. * @dev Must return the voting units held by an account.
  160. */
  161. - function _getVotingUnits(address) internal view virtual returns (uint256);
  162. + function _getVotingUnits(address) public virtual returns (uint256); // HARNESS: internal -> public
  163. }
  164. diff -ruN metatx/MinimalForwarder.sol metatx/MinimalForwarder.sol
  165. --- metatx/MinimalForwarder.sol 2022-08-11 21:28:00.000000000 -0700
  166. +++ metatx/MinimalForwarder.sol 2022-08-11 21:28:36.000000000 -0700
  167. @@ -8,11 +8,6 @@
  168. /**
  169. * @dev Simple minimal forwarder to be used together with an ERC2771 compatible contract. See {ERC2771Context}.
  170. - *
  171. - * MinimalForwarder is mainly meant for testing, as it is missing features to be a good production-ready forwarder. This
  172. - * contract does not intend to have all the properties that are needed for a sound forwarding system. A fully
  173. - * functioning forwarding system with good properties requires more complexity. We suggest you look at other projects
  174. - * such as the GSN which do have the goal of building a system like that.
  175. */
  176. contract MinimalForwarder is EIP712 {
  177. using ECDSA for bytes32;
  178. diff -ruN mocks/ERC20TokenizedVaultMock.sol mocks/ERC20TokenizedVaultMock.sol
  179. --- mocks/ERC20TokenizedVaultMock.sol 1969-12-31 16:00:00.000000000 -0800
  180. +++ mocks/ERC20TokenizedVaultMock.sol 2022-08-11 21:28:36.000000000 -0700
  181. @@ -0,0 +1,22 @@
  182. +// SPDX-License-Identifier: MIT
  183. +
  184. +pragma solidity ^0.8.0;
  185. +
  186. +import "../token/ERC20/extensions/ERC20TokenizedVault.sol";
  187. +
  188. +// mock class using ERC20
  189. +contract ERC20TokenizedVaultMock is ERC20TokenizedVault {
  190. + constructor(
  191. + IERC20Metadata asset,
  192. + string memory name,
  193. + string memory symbol
  194. + ) ERC20(name, symbol) ERC20TokenizedVault(asset) {}
  195. +
  196. + function mockMint(address account, uint256 amount) public {
  197. + _mint(account, amount);
  198. + }
  199. +
  200. + function mockBurn(address account, uint256 amount) public {
  201. + _burn(account, amount);
  202. + }
  203. +}
  204. diff -ruN mocks/ERC4626Mock.sol mocks/ERC4626Mock.sol
  205. --- mocks/ERC4626Mock.sol 2022-08-11 21:28:00.000000000 -0700
  206. +++ mocks/ERC4626Mock.sol 1969-12-31 16:00:00.000000000 -0800
  207. @@ -1,22 +0,0 @@
  208. -// SPDX-License-Identifier: MIT
  209. -
  210. -pragma solidity ^0.8.0;
  211. -
  212. -import "../token/ERC20/extensions/ERC4626.sol";
  213. -
  214. -// mock class using ERC20
  215. -contract ERC4626Mock is ERC4626 {
  216. - constructor(
  217. - IERC20Metadata asset,
  218. - string memory name,
  219. - string memory symbol
  220. - ) ERC20(name, symbol) ERC4626(asset) {}
  221. -
  222. - function mockMint(address account, uint256 amount) public {
  223. - _mint(account, amount);
  224. - }
  225. -
  226. - function mockBurn(address account, uint256 amount) public {
  227. - _burn(account, amount);
  228. - }
  229. -}
  230. diff -ruN mocks/MathMock.sol mocks/MathMock.sol
  231. --- mocks/MathMock.sol 2022-08-11 21:28:00.000000000 -0700
  232. +++ mocks/MathMock.sol 2022-08-11 21:28:36.000000000 -0700
  233. @@ -29,8 +29,4 @@
  234. ) public pure returns (uint256) {
  235. return Math.mulDiv(a, b, denominator, direction);
  236. }
  237. -
  238. - function sqrt(uint256 a, Math.Rounding direction) public pure returns (uint256) {
  239. - return Math.sqrt(a, direction);
  240. - }
  241. }
  242. diff -ruN mocks/SafeERC20Helper.sol mocks/SafeERC20Helper.sol
  243. --- mocks/SafeERC20Helper.sol 2022-08-11 21:28:00.000000000 -0700
  244. +++ mocks/SafeERC20Helper.sol 2022-08-11 21:28:36.000000000 -0700
  245. @@ -4,7 +4,6 @@
  246. import "../utils/Context.sol";
  247. import "../token/ERC20/IERC20.sol";
  248. -import "../token/ERC20/extensions/draft-ERC20Permit.sol";
  249. import "../token/ERC20/utils/SafeERC20.sol";
  250. contract ERC20ReturnFalseMock is Context {
  251. @@ -106,43 +105,6 @@
  252. }
  253. }
  254. -contract ERC20PermitNoRevertMock is
  255. - ERC20("ERC20PermitNoRevertMock", "ERC20PermitNoRevertMock"),
  256. - ERC20Permit("ERC20PermitNoRevertMock")
  257. -{
  258. - function getChainId() external view returns (uint256) {
  259. - return block.chainid;
  260. - }
  261. -
  262. - function permitThatMayRevert(
  263. - address owner,
  264. - address spender,
  265. - uint256 value,
  266. - uint256 deadline,
  267. - uint8 v,
  268. - bytes32 r,
  269. - bytes32 s
  270. - ) public virtual {
  271. - super.permit(owner, spender, value, deadline, v, r, s);
  272. - }
  273. -
  274. - function permit(
  275. - address owner,
  276. - address spender,
  277. - uint256 value,
  278. - uint256 deadline,
  279. - uint8 v,
  280. - bytes32 r,
  281. - bytes32 s
  282. - ) public virtual override {
  283. - try this.permitThatMayRevert(owner, spender, value, deadline, v, r, s) {
  284. - // do nothing
  285. - } catch {
  286. - // do nothing
  287. - }
  288. - }
  289. -}
  290. -
  291. contract SafeERC20Wrapper is Context {
  292. using SafeERC20 for IERC20;
  293. @@ -172,18 +134,6 @@
  294. _token.safeDecreaseAllowance(address(0), amount);
  295. }
  296. - function permit(
  297. - address owner,
  298. - address spender,
  299. - uint256 value,
  300. - uint256 deadline,
  301. - uint8 v,
  302. - bytes32 r,
  303. - bytes32 s
  304. - ) public {
  305. - SafeERC20.safePermit(IERC20Permit(address(_token)), owner, spender, value, deadline, v, r, s);
  306. - }
  307. -
  308. function setAllowance(uint256 allowance_) public {
  309. ERC20ReturnTrueMock(address(_token)).setAllowance(allowance_);
  310. }
  311. diff -ruN proxy/Clones.sol proxy/Clones.sol
  312. --- proxy/Clones.sol 2022-08-11 21:28:00.000000000 -0700
  313. +++ proxy/Clones.sol 2022-08-11 21:28:36.000000000 -0700
  314. @@ -26,10 +26,10 @@
  315. /// @solidity memory-safe-assembly
  316. assembly {
  317. let ptr := mload(0x40)
  318. - mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
  319. - mstore(add(ptr, 0x14), shl(0x60, implementation))
  320. - mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
  321. - instance := create(0, ptr, 0x37)
  322. + mstore(ptr, 0x602d8060093d393df3363d3d373d3d3d363d7300000000000000000000000000)
  323. + mstore(add(ptr, 0x13), shl(0x60, implementation))
  324. + mstore(add(ptr, 0x27), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
  325. + instance := create(0, ptr, 0x36)
  326. }
  327. require(instance != address(0), "ERC1167: create failed");
  328. }
  329. @@ -45,10 +45,10 @@
  330. /// @solidity memory-safe-assembly
  331. assembly {
  332. let ptr := mload(0x40)
  333. - mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
  334. - mstore(add(ptr, 0x14), shl(0x60, implementation))
  335. - mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
  336. - instance := create2(0, ptr, 0x37, salt)
  337. + mstore(ptr, 0x602d8060093d393df3363d3d373d3d3d363d7300000000000000000000000000)
  338. + mstore(add(ptr, 0x13), shl(0x60, implementation))
  339. + mstore(add(ptr, 0x27), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
  340. + instance := create2(0, ptr, 0x36, salt)
  341. }
  342. require(instance != address(0), "ERC1167: create2 failed");
  343. }
  344. @@ -64,13 +64,13 @@
  345. /// @solidity memory-safe-assembly
  346. assembly {
  347. let ptr := mload(0x40)
  348. - mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
  349. - mstore(add(ptr, 0x14), shl(0x60, implementation))
  350. - mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
  351. - mstore(add(ptr, 0x38), shl(0x60, deployer))
  352. - mstore(add(ptr, 0x4c), salt)
  353. - mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
  354. - predicted := keccak256(add(ptr, 0x37), 0x55)
  355. + mstore(ptr, 0x602d8060093d393df3363d3d373d3d3d363d7300000000000000000000000000)
  356. + mstore(add(ptr, 0x13), shl(0x60, implementation))
  357. + mstore(add(ptr, 0x27), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
  358. + mstore(add(ptr, 0x37), shl(0x60, deployer))
  359. + mstore(add(ptr, 0x4b), salt)
  360. + mstore(add(ptr, 0x6b), keccak256(ptr, 0x36))
  361. + predicted := keccak256(add(ptr, 0x36), 0x55)
  362. }
  363. }
  364. diff -ruN proxy/ERC1967/ERC1967Proxy.sol proxy/ERC1967/ERC1967Proxy.sol
  365. --- proxy/ERC1967/ERC1967Proxy.sol 2022-08-11 21:28:00.000000000 -0700
  366. +++ proxy/ERC1967/ERC1967Proxy.sol 2022-08-11 21:28:36.000000000 -0700
  367. @@ -20,6 +20,7 @@
  368. * function call, and allows initializing the storage of the proxy like a Solidity constructor.
  369. */
  370. constructor(address _logic, bytes memory _data) payable {
  371. + assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
  372. _upgradeToAndCall(_logic, _data, false);
  373. }
  374. diff -ruN proxy/beacon/BeaconProxy.sol proxy/beacon/BeaconProxy.sol
  375. --- proxy/beacon/BeaconProxy.sol 2022-08-11 21:28:00.000000000 -0700
  376. +++ proxy/beacon/BeaconProxy.sol 2022-08-11 21:28:36.000000000 -0700
  377. @@ -28,6 +28,7 @@
  378. * - `beacon` must be a contract with the interface {IBeacon}.
  379. */
  380. constructor(address beacon, bytes memory data) payable {
  381. + assert(_BEACON_SLOT == bytes32(uint256(keccak256("eip1967.proxy.beacon")) - 1));
  382. _upgradeBeaconToAndCall(beacon, data, false);
  383. }
  384. diff -ruN proxy/transparent/TransparentUpgradeableProxy.sol proxy/transparent/TransparentUpgradeableProxy.sol
  385. --- proxy/transparent/TransparentUpgradeableProxy.sol 2022-08-11 21:28:00.000000000 -0700
  386. +++ proxy/transparent/TransparentUpgradeableProxy.sol 2022-08-11 21:28:36.000000000 -0700
  387. @@ -36,6 +36,7 @@
  388. address admin_,
  389. bytes memory _data
  390. ) payable ERC1967Proxy(_logic, _data) {
  391. + assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
  392. _changeAdmin(admin_);
  393. }
  394. diff -ruN proxy/utils/Initializable.sol proxy/utils/Initializable.sol
  395. --- proxy/utils/Initializable.sol 2022-08-11 21:28:00.000000000 -0700
  396. +++ proxy/utils/Initializable.sol 2022-08-11 21:28:36.000000000 -0700
  397. @@ -59,12 +59,12 @@
  398. * @dev Indicates that the contract has been initialized.
  399. * @custom:oz-retyped-from bool
  400. */
  401. - uint8 private _initialized;
  402. + uint8 internal _initialized;
  403. /**
  404. * @dev Indicates that the contract is in the process of being initialized.
  405. */
  406. - bool private _initializing;
  407. + bool internal _initializing;
  408. /**
  409. * @dev Triggered when the contract has been initialized or reinitialized.
  410. diff -ruN proxy/utils/Initializable.sol.orig proxy/utils/Initializable.sol.orig
  411. --- proxy/utils/Initializable.sol.orig 1969-12-31 16:00:00.000000000 -0800
  412. +++ proxy/utils/Initializable.sol.orig 2022-08-11 21:28:36.000000000 -0700
  413. @@ -0,0 +1,138 @@
  414. +// SPDX-License-Identifier: MIT
  415. +// OpenZeppelin Contracts (last updated v4.6.0) (proxy/utils/Initializable.sol)
  416. +
  417. +pragma solidity ^0.8.2;
  418. +
  419. +import "../../utils/Address.sol";
  420. +
  421. +/**
  422. + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
  423. + * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
  424. + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
  425. + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
  426. + *
  427. + * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
  428. + * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
  429. + * case an upgrade adds a module that needs to be initialized.
  430. + *
  431. + * For example:
  432. + *
  433. + * [.hljs-theme-light.nopadding]
  434. + * ```
  435. + * contract MyToken is ERC20Upgradeable {
  436. + * function initialize() initializer public {
  437. + * __ERC20_init("MyToken", "MTK");
  438. + * }
  439. + * }
  440. + * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
  441. + * function initializeV2() reinitializer(2) public {
  442. + * __ERC20Permit_init("MyToken");
  443. + * }
  444. + * }
  445. + * ```
  446. + *
  447. + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
  448. + * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
  449. + *
  450. + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
  451. + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
  452. + *
  453. + * [CAUTION]
  454. + * ====
  455. + * Avoid leaving a contract uninitialized.
  456. + *
  457. + * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
  458. + * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
  459. + * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
  460. + *
  461. + * [.hljs-theme-light.nopadding]
  462. + * ```
  463. + * /// @custom:oz-upgrades-unsafe-allow constructor
  464. + * constructor() {
  465. + * _disableInitializers();
  466. + * }
  467. + * ```
  468. + * ====
  469. + */
  470. +abstract contract Initializable {
  471. + /**
  472. + * @dev Indicates that the contract has been initialized.
  473. + * @custom:oz-retyped-from bool
  474. + */
  475. + uint8 private _initialized;
  476. +
  477. + /**
  478. + * @dev Indicates that the contract is in the process of being initialized.
  479. + */
  480. + bool private _initializing;
  481. +
  482. + /**
  483. + * @dev Triggered when the contract has been initialized or reinitialized.
  484. + */
  485. + event Initialized(uint8 version);
  486. +
  487. + /**
  488. + * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
  489. + * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
  490. + */
  491. + modifier initializer() {
  492. + bool isTopLevelCall = !_initializing;
  493. + require(
  494. + (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
  495. + "Initializable: contract is already initialized"
  496. + );
  497. + _initialized = 1;
  498. + if (isTopLevelCall) {
  499. + _initializing = true;
  500. + }
  501. + _;
  502. + if (isTopLevelCall) {
  503. + _initializing = false;
  504. + emit Initialized(1);
  505. + }
  506. + }
  507. +
  508. + /**
  509. + * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
  510. + * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
  511. + * used to initialize parent contracts.
  512. + *
  513. + * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
  514. + * initialization step. This is essential to configure modules that are added through upgrades and that require
  515. + * initialization.
  516. + *
  517. + * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
  518. + * a contract, executing them in the right order is up to the developer or operator.
  519. + */
  520. + modifier reinitializer(uint8 version) {
  521. + require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
  522. + _initialized = version;
  523. + _initializing = true;
  524. + _;
  525. + _initializing = false;
  526. + emit Initialized(version);
  527. + }
  528. +
  529. + /**
  530. + * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
  531. + * {initializer} and {reinitializer} modifiers, directly or indirectly.
  532. + */
  533. + modifier onlyInitializing() {
  534. + require(_initializing, "Initializable: contract is not initializing");
  535. + _;
  536. + }
  537. +
  538. + /**
  539. + * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
  540. + * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
  541. + * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
  542. + * through proxies.
  543. + */
  544. + function _disableInitializers() internal virtual {
  545. + require(!_initializing, "Initializable: contract is initializing");
  546. + if (_initialized < type(uint8).max) {
  547. + _initialized = type(uint8).max;
  548. + emit Initialized(type(uint8).max);
  549. + }
  550. + }
  551. +}
  552. diff -ruN proxy/utils/Initializable.sol.rej proxy/utils/Initializable.sol.rej
  553. --- proxy/utils/Initializable.sol.rej 1969-12-31 16:00:00.000000000 -0800
  554. +++ proxy/utils/Initializable.sol.rej 2022-08-11 21:28:36.000000000 -0700
  555. @@ -0,0 +1,17 @@
  556. +***************
  557. +*** 130,136 ****
  558. + _setInitializedVersion(type(uint8).max);
  559. + }
  560. +
  561. +- function _setInitializedVersion(uint8 version) private returns (bool) {
  562. + // If the contract is initializing we ignore whether _initialized is set in order to support multiple
  563. + // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level
  564. + // of initializers, because in other contexts the contract may have been reentered.
  565. +--- 130,136 ----
  566. + _setInitializedVersion(type(uint8).max);
  567. + }
  568. +
  569. ++ function _setInitializedVersion(uint8 version) internal returns (bool) {
  570. + // If the contract is initializing we ignore whether _initialized is set in order to support multiple
  571. + // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level
  572. + // of initializers, because in other contexts the contract may have been reentered.
  573. diff -ruN security/Pausable.sol security/Pausable.sol
  574. --- security/Pausable.sol 2022-08-11 21:28:00.000000000 -0700
  575. +++ security/Pausable.sol 2022-08-11 21:28:36.000000000 -0700
  576. @@ -35,6 +35,13 @@
  577. }
  578. /**
  579. + * @dev Returns true if the contract is paused, and false otherwise.
  580. + */
  581. + function paused() public view virtual returns (bool) {
  582. + return _paused;
  583. + }
  584. +
  585. + /**
  586. * @dev Modifier to make a function callable only when the contract is not paused.
  587. *
  588. * Requirements:
  589. @@ -42,7 +49,7 @@
  590. * - The contract must not be paused.
  591. */
  592. modifier whenNotPaused() {
  593. - _requireNotPaused();
  594. + require(!paused(), "Pausable: paused");
  595. _;
  596. }
  597. @@ -54,29 +61,8 @@
  598. * - The contract must be paused.
  599. */
  600. modifier whenPaused() {
  601. - _requirePaused();
  602. - _;
  603. - }
  604. -
  605. - /**
  606. - * @dev Returns true if the contract is paused, and false otherwise.
  607. - */
  608. - function paused() public view virtual returns (bool) {
  609. - return _paused;
  610. - }
  611. -
  612. - /**
  613. - * @dev Throws if the contract is paused.
  614. - */
  615. - function _requireNotPaused() internal view virtual {
  616. - require(!paused(), "Pausable: paused");
  617. - }
  618. -
  619. - /**
  620. - * @dev Throws if the contract is not paused.
  621. - */
  622. - function _requirePaused() internal view virtual {
  623. require(paused(), "Pausable: not paused");
  624. + _;
  625. }
  626. /**
  627. diff -ruN token/ERC1155/ERC1155.sol token/ERC1155/ERC1155.sol
  628. --- token/ERC1155/ERC1155.sol 2022-08-11 21:28:00.000000000 -0700
  629. +++ token/ERC1155/ERC1155.sol 2022-08-11 21:28:36.000000000 -0700
  630. @@ -21,7 +21,7 @@
  631. using Address for address;
  632. // Mapping from token ID to account balances
  633. - mapping(uint256 => mapping(address => uint256)) private _balances;
  634. + mapping(uint256 => mapping(address => uint256)) internal _balances; // MUNGED private => internal
  635. // Mapping from account to operator approvals
  636. mapping(address => mapping(address => bool)) private _operatorApprovals;
  637. @@ -471,7 +471,7 @@
  638. uint256 id,
  639. uint256 amount,
  640. bytes memory data
  641. - ) private {
  642. + ) public { // HARNESS: private -> public
  643. if (to.isContract()) {
  644. try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
  645. if (response != IERC1155Receiver.onERC1155Received.selector) {
  646. @@ -492,7 +492,7 @@
  647. uint256[] memory ids,
  648. uint256[] memory amounts,
  649. bytes memory data
  650. - ) private {
  651. + ) public { // HARNESS: private -> public
  652. if (to.isContract()) {
  653. try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
  654. bytes4 response
  655. diff -ruN token/ERC20/ERC20.sol token/ERC20/ERC20.sol
  656. --- token/ERC20/ERC20.sol 2022-08-11 21:28:00.000000000 -0700
  657. +++ token/ERC20/ERC20.sol 2022-08-11 23:01:50.000000000 -0700
  658. @@ -277,7 +277,7 @@
  659. * - `account` cannot be the zero address.
  660. * - `account` must have at least `amount` tokens.
  661. */
  662. - function _burn(address account, uint256 amount) internal virtual {
  663. + function _burn(address account, uint256 amount) public virtual { // HARNESS: internal -> public
  664. require(account != address(0), "ERC20: burn from the zero address");
  665. _beforeTokenTransfer(account, address(0), amount);
  666. diff -ruN token/ERC20/README.adoc token/ERC20/README.adoc
  667. --- token/ERC20/README.adoc 2022-08-11 21:28:00.000000000 -0700
  668. +++ token/ERC20/README.adoc 2022-08-11 21:28:36.000000000 -0700
  669. @@ -24,7 +24,7 @@
  670. * {ERC20Votes}: support for voting and vote delegation.
  671. * {ERC20VotesComp}: support for voting and vote delegation (compatible with Compound's token, with uint96 restrictions).
  672. * {ERC20Wrapper}: wrapper to create an ERC20 backed by another ERC20, with deposit and withdraw methods. Useful in conjunction with {ERC20Votes}.
  673. -* {ERC4626}: tokenized vault that manages shares (represented as ERC20) that are backed by assets (another ERC20).
  674. +* {ERC20TokenizedVault}: tokenized vault that manages shares (represented as ERC20) that are backed by assets (another ERC20).
  675. Finally, there are some utilities to interact with ERC20 contracts in various ways.
  676. @@ -63,7 +63,7 @@
  677. {{ERC20FlashMint}}
  678. -{{ERC4626}}
  679. +{{ERC20TokenizedVault}}
  680. == Draft EIPs
  681. diff -ruN token/ERC20/extensions/ERC20FlashMint.sol token/ERC20/extensions/ERC20FlashMint.sol
  682. --- token/ERC20/extensions/ERC20FlashMint.sol 2022-08-11 21:28:00.000000000 -0700
  683. +++ token/ERC20/extensions/ERC20FlashMint.sol 2022-08-11 21:28:36.000000000 -0700
  684. @@ -40,9 +40,11 @@
  685. require(token == address(this), "ERC20FlashMint: wrong token");
  686. // silence warning about unused variable without the addition of bytecode.
  687. amount;
  688. - return 0;
  689. + return fee; // HARNESS: made "return" nonzero
  690. }
  691. + uint256 public fee; // HARNESS: added it to simulate random fee amount
  692. +
  693. /**
  694. * @dev Returns the receiver address of the flash fee. By default this
  695. * implementation returns the address(0) which means the fee amount will be burnt.
  696. diff -ruN token/ERC20/extensions/ERC20TokenizedVault.sol token/ERC20/extensions/ERC20TokenizedVault.sol
  697. --- token/ERC20/extensions/ERC20TokenizedVault.sol 1969-12-31 16:00:00.000000000 -0800
  698. +++ token/ERC20/extensions/ERC20TokenizedVault.sol 2022-08-11 21:28:36.000000000 -0700
  699. @@ -0,0 +1,217 @@
  700. +// SPDX-License-Identifier: MIT
  701. +
  702. +pragma solidity ^0.8.0;
  703. +
  704. +import "../ERC20.sol";
  705. +import "../utils/SafeERC20.sol";
  706. +import "../../../interfaces/IERC4626.sol";
  707. +import "../../../utils/math/Math.sol";
  708. +
  709. +/**
  710. + * @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in
  711. + * https://eips.ethereum.org/EIPS/eip-4626[EIP-4626].
  712. + *
  713. + * This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for
  714. + * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
  715. + * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this
  716. + * contract and not the "assets" token which is an independent contract.
  717. + *
  718. + * _Available since v4.7._
  719. + */
  720. +abstract contract ERC20TokenizedVault is ERC20, IERC4626 {
  721. + using Math for uint256;
  722. +
  723. + IERC20Metadata private immutable _asset;
  724. +
  725. + /**
  726. + * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777).
  727. + */
  728. + constructor(IERC20Metadata asset_) {
  729. + _asset = asset_;
  730. + }
  731. +
  732. + /** @dev See {IERC4262-asset} */
  733. + function asset() public view virtual override returns (address) {
  734. + return address(_asset);
  735. + }
  736. +
  737. + /** @dev See {IERC4262-totalAssets} */
  738. + function totalAssets() public view virtual override returns (uint256) {
  739. + return _asset.balanceOf(address(this));
  740. + }
  741. +
  742. + /** @dev See {IERC4262-convertToShares} */
  743. + function convertToShares(uint256 assets) public view virtual override returns (uint256 shares) {
  744. + return _convertToShares(assets, Math.Rounding.Down);
  745. + }
  746. +
  747. + /** @dev See {IERC4262-convertToAssets} */
  748. + function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets) {
  749. + return _convertToAssets(shares, Math.Rounding.Down);
  750. + }
  751. +
  752. + /** @dev See {IERC4262-maxDeposit} */
  753. + function maxDeposit(address) public view virtual override returns (uint256) {
  754. + return _isVaultCollateralized() ? type(uint256).max : 0;
  755. + }
  756. +
  757. + /** @dev See {IERC4262-maxMint} */
  758. + function maxMint(address) public view virtual override returns (uint256) {
  759. + return type(uint256).max;
  760. + }
  761. +
  762. + /** @dev See {IERC4262-maxWithdraw} */
  763. + function maxWithdraw(address owner) public view virtual override returns (uint256) {
  764. + return _convertToAssets(balanceOf(owner), Math.Rounding.Down);
  765. + }
  766. +
  767. + /** @dev See {IERC4262-maxRedeem} */
  768. + function maxRedeem(address owner) public view virtual override returns (uint256) {
  769. + return balanceOf(owner);
  770. + }
  771. +
  772. + /** @dev See {IERC4262-previewDeposit} */
  773. + function previewDeposit(uint256 assets) public view virtual override returns (uint256) {
  774. + return _convertToShares(assets, Math.Rounding.Down);
  775. + }
  776. +
  777. + /** @dev See {IERC4262-previewMint} */
  778. + function previewMint(uint256 shares) public view virtual override returns (uint256) {
  779. + return _convertToAssets(shares, Math.Rounding.Up);
  780. + }
  781. +
  782. + /** @dev See {IERC4262-previewWithdraw} */
  783. + function previewWithdraw(uint256 assets) public view virtual override returns (uint256) {
  784. + return _convertToShares(assets, Math.Rounding.Up);
  785. + }
  786. +
  787. + /** @dev See {IERC4262-previewRedeem} */
  788. + function previewRedeem(uint256 shares) public view virtual override returns (uint256) {
  789. + return _convertToAssets(shares, Math.Rounding.Down);
  790. + }
  791. +
  792. + /** @dev See {IERC4262-deposit} */
  793. + function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
  794. + require(assets <= maxDeposit(receiver), "ERC20TokenizedVault: deposit more than max");
  795. +
  796. + uint256 shares = previewDeposit(assets);
  797. + _deposit(_msgSender(), receiver, assets, shares);
  798. +
  799. + return shares;
  800. + }
  801. +
  802. + /** @dev See {IERC4262-mint} */
  803. + function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
  804. + require(shares <= maxMint(receiver), "ERC20TokenizedVault: mint more than max");
  805. +
  806. + uint256 assets = previewMint(shares);
  807. + _deposit(_msgSender(), receiver, assets, shares);
  808. +
  809. + return assets;
  810. + }
  811. +
  812. + /** @dev See {IERC4262-withdraw} */
  813. + function withdraw(
  814. + uint256 assets,
  815. + address receiver,
  816. + address owner
  817. + ) public virtual override returns (uint256) {
  818. + require(assets <= maxWithdraw(owner), "ERC20TokenizedVault: withdraw more than max");
  819. +
  820. + uint256 shares = previewWithdraw(assets);
  821. + _withdraw(_msgSender(), receiver, owner, assets, shares);
  822. +
  823. + return shares;
  824. + }
  825. +
  826. + /** @dev See {IERC4262-redeem} */
  827. + function redeem(
  828. + uint256 shares,
  829. + address receiver,
  830. + address owner
  831. + ) public virtual override returns (uint256) {
  832. + require(shares <= maxRedeem(owner), "ERC20TokenizedVault: redeem more than max");
  833. +
  834. + uint256 assets = previewRedeem(shares);
  835. + _withdraw(_msgSender(), receiver, owner, assets, shares);
  836. +
  837. + return assets;
  838. + }
  839. +
  840. + /**
  841. + * @dev Internal convertion function (from assets to shares) with support for rounding direction
  842. + *
  843. + * Will revert if assets > 0, totalSupply > 0 and totalAssets = 0. That corresponds to a case where any asset
  844. + * would represent an infinite amout of shares.
  845. + */
  846. + function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256 shares) {
  847. + uint256 supply = totalSupply();
  848. + return
  849. + (assets == 0 || supply == 0)
  850. + ? assets.mulDiv(10**decimals(), 10**_asset.decimals(), rounding)
  851. + : assets.mulDiv(supply, totalAssets(), rounding);
  852. + }
  853. +
  854. + /**
  855. + * @dev Internal convertion function (from shares to assets) with support for rounding direction
  856. + */
  857. + function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256 assets) {
  858. + uint256 supply = totalSupply();
  859. + return
  860. + (supply == 0)
  861. + ? shares.mulDiv(10**_asset.decimals(), 10**decimals(), rounding)
  862. + : shares.mulDiv(totalAssets(), supply, rounding);
  863. + }
  864. +
  865. + /**
  866. + * @dev Deposit/mint common workflow
  867. + */
  868. + function _deposit(
  869. + address caller,
  870. + address receiver,
  871. + uint256 assets,
  872. + uint256 shares
  873. + ) private {
  874. + // If _asset is ERC777, `transferFrom` can trigger a reenterancy BEFORE the transfer happens through the
  875. + // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
  876. + // calls the vault, which is assumed not malicious.
  877. + //
  878. + // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
  879. + // assets are transfered and before the shares are minted, which is a valid state.
  880. + // slither-disable-next-line reentrancy-no-eth
  881. + SafeERC20.safeTransferFrom(_asset, caller, address(this), assets);
  882. + _mint(receiver, shares);
  883. +
  884. + emit Deposit(caller, receiver, assets, shares);
  885. + }
  886. +
  887. + /**
  888. + * @dev Withdraw/redeem common workflow
  889. + */
  890. + function _withdraw(
  891. + address caller,
  892. + address receiver,
  893. + address owner,
  894. + uint256 assets,
  895. + uint256 shares
  896. + ) private {
  897. + if (caller != owner) {
  898. + _spendAllowance(owner, caller, shares);
  899. + }
  900. +
  901. + // If _asset is ERC777, `transfer` can trigger trigger a reentrancy AFTER the transfer happens through the
  902. + // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
  903. + // calls the vault, which is assumed not malicious.
  904. + //
  905. + // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
  906. + // shares are burned and after the assets are transfered, which is a valid state.
  907. + _burn(owner, shares);
  908. + SafeERC20.safeTransfer(_asset, receiver, assets);
  909. +
  910. + emit Withdraw(caller, receiver, owner, assets, shares);
  911. + }
  912. +
  913. + function _isVaultCollateralized() private view returns (bool) {
  914. + return totalAssets() > 0 || totalSupply() == 0;
  915. + }
  916. +}
  917. diff -ruN token/ERC20/extensions/ERC20Votes.sol token/ERC20/extensions/ERC20Votes.sol
  918. --- token/ERC20/extensions/ERC20Votes.sol 2022-08-11 21:16:57.000000000 -0700
  919. +++ token/ERC20/extensions/ERC20Votes.sol 2022-08-11 22:47:30.000000000 -0700
  920. @@ -33,8 +33,8 @@
  921. bytes32 private constant _DELEGATION_TYPEHASH =
  922. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  923. - mapping(address => address) private _delegates;
  924. - mapping(address => Checkpoint[]) private _checkpoints;
  925. + mapping(address => address) public _delegates;
  926. + mapping(address => Checkpoint[]) public _checkpoints;
  927. Checkpoint[] private _totalSupplyCheckpoints;
  928. /**
  929. @@ -152,7 +152,7 @@
  930. /**
  931. * @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).
  932. */
  933. - function _maxSupply() internal view virtual returns (uint224) {
  934. + function _maxSupply() public view virtual returns (uint224) { //harnessed to public
  935. return type(uint224).max;
  936. }
  937. @@ -163,16 +163,16 @@
  938. super._mint(account, amount);
  939. require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
  940. - _writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
  941. + _writeCheckpointAdd(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  942. }
  943. /**
  944. * @dev Snapshots the totalSupply after it has been decreased.
  945. */
  946. - function _burn(address account, uint256 amount) internal virtual override {
  947. + function _burn(address account, uint256 amount) public virtual override { // HARNESS: internal -> public (to comply with the ERC20 harness)
  948. super._burn(account, amount);
  949. - _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
  950. + _writeCheckpointSub(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  951. }
  952. /**
  953. @@ -187,7 +187,7 @@
  954. ) internal virtual override {
  955. super._afterTokenTransfer(from, to, amount);
  956. - _moveVotingPower(delegates(from), delegates(to), amount);
  957. + _moveVotingPower(delegates(from), delegates(to), amount);
  958. }
  959. /**
  960. @@ -195,7 +195,7 @@
  961. *
  962. * Emits events {DelegateChanged} and {DelegateVotesChanged}.
  963. */
  964. - function _delegate(address delegator, address delegatee) internal virtual {
  965. + function _delegate(address delegator, address delegatee) public virtual { // HARNESSED TO MAKE PUBLIC
  966. address currentDelegate = delegates(delegator);
  967. uint256 delegatorBalance = balanceOf(delegator);
  968. _delegates[delegator] = delegatee;
  969. @@ -212,25 +212,25 @@
  970. ) private {
  971. if (src != dst && amount > 0) {
  972. if (src != address(0)) {
  973. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
  974. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointSub(_checkpoints[src], amount); // HARNESS: new version without pointer
  975. emit DelegateVotesChanged(src, oldWeight, newWeight);
  976. }
  977. if (dst != address(0)) {
  978. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
  979. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointAdd(_checkpoints[dst], amount); // HARNESS: new version without pointer
  980. emit DelegateVotesChanged(dst, oldWeight, newWeight);
  981. }
  982. }
  983. }
  984. - function _writeCheckpoint(
  985. + // HARNESS: split _writeCheckpoint() to two functions as a workaround for function pointers that cannot be managed by the tool
  986. + function _writeCheckpointAdd(
  987. Checkpoint[] storage ckpts,
  988. - function(uint256, uint256) view returns (uint256) op,
  989. uint256 delta
  990. ) private returns (uint256 oldWeight, uint256 newWeight) {
  991. uint256 pos = ckpts.length;
  992. oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  993. - newWeight = op(oldWeight, delta);
  994. + newWeight = _add(oldWeight, delta);
  995. if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
  996. ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  997. @@ -239,6 +239,39 @@
  998. }
  999. }
  1000. + function _writeCheckpointSub(
  1001. + Checkpoint[] storage ckpts,
  1002. + uint256 delta
  1003. + ) private returns (uint256 oldWeight, uint256 newWeight) {
  1004. + uint256 pos = ckpts.length;
  1005. + oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  1006. + newWeight = _subtract(oldWeight, delta);
  1007. +
  1008. + if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
  1009. + ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  1010. + } else {
  1011. + ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)}));
  1012. + }
  1013. + }
  1014. +
  1015. + // backup of original function
  1016. + //
  1017. + // function _writeCheckpoint(
  1018. + // Checkpoint[] storage ckpts,
  1019. + // function(uint256, uint256) view returns (uint256) op,
  1020. + // uint256 delta
  1021. + // ) private returns (uint256 oldWeight, uint256 newWeight) {
  1022. + // uint256 pos = ckpts.length;
  1023. + // oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  1024. + // newWeight = op(oldWeight, delta);
  1025. + //
  1026. + // if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
  1027. + // ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  1028. + // } else {
  1029. + // ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)}));
  1030. + // }
  1031. + // }
  1032. +
  1033. function _add(uint256 a, uint256 b) private pure returns (uint256) {
  1034. return a + b;
  1035. }
  1036. diff -ruN token/ERC20/extensions/ERC20Wrapper.sol token/ERC20/extensions/ERC20Wrapper.sol
  1037. --- token/ERC20/extensions/ERC20Wrapper.sol 2022-08-11 21:28:00.000000000 -0700
  1038. +++ token/ERC20/extensions/ERC20Wrapper.sol 2022-08-11 21:29:19.000000000 -0700
  1039. @@ -1,5 +1,5 @@
  1040. // SPDX-License-Identifier: MIT
  1041. -// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/extensions/ERC20Wrapper.sol)
  1042. +// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Wrapper.sol)
  1043. pragma solidity ^0.8.0;
  1044. @@ -23,17 +23,6 @@
  1045. }
  1046. /**
  1047. - * @dev See {ERC20-decimals}.
  1048. - */
  1049. - function decimals() public view virtual override returns (uint8) {
  1050. - try IERC20Metadata(address(underlying)).decimals() returns (uint8 value) {
  1051. - return value;
  1052. - } catch {
  1053. - return super.decimals();
  1054. - }
  1055. - }
  1056. -
  1057. - /**
  1058. * @dev Allow a user to deposit underlying tokens and mint the corresponding number of wrapped tokens.
  1059. */
  1060. function depositFor(address account, uint256 amount) public virtual returns (bool) {
  1061. @@ -55,7 +44,7 @@
  1062. * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
  1063. * function that can be exposed with access control if desired.
  1064. */
  1065. - function _recover(address account) internal virtual returns (uint256) {
  1066. + function _recover(address account) public virtual returns (uint256) { // HARNESS: internal -> public
  1067. uint256 value = underlying.balanceOf(address(this)) - totalSupply();
  1068. _mint(account, value);
  1069. return value;
  1070. diff -ruN token/ERC20/extensions/ERC4626.sol token/ERC20/extensions/ERC4626.sol
  1071. --- token/ERC20/extensions/ERC4626.sol 2022-08-11 21:28:00.000000000 -0700
  1072. +++ token/ERC20/extensions/ERC4626.sol 1969-12-31 16:00:00.000000000 -0800
  1073. @@ -1,217 +0,0 @@
  1074. -// SPDX-License-Identifier: MIT
  1075. -
  1076. -pragma solidity ^0.8.0;
  1077. -
  1078. -import "../ERC20.sol";
  1079. -import "../utils/SafeERC20.sol";
  1080. -import "../../../interfaces/IERC4626.sol";
  1081. -import "../../../utils/math/Math.sol";
  1082. -
  1083. -/**
  1084. - * @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in
  1085. - * https://eips.ethereum.org/EIPS/eip-4626[EIP-4626].
  1086. - *
  1087. - * This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for
  1088. - * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
  1089. - * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this
  1090. - * contract and not the "assets" token which is an independent contract.
  1091. - *
  1092. - * _Available since v4.7._
  1093. - */
  1094. -abstract contract ERC4626 is ERC20, IERC4626 {
  1095. - using Math for uint256;
  1096. -
  1097. - IERC20Metadata private immutable _asset;
  1098. -
  1099. - /**
  1100. - * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777).
  1101. - */
  1102. - constructor(IERC20Metadata asset_) {
  1103. - _asset = asset_;
  1104. - }
  1105. -
  1106. - /** @dev See {IERC4262-asset} */
  1107. - function asset() public view virtual override returns (address) {
  1108. - return address(_asset);
  1109. - }
  1110. -
  1111. - /** @dev See {IERC4262-totalAssets} */
  1112. - function totalAssets() public view virtual override returns (uint256) {
  1113. - return _asset.balanceOf(address(this));
  1114. - }
  1115. -
  1116. - /** @dev See {IERC4262-convertToShares} */
  1117. - function convertToShares(uint256 assets) public view virtual override returns (uint256 shares) {
  1118. - return _convertToShares(assets, Math.Rounding.Down);
  1119. - }
  1120. -
  1121. - /** @dev See {IERC4262-convertToAssets} */
  1122. - function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets) {
  1123. - return _convertToAssets(shares, Math.Rounding.Down);
  1124. - }
  1125. -
  1126. - /** @dev See {IERC4262-maxDeposit} */
  1127. - function maxDeposit(address) public view virtual override returns (uint256) {
  1128. - return _isVaultCollateralized() ? type(uint256).max : 0;
  1129. - }
  1130. -
  1131. - /** @dev See {IERC4262-maxMint} */
  1132. - function maxMint(address) public view virtual override returns (uint256) {
  1133. - return type(uint256).max;
  1134. - }
  1135. -
  1136. - /** @dev See {IERC4262-maxWithdraw} */
  1137. - function maxWithdraw(address owner) public view virtual override returns (uint256) {
  1138. - return _convertToAssets(balanceOf(owner), Math.Rounding.Down);
  1139. - }
  1140. -
  1141. - /** @dev See {IERC4262-maxRedeem} */
  1142. - function maxRedeem(address owner) public view virtual override returns (uint256) {
  1143. - return balanceOf(owner);
  1144. - }
  1145. -
  1146. - /** @dev See {IERC4262-previewDeposit} */
  1147. - function previewDeposit(uint256 assets) public view virtual override returns (uint256) {
  1148. - return _convertToShares(assets, Math.Rounding.Down);
  1149. - }
  1150. -
  1151. - /** @dev See {IERC4262-previewMint} */
  1152. - function previewMint(uint256 shares) public view virtual override returns (uint256) {
  1153. - return _convertToAssets(shares, Math.Rounding.Up);
  1154. - }
  1155. -
  1156. - /** @dev See {IERC4262-previewWithdraw} */
  1157. - function previewWithdraw(uint256 assets) public view virtual override returns (uint256) {
  1158. - return _convertToShares(assets, Math.Rounding.Up);
  1159. - }
  1160. -
  1161. - /** @dev See {IERC4262-previewRedeem} */
  1162. - function previewRedeem(uint256 shares) public view virtual override returns (uint256) {
  1163. - return _convertToAssets(shares, Math.Rounding.Down);
  1164. - }
  1165. -
  1166. - /** @dev See {IERC4262-deposit} */
  1167. - function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
  1168. - require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max");
  1169. -
  1170. - uint256 shares = previewDeposit(assets);
  1171. - _deposit(_msgSender(), receiver, assets, shares);
  1172. -
  1173. - return shares;
  1174. - }
  1175. -
  1176. - /** @dev See {IERC4262-mint} */
  1177. - function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
  1178. - require(shares <= maxMint(receiver), "ERC4626: mint more than max");
  1179. -
  1180. - uint256 assets = previewMint(shares);
  1181. - _deposit(_msgSender(), receiver, assets, shares);
  1182. -
  1183. - return assets;
  1184. - }
  1185. -
  1186. - /** @dev See {IERC4262-withdraw} */
  1187. - function withdraw(
  1188. - uint256 assets,
  1189. - address receiver,
  1190. - address owner
  1191. - ) public virtual override returns (uint256) {
  1192. - require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");
  1193. -
  1194. - uint256 shares = previewWithdraw(assets);
  1195. - _withdraw(_msgSender(), receiver, owner, assets, shares);
  1196. -
  1197. - return shares;
  1198. - }
  1199. -
  1200. - /** @dev See {IERC4262-redeem} */
  1201. - function redeem(
  1202. - uint256 shares,
  1203. - address receiver,
  1204. - address owner
  1205. - ) public virtual override returns (uint256) {
  1206. - require(shares <= maxRedeem(owner), "ERC4626: redeem more than max");
  1207. -
  1208. - uint256 assets = previewRedeem(shares);
  1209. - _withdraw(_msgSender(), receiver, owner, assets, shares);
  1210. -
  1211. - return assets;
  1212. - }
  1213. -
  1214. - /**
  1215. - * @dev Internal convertion function (from assets to shares) with support for rounding direction
  1216. - *
  1217. - * Will revert if assets > 0, totalSupply > 0 and totalAssets = 0. That corresponds to a case where any asset
  1218. - * would represent an infinite amout of shares.
  1219. - */
  1220. - function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256 shares) {
  1221. - uint256 supply = totalSupply();
  1222. - return
  1223. - (assets == 0 || supply == 0)
  1224. - ? assets.mulDiv(10**decimals(), 10**_asset.decimals(), rounding)
  1225. - : assets.mulDiv(supply, totalAssets(), rounding);
  1226. - }
  1227. -
  1228. - /**
  1229. - * @dev Internal convertion function (from shares to assets) with support for rounding direction
  1230. - */
  1231. - function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256 assets) {
  1232. - uint256 supply = totalSupply();
  1233. - return
  1234. - (supply == 0)
  1235. - ? shares.mulDiv(10**_asset.decimals(), 10**decimals(), rounding)
  1236. - : shares.mulDiv(totalAssets(), supply, rounding);
  1237. - }
  1238. -
  1239. - /**
  1240. - * @dev Deposit/mint common workflow
  1241. - */
  1242. - function _deposit(
  1243. - address caller,
  1244. - address receiver,
  1245. - uint256 assets,
  1246. - uint256 shares
  1247. - ) private {
  1248. - // If _asset is ERC777, `transferFrom` can trigger a reenterancy BEFORE the transfer happens through the
  1249. - // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
  1250. - // calls the vault, which is assumed not malicious.
  1251. - //
  1252. - // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
  1253. - // assets are transfered and before the shares are minted, which is a valid state.
  1254. - // slither-disable-next-line reentrancy-no-eth
  1255. - SafeERC20.safeTransferFrom(_asset, caller, address(this), assets);
  1256. - _mint(receiver, shares);
  1257. -
  1258. - emit Deposit(caller, receiver, assets, shares);
  1259. - }
  1260. -
  1261. - /**
  1262. - * @dev Withdraw/redeem common workflow
  1263. - */
  1264. - function _withdraw(
  1265. - address caller,
  1266. - address receiver,
  1267. - address owner,
  1268. - uint256 assets,
  1269. - uint256 shares
  1270. - ) private {
  1271. - if (caller != owner) {
  1272. - _spendAllowance(owner, caller, shares);
  1273. - }
  1274. -
  1275. - // If _asset is ERC777, `transfer` can trigger trigger a reentrancy AFTER the transfer happens through the
  1276. - // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
  1277. - // calls the vault, which is assumed not malicious.
  1278. - //
  1279. - // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
  1280. - // shares are burned and after the assets are transfered, which is a valid state.
  1281. - _burn(owner, shares);
  1282. - SafeERC20.safeTransfer(_asset, receiver, assets);
  1283. -
  1284. - emit Withdraw(caller, receiver, owner, assets, shares);
  1285. - }
  1286. -
  1287. - function _isVaultCollateralized() private view returns (bool) {
  1288. - return totalAssets() > 0 || totalSupply() == 0;
  1289. - }
  1290. -}
  1291. diff -ruN token/ERC20/utils/SafeERC20.sol token/ERC20/utils/SafeERC20.sol
  1292. --- token/ERC20/utils/SafeERC20.sol 2022-08-11 21:28:00.000000000 -0700
  1293. +++ token/ERC20/utils/SafeERC20.sol 2022-08-11 21:28:36.000000000 -0700
  1294. @@ -4,7 +4,6 @@
  1295. pragma solidity ^0.8.0;
  1296. import "../IERC20.sol";
  1297. -import "../extensions/draft-IERC20Permit.sol";
  1298. import "../../../utils/Address.sol";
  1299. /**
  1300. @@ -80,22 +79,6 @@
  1301. }
  1302. }
  1303. - function safePermit(
  1304. - IERC20Permit token,
  1305. - address owner,
  1306. - address spender,
  1307. - uint256 value,
  1308. - uint256 deadline,
  1309. - uint8 v,
  1310. - bytes32 r,
  1311. - bytes32 s
  1312. - ) internal {
  1313. - uint256 nonceBefore = token.nonces(owner);
  1314. - token.permit(owner, spender, value, deadline, v, r, s);
  1315. - uint256 nonceAfter = token.nonces(owner);
  1316. - require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
  1317. - }
  1318. -
  1319. /**
  1320. * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
  1321. * on the return value: the return value is optional (but if data is returned, it must not be false).
  1322. diff -ruN token/ERC721/extensions/draft-ERC721Votes.sol token/ERC721/extensions/draft-ERC721Votes.sol
  1323. --- token/ERC721/extensions/draft-ERC721Votes.sol 2022-08-11 21:28:00.000000000 -0700
  1324. +++ token/ERC721/extensions/draft-ERC721Votes.sol 2022-08-11 21:28:36.000000000 -0700
  1325. @@ -34,7 +34,7 @@
  1326. /**
  1327. * @dev Returns the balance of `account`.
  1328. */
  1329. - function _getVotingUnits(address account) internal view virtual override returns (uint256) {
  1330. + function _getVotingUnits(address account) public view virtual override returns (uint256) {
  1331. return balanceOf(account);
  1332. }
  1333. }
  1334. diff -ruN utils/Address.sol utils/Address.sol
  1335. --- utils/Address.sol 2022-08-11 21:28:00.000000000 -0700
  1336. +++ utils/Address.sol 2022-08-11 21:28:36.000000000 -0700
  1337. @@ -131,6 +131,7 @@
  1338. uint256 value,
  1339. string memory errorMessage
  1340. ) internal returns (bytes memory) {
  1341. + return ""; // external calls havoc
  1342. require(address(this).balance >= value, "Address: insufficient balance for call");
  1343. require(isContract(target), "Address: call to non-contract");
  1344. diff -ruN utils/math/Math.sol utils/math/Math.sol
  1345. --- utils/math/Math.sol 2022-08-11 21:28:00.000000000 -0700
  1346. +++ utils/math/Math.sol 2022-08-11 21:28:36.000000000 -0700
  1347. @@ -149,78 +149,4 @@
  1348. }
  1349. return result;
  1350. }
  1351. -
  1352. - /**
  1353. - * @dev Returns the square root of a number. It the number is not a perfect square, the value is rounded down.
  1354. - *
  1355. - * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
  1356. - */
  1357. - function sqrt(uint256 a) internal pure returns (uint256) {
  1358. - if (a == 0) {
  1359. - return 0;
  1360. - }
  1361. -
  1362. - // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
  1363. - // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
  1364. - // `msb(a) <= a < 2*msb(a)`.
  1365. - // We also know that `k`, the position of the most significant bit, is such that `msb(a) = 2**k`.
  1366. - // This gives `2**k < a <= 2**(k+1)` → `2**(k/2) <= sqrt(a) < 2 ** (k/2+1)`.
  1367. - // Using an algorithm similar to the msb conmputation, we are able to compute `result = 2**(k/2)` which is a
  1368. - // good first aproximation of `sqrt(a)` with at least 1 correct bit.
  1369. - uint256 result = 1;
  1370. - uint256 x = a;
  1371. - if (x >> 128 > 0) {
  1372. - x >>= 128;
  1373. - result <<= 64;
  1374. - }
  1375. - if (x >> 64 > 0) {
  1376. - x >>= 64;
  1377. - result <<= 32;
  1378. - }
  1379. - if (x >> 32 > 0) {
  1380. - x >>= 32;
  1381. - result <<= 16;
  1382. - }
  1383. - if (x >> 16 > 0) {
  1384. - x >>= 16;
  1385. - result <<= 8;
  1386. - }
  1387. - if (x >> 8 > 0) {
  1388. - x >>= 8;
  1389. - result <<= 4;
  1390. - }
  1391. - if (x >> 4 > 0) {
  1392. - x >>= 4;
  1393. - result <<= 2;
  1394. - }
  1395. - if (x >> 2 > 0) {
  1396. - result <<= 1;
  1397. - }
  1398. -
  1399. - // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
  1400. - // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
  1401. - // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
  1402. - // into the expected uint128 result.
  1403. - unchecked {
  1404. - result = (result + a / result) >> 1;
  1405. - result = (result + a / result) >> 1;
  1406. - result = (result + a / result) >> 1;
  1407. - result = (result + a / result) >> 1;
  1408. - result = (result + a / result) >> 1;
  1409. - result = (result + a / result) >> 1;
  1410. - result = (result + a / result) >> 1;
  1411. - return min(result, a / result);
  1412. - }
  1413. - }
  1414. -
  1415. - /**
  1416. - * @notice Calculates sqrt(a), following the selected rounding direction.
  1417. - */
  1418. - function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
  1419. - uint256 result = sqrt(a);
  1420. - if (rounding == Rounding.Up && result * result < a) {
  1421. - result += 1;
  1422. - }
  1423. - return result;
  1424. - }
  1425. }