applyHarness.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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-03-24 18:08:46.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-03-24 18:08:46.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,11 @@
  27. emit MinDelayChange(_minDelay, newDelay);
  28. _minDelay = newDelay;
  29. }
  30. -}
  31. +
  32. +
  33. +
  34. + function scheduleCheck1(bytes32 id) public virtual onlyRole(PROPOSER_ROLE) {
  35. + bool tmp = false;
  36. + require(tmp);
  37. + }
  38. +}
  39. diff -ruN governance/utils/Votes.sol governance/utils/Votes.sol
  40. --- governance/utils/Votes.sol 2022-03-02 09:14:55.000000000 -0800
  41. +++ governance/utils/Votes.sol 2022-03-24 18:08:46.000000000 -0700
  42. @@ -207,5 +207,5 @@
  43. /**
  44. * @dev Must return the voting units held by an account.
  45. */
  46. - function _getVotingUnits(address) internal virtual returns (uint256);
  47. + function _getVotingUnits(address) public virtual returns (uint256); // HARNESS: internal -> public
  48. }
  49. diff -ruN token/ERC20/ERC20.sol token/ERC20/ERC20.sol
  50. --- token/ERC20/ERC20.sol 2022-03-02 09:14:55.000000000 -0800
  51. +++ token/ERC20/ERC20.sol 2022-03-24 18:08:46.000000000 -0700
  52. @@ -277,7 +277,7 @@
  53. * - `account` cannot be the zero address.
  54. * - `account` must have at least `amount` tokens.
  55. */
  56. - function _burn(address account, uint256 amount) internal virtual {
  57. + function _burn(address account, uint256 amount) public virtual returns (bool) { // HARNESS: internal -> public
  58. require(account != address(0), "ERC20: burn from the zero address");
  59. _beforeTokenTransfer(account, address(0), amount);
  60. @@ -292,6 +292,8 @@
  61. emit Transfer(account, address(0), amount);
  62. _afterTokenTransfer(account, address(0), amount);
  63. +
  64. + return true;
  65. }
  66. /**
  67. diff -ruN token/ERC20/extensions/ERC20FlashMint.sol token/ERC20/extensions/ERC20FlashMint.sol
  68. --- token/ERC20/extensions/ERC20FlashMint.sol 2022-03-02 09:14:55.000000000 -0800
  69. +++ token/ERC20/extensions/ERC20FlashMint.sol 2022-03-24 18:08:46.000000000 -0700
  70. @@ -40,9 +40,11 @@
  71. require(token == address(this), "ERC20FlashMint: wrong token");
  72. // silence warning about unused variable without the addition of bytecode.
  73. amount;
  74. - return 0;
  75. + return fee; // HARNESS: made "return" nonzero
  76. }
  77. + uint256 public fee; // HARNESS: added it to simulate random fee amount
  78. +
  79. /**
  80. * @dev Performs a flash loan. New tokens are minted and sent to the
  81. * `receiver`, who is required to implement the {IERC3156FlashBorrower}
  82. @@ -70,7 +72,7 @@
  83. uint256 fee = flashFee(token, amount);
  84. _mint(address(receiver), amount);
  85. require(
  86. - receiver.onFlashLoan(msg.sender, token, amount, fee, data) == _RETURN_VALUE,
  87. + receiver.onFlashLoan(msg.sender, token, amount, fee, data) == _RETURN_VALUE, // HAVOC_ALL
  88. "ERC20FlashMint: invalid return value"
  89. );
  90. uint256 currentAllowance = allowance(address(receiver), address(this));
  91. diff -ruN token/ERC20/extensions/ERC20Votes.sol token/ERC20/extensions/ERC20Votes.sol
  92. --- token/ERC20/extensions/ERC20Votes.sol 2022-03-02 09:14:55.000000000 -0800
  93. +++ token/ERC20/extensions/ERC20Votes.sol 2022-03-25 13:13:49.000000000 -0700
  94. @@ -33,8 +33,8 @@
  95. bytes32 private constant _DELEGATION_TYPEHASH =
  96. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  97. - mapping(address => address) private _delegates;
  98. - mapping(address => Checkpoint[]) private _checkpoints;
  99. + mapping(address => address) public _delegates;
  100. + mapping(address => Checkpoint[]) public _checkpoints;
  101. Checkpoint[] private _totalSupplyCheckpoints;
  102. /**
  103. @@ -152,7 +152,7 @@
  104. /**
  105. * @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).
  106. */
  107. - function _maxSupply() internal view virtual returns (uint224) {
  108. + function _maxSupply() public view virtual returns (uint224) { //harnessed to public
  109. return type(uint224).max;
  110. }
  111. @@ -163,16 +163,17 @@
  112. super._mint(account, amount);
  113. require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
  114. - _writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
  115. + _writeCheckpointAdd(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  116. }
  117. /**
  118. * @dev Snapshots the totalSupply after it has been decreased.
  119. */
  120. - function _burn(address account, uint256 amount) internal virtual override {
  121. + function _burn(address account, uint256 amount) public virtual override returns (bool){ // HARNESS: internal -> public (to comply with the ERC20 harness)
  122. super._burn(account, amount);
  123. - _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
  124. + _writeCheckpointSub(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  125. + return true;
  126. }
  127. /**
  128. @@ -187,7 +188,7 @@
  129. ) internal virtual override {
  130. super._afterTokenTransfer(from, to, amount);
  131. - _moveVotingPower(delegates(from), delegates(to), amount);
  132. + _moveVotingPower(delegates(from), delegates(to), amount);
  133. }
  134. /**
  135. @@ -195,7 +196,7 @@
  136. *
  137. * Emits events {DelegateChanged} and {DelegateVotesChanged}.
  138. */
  139. - function _delegate(address delegator, address delegatee) internal virtual {
  140. + function _delegate(address delegator, address delegatee) public virtual { // HARNESSED TO MAKE PUBLIC
  141. address currentDelegate = delegates(delegator);
  142. uint256 delegatorBalance = balanceOf(delegator);
  143. _delegates[delegator] = delegatee;
  144. @@ -212,25 +213,25 @@
  145. ) private {
  146. if (src != dst && amount > 0) {
  147. if (src != address(0)) {
  148. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
  149. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointSub(_checkpoints[src], amount); // HARNESS: new version without pointer
  150. emit DelegateVotesChanged(src, oldWeight, newWeight);
  151. }
  152. if (dst != address(0)) {
  153. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
  154. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointAdd(_checkpoints[dst], amount); // HARNESS: new version without pointer
  155. emit DelegateVotesChanged(dst, oldWeight, newWeight);
  156. }
  157. }
  158. }
  159. - function _writeCheckpoint(
  160. + // HARNESS: split _writeCheckpoint() to two functions as a workaround for function pointers that cannot be managed by the tool
  161. + function _writeCheckpointAdd(
  162. Checkpoint[] storage ckpts,
  163. - function(uint256, uint256) view returns (uint256) op,
  164. uint256 delta
  165. ) private returns (uint256 oldWeight, uint256 newWeight) {
  166. uint256 pos = ckpts.length;
  167. oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  168. - newWeight = op(oldWeight, delta);
  169. + newWeight = _add(oldWeight, delta);
  170. if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
  171. ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  172. @@ -239,6 +240,39 @@
  173. }
  174. }
  175. + function _writeCheckpointSub(
  176. + Checkpoint[] storage ckpts,
  177. + uint256 delta
  178. + ) private returns (uint256 oldWeight, uint256 newWeight) {
  179. + uint256 pos = ckpts.length;
  180. + oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  181. + newWeight = _subtract(oldWeight, delta);
  182. +
  183. + if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
  184. + ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  185. + } else {
  186. + ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)}));
  187. + }
  188. + }
  189. +
  190. + // backup of original function
  191. + //
  192. + // function _writeCheckpoint(
  193. + // Checkpoint[] storage ckpts,
  194. + // function(uint256, uint256) view returns (uint256) op,
  195. + // uint256 delta
  196. + // ) private returns (uint256 oldWeight, uint256 newWeight) {
  197. + // uint256 pos = ckpts.length;
  198. + // oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  199. + // newWeight = op(oldWeight, delta);
  200. + //
  201. + // if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
  202. + // ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  203. + // } else {
  204. + // ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)}));
  205. + // }
  206. + // }
  207. +
  208. function _add(uint256 a, uint256 b) private pure returns (uint256) {
  209. return a + b;
  210. }
  211. diff -ruN token/ERC20/extensions/ERC20Wrapper.sol token/ERC20/extensions/ERC20Wrapper.sol
  212. --- token/ERC20/extensions/ERC20Wrapper.sol 2022-03-02 09:14:55.000000000 -0800
  213. +++ token/ERC20/extensions/ERC20Wrapper.sol 2022-03-24 18:08:46.000000000 -0700
  214. @@ -44,7 +44,7 @@
  215. * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
  216. * function that can be exposed with access control if desired.
  217. */
  218. - function _recover(address account) internal virtual returns (uint256) {
  219. + function _recover(address account) public virtual returns (uint256) { // HARNESS: internal -> public
  220. uint256 value = underlying.balanceOf(address(this)) - totalSupply();
  221. _mint(account, value);
  222. return value;