applyHarness.patch 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. diff -ruN .gitignore .gitignore
  2. --- .gitignore 1969-12-31 16:00:00.000000000 -0800
  3. +++ .gitignore 2022-06-06 11:21:40.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 11:21:40.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 governance/Governor.sol governance/Governor.sol
  19. --- governance/Governor.sol 2022-06-06 10:42:37.000000000 -0700
  20. +++ governance/Governor.sol 2022-06-06 11:21:40.000000000 -0700
  21. @@ -44,7 +44,7 @@
  22. string private _name;
  23. - mapping(uint256 => ProposalCore) private _proposals;
  24. + mapping(uint256 => ProposalCore) internal _proposals;
  25. // This queue keeps track of the governor operating on itself. Calls to functions protected by the
  26. // {onlyGovernance} modifier needs to be whitelisted in this queue. Whitelisting is set in {_beforeExecute},
  27. diff -ruN governance/TimelockController.sol governance/TimelockController.sol
  28. --- governance/TimelockController.sol 2022-06-06 10:42:37.000000000 -0700
  29. +++ governance/TimelockController.sol 2022-06-06 11:21:40.000000000 -0700
  30. @@ -28,10 +28,10 @@
  31. bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
  32. bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
  33. bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");
  34. - uint256 internal constant _DONE_TIMESTAMP = uint256(1);
  35. + uint256 public constant _DONE_TIMESTAMP = uint256(1);
  36. mapping(bytes32 => uint256) private _timestamps;
  37. - uint256 private _minDelay;
  38. + uint256 public _minDelay;
  39. /**
  40. * @dev Emitted when a call is scheduled as part of operation `id`.
  41. diff -ruN governance/extensions/GovernorCountingSimple.sol governance/extensions/GovernorCountingSimple.sol
  42. --- governance/extensions/GovernorCountingSimple.sol 2022-06-06 10:42:37.000000000 -0700
  43. +++ governance/extensions/GovernorCountingSimple.sol 2022-06-06 11:21:40.000000000 -0700
  44. @@ -27,7 +27,7 @@
  45. mapping(address => bool) hasVoted;
  46. }
  47. - mapping(uint256 => ProposalVote) private _proposalVotes;
  48. + mapping(uint256 => ProposalVote) internal _proposalVotes;
  49. /**
  50. * @dev See {IGovernor-COUNTING_MODE}.
  51. diff -ruN governance/extensions/GovernorPreventLateQuorum.sol governance/extensions/GovernorPreventLateQuorum.sol
  52. --- governance/extensions/GovernorPreventLateQuorum.sol 2022-06-06 10:42:37.000000000 -0700
  53. +++ governance/extensions/GovernorPreventLateQuorum.sol 2022-06-06 11:21:40.000000000 -0700
  54. @@ -21,8 +21,8 @@
  55. using SafeCast for uint256;
  56. using Timers for Timers.BlockNumber;
  57. - uint64 private _voteExtension;
  58. - mapping(uint256 => Timers.BlockNumber) private _extendedDeadlines;
  59. + uint64 internal _voteExtension;
  60. + mapping(uint256 => Timers.BlockNumber) internal _extendedDeadlines;
  61. /// @dev Emitted when a proposal deadline is pushed back due to reaching quorum late in its voting period.
  62. event ProposalExtended(uint256 indexed proposalId, uint64 extendedDeadline);
  63. diff -ruN governance/utils/Votes.sol governance/utils/Votes.sol
  64. --- governance/utils/Votes.sol 2022-06-06 10:42:37.000000000 -0700
  65. +++ governance/utils/Votes.sol 2022-06-06 11:21:40.000000000 -0700
  66. @@ -35,7 +35,25 @@
  67. bytes32 private constant _DELEGATION_TYPEHASH =
  68. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  69. - mapping(address => address) private _delegation;
  70. + // HARNESS : Hooks cannot access any information from Checkpoints yet, so I am also updating votes and fromBlock in this struct
  71. + struct Ckpt {
  72. + uint32 fromBlock;
  73. + uint224 votes;
  74. + }
  75. + mapping(address => Ckpt) public _checkpoints;
  76. +
  77. + // HARNESSED getters
  78. + function numCheckpoints(address account) public view returns (uint32) {
  79. + return SafeCast.toUint32(_delegateCheckpoints[account]._checkpoints.length);
  80. + }
  81. + function ckptFromBlock(address account, uint32 pos) public view returns (uint32) {
  82. + return _delegateCheckpoints[account]._checkpoints[pos]._blockNumber;
  83. + }
  84. + function ckptVotes(address account, uint32 pos) public view returns (uint224) {
  85. + return _delegateCheckpoints[account]._checkpoints[pos]._value;
  86. + }
  87. +
  88. + mapping(address => address) public _delegation;
  89. mapping(address => Checkpoints.History) private _delegateCheckpoints;
  90. Checkpoints.History private _totalCheckpoints;
  91. @@ -124,7 +142,7 @@
  92. *
  93. * Emits events {DelegateChanged} and {DelegateVotesChanged}.
  94. */
  95. - function _delegate(address account, address delegatee) internal virtual {
  96. + function _delegate(address account, address delegatee) public virtual {
  97. address oldDelegate = delegates(account);
  98. _delegation[account] = delegatee;
  99. @@ -142,10 +160,10 @@
  100. uint256 amount
  101. ) internal virtual {
  102. if (from == address(0)) {
  103. - _totalCheckpoints.push(_add, amount);
  104. + _totalCheckpoints.push(_totalCheckpoints.latest() + amount); // Harnessed to remove function pointers
  105. }
  106. if (to == address(0)) {
  107. - _totalCheckpoints.push(_subtract, amount);
  108. + _totalCheckpoints.push(_totalCheckpoints.latest() - amount); // Harnessed to remove function pointers
  109. }
  110. _moveDelegateVotes(delegates(from), delegates(to), amount);
  111. }
  112. @@ -160,11 +178,13 @@
  113. ) private {
  114. if (from != to && amount > 0) {
  115. if (from != address(0)) {
  116. - (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[from].push(_subtract, amount);
  117. + (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[from].push(_delegateCheckpoints[from].latest() - amount); // HARNESSED TO REMOVE FUNCTION POINTERS
  118. + _checkpoints[from] = Ckpt({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newValue)}); // HARNESS
  119. emit DelegateVotesChanged(from, oldValue, newValue);
  120. }
  121. if (to != address(0)) {
  122. - (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[to].push(_add, amount);
  123. + (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[to].push(_delegateCheckpoints[to].latest() + amount); // HARNESSED TO REMOVE FUNCTION POINTERS
  124. + _checkpoints[to] = Ckpt({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newValue)}); // HARNESS
  125. emit DelegateVotesChanged(to, oldValue, newValue);
  126. }
  127. }
  128. @@ -207,5 +227,5 @@
  129. /**
  130. * @dev Must return the voting units held by an account.
  131. */
  132. - function _getVotingUnits(address) internal view virtual returns (uint256);
  133. + function _getVotingUnits(address) public virtual returns (uint256); // HARNESS: internal -> public
  134. }
  135. diff -ruN proxy/utils/Initializable.sol proxy/utils/Initializable.sol
  136. --- proxy/utils/Initializable.sol 2022-06-06 10:42:37.000000000 -0700
  137. +++ proxy/utils/Initializable.sol 2022-06-06 11:21:40.000000000 -0700
  138. @@ -59,12 +59,12 @@
  139. * @dev Indicates that the contract has been initialized.
  140. * @custom:oz-retyped-from bool
  141. */
  142. - uint8 private _initialized;
  143. + uint8 internal _initialized;
  144. /**
  145. * @dev Indicates that the contract is in the process of being initialized.
  146. */
  147. - bool private _initializing;
  148. + bool internal _initializing;
  149. /**
  150. * @dev Triggered when the contract has been initialized or reinitialized.
  151. diff -ruN proxy/utils/Initializable.sol.orig proxy/utils/Initializable.sol.orig
  152. --- proxy/utils/Initializable.sol.orig 1969-12-31 16:00:00.000000000 -0800
  153. +++ proxy/utils/Initializable.sol.orig 2022-06-06 11:21:40.000000000 -0700
  154. @@ -0,0 +1,138 @@
  155. +// SPDX-License-Identifier: MIT
  156. +// OpenZeppelin Contracts (last updated v4.6.0) (proxy/utils/Initializable.sol)
  157. +
  158. +pragma solidity ^0.8.2;
  159. +
  160. +import "../../utils/Address.sol";
  161. +
  162. +/**
  163. + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
  164. + * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
  165. + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
  166. + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
  167. + *
  168. + * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
  169. + * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
  170. + * case an upgrade adds a module that needs to be initialized.
  171. + *
  172. + * For example:
  173. + *
  174. + * [.hljs-theme-light.nopadding]
  175. + * ```
  176. + * contract MyToken is ERC20Upgradeable {
  177. + * function initialize() initializer public {
  178. + * __ERC20_init("MyToken", "MTK");
  179. + * }
  180. + * }
  181. + * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
  182. + * function initializeV2() reinitializer(2) public {
  183. + * __ERC20Permit_init("MyToken");
  184. + * }
  185. + * }
  186. + * ```
  187. + *
  188. + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
  189. + * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
  190. + *
  191. + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
  192. + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
  193. + *
  194. + * [CAUTION]
  195. + * ====
  196. + * Avoid leaving a contract uninitialized.
  197. + *
  198. + * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
  199. + * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
  200. + * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
  201. + *
  202. + * [.hljs-theme-light.nopadding]
  203. + * ```
  204. + * /// @custom:oz-upgrades-unsafe-allow constructor
  205. + * constructor() {
  206. + * _disableInitializers();
  207. + * }
  208. + * ```
  209. + * ====
  210. + */
  211. +abstract contract Initializable {
  212. + /**
  213. + * @dev Indicates that the contract has been initialized.
  214. + * @custom:oz-retyped-from bool
  215. + */
  216. + uint8 private _initialized;
  217. +
  218. + /**
  219. + * @dev Indicates that the contract is in the process of being initialized.
  220. + */
  221. + bool private _initializing;
  222. +
  223. + /**
  224. + * @dev Triggered when the contract has been initialized or reinitialized.
  225. + */
  226. + event Initialized(uint8 version);
  227. +
  228. + /**
  229. + * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
  230. + * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
  231. + */
  232. + modifier initializer() {
  233. + bool isTopLevelCall = !_initializing;
  234. + require(
  235. + (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
  236. + "Initializable: contract is already initialized"
  237. + );
  238. + _initialized = 1;
  239. + if (isTopLevelCall) {
  240. + _initializing = true;
  241. + }
  242. + _;
  243. + if (isTopLevelCall) {
  244. + _initializing = false;
  245. + emit Initialized(1);
  246. + }
  247. + }
  248. +
  249. + /**
  250. + * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
  251. + * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
  252. + * used to initialize parent contracts.
  253. + *
  254. + * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
  255. + * initialization step. This is essential to configure modules that are added through upgrades and that require
  256. + * initialization.
  257. + *
  258. + * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
  259. + * a contract, executing them in the right order is up to the developer or operator.
  260. + */
  261. + modifier reinitializer(uint8 version) {
  262. + require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
  263. + _initialized = version;
  264. + _initializing = true;
  265. + _;
  266. + _initializing = false;
  267. + emit Initialized(version);
  268. + }
  269. +
  270. + /**
  271. + * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
  272. + * {initializer} and {reinitializer} modifiers, directly or indirectly.
  273. + */
  274. + modifier onlyInitializing() {
  275. + require(_initializing, "Initializable: contract is not initializing");
  276. + _;
  277. + }
  278. +
  279. + /**
  280. + * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
  281. + * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
  282. + * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
  283. + * through proxies.
  284. + */
  285. + function _disableInitializers() internal virtual {
  286. + require(!_initializing, "Initializable: contract is initializing");
  287. + if (_initialized < type(uint8).max) {
  288. + _initialized = type(uint8).max;
  289. + emit Initialized(type(uint8).max);
  290. + }
  291. + }
  292. +}
  293. diff -ruN proxy/utils/Initializable.sol.rej proxy/utils/Initializable.sol.rej
  294. --- proxy/utils/Initializable.sol.rej 1969-12-31 16:00:00.000000000 -0800
  295. +++ proxy/utils/Initializable.sol.rej 2022-06-06 11:21:40.000000000 -0700
  296. @@ -0,0 +1,17 @@
  297. +***************
  298. +*** 130,136 ****
  299. + _setInitializedVersion(type(uint8).max);
  300. + }
  301. +
  302. +- function _setInitializedVersion(uint8 version) private returns (bool) {
  303. + // If the contract is initializing we ignore whether _initialized is set in order to support multiple
  304. + // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level
  305. + // of initializers, because in other contexts the contract may have been reentered.
  306. +--- 130,136 ----
  307. + _setInitializedVersion(type(uint8).max);
  308. + }
  309. +
  310. ++ function _setInitializedVersion(uint8 version) internal returns (bool) {
  311. + // If the contract is initializing we ignore whether _initialized is set in order to support multiple
  312. + // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level
  313. + // of initializers, because in other contexts the contract may have been reentered.
  314. diff -ruN token/ERC1155/ERC1155.sol token/ERC1155/ERC1155.sol
  315. --- token/ERC1155/ERC1155.sol 2022-06-06 10:42:37.000000000 -0700
  316. +++ token/ERC1155/ERC1155.sol 2022-06-06 11:23:46.000000000 -0700
  317. @@ -471,7 +471,7 @@
  318. uint256 id,
  319. uint256 amount,
  320. bytes memory data
  321. - ) private {
  322. + ) public { // HARNESS: private -> public
  323. if (to.isContract()) {
  324. try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
  325. if (response != IERC1155Receiver.onERC1155Received.selector) {
  326. @@ -492,7 +492,7 @@
  327. uint256[] memory ids,
  328. uint256[] memory amounts,
  329. bytes memory data
  330. - ) private {
  331. + ) public { // HARNESS: private -> public
  332. if (to.isContract()) {
  333. try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
  334. bytes4 response
  335. diff -ruN token/ERC20/ERC20.sol token/ERC20/ERC20.sol
  336. --- token/ERC20/ERC20.sol 2022-06-06 10:42:37.000000000 -0700
  337. +++ token/ERC20/ERC20.sol 2022-06-06 11:21:40.000000000 -0700
  338. @@ -277,7 +277,7 @@
  339. * - `account` cannot be the zero address.
  340. * - `account` must have at least `amount` tokens.
  341. */
  342. - function _burn(address account, uint256 amount) internal virtual {
  343. + function _burn(address account, uint256 amount) public virtual { // HARNESS: internal -> public
  344. require(account != address(0), "ERC20: burn from the zero address");
  345. _beforeTokenTransfer(account, address(0), amount);
  346. diff -ruN token/ERC20/extensions/ERC20FlashMint.sol token/ERC20/extensions/ERC20FlashMint.sol
  347. --- token/ERC20/extensions/ERC20FlashMint.sol 2022-06-06 10:42:37.000000000 -0700
  348. +++ token/ERC20/extensions/ERC20FlashMint.sol 2022-06-06 11:21:40.000000000 -0700
  349. @@ -40,9 +40,11 @@
  350. require(token == address(this), "ERC20FlashMint: wrong token");
  351. // silence warning about unused variable without the addition of bytecode.
  352. amount;
  353. - return 0;
  354. + return fee; // HARNESS: made "return" nonzero
  355. }
  356. + uint256 public fee; // HARNESS: added it to simulate random fee amount
  357. +
  358. /**
  359. * @dev Returns the receiver address of the flash fee. By default this
  360. * implementation returns the address(0) which means the fee amount will be burnt.
  361. diff -ruN token/ERC20/extensions/ERC20Votes.sol token/ERC20/extensions/ERC20Votes.sol
  362. --- token/ERC20/extensions/ERC20Votes.sol 2022-06-06 10:42:37.000000000 -0700
  363. +++ token/ERC20/extensions/ERC20Votes.sol 2022-06-06 11:21:40.000000000 -0700
  364. @@ -33,8 +33,8 @@
  365. bytes32 private constant _DELEGATION_TYPEHASH =
  366. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  367. - mapping(address => address) private _delegates;
  368. - mapping(address => Checkpoint[]) private _checkpoints;
  369. + mapping(address => address) public _delegates;
  370. + mapping(address => Checkpoint[]) public _checkpoints;
  371. Checkpoint[] private _totalSupplyCheckpoints;
  372. /**
  373. @@ -169,7 +169,7 @@
  374. /**
  375. * @dev Snapshots the totalSupply after it has been decreased.
  376. */
  377. - function _burn(address account, uint256 amount) internal virtual override {
  378. + function _burn(address account, uint256 amount) public virtual override {
  379. super._burn(account, amount);
  380. _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
  381. diff -ruN token/ERC20/extensions/ERC20Wrapper.sol token/ERC20/extensions/ERC20Wrapper.sol
  382. --- token/ERC20/extensions/ERC20Wrapper.sol 2022-06-06 10:42:37.000000000 -0700
  383. +++ token/ERC20/extensions/ERC20Wrapper.sol 2022-06-06 11:21:40.000000000 -0700
  384. @@ -55,7 +55,7 @@
  385. * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
  386. * function that can be exposed with access control if desired.
  387. */
  388. - function _recover(address account) internal virtual returns (uint256) {
  389. + function _recover(address account) public virtual returns (uint256) { // HARNESS: internal -> public
  390. uint256 value = underlying.balanceOf(address(this)) - totalSupply();
  391. _mint(account, value);
  392. return value;
  393. diff -ruN token/ERC721/extensions/draft-ERC721Votes.sol token/ERC721/extensions/draft-ERC721Votes.sol
  394. --- token/ERC721/extensions/draft-ERC721Votes.sol 2022-06-06 10:42:37.000000000 -0700
  395. +++ token/ERC721/extensions/draft-ERC721Votes.sol 2022-06-06 11:21:40.000000000 -0700
  396. @@ -34,7 +34,7 @@
  397. /**
  398. * @dev Returns the balance of `account`.
  399. */
  400. - function _getVotingUnits(address account) internal view virtual override returns (uint256) {
  401. + function _getVotingUnits(address account) public view virtual override returns (uint256) {
  402. return balanceOf(account);
  403. }
  404. }
  405. diff -ruN utils/Address.sol utils/Address.sol
  406. --- utils/Address.sol 2022-06-06 10:42:37.000000000 -0700
  407. +++ utils/Address.sol 2022-06-06 11:21:40.000000000 -0700
  408. @@ -131,6 +131,7 @@
  409. uint256 value,
  410. string memory errorMessage
  411. ) internal returns (bytes memory) {
  412. + return ""; // external calls havoc
  413. require(address(this).balance >= value, "Address: insufficient balance for call");
  414. require(isContract(target), "Address: call to non-contract");