applyHarness.patch 16 KB

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