applyHarness.patch 18 KB

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