applyHarness.patch 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. diff -ruN .gitignore .gitignore
  2. --- .gitignore 1969-12-31 16:00:00.000000000 -0800
  3. +++ .gitignore 2022-08-11 21:15:52.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:13:55.000000000 -0700
  9. +++ access/AccessControl.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  20. +++ access/Ownable.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  49. +++ governance/Governor.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  58. +++ governance/TimelockController.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  72. +++ governance/extensions/GovernorCountingSimple.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  82. +++ governance/extensions/GovernorPreventLateQuorum.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  94. +++ governance/utils/Votes.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  166. +++ metatx/MinimalForwarder.sol 2022-08-11 21:15:52.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:15:52.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:13:55.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:13:55.000000000 -0700
  232. +++ mocks/MathMock.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  244. +++ mocks/SafeERC20Helper.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  313. +++ proxy/Clones.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  366. +++ proxy/ERC1967/ERC1967Proxy.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  376. +++ proxy/beacon/BeaconProxy.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  386. +++ proxy/transparent/TransparentUpgradeableProxy.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  396. +++ proxy/utils/Initializable.sol 2022-08-11 21:15:52.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:15:52.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:15:52.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:13:55.000000000 -0700
  575. +++ security/Pausable.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  629. +++ token/ERC1155/ERC1155.sol 2022-08-11 21:15:52.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:25:35.000000000 -0700
  657. +++ token/ERC20/ERC20.sol 2022-08-11 21:15:52.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:13:55.000000000 -0700
  668. +++ token/ERC20/README.adoc 2022-08-11 21:15:52.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:13:55.000000000 -0700
  683. +++ token/ERC20/extensions/ERC20FlashMint.sol 2022-08-11 21:15:52.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:15:52.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 21:25:13.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:13:55.000000000 -0700
  1038. +++ token/ERC20/extensions/ERC20Wrapper.sol 2022-08-11 21:15:52.000000000 -0700
  1039. @@ -55,7 +55,7 @@
  1040. * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
  1041. * function that can be exposed with access control if desired.
  1042. */
  1043. - function _recover(address account) internal virtual returns (uint256) {
  1044. + function _recover(address account) public virtual returns (uint256) { // HARNESS: internal -> public
  1045. uint256 value = underlying.balanceOf(address(this)) - totalSupply();
  1046. _mint(account, value);
  1047. return value;
  1048. diff -ruN token/ERC20/extensions/ERC4626.sol token/ERC20/extensions/ERC4626.sol
  1049. --- token/ERC20/extensions/ERC4626.sol 2022-08-11 21:13:55.000000000 -0700
  1050. +++ token/ERC20/extensions/ERC4626.sol 1969-12-31 16:00:00.000000000 -0800
  1051. @@ -1,217 +0,0 @@
  1052. -// SPDX-License-Identifier: MIT
  1053. -
  1054. -pragma solidity ^0.8.0;
  1055. -
  1056. -import "../ERC20.sol";
  1057. -import "../utils/SafeERC20.sol";
  1058. -import "../../../interfaces/IERC4626.sol";
  1059. -import "../../../utils/math/Math.sol";
  1060. -
  1061. -/**
  1062. - * @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in
  1063. - * https://eips.ethereum.org/EIPS/eip-4626[EIP-4626].
  1064. - *
  1065. - * This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for
  1066. - * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
  1067. - * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this
  1068. - * contract and not the "assets" token which is an independent contract.
  1069. - *
  1070. - * _Available since v4.7._
  1071. - */
  1072. -abstract contract ERC4626 is ERC20, IERC4626 {
  1073. - using Math for uint256;
  1074. -
  1075. - IERC20Metadata private immutable _asset;
  1076. -
  1077. - /**
  1078. - * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777).
  1079. - */
  1080. - constructor(IERC20Metadata asset_) {
  1081. - _asset = asset_;
  1082. - }
  1083. -
  1084. - /** @dev See {IERC4262-asset} */
  1085. - function asset() public view virtual override returns (address) {
  1086. - return address(_asset);
  1087. - }
  1088. -
  1089. - /** @dev See {IERC4262-totalAssets} */
  1090. - function totalAssets() public view virtual override returns (uint256) {
  1091. - return _asset.balanceOf(address(this));
  1092. - }
  1093. -
  1094. - /** @dev See {IERC4262-convertToShares} */
  1095. - function convertToShares(uint256 assets) public view virtual override returns (uint256 shares) {
  1096. - return _convertToShares(assets, Math.Rounding.Down);
  1097. - }
  1098. -
  1099. - /** @dev See {IERC4262-convertToAssets} */
  1100. - function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets) {
  1101. - return _convertToAssets(shares, Math.Rounding.Down);
  1102. - }
  1103. -
  1104. - /** @dev See {IERC4262-maxDeposit} */
  1105. - function maxDeposit(address) public view virtual override returns (uint256) {
  1106. - return _isVaultCollateralized() ? type(uint256).max : 0;
  1107. - }
  1108. -
  1109. - /** @dev See {IERC4262-maxMint} */
  1110. - function maxMint(address) public view virtual override returns (uint256) {
  1111. - return type(uint256).max;
  1112. - }
  1113. -
  1114. - /** @dev See {IERC4262-maxWithdraw} */
  1115. - function maxWithdraw(address owner) public view virtual override returns (uint256) {
  1116. - return _convertToAssets(balanceOf(owner), Math.Rounding.Down);
  1117. - }
  1118. -
  1119. - /** @dev See {IERC4262-maxRedeem} */
  1120. - function maxRedeem(address owner) public view virtual override returns (uint256) {
  1121. - return balanceOf(owner);
  1122. - }
  1123. -
  1124. - /** @dev See {IERC4262-previewDeposit} */
  1125. - function previewDeposit(uint256 assets) public view virtual override returns (uint256) {
  1126. - return _convertToShares(assets, Math.Rounding.Down);
  1127. - }
  1128. -
  1129. - /** @dev See {IERC4262-previewMint} */
  1130. - function previewMint(uint256 shares) public view virtual override returns (uint256) {
  1131. - return _convertToAssets(shares, Math.Rounding.Up);
  1132. - }
  1133. -
  1134. - /** @dev See {IERC4262-previewWithdraw} */
  1135. - function previewWithdraw(uint256 assets) public view virtual override returns (uint256) {
  1136. - return _convertToShares(assets, Math.Rounding.Up);
  1137. - }
  1138. -
  1139. - /** @dev See {IERC4262-previewRedeem} */
  1140. - function previewRedeem(uint256 shares) public view virtual override returns (uint256) {
  1141. - return _convertToAssets(shares, Math.Rounding.Down);
  1142. - }
  1143. -
  1144. - /** @dev See {IERC4262-deposit} */
  1145. - function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
  1146. - require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max");
  1147. -
  1148. - uint256 shares = previewDeposit(assets);
  1149. - _deposit(_msgSender(), receiver, assets, shares);
  1150. -
  1151. - return shares;
  1152. - }
  1153. -
  1154. - /** @dev See {IERC4262-mint} */
  1155. - function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
  1156. - require(shares <= maxMint(receiver), "ERC4626: mint more than max");
  1157. -
  1158. - uint256 assets = previewMint(shares);
  1159. - _deposit(_msgSender(), receiver, assets, shares);
  1160. -
  1161. - return assets;
  1162. - }
  1163. -
  1164. - /** @dev See {IERC4262-withdraw} */
  1165. - function withdraw(
  1166. - uint256 assets,
  1167. - address receiver,
  1168. - address owner
  1169. - ) public virtual override returns (uint256) {
  1170. - require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");
  1171. -
  1172. - uint256 shares = previewWithdraw(assets);
  1173. - _withdraw(_msgSender(), receiver, owner, assets, shares);
  1174. -
  1175. - return shares;
  1176. - }
  1177. -
  1178. - /** @dev See {IERC4262-redeem} */
  1179. - function redeem(
  1180. - uint256 shares,
  1181. - address receiver,
  1182. - address owner
  1183. - ) public virtual override returns (uint256) {
  1184. - require(shares <= maxRedeem(owner), "ERC4626: redeem more than max");
  1185. -
  1186. - uint256 assets = previewRedeem(shares);
  1187. - _withdraw(_msgSender(), receiver, owner, assets, shares);
  1188. -
  1189. - return assets;
  1190. - }
  1191. -
  1192. - /**
  1193. - * @dev Internal convertion function (from assets to shares) with support for rounding direction
  1194. - *
  1195. - * Will revert if assets > 0, totalSupply > 0 and totalAssets = 0. That corresponds to a case where any asset
  1196. - * would represent an infinite amout of shares.
  1197. - */
  1198. - function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256 shares) {
  1199. - uint256 supply = totalSupply();
  1200. - return
  1201. - (assets == 0 || supply == 0)
  1202. - ? assets.mulDiv(10**decimals(), 10**_asset.decimals(), rounding)
  1203. - : assets.mulDiv(supply, totalAssets(), rounding);
  1204. - }
  1205. -
  1206. - /**
  1207. - * @dev Internal convertion function (from shares to assets) with support for rounding direction
  1208. - */
  1209. - function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256 assets) {
  1210. - uint256 supply = totalSupply();
  1211. - return
  1212. - (supply == 0)
  1213. - ? shares.mulDiv(10**_asset.decimals(), 10**decimals(), rounding)
  1214. - : shares.mulDiv(totalAssets(), supply, rounding);
  1215. - }
  1216. -
  1217. - /**
  1218. - * @dev Deposit/mint common workflow
  1219. - */
  1220. - function _deposit(
  1221. - address caller,
  1222. - address receiver,
  1223. - uint256 assets,
  1224. - uint256 shares
  1225. - ) private {
  1226. - // If _asset is ERC777, `transferFrom` can trigger a reenterancy BEFORE the transfer happens through the
  1227. - // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
  1228. - // calls the vault, which is assumed not malicious.
  1229. - //
  1230. - // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
  1231. - // assets are transfered and before the shares are minted, which is a valid state.
  1232. - // slither-disable-next-line reentrancy-no-eth
  1233. - SafeERC20.safeTransferFrom(_asset, caller, address(this), assets);
  1234. - _mint(receiver, shares);
  1235. -
  1236. - emit Deposit(caller, receiver, assets, shares);
  1237. - }
  1238. -
  1239. - /**
  1240. - * @dev Withdraw/redeem common workflow
  1241. - */
  1242. - function _withdraw(
  1243. - address caller,
  1244. - address receiver,
  1245. - address owner,
  1246. - uint256 assets,
  1247. - uint256 shares
  1248. - ) private {
  1249. - if (caller != owner) {
  1250. - _spendAllowance(owner, caller, shares);
  1251. - }
  1252. -
  1253. - // If _asset is ERC777, `transfer` can trigger trigger a reentrancy AFTER the transfer happens through the
  1254. - // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
  1255. - // calls the vault, which is assumed not malicious.
  1256. - //
  1257. - // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
  1258. - // shares are burned and after the assets are transfered, which is a valid state.
  1259. - _burn(owner, shares);
  1260. - SafeERC20.safeTransfer(_asset, receiver, assets);
  1261. -
  1262. - emit Withdraw(caller, receiver, owner, assets, shares);
  1263. - }
  1264. -
  1265. - function _isVaultCollateralized() private view returns (bool) {
  1266. - return totalAssets() > 0 || totalSupply() == 0;
  1267. - }
  1268. -}
  1269. diff -ruN token/ERC20/utils/SafeERC20.sol token/ERC20/utils/SafeERC20.sol
  1270. --- token/ERC20/utils/SafeERC20.sol 2022-08-11 21:13:55.000000000 -0700
  1271. +++ token/ERC20/utils/SafeERC20.sol 2022-08-11 21:15:52.000000000 -0700
  1272. @@ -4,7 +4,6 @@
  1273. pragma solidity ^0.8.0;
  1274. import "../IERC20.sol";
  1275. -import "../extensions/draft-IERC20Permit.sol";
  1276. import "../../../utils/Address.sol";
  1277. /**
  1278. @@ -80,22 +79,6 @@
  1279. }
  1280. }
  1281. - function safePermit(
  1282. - IERC20Permit token,
  1283. - address owner,
  1284. - address spender,
  1285. - uint256 value,
  1286. - uint256 deadline,
  1287. - uint8 v,
  1288. - bytes32 r,
  1289. - bytes32 s
  1290. - ) internal {
  1291. - uint256 nonceBefore = token.nonces(owner);
  1292. - token.permit(owner, spender, value, deadline, v, r, s);
  1293. - uint256 nonceAfter = token.nonces(owner);
  1294. - require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
  1295. - }
  1296. -
  1297. /**
  1298. * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
  1299. * on the return value: the return value is optional (but if data is returned, it must not be false).
  1300. diff -ruN token/ERC721/extensions/draft-ERC721Votes.sol token/ERC721/extensions/draft-ERC721Votes.sol
  1301. --- token/ERC721/extensions/draft-ERC721Votes.sol 2022-08-11 21:13:55.000000000 -0700
  1302. +++ token/ERC721/extensions/draft-ERC721Votes.sol 2022-08-11 21:15:52.000000000 -0700
  1303. @@ -34,7 +34,7 @@
  1304. /**
  1305. * @dev Returns the balance of `account`.
  1306. */
  1307. - function _getVotingUnits(address account) internal view virtual override returns (uint256) {
  1308. + function _getVotingUnits(address account) public view virtual override returns (uint256) {
  1309. return balanceOf(account);
  1310. }
  1311. }
  1312. diff -ruN utils/Address.sol utils/Address.sol
  1313. --- utils/Address.sol 2022-08-11 21:13:55.000000000 -0700
  1314. +++ utils/Address.sol 2022-08-11 21:15:52.000000000 -0700
  1315. @@ -131,6 +131,7 @@
  1316. uint256 value,
  1317. string memory errorMessage
  1318. ) internal returns (bytes memory) {
  1319. + return ""; // external calls havoc
  1320. require(address(this).balance >= value, "Address: insufficient balance for call");
  1321. require(isContract(target), "Address: call to non-contract");
  1322. diff -ruN utils/math/Math.sol utils/math/Math.sol
  1323. --- utils/math/Math.sol 2022-08-11 21:13:55.000000000 -0700
  1324. +++ utils/math/Math.sol 2022-08-11 21:15:52.000000000 -0700
  1325. @@ -149,78 +149,4 @@
  1326. }
  1327. return result;
  1328. }
  1329. -
  1330. - /**
  1331. - * @dev Returns the square root of a number. It the number is not a perfect square, the value is rounded down.
  1332. - *
  1333. - * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
  1334. - */
  1335. - function sqrt(uint256 a) internal pure returns (uint256) {
  1336. - if (a == 0) {
  1337. - return 0;
  1338. - }
  1339. -
  1340. - // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
  1341. - // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
  1342. - // `msb(a) <= a < 2*msb(a)`.
  1343. - // We also know that `k`, the position of the most significant bit, is such that `msb(a) = 2**k`.
  1344. - // This gives `2**k < a <= 2**(k+1)` → `2**(k/2) <= sqrt(a) < 2 ** (k/2+1)`.
  1345. - // Using an algorithm similar to the msb conmputation, we are able to compute `result = 2**(k/2)` which is a
  1346. - // good first aproximation of `sqrt(a)` with at least 1 correct bit.
  1347. - uint256 result = 1;
  1348. - uint256 x = a;
  1349. - if (x >> 128 > 0) {
  1350. - x >>= 128;
  1351. - result <<= 64;
  1352. - }
  1353. - if (x >> 64 > 0) {
  1354. - x >>= 64;
  1355. - result <<= 32;
  1356. - }
  1357. - if (x >> 32 > 0) {
  1358. - x >>= 32;
  1359. - result <<= 16;
  1360. - }
  1361. - if (x >> 16 > 0) {
  1362. - x >>= 16;
  1363. - result <<= 8;
  1364. - }
  1365. - if (x >> 8 > 0) {
  1366. - x >>= 8;
  1367. - result <<= 4;
  1368. - }
  1369. - if (x >> 4 > 0) {
  1370. - x >>= 4;
  1371. - result <<= 2;
  1372. - }
  1373. - if (x >> 2 > 0) {
  1374. - result <<= 1;
  1375. - }
  1376. -
  1377. - // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
  1378. - // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
  1379. - // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
  1380. - // into the expected uint128 result.
  1381. - unchecked {
  1382. - result = (result + a / result) >> 1;
  1383. - result = (result + a / result) >> 1;
  1384. - result = (result + a / result) >> 1;
  1385. - result = (result + a / result) >> 1;
  1386. - result = (result + a / result) >> 1;
  1387. - result = (result + a / result) >> 1;
  1388. - result = (result + a / result) >> 1;
  1389. - return min(result, a / result);
  1390. - }
  1391. - }
  1392. -
  1393. - /**
  1394. - * @notice Calculates sqrt(a), following the selected rounding direction.
  1395. - */
  1396. - function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
  1397. - uint256 result = sqrt(a);
  1398. - if (rounding == Rounding.Up && result * result < a) {
  1399. - result += 1;
  1400. - }
  1401. - return result;
  1402. - }
  1403. }