applyHarness.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. diff -druN access/AccessControl.sol access/AccessControl.sol
  2. --- access/AccessControl.sol 2023-02-27 10:59:32.652558153 +0100
  3. +++ access/AccessControl.sol 2023-02-27 11:58:55.064499723 +0100
  4. @@ -94,7 +94,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 -druN governance/extensions/GovernorCountingSimple.sol governance/extensions/GovernorCountingSimple.sol
  13. --- governance/extensions/GovernorCountingSimple.sol 2023-02-27 10:59:32.652558153 +0100
  14. +++ governance/extensions/GovernorCountingSimple.sol 2023-02-27 11:58:55.064499723 +0100
  15. @@ -27,7 +27,7 @@
  16. mapping(address => bool) hasVoted;
  17. }
  18. - mapping(uint256 => ProposalVote) private _proposalVotes;
  19. + mapping(uint256 => ProposalVote) internal _proposalVotes; // HARNESS: private -> internal
  20. /**
  21. * @dev See {IGovernor-COUNTING_MODE}.
  22. diff -druN governance/extensions/GovernorPreventLateQuorum.sol governance/extensions/GovernorPreventLateQuorum.sol
  23. --- governance/extensions/GovernorPreventLateQuorum.sol 2023-02-27 10:59:32.652558153 +0100
  24. +++ governance/extensions/GovernorPreventLateQuorum.sol 2023-02-27 11:58:55.064499723 +0100
  25. @@ -20,10 +20,10 @@
  26. abstract contract GovernorPreventLateQuorum is Governor {
  27. using SafeCast for uint256;
  28. - uint64 private _voteExtension;
  29. + uint64 internal _voteExtension; // HARNESS: private -> internal
  30. /// @custom:oz-retyped-from mapping(uint256 => Timers.BlockNumber)
  31. - mapping(uint256 => uint64) private _extendedDeadlines;
  32. + mapping(uint256 => uint64) internal _extendedDeadlines; // HARNESS: private -> internal
  33. /// @dev Emitted when a proposal deadline is pushed back due to reaching quorum late in its voting period.
  34. event ProposalExtended(uint256 indexed proposalId, uint64 extendedDeadline);
  35. diff -druN governance/extensions/GovernorVotesQuorumFraction.sol governance/extensions/GovernorVotesQuorumFraction.sol
  36. --- governance/extensions/GovernorVotesQuorumFraction.sol 2023-02-27 10:59:32.655891529 +0100
  37. +++ governance/extensions/GovernorVotesQuorumFraction.sol 2023-02-27 11:58:55.064499723 +0100
  38. @@ -17,10 +17,10 @@
  39. using SafeCast for *;
  40. using Checkpoints for Checkpoints.Trace224;
  41. - uint256 private _quorumNumerator; // DEPRECATED in favor of _quorumNumeratorHistory
  42. + uint256 internal _quorumNumerator; // DEPRECATED // MUNGED private => internal
  43. /// @custom:oz-retyped-from Checkpoints.History
  44. - Checkpoints.Trace224 private _quorumNumeratorHistory;
  45. + Checkpoints.Trace224 internal _quorumNumeratorHistory; // MUNGED private => internal
  46. event QuorumNumeratorUpdated(uint256 oldQuorumNumerator, uint256 newQuorumNumerator);
  47. diff -druN governance/Governor.sol governance/Governor.sol
  48. --- governance/Governor.sol 2023-02-27 10:59:32.652558153 +0100
  49. +++ governance/Governor.sol 2023-02-27 11:58:55.064499723 +0100
  50. @@ -51,7 +51,7 @@
  51. string private _name;
  52. /// @custom:oz-retyped-from mapping(uint256 => Governor.ProposalCore)
  53. - mapping(uint256 => ProposalCore) private _proposals;
  54. + mapping(uint256 => ProposalCore) internal _proposals; // HARNESS: private -> internal
  55. // This queue keeps track of the governor operating on itself. Calls to functions protected by the
  56. // {onlyGovernance} modifier needs to be whitelisted in this queue. Whitelisting is set in {_beforeExecute},
  57. diff -druN governance/TimelockController.sol governance/TimelockController.sol
  58. --- governance/TimelockController.sol 2023-02-27 10:59:32.652558153 +0100
  59. +++ governance/TimelockController.sol 2023-02-27 11:58:55.067833070 +0100
  60. @@ -28,10 +28,10 @@
  61. bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
  62. bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
  63. bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");
  64. - uint256 internal constant _DONE_TIMESTAMP = uint256(1);
  65. + uint256 public constant _DONE_TIMESTAMP = uint256(1); // HARNESS: internal -> public
  66. mapping(bytes32 => uint256) private _timestamps;
  67. - uint256 private _minDelay;
  68. + uint256 public _minDelay; // HARNESS: private -> public
  69. /**
  70. * @dev Emitted when a call is scheduled as part of operation `id`.
  71. diff -druN governance/utils/Votes.sol governance/utils/Votes.sol
  72. --- governance/utils/Votes.sol 2023-02-27 10:59:32.655891529 +0100
  73. +++ governance/utils/Votes.sol 2023-02-27 11:58:55.067833070 +0100
  74. @@ -35,7 +35,25 @@
  75. bytes32 private constant _DELEGATION_TYPEHASH =
  76. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  77. - mapping(address => address) private _delegation;
  78. + // HARNESS : Hooks cannot access any information from Checkpoints yet, so I am also updating votes and fromBlock in this struct
  79. + struct Ckpt {
  80. + uint32 fromBlock;
  81. + uint224 votes;
  82. + }
  83. + mapping(address => Ckpt) public _checkpoints;
  84. +
  85. + // HARNESSED getters
  86. + function numCheckpoints(address account) public view returns (uint32) {
  87. + return SafeCast.toUint32(_delegateCheckpoints[account]._checkpoints.length);
  88. + }
  89. + function ckptFromBlock(address account, uint32 pos) public view returns (uint32) {
  90. + return _delegateCheckpoints[account]._checkpoints[pos]._blockNumber;
  91. + }
  92. + function ckptVotes(address account, uint32 pos) public view returns (uint224) {
  93. + return _delegateCheckpoints[account]._checkpoints[pos]._value;
  94. + }
  95. +
  96. + mapping(address => address) public _delegation; // HARNESS: private -> public
  97. /// @custom:oz-retyped-from mapping(address => Checkpoints.History)
  98. mapping(address => Checkpoints.Trace224) private _delegateCheckpoints;
  99. diff -druN proxy/utils/Initializable.sol proxy/utils/Initializable.sol
  100. --- proxy/utils/Initializable.sol 2023-02-27 10:59:32.655891529 +0100
  101. +++ proxy/utils/Initializable.sol 2023-02-27 11:58:55.067833070 +0100
  102. @@ -60,12 +60,12 @@
  103. * @dev Indicates that the contract has been initialized.
  104. * @custom:oz-retyped-from bool
  105. */
  106. - uint8 private _initialized;
  107. + uint8 internal _initialized; // HARNESS: private -> internal
  108. /**
  109. * @dev Indicates that the contract is in the process of being initialized.
  110. */
  111. - bool private _initializing;
  112. + bool internal _initializing; // HARNESS: private -> internal
  113. /**
  114. * @dev Triggered when the contract has been initialized or reinitialized.
  115. diff -druN token/ERC1155/ERC1155.sol token/ERC1155/ERC1155.sol
  116. --- token/ERC1155/ERC1155.sol 2023-02-27 10:59:32.655891529 +0100
  117. +++ token/ERC1155/ERC1155.sol 2023-02-27 11:58:55.067833070 +0100
  118. @@ -21,7 +21,7 @@
  119. using Address for address;
  120. // Mapping from token ID to account balances
  121. - mapping(uint256 => mapping(address => uint256)) private _balances;
  122. + mapping(uint256 => mapping(address => uint256)) internal _balances; // HARNESS: private -> internal
  123. // Mapping from account to operator approvals
  124. mapping(address => mapping(address => bool)) private _operatorApprovals;
  125. @@ -451,7 +451,7 @@
  126. uint256 id,
  127. uint256 amount,
  128. bytes memory data
  129. - ) private {
  130. + ) public { // HARNESS: private -> public
  131. if (to.isContract()) {
  132. try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
  133. if (response != IERC1155Receiver.onERC1155Received.selector) {
  134. @@ -472,7 +472,7 @@
  135. uint256[] memory ids,
  136. uint256[] memory amounts,
  137. bytes memory data
  138. - ) private {
  139. + ) public { // HARNESS: private -> public
  140. if (to.isContract()) {
  141. try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
  142. bytes4 response
  143. diff -druN token/ERC20/ERC20.sol token/ERC20/ERC20.sol
  144. --- token/ERC20/ERC20.sol 2023-02-27 10:59:32.655891529 +0100
  145. +++ token/ERC20/ERC20.sol 2023-02-27 11:58:55.067833070 +0100
  146. @@ -248,7 +248,7 @@
  147. *
  148. * - `account` cannot be the zero address.
  149. */
  150. - function _mint(address account, uint256 amount) internal virtual {
  151. + function _mint(address account, uint256 amount) public virtual { // HARNESS: internal -> public
  152. require(account != address(0), "ERC20: mint to the zero address");
  153. _beforeTokenTransfer(address(0), account, amount);
  154. @@ -274,7 +274,7 @@
  155. * - `account` cannot be the zero address.
  156. * - `account` must have at least `amount` tokens.
  157. */
  158. - function _burn(address account, uint256 amount) internal virtual {
  159. + function _burn(address account, uint256 amount) public virtual { // HARNESS: internal -> public
  160. require(account != address(0), "ERC20: burn from the zero address");
  161. _beforeTokenTransfer(account, address(0), amount);
  162. diff -druN token/ERC20/extensions/ERC20Capped.sol token/ERC20/extensions/ERC20Capped.sol
  163. --- token/ERC20/extensions/ERC20Capped.sol 2023-02-22 15:43:36.624717708 +0100
  164. +++ token/ERC20/extensions/ERC20Capped.sol 2023-02-27 11:58:55.067833070 +0100
  165. @@ -30,7 +30,7 @@
  166. /**
  167. * @dev See {ERC20-_mint}.
  168. */
  169. - function _mint(address account, uint256 amount) internal virtual override {
  170. + function _mint(address account, uint256 amount) public virtual override { // HARNESS: internal -> public
  171. require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
  172. super._mint(account, amount);
  173. }
  174. diff -druN token/ERC20/extensions/ERC20FlashMint.sol token/ERC20/extensions/ERC20FlashMint.sol
  175. --- token/ERC20/extensions/ERC20FlashMint.sol 2023-02-27 10:59:32.655891529 +0100
  176. +++ token/ERC20/extensions/ERC20FlashMint.sol 2023-02-27 11:58:55.067833070 +0100
  177. @@ -53,9 +53,11 @@
  178. // silence warning about unused variable without the addition of bytecode.
  179. token;
  180. amount;
  181. - return 0;
  182. + return fee; // HARNESS: made "return" nonzero
  183. }
  184. + uint256 public fee; // HARNESS: added it to simulate random fee amount
  185. +
  186. /**
  187. * @dev Returns the receiver address of the flash fee. By default this
  188. * implementation returns the address(0) which means the fee amount will be burnt.
  189. diff -druN token/ERC20/extensions/ERC20Votes.sol token/ERC20/extensions/ERC20Votes.sol
  190. --- token/ERC20/extensions/ERC20Votes.sol 2023-02-27 10:59:32.655891529 +0100
  191. +++ token/ERC20/extensions/ERC20Votes.sol 2023-02-27 11:58:55.067833070 +0100
  192. @@ -33,8 +33,8 @@
  193. bytes32 private constant _DELEGATION_TYPEHASH =
  194. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  195. - mapping(address => address) private _delegates;
  196. - mapping(address => Checkpoint[]) private _checkpoints;
  197. + mapping(address => address) public _delegates; // HARNESS: private -> public
  198. + mapping(address => Checkpoint[]) public _checkpoints; // HARNESS: private -> public
  199. Checkpoint[] private _totalSupplyCheckpoints;
  200. /**
  201. @@ -186,27 +186,27 @@
  202. /**
  203. * @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).
  204. */
  205. - function _maxSupply() internal view virtual returns (uint224) {
  206. + function _maxSupply() public view virtual returns (uint224) { // HARNESS: internal -> public
  207. return type(uint224).max;
  208. }
  209. /**
  210. * @dev Snapshots the totalSupply after it has been increased.
  211. */
  212. - function _mint(address account, uint256 amount) internal virtual override {
  213. + function _mint(address account, uint256 amount) public virtual override { // HARNESS: internal -> public
  214. super._mint(account, amount);
  215. require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
  216. - _writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
  217. + _writeCheckpointAdd(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  218. }
  219. /**
  220. * @dev Snapshots the totalSupply after it has been decreased.
  221. */
  222. - function _burn(address account, uint256 amount) internal virtual override {
  223. + function _burn(address account, uint256 amount) public virtual override { // HARNESS: internal -> public (to comply with the ERC20 harness)
  224. super._burn(account, amount);
  225. - _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
  226. + _writeCheckpointSub(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  227. }
  228. /**
  229. @@ -225,7 +225,7 @@
  230. *
  231. * Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.
  232. */
  233. - function _delegate(address delegator, address delegatee) internal virtual {
  234. + function _delegate(address delegator, address delegatee) public virtual { // HARNESS: internal -> public
  235. address currentDelegate = delegates(delegator);
  236. uint256 delegatorBalance = balanceOf(delegator);
  237. _delegates[delegator] = delegatee;
  238. @@ -238,35 +238,60 @@
  239. function _moveVotingPower(address src, address dst, uint256 amount) private {
  240. if (src != dst && amount > 0) {
  241. if (src != address(0)) {
  242. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
  243. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointSub(_checkpoints[src], amount); // HARNESS: new version without pointer
  244. emit DelegateVotesChanged(src, oldWeight, newWeight);
  245. }
  246. if (dst != address(0)) {
  247. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
  248. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointAdd(_checkpoints[dst], amount); // HARNESS: new version without pointer
  249. emit DelegateVotesChanged(dst, oldWeight, newWeight);
  250. }
  251. }
  252. }
  253. - function _writeCheckpoint(
  254. - Checkpoint[] storage ckpts,
  255. - function(uint256, uint256) view returns (uint256) op,
  256. - uint256 delta
  257. - ) private returns (uint256 oldWeight, uint256 newWeight) {
  258. + // HARNESS: split _writeCheckpoint() to two functions as a workaround for function pointers that cannot be managed by the tool
  259. + // function _writeCheckpoint(
  260. + // Checkpoint[] storage ckpts,
  261. + // function(uint256, uint256) view returns (uint256) op,
  262. + // uint256 delta
  263. + // ) private returns (uint256 oldWeight, uint256 newWeight) {
  264. + // uint256 pos = ckpts.length;
  265. +
  266. + // unchecked {
  267. + // Checkpoint memory oldCkpt = pos == 0 ? Checkpoint(0, 0) : _unsafeAccess(ckpts, pos - 1);
  268. +
  269. + // oldWeight = oldCkpt.votes;
  270. + // newWeight = op(oldWeight, delta);
  271. +
  272. + // if (pos > 0 && oldCkpt.fromBlock == clock()) {
  273. + // _unsafeAccess(ckpts, pos - 1).votes = SafeCast.toUint224(newWeight);
  274. + // } else {
  275. + // ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(clock()), votes: SafeCast.toUint224(newWeight)}));
  276. + // }
  277. + // }
  278. + // }
  279. +
  280. + function _writeCheckpointAdd(Checkpoint[] storage ckpts, uint256 delta) private returns (uint256 oldWeight, uint256 newWeight) {
  281. uint256 pos = ckpts.length;
  282. + oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  283. + newWeight = _add(oldWeight, delta);
  284. - unchecked {
  285. - Checkpoint memory oldCkpt = pos == 0 ? Checkpoint(0, 0) : _unsafeAccess(ckpts, pos - 1);
  286. + if (pos > 0 && ckpts[pos - 1].fromBlock == clock()) {
  287. + ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  288. + } else {
  289. + ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(clock()), votes: SafeCast.toUint224(newWeight)}));
  290. + }
  291. + }
  292. - oldWeight = oldCkpt.votes;
  293. - newWeight = op(oldWeight, delta);
  294. + function _writeCheckpointSub(Checkpoint[] storage ckpts, uint256 delta) private returns (uint256 oldWeight, uint256 newWeight) {
  295. + uint256 pos = ckpts.length;
  296. + oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  297. + newWeight = _subtract(oldWeight, delta);
  298. - if (pos > 0 && oldCkpt.fromBlock == clock()) {
  299. - _unsafeAccess(ckpts, pos - 1).votes = SafeCast.toUint224(newWeight);
  300. - } else {
  301. - ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(clock()), votes: SafeCast.toUint224(newWeight)}));
  302. - }
  303. + if (pos > 0 && ckpts[pos - 1].fromBlock == clock()) {
  304. + ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  305. + } else {
  306. + ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(clock()), votes: SafeCast.toUint224(newWeight)}));
  307. }
  308. }
  309. diff -druN token/ERC20/extensions/ERC20Wrapper.sol token/ERC20/extensions/ERC20Wrapper.sol
  310. --- token/ERC20/extensions/ERC20Wrapper.sol 2023-02-27 10:59:32.655891529 +0100
  311. +++ token/ERC20/extensions/ERC20Wrapper.sol 2023-02-27 11:58:55.067833070 +0100
  312. @@ -62,7 +62,7 @@
  313. * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
  314. * function that can be exposed with access control if desired.
  315. */
  316. - function _recover(address account) internal virtual returns (uint256) {
  317. + function _recover(address account) public virtual returns (uint256) { // HARNESS: internal -> public
  318. uint256 value = _underlying.balanceOf(address(this)) - totalSupply();
  319. _mint(account, value);
  320. return value;
  321. diff -druN token/ERC721/extensions/ERC721Votes.sol token/ERC721/extensions/ERC721Votes.sol
  322. --- token/ERC721/extensions/ERC721Votes.sol 2023-02-27 10:59:32.655891529 +0100
  323. +++ token/ERC721/extensions/ERC721Votes.sol 2023-02-27 11:58:55.067833070 +0100
  324. @@ -35,7 +35,7 @@
  325. /**
  326. * @dev Returns the balance of `account`.
  327. */
  328. - function _getVotingUnits(address account) internal view virtual override returns (uint256) {
  329. + function _getVotingUnits(address account) public view virtual override returns (uint256) { // HARNESS: internal -> public
  330. return balanceOf(account);
  331. }
  332. }
  333. diff -druN utils/Address.sol utils/Address.sol
  334. --- utils/Address.sol 2023-02-27 10:59:32.659224903 +0100
  335. +++ utils/Address.sol 2023-02-27 11:58:55.067833070 +0100
  336. @@ -197,7 +197,7 @@
  337. bool success,
  338. bytes memory returndata,
  339. string memory errorMessage
  340. - ) internal view returns (bytes memory) {
  341. + ) internal view returns (bytes memory val) { // MUNGED undeterministic return causes error for Prover
  342. if (success) {
  343. if (returndata.length == 0) {
  344. // only check isContract if the call was successful and the return data is empty
  345. @@ -220,7 +220,7 @@
  346. bool success,
  347. bytes memory returndata,
  348. string memory errorMessage
  349. - ) internal pure returns (bytes memory) {
  350. + ) internal pure returns (bytes memory val) { // MUNGED undeterministic return causes error for Prover
  351. if (success) {
  352. return returndata;
  353. } else {
  354. diff -druN utils/Checkpoints.sol utils/Checkpoints.sol
  355. --- utils/Checkpoints.sol 2023-02-27 10:59:32.659224903 +0100
  356. +++ utils/Checkpoints.sol 2023-02-27 11:58:55.071166417 +0100
  357. @@ -84,13 +84,13 @@
  358. *
  359. * Returns previous value and new value.
  360. */
  361. - function push(
  362. - History storage self,
  363. - function(uint256, uint256) view returns (uint256) op,
  364. - uint256 delta
  365. - ) internal returns (uint256, uint256) {
  366. - return push(self, op(latest(self), delta));
  367. - }
  368. + // function push(
  369. + // History storage self,
  370. + // function(uint256, uint256) view returns (uint256) op,
  371. + // uint256 delta
  372. + // ) internal returns (uint256, uint256) {
  373. + // return push(self, op(latest(self), delta));
  374. + // }
  375. /**
  376. * @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.