applyHarness.patch 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. diff -ruN access/AccessControl.sol access/AccessControl.sol
  2. --- access/AccessControl.sol 2022-05-06 13:44:28.000000000 -0700
  3. +++ access/AccessControl.sol 2022-05-09 09:49:26.000000000 -0700
  4. @@ -93,7 +93,7 @@
  5. *
  6. * _Available since v4.6._
  7. */
  8. - function _checkRole(bytes32 role) internal view virtual {
  9. + function _checkRole(bytes32 role) public view virtual { // HARNESS: internal -> public
  10. _checkRole(role, _msgSender());
  11. }
  12. diff -ruN governance/Governor.sol governance/Governor.sol
  13. --- governance/Governor.sol 2022-05-09 09:11:10.000000000 -0700
  14. +++ governance/Governor.sol 2022-05-09 09:49:26.000000000 -0700
  15. @@ -42,7 +42,7 @@
  16. string private _name;
  17. - mapping(uint256 => ProposalCore) private _proposals;
  18. + mapping(uint256 => ProposalCore) internal _proposals;
  19. // This queue keeps track of the governor operating on itself. Calls to functions protected by the
  20. // {onlyGovernance} modifier needs to be whitelisted in this queue. Whitelisting is set in {_beforeExecute},
  21. diff -ruN governance/TimelockController.sol governance/TimelockController.sol
  22. --- governance/TimelockController.sol 2022-05-06 13:44:28.000000000 -0700
  23. +++ governance/TimelockController.sol 2022-05-09 09:49:26.000000000 -0700
  24. @@ -24,10 +24,10 @@
  25. bytes32 public constant TIMELOCK_ADMIN_ROLE = keccak256("TIMELOCK_ADMIN_ROLE");
  26. bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
  27. bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
  28. - uint256 internal constant _DONE_TIMESTAMP = uint256(1);
  29. + uint256 public constant _DONE_TIMESTAMP = uint256(1); // HARNESS: internal -> public
  30. mapping(bytes32 => uint256) private _timestamps;
  31. - uint256 private _minDelay;
  32. + uint256 public _minDelay; // HARNESS: private -> public
  33. /**
  34. * @dev Emitted when a call is scheduled as part of operation `id`.
  35. @@ -353,4 +353,4 @@
  36. emit MinDelayChange(_minDelay, newDelay);
  37. _minDelay = newDelay;
  38. }
  39. -}
  40. +}
  41. diff -ruN governance/extensions/GovernorPreventLateQuorum.sol governance/extensions/GovernorPreventLateQuorum.sol
  42. --- governance/extensions/GovernorPreventLateQuorum.sol 2022-05-09 09:11:01.000000000 -0700
  43. +++ governance/extensions/GovernorPreventLateQuorum.sol 2022-05-09 09:49:26.000000000 -0700
  44. @@ -21,8 +21,8 @@
  45. using SafeCast for uint256;
  46. using Timers for Timers.BlockNumber;
  47. - uint64 private _voteExtension;
  48. - mapping(uint256 => Timers.BlockNumber) private _extendedDeadlines;
  49. + uint64 internal _voteExtension;
  50. + mapping(uint256 => Timers.BlockNumber) internal _extendedDeadlines;
  51. /// @dev Emitted when a proposal deadline is pushed back due to reaching quorum late in its voting period.
  52. event ProposalExtended(uint256 indexed proposalId, uint64 extendedDeadline);
  53. diff -ruN governance/utils/Votes.sol governance/utils/Votes.sol
  54. --- governance/utils/Votes.sol 2022-05-06 13:44:28.000000000 -0700
  55. +++ governance/utils/Votes.sol 2022-05-09 09:49:26.000000000 -0700
  56. @@ -35,7 +35,25 @@
  57. bytes32 private constant _DELEGATION_TYPEHASH =
  58. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  59. - mapping(address => address) private _delegation;
  60. + // HARNESS : Hooks cannot access any information from Checkpoints yet, so I am also updating votes and fromBlock in this struct
  61. + struct Ckpt {
  62. + uint32 fromBlock;
  63. + uint224 votes;
  64. + }
  65. + mapping(address => Ckpt) public _checkpoints;
  66. +
  67. + // HARNESSED getters
  68. + function numCheckpoints(address account) public view returns (uint32) {
  69. + return SafeCast.toUint32(_delegateCheckpoints[account]._checkpoints.length);
  70. + }
  71. + function ckptFromBlock(address account, uint32 pos) public view returns (uint32) {
  72. + return _delegateCheckpoints[account]._checkpoints[pos]._blockNumber;
  73. + }
  74. + function ckptVotes(address account, uint32 pos) public view returns (uint224) {
  75. + return _delegateCheckpoints[account]._checkpoints[pos]._value;
  76. + }
  77. +
  78. + mapping(address => address) public _delegation;
  79. mapping(address => Checkpoints.History) private _delegateCheckpoints;
  80. Checkpoints.History private _totalCheckpoints;
  81. @@ -124,7 +142,7 @@
  82. *
  83. * Emits events {DelegateChanged} and {DelegateVotesChanged}.
  84. */
  85. - function _delegate(address account, address delegatee) internal virtual {
  86. + function _delegate(address account, address delegatee) public virtual {
  87. address oldDelegate = delegates(account);
  88. _delegation[account] = delegatee;
  89. @@ -142,10 +160,10 @@
  90. uint256 amount
  91. ) internal virtual {
  92. if (from == address(0)) {
  93. - _totalCheckpoints.push(_add, amount);
  94. + _totalCheckpoints.push(_totalCheckpoints.latest() + amount); // Harnessed to remove function pointers
  95. }
  96. if (to == address(0)) {
  97. - _totalCheckpoints.push(_subtract, amount);
  98. + _totalCheckpoints.push(_totalCheckpoints.latest() - amount); // Harnessed to remove function pointers
  99. }
  100. _moveDelegateVotes(delegates(from), delegates(to), amount);
  101. }
  102. @@ -160,11 +178,13 @@
  103. ) private {
  104. if (from != to && amount > 0) {
  105. if (from != address(0)) {
  106. - (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[from].push(_subtract, amount);
  107. + (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[from].push(_delegateCheckpoints[from].latest() - amount); // HARNESSED TO REMOVE FUNCTION POINTERS
  108. + _checkpoints[from] = Ckpt({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newValue)}); // HARNESS
  109. emit DelegateVotesChanged(from, oldValue, newValue);
  110. }
  111. if (to != address(0)) {
  112. - (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[to].push(_add, amount);
  113. + (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[to].push(_delegateCheckpoints[to].latest() + amount); // HARNESSED TO REMOVE FUNCTION POINTERS
  114. + _checkpoints[to] = Ckpt({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newValue)}); // HARNESS
  115. emit DelegateVotesChanged(to, oldValue, newValue);
  116. }
  117. }
  118. @@ -207,5 +227,5 @@
  119. /**
  120. * @dev Must return the voting units held by an account.
  121. */
  122. - function _getVotingUnits(address) internal virtual returns (uint256);
  123. + function _getVotingUnits(address) public virtual returns (uint256); // HARNESS: internal -> public
  124. }
  125. diff -ruN token/ERC1155/ERC1155.sol token/ERC1155/ERC1155.sol
  126. --- token/ERC1155/ERC1155.sol 2022-05-06 13:44:28.000000000 -0700
  127. +++ token/ERC1155/ERC1155.sol 2022-05-09 09:49:26.000000000 -0700
  128. @@ -268,7 +268,7 @@
  129. uint256 id,
  130. uint256 amount,
  131. bytes memory data
  132. - ) internal virtual {
  133. + ) public virtual { // HARNESS: internal -> public
  134. require(to != address(0), "ERC1155: mint to the zero address");
  135. address operator = _msgSender();
  136. @@ -299,7 +299,7 @@
  137. uint256[] memory ids,
  138. uint256[] memory amounts,
  139. bytes memory data
  140. - ) internal virtual {
  141. + ) public virtual { // HARNESS: internal -> public
  142. require(to != address(0), "ERC1155: mint to the zero address");
  143. require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
  144. @@ -330,7 +330,7 @@
  145. address from,
  146. uint256 id,
  147. uint256 amount
  148. - ) internal virtual {
  149. + ) public virtual { // HARNESS: internal -> public
  150. require(from != address(0), "ERC1155: burn from the zero address");
  151. address operator = _msgSender();
  152. @@ -361,7 +361,7 @@
  153. address from,
  154. uint256[] memory ids,
  155. uint256[] memory amounts
  156. - ) internal virtual {
  157. + ) public virtual { // HARNESS: internal -> public
  158. require(from != address(0), "ERC1155: burn from the zero address");
  159. require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
  160. @@ -465,7 +465,7 @@
  161. uint256 id,
  162. uint256 amount,
  163. bytes memory data
  164. - ) private {
  165. + ) public { // HARNESS: private -> public
  166. if (to.isContract()) {
  167. try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
  168. if (response != IERC1155Receiver.onERC1155Received.selector) {
  169. @@ -486,7 +486,7 @@
  170. uint256[] memory ids,
  171. uint256[] memory amounts,
  172. bytes memory data
  173. - ) private {
  174. + ) public { // HARNESS: private -> public
  175. if (to.isContract()) {
  176. try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
  177. bytes4 response
  178. diff -ruN token/ERC20/ERC20.sol token/ERC20/ERC20.sol
  179. --- token/ERC20/ERC20.sol 2022-05-06 13:44:28.000000000 -0700
  180. +++ token/ERC20/ERC20.sol 2022-05-09 09:49:26.000000000 -0700
  181. @@ -277,7 +277,7 @@
  182. * - `account` cannot be the zero address.
  183. * - `account` must have at least `amount` tokens.
  184. */
  185. - function _burn(address account, uint256 amount) internal virtual {
  186. + function _burn(address account, uint256 amount) public virtual returns (bool) { // HARNESS: internal -> public
  187. require(account != address(0), "ERC20: burn from the zero address");
  188. _beforeTokenTransfer(account, address(0), amount);
  189. @@ -292,6 +292,8 @@
  190. emit Transfer(account, address(0), amount);
  191. _afterTokenTransfer(account, address(0), amount);
  192. +
  193. + return true;
  194. }
  195. /**
  196. diff -ruN token/ERC20/extensions/ERC20FlashMint.sol token/ERC20/extensions/ERC20FlashMint.sol
  197. --- token/ERC20/extensions/ERC20FlashMint.sol 2022-05-06 13:44:28.000000000 -0700
  198. +++ token/ERC20/extensions/ERC20FlashMint.sol 2022-05-09 09:49:26.000000000 -0700
  199. @@ -40,9 +40,11 @@
  200. require(token == address(this), "ERC20FlashMint: wrong token");
  201. // silence warning about unused variable without the addition of bytecode.
  202. amount;
  203. - return 0;
  204. + return fee; // HARNESS: made "return" nonzero
  205. }
  206. + uint256 public fee; // HARNESS: added it to simulate random fee amount
  207. +
  208. /**
  209. * @dev Performs a flash loan. New tokens are minted and sent to the
  210. * `receiver`, who is required to implement the {IERC3156FlashBorrower}
  211. diff -ruN token/ERC20/extensions/ERC20Votes.sol token/ERC20/extensions/ERC20Votes.sol
  212. --- token/ERC20/extensions/ERC20Votes.sol 2022-05-06 13:43:21.000000000 -0700
  213. +++ token/ERC20/extensions/ERC20Votes.sol 2022-05-09 09:49:26.000000000 -0700
  214. @@ -33,8 +33,8 @@
  215. bytes32 private constant _DELEGATION_TYPEHASH =
  216. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  217. - mapping(address => address) private _delegates;
  218. - mapping(address => Checkpoint[]) private _checkpoints;
  219. + mapping(address => address) public _delegates;
  220. + mapping(address => Checkpoint[]) public _checkpoints;
  221. Checkpoint[] private _totalSupplyCheckpoints;
  222. /**
  223. @@ -152,7 +152,7 @@
  224. /**
  225. * @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).
  226. */
  227. - function _maxSupply() internal view virtual returns (uint224) {
  228. + function _maxSupply() public view virtual returns (uint224) { //harnessed to public
  229. return type(uint224).max;
  230. }
  231. @@ -163,16 +163,17 @@
  232. super._mint(account, amount);
  233. require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
  234. - _writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
  235. + _writeCheckpointAdd(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  236. }
  237. /**
  238. * @dev Snapshots the totalSupply after it has been decreased.
  239. */
  240. - function _burn(address account, uint256 amount) internal virtual override {
  241. + function _burn(address account, uint256 amount) public virtual override returns (bool){ // HARNESS: internal -> public (to comply with the ERC20 harness)
  242. super._burn(account, amount);
  243. - _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
  244. + _writeCheckpointSub(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  245. + return true;
  246. }
  247. /**
  248. @@ -187,7 +188,7 @@
  249. ) internal virtual override {
  250. super._afterTokenTransfer(from, to, amount);
  251. - _moveVotingPower(delegates(from), delegates(to), amount);
  252. + _moveVotingPower(delegates(from), delegates(to), amount);
  253. }
  254. /**
  255. @@ -195,7 +196,7 @@
  256. *
  257. * Emits events {DelegateChanged} and {DelegateVotesChanged}.
  258. */
  259. - function _delegate(address delegator, address delegatee) internal virtual {
  260. + function _delegate(address delegator, address delegatee) public virtual { // HARNESSED TO MAKE PUBLIC
  261. address currentDelegate = delegates(delegator);
  262. uint256 delegatorBalance = balanceOf(delegator);
  263. _delegates[delegator] = delegatee;
  264. @@ -212,25 +213,25 @@
  265. ) private {
  266. if (src != dst && amount > 0) {
  267. if (src != address(0)) {
  268. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
  269. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointSub(_checkpoints[src], amount); // HARNESS: new version without pointer
  270. emit DelegateVotesChanged(src, oldWeight, newWeight);
  271. }
  272. if (dst != address(0)) {
  273. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
  274. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointAdd(_checkpoints[dst], amount); // HARNESS: new version without pointer
  275. emit DelegateVotesChanged(dst, oldWeight, newWeight);
  276. }
  277. }
  278. }
  279. - function _writeCheckpoint(
  280. + // HARNESS: split _writeCheckpoint() to two functions as a workaround for function pointers that cannot be managed by the tool
  281. + function _writeCheckpointAdd(
  282. Checkpoint[] storage ckpts,
  283. - function(uint256, uint256) view returns (uint256) op,
  284. uint256 delta
  285. ) private returns (uint256 oldWeight, uint256 newWeight) {
  286. uint256 pos = ckpts.length;
  287. oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  288. - newWeight = op(oldWeight, delta);
  289. + newWeight = _add(oldWeight, delta);
  290. if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
  291. ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  292. @@ -239,6 +240,39 @@
  293. }
  294. }
  295. + function _writeCheckpointSub(
  296. + Checkpoint[] storage ckpts,
  297. + uint256 delta
  298. + ) private returns (uint256 oldWeight, uint256 newWeight) {
  299. + uint256 pos = ckpts.length;
  300. + oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  301. + newWeight = _subtract(oldWeight, delta);
  302. +
  303. + if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
  304. + ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  305. + } else {
  306. + ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)}));
  307. + }
  308. + }
  309. +
  310. + // backup of original function
  311. + //
  312. + // function _writeCheckpoint(
  313. + // Checkpoint[] storage ckpts,
  314. + // function(uint256, uint256) view returns (uint256) op,
  315. + // uint256 delta
  316. + // ) private returns (uint256 oldWeight, uint256 newWeight) {
  317. + // uint256 pos = ckpts.length;
  318. + // oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  319. + // newWeight = op(oldWeight, delta);
  320. + //
  321. + // if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
  322. + // ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  323. + // } else {
  324. + // ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)}));
  325. + // }
  326. + // }
  327. +
  328. function _add(uint256 a, uint256 b) private pure returns (uint256) {
  329. return a + b;
  330. }
  331. diff -ruN token/ERC20/extensions/ERC20Wrapper.sol token/ERC20/extensions/ERC20Wrapper.sol
  332. --- token/ERC20/extensions/ERC20Wrapper.sol 2022-05-06 13:44:28.000000000 -0700
  333. +++ token/ERC20/extensions/ERC20Wrapper.sol 2022-05-09 09:49:26.000000000 -0700
  334. @@ -44,7 +44,7 @@
  335. * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
  336. * function that can be exposed with access control if desired.
  337. */
  338. - function _recover(address account) internal virtual returns (uint256) {
  339. + function _recover(address account) public virtual returns (uint256) { // HARNESS: internal -> public
  340. uint256 value = underlying.balanceOf(address(this)) - totalSupply();
  341. _mint(account, value);
  342. return value;
  343. diff -ruN token/ERC721/extensions/draft-ERC721Votes.sol token/ERC721/extensions/draft-ERC721Votes.sol
  344. --- token/ERC721/extensions/draft-ERC721Votes.sol 2022-05-06 13:44:28.000000000 -0700
  345. +++ token/ERC721/extensions/draft-ERC721Votes.sol 2022-05-09 09:49:26.000000000 -0700
  346. @@ -34,7 +34,7 @@
  347. /**
  348. * @dev Returns the balance of `account`.
  349. */
  350. - function _getVotingUnits(address account) internal virtual override returns (uint256) {
  351. + function _getVotingUnits(address account) public virtual override returns (uint256) {
  352. return balanceOf(account);
  353. }
  354. }