applyHarness.patch 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. diff -ruN .gitignore .gitignore
  2. --- .gitignore 1969-12-31 16:00:00.000000000 -0800
  3. +++ .gitignore 2022-06-06 12:25:10.000000000 -0700
  4. @@ -0,0 +1,2 @@
  5. +*
  6. +!.gitignore
  7. diff -ruN access/AccessControl.sol access/AccessControl.sol
  8. --- access/AccessControl.sol 2022-06-06 10:42:37.000000000 -0700
  9. +++ access/AccessControl.sol 2022-06-06 12:25:10.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-06-14 06:30:55.000000000 -0700
  20. +++ access/Ownable.sol 2022-06-06 12:25:10.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-06-06 10:42:37.000000000 -0700
  49. +++ governance/Governor.sol 2022-06-06 12:25:10.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-06-06 10:42:37.000000000 -0700
  58. +++ governance/TimelockController.sol 2022-06-06 12:25:10.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-06-14 16:49:50.000000000 -0700
  72. +++ governance/extensions/GovernorCountingSimple.sol 2022-06-06 12:25:10.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-06-06 10:42:37.000000000 -0700
  82. +++ governance/extensions/GovernorPreventLateQuorum.sol 2022-06-15 17:00:30.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-06-06 10:42:37.000000000 -0700
  94. +++ governance/utils/Votes.sol 2022-06-06 12:25:10.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-06-14 06:30:55.000000000 -0700
  166. +++ metatx/MinimalForwarder.sol 2022-06-06 12:25:10.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-06-06 12:25:10.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-06-15 14:13:43.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-06-14 06:30:55.000000000 -0700
  232. +++ mocks/MathMock.sol 2022-06-06 12:25:10.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-06-14 06:30:55.000000000 -0700
  244. +++ mocks/SafeERC20Helper.sol 2022-06-06 12:25:10.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-06-14 06:30:55.000000000 -0700
  313. +++ proxy/Clones.sol 2022-06-06 12:25:10.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-06-14 06:30:55.000000000 -0700
  366. +++ proxy/ERC1967/ERC1967Proxy.sol 2022-06-06 12:25:10.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-06-14 06:30:55.000000000 -0700
  376. +++ proxy/beacon/BeaconProxy.sol 2022-06-06 12:25:10.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-06-14 06:30:55.000000000 -0700
  386. +++ proxy/transparent/TransparentUpgradeableProxy.sol 2022-06-06 12:25:10.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-06-06 10:42:37.000000000 -0700
  396. +++ proxy/utils/Initializable.sol 2022-06-06 12:25:10.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-06-06 12:25:10.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-06-06 12:25:10.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-06-14 06:30:55.000000000 -0700
  575. +++ security/Pausable.sol 2022-06-06 12:25:10.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-06-06 10:42:37.000000000 -0700
  629. +++ token/ERC1155/ERC1155.sol 2022-06-15 16:37:15.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-06-06 10:42:37.000000000 -0700
  657. +++ token/ERC20/ERC20.sol 2022-06-06 12:25:10.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-06-15 14:13:43.000000000 -0700
  668. +++ token/ERC20/README.adoc 2022-06-06 12:25:10.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-06-06 10:42:37.000000000 -0700
  683. +++ token/ERC20/extensions/ERC20FlashMint.sol 2022-06-06 12:25:10.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-06-06 12:25:10.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-06-06 10:42:37.000000000 -0700
  919. +++ token/ERC20/extensions/ERC20Votes.sol 2022-06-06 12:25:10.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. @@ -169,7 +169,7 @@
  930. /**
  931. * @dev Snapshots the totalSupply after it has been decreased.
  932. */
  933. - function _burn(address account, uint256 amount) internal virtual override {
  934. + function _burn(address account, uint256 amount) public virtual override {
  935. super._burn(account, amount);
  936. _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
  937. diff -ruN token/ERC20/extensions/ERC20Wrapper.sol token/ERC20/extensions/ERC20Wrapper.sol
  938. --- token/ERC20/extensions/ERC20Wrapper.sol 2022-06-06 10:42:37.000000000 -0700
  939. +++ token/ERC20/extensions/ERC20Wrapper.sol 2022-06-06 12:25:10.000000000 -0700
  940. @@ -55,7 +55,7 @@
  941. * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
  942. * function that can be exposed with access control if desired.
  943. */
  944. - function _recover(address account) internal virtual returns (uint256) {
  945. + function _recover(address account) public virtual returns (uint256) { // HARNESS: internal -> public
  946. uint256 value = underlying.balanceOf(address(this)) - totalSupply();
  947. _mint(account, value);
  948. return value;
  949. diff -ruN token/ERC20/extensions/ERC4626.sol token/ERC20/extensions/ERC4626.sol
  950. --- token/ERC20/extensions/ERC4626.sol 2022-06-15 14:13:43.000000000 -0700
  951. +++ token/ERC20/extensions/ERC4626.sol 1969-12-31 16:00:00.000000000 -0800
  952. @@ -1,217 +0,0 @@
  953. -// SPDX-License-Identifier: MIT
  954. -
  955. -pragma solidity ^0.8.0;
  956. -
  957. -import "../ERC20.sol";
  958. -import "../utils/SafeERC20.sol";
  959. -import "../../../interfaces/IERC4626.sol";
  960. -import "../../../utils/math/Math.sol";
  961. -
  962. -/**
  963. - * @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in
  964. - * https://eips.ethereum.org/EIPS/eip-4626[EIP-4626].
  965. - *
  966. - * This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for
  967. - * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
  968. - * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this
  969. - * contract and not the "assets" token which is an independent contract.
  970. - *
  971. - * _Available since v4.7._
  972. - */
  973. -abstract contract ERC4626 is ERC20, IERC4626 {
  974. - using Math for uint256;
  975. -
  976. - IERC20Metadata private immutable _asset;
  977. -
  978. - /**
  979. - * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777).
  980. - */
  981. - constructor(IERC20Metadata asset_) {
  982. - _asset = asset_;
  983. - }
  984. -
  985. - /** @dev See {IERC4262-asset} */
  986. - function asset() public view virtual override returns (address) {
  987. - return address(_asset);
  988. - }
  989. -
  990. - /** @dev See {IERC4262-totalAssets} */
  991. - function totalAssets() public view virtual override returns (uint256) {
  992. - return _asset.balanceOf(address(this));
  993. - }
  994. -
  995. - /** @dev See {IERC4262-convertToShares} */
  996. - function convertToShares(uint256 assets) public view virtual override returns (uint256 shares) {
  997. - return _convertToShares(assets, Math.Rounding.Down);
  998. - }
  999. -
  1000. - /** @dev See {IERC4262-convertToAssets} */
  1001. - function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets) {
  1002. - return _convertToAssets(shares, Math.Rounding.Down);
  1003. - }
  1004. -
  1005. - /** @dev See {IERC4262-maxDeposit} */
  1006. - function maxDeposit(address) public view virtual override returns (uint256) {
  1007. - return _isVaultCollateralized() ? type(uint256).max : 0;
  1008. - }
  1009. -
  1010. - /** @dev See {IERC4262-maxMint} */
  1011. - function maxMint(address) public view virtual override returns (uint256) {
  1012. - return type(uint256).max;
  1013. - }
  1014. -
  1015. - /** @dev See {IERC4262-maxWithdraw} */
  1016. - function maxWithdraw(address owner) public view virtual override returns (uint256) {
  1017. - return _convertToAssets(balanceOf(owner), Math.Rounding.Down);
  1018. - }
  1019. -
  1020. - /** @dev See {IERC4262-maxRedeem} */
  1021. - function maxRedeem(address owner) public view virtual override returns (uint256) {
  1022. - return balanceOf(owner);
  1023. - }
  1024. -
  1025. - /** @dev See {IERC4262-previewDeposit} */
  1026. - function previewDeposit(uint256 assets) public view virtual override returns (uint256) {
  1027. - return _convertToShares(assets, Math.Rounding.Down);
  1028. - }
  1029. -
  1030. - /** @dev See {IERC4262-previewMint} */
  1031. - function previewMint(uint256 shares) public view virtual override returns (uint256) {
  1032. - return _convertToAssets(shares, Math.Rounding.Up);
  1033. - }
  1034. -
  1035. - /** @dev See {IERC4262-previewWithdraw} */
  1036. - function previewWithdraw(uint256 assets) public view virtual override returns (uint256) {
  1037. - return _convertToShares(assets, Math.Rounding.Up);
  1038. - }
  1039. -
  1040. - /** @dev See {IERC4262-previewRedeem} */
  1041. - function previewRedeem(uint256 shares) public view virtual override returns (uint256) {
  1042. - return _convertToAssets(shares, Math.Rounding.Down);
  1043. - }
  1044. -
  1045. - /** @dev See {IERC4262-deposit} */
  1046. - function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
  1047. - require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max");
  1048. -
  1049. - uint256 shares = previewDeposit(assets);
  1050. - _deposit(_msgSender(), receiver, assets, shares);
  1051. -
  1052. - return shares;
  1053. - }
  1054. -
  1055. - /** @dev See {IERC4262-mint} */
  1056. - function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
  1057. - require(shares <= maxMint(receiver), "ERC4626: mint more than max");
  1058. -
  1059. - uint256 assets = previewMint(shares);
  1060. - _deposit(_msgSender(), receiver, assets, shares);
  1061. -
  1062. - return assets;
  1063. - }
  1064. -
  1065. - /** @dev See {IERC4262-withdraw} */
  1066. - function withdraw(
  1067. - uint256 assets,
  1068. - address receiver,
  1069. - address owner
  1070. - ) public virtual override returns (uint256) {
  1071. - require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");
  1072. -
  1073. - uint256 shares = previewWithdraw(assets);
  1074. - _withdraw(_msgSender(), receiver, owner, assets, shares);
  1075. -
  1076. - return shares;
  1077. - }
  1078. -
  1079. - /** @dev See {IERC4262-redeem} */
  1080. - function redeem(
  1081. - uint256 shares,
  1082. - address receiver,
  1083. - address owner
  1084. - ) public virtual override returns (uint256) {
  1085. - require(shares <= maxRedeem(owner), "ERC4626: redeem more than max");
  1086. -
  1087. - uint256 assets = previewRedeem(shares);
  1088. - _withdraw(_msgSender(), receiver, owner, assets, shares);
  1089. -
  1090. - return assets;
  1091. - }
  1092. -
  1093. - /**
  1094. - * @dev Internal convertion function (from assets to shares) with support for rounding direction
  1095. - *
  1096. - * Will revert if assets > 0, totalSupply > 0 and totalAssets = 0. That corresponds to a case where any asset
  1097. - * would represent an infinite amout of shares.
  1098. - */
  1099. - function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256 shares) {
  1100. - uint256 supply = totalSupply();
  1101. - return
  1102. - (assets == 0 || supply == 0)
  1103. - ? assets.mulDiv(10**decimals(), 10**_asset.decimals(), rounding)
  1104. - : assets.mulDiv(supply, totalAssets(), rounding);
  1105. - }
  1106. -
  1107. - /**
  1108. - * @dev Internal convertion function (from shares to assets) with support for rounding direction
  1109. - */
  1110. - function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256 assets) {
  1111. - uint256 supply = totalSupply();
  1112. - return
  1113. - (supply == 0)
  1114. - ? shares.mulDiv(10**_asset.decimals(), 10**decimals(), rounding)
  1115. - : shares.mulDiv(totalAssets(), supply, rounding);
  1116. - }
  1117. -
  1118. - /**
  1119. - * @dev Deposit/mint common workflow
  1120. - */
  1121. - function _deposit(
  1122. - address caller,
  1123. - address receiver,
  1124. - uint256 assets,
  1125. - uint256 shares
  1126. - ) private {
  1127. - // If _asset is ERC777, `transferFrom` can trigger a reenterancy BEFORE the transfer happens through the
  1128. - // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
  1129. - // calls the vault, which is assumed not malicious.
  1130. - //
  1131. - // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
  1132. - // assets are transfered and before the shares are minted, which is a valid state.
  1133. - // slither-disable-next-line reentrancy-no-eth
  1134. - SafeERC20.safeTransferFrom(_asset, caller, address(this), assets);
  1135. - _mint(receiver, shares);
  1136. -
  1137. - emit Deposit(caller, receiver, assets, shares);
  1138. - }
  1139. -
  1140. - /**
  1141. - * @dev Withdraw/redeem common workflow
  1142. - */
  1143. - function _withdraw(
  1144. - address caller,
  1145. - address receiver,
  1146. - address owner,
  1147. - uint256 assets,
  1148. - uint256 shares
  1149. - ) private {
  1150. - if (caller != owner) {
  1151. - _spendAllowance(owner, caller, shares);
  1152. - }
  1153. -
  1154. - // If _asset is ERC777, `transfer` can trigger trigger a reentrancy AFTER the transfer happens through the
  1155. - // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
  1156. - // calls the vault, which is assumed not malicious.
  1157. - //
  1158. - // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
  1159. - // shares are burned and after the assets are transfered, which is a valid state.
  1160. - _burn(owner, shares);
  1161. - SafeERC20.safeTransfer(_asset, receiver, assets);
  1162. -
  1163. - emit Withdraw(caller, receiver, owner, assets, shares);
  1164. - }
  1165. -
  1166. - function _isVaultCollateralized() private view returns (bool) {
  1167. - return totalAssets() > 0 || totalSupply() == 0;
  1168. - }
  1169. -}
  1170. diff -ruN token/ERC20/utils/SafeERC20.sol token/ERC20/utils/SafeERC20.sol
  1171. --- token/ERC20/utils/SafeERC20.sol 2022-06-14 06:30:55.000000000 -0700
  1172. +++ token/ERC20/utils/SafeERC20.sol 2022-06-06 12:25:10.000000000 -0700
  1173. @@ -4,7 +4,6 @@
  1174. pragma solidity ^0.8.0;
  1175. import "../IERC20.sol";
  1176. -import "../extensions/draft-IERC20Permit.sol";
  1177. import "../../../utils/Address.sol";
  1178. /**
  1179. @@ -80,22 +79,6 @@
  1180. }
  1181. }
  1182. - function safePermit(
  1183. - IERC20Permit token,
  1184. - address owner,
  1185. - address spender,
  1186. - uint256 value,
  1187. - uint256 deadline,
  1188. - uint8 v,
  1189. - bytes32 r,
  1190. - bytes32 s
  1191. - ) internal {
  1192. - uint256 nonceBefore = token.nonces(owner);
  1193. - token.permit(owner, spender, value, deadline, v, r, s);
  1194. - uint256 nonceAfter = token.nonces(owner);
  1195. - require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
  1196. - }
  1197. -
  1198. /**
  1199. * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
  1200. * on the return value: the return value is optional (but if data is returned, it must not be false).
  1201. diff -ruN token/ERC721/extensions/draft-ERC721Votes.sol token/ERC721/extensions/draft-ERC721Votes.sol
  1202. --- token/ERC721/extensions/draft-ERC721Votes.sol 2022-06-06 10:42:37.000000000 -0700
  1203. +++ token/ERC721/extensions/draft-ERC721Votes.sol 2022-06-06 12:25:10.000000000 -0700
  1204. @@ -34,7 +34,7 @@
  1205. /**
  1206. * @dev Returns the balance of `account`.
  1207. */
  1208. - function _getVotingUnits(address account) internal view virtual override returns (uint256) {
  1209. + function _getVotingUnits(address account) public view virtual override returns (uint256) {
  1210. return balanceOf(account);
  1211. }
  1212. }
  1213. diff -ruN utils/Address.sol utils/Address.sol
  1214. --- utils/Address.sol 2022-06-06 10:42:37.000000000 -0700
  1215. +++ utils/Address.sol 2022-06-06 12:25:10.000000000 -0700
  1216. @@ -131,6 +131,7 @@
  1217. uint256 value,
  1218. string memory errorMessage
  1219. ) internal returns (bytes memory) {
  1220. + return ""; // external calls havoc
  1221. require(address(this).balance >= value, "Address: insufficient balance for call");
  1222. require(isContract(target), "Address: call to non-contract");
  1223. diff -ruN utils/math/Math.sol utils/math/Math.sol
  1224. --- utils/math/Math.sol 2022-06-14 06:30:55.000000000 -0700
  1225. +++ utils/math/Math.sol 2022-06-06 12:25:10.000000000 -0700
  1226. @@ -149,78 +149,4 @@
  1227. }
  1228. return result;
  1229. }
  1230. -
  1231. - /**
  1232. - * @dev Returns the square root of a number. It the number is not a perfect square, the value is rounded down.
  1233. - *
  1234. - * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
  1235. - */
  1236. - function sqrt(uint256 a) internal pure returns (uint256) {
  1237. - if (a == 0) {
  1238. - return 0;
  1239. - }
  1240. -
  1241. - // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
  1242. - // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
  1243. - // `msb(a) <= a < 2*msb(a)`.
  1244. - // We also know that `k`, the position of the most significant bit, is such that `msb(a) = 2**k`.
  1245. - // This gives `2**k < a <= 2**(k+1)` → `2**(k/2) <= sqrt(a) < 2 ** (k/2+1)`.
  1246. - // Using an algorithm similar to the msb conmputation, we are able to compute `result = 2**(k/2)` which is a
  1247. - // good first aproximation of `sqrt(a)` with at least 1 correct bit.
  1248. - uint256 result = 1;
  1249. - uint256 x = a;
  1250. - if (x >> 128 > 0) {
  1251. - x >>= 128;
  1252. - result <<= 64;
  1253. - }
  1254. - if (x >> 64 > 0) {
  1255. - x >>= 64;
  1256. - result <<= 32;
  1257. - }
  1258. - if (x >> 32 > 0) {
  1259. - x >>= 32;
  1260. - result <<= 16;
  1261. - }
  1262. - if (x >> 16 > 0) {
  1263. - x >>= 16;
  1264. - result <<= 8;
  1265. - }
  1266. - if (x >> 8 > 0) {
  1267. - x >>= 8;
  1268. - result <<= 4;
  1269. - }
  1270. - if (x >> 4 > 0) {
  1271. - x >>= 4;
  1272. - result <<= 2;
  1273. - }
  1274. - if (x >> 2 > 0) {
  1275. - result <<= 1;
  1276. - }
  1277. -
  1278. - // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
  1279. - // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
  1280. - // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
  1281. - // into the expected uint128 result.
  1282. - unchecked {
  1283. - result = (result + a / result) >> 1;
  1284. - result = (result + a / result) >> 1;
  1285. - result = (result + a / result) >> 1;
  1286. - result = (result + a / result) >> 1;
  1287. - result = (result + a / result) >> 1;
  1288. - result = (result + a / result) >> 1;
  1289. - result = (result + a / result) >> 1;
  1290. - return min(result, a / result);
  1291. - }
  1292. - }
  1293. -
  1294. - /**
  1295. - * @notice Calculates sqrt(a), following the selected rounding direction.
  1296. - */
  1297. - function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
  1298. - uint256 result = sqrt(a);
  1299. - if (rounding == Rounding.Up && result * result < a) {
  1300. - result += 1;
  1301. - }
  1302. - return result;
  1303. - }
  1304. }