applyHarness.patch 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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 13:45:38.363620120 +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. @@ -240,5 +258,5 @@
  100. /**
  101. * @dev Must return the voting units held by an account.
  102. */
  103. - function _getVotingUnits(address) internal view virtual returns (uint256);
  104. + function _getVotingUnits(address) public view virtual returns (uint256); // HARNESS: internal -> public
  105. }
  106. diff -druN proxy/utils/Initializable.sol proxy/utils/Initializable.sol
  107. --- proxy/utils/Initializable.sol 2023-02-27 10:59:32.655891529 +0100
  108. +++ proxy/utils/Initializable.sol 2023-02-27 11:58:55.067833070 +0100
  109. @@ -60,12 +60,12 @@
  110. * @dev Indicates that the contract has been initialized.
  111. * @custom:oz-retyped-from bool
  112. */
  113. - uint8 private _initialized;
  114. + uint8 internal _initialized; // HARNESS: private -> internal
  115. /**
  116. * @dev Indicates that the contract is in the process of being initialized.
  117. */
  118. - bool private _initializing;
  119. + bool internal _initializing; // HARNESS: private -> internal
  120. /**
  121. * @dev Triggered when the contract has been initialized or reinitialized.
  122. diff -druN token/ERC1155/ERC1155.sol token/ERC1155/ERC1155.sol
  123. --- token/ERC1155/ERC1155.sol 2023-02-27 10:59:32.655891529 +0100
  124. +++ token/ERC1155/ERC1155.sol 2023-02-27 11:58:55.067833070 +0100
  125. @@ -21,7 +21,7 @@
  126. using Address for address;
  127. // Mapping from token ID to account balances
  128. - mapping(uint256 => mapping(address => uint256)) private _balances;
  129. + mapping(uint256 => mapping(address => uint256)) internal _balances; // HARNESS: private -> internal
  130. // Mapping from account to operator approvals
  131. mapping(address => mapping(address => bool)) private _operatorApprovals;
  132. @@ -451,7 +451,7 @@
  133. uint256 id,
  134. uint256 amount,
  135. bytes memory data
  136. - ) private {
  137. + ) public { // HARNESS: private -> public
  138. if (to.isContract()) {
  139. try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
  140. if (response != IERC1155Receiver.onERC1155Received.selector) {
  141. @@ -472,7 +472,7 @@
  142. uint256[] memory ids,
  143. uint256[] memory amounts,
  144. bytes memory data
  145. - ) private {
  146. + ) public { // HARNESS: private -> public
  147. if (to.isContract()) {
  148. try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
  149. bytes4 response
  150. diff -druN token/ERC20/ERC20.sol token/ERC20/ERC20.sol
  151. --- token/ERC20/ERC20.sol 2023-02-27 10:59:32.655891529 +0100
  152. +++ token/ERC20/ERC20.sol 2023-02-27 11:58:55.067833070 +0100
  153. @@ -248,7 +248,7 @@
  154. *
  155. * - `account` cannot be the zero address.
  156. */
  157. - function _mint(address account, uint256 amount) internal virtual {
  158. + function _mint(address account, uint256 amount) public virtual { // HARNESS: internal -> public
  159. require(account != address(0), "ERC20: mint to the zero address");
  160. _beforeTokenTransfer(address(0), account, amount);
  161. @@ -274,7 +274,7 @@
  162. * - `account` cannot be the zero address.
  163. * - `account` must have at least `amount` tokens.
  164. */
  165. - function _burn(address account, uint256 amount) internal virtual {
  166. + function _burn(address account, uint256 amount) public virtual { // HARNESS: internal -> public
  167. require(account != address(0), "ERC20: burn from the zero address");
  168. _beforeTokenTransfer(account, address(0), amount);
  169. diff -druN token/ERC20/extensions/ERC20Capped.sol token/ERC20/extensions/ERC20Capped.sol
  170. --- token/ERC20/extensions/ERC20Capped.sol 2023-02-22 15:43:36.624717708 +0100
  171. +++ token/ERC20/extensions/ERC20Capped.sol 2023-02-27 11:58:55.067833070 +0100
  172. @@ -30,7 +30,7 @@
  173. /**
  174. * @dev See {ERC20-_mint}.
  175. */
  176. - function _mint(address account, uint256 amount) internal virtual override {
  177. + function _mint(address account, uint256 amount) public virtual override { // HARNESS: internal -> public
  178. require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
  179. super._mint(account, amount);
  180. }
  181. diff -druN token/ERC20/extensions/ERC20FlashMint.sol token/ERC20/extensions/ERC20FlashMint.sol
  182. --- token/ERC20/extensions/ERC20FlashMint.sol 2023-02-27 10:59:32.655891529 +0100
  183. +++ token/ERC20/extensions/ERC20FlashMint.sol 2023-02-27 11:58:55.067833070 +0100
  184. @@ -53,9 +53,11 @@
  185. // silence warning about unused variable without the addition of bytecode.
  186. token;
  187. amount;
  188. - return 0;
  189. + return fee; // HARNESS: made "return" nonzero
  190. }
  191. + uint256 public fee; // HARNESS: added it to simulate random fee amount
  192. +
  193. /**
  194. * @dev Returns the receiver address of the flash fee. By default this
  195. * implementation returns the address(0) which means the fee amount will be burnt.
  196. diff -druN token/ERC20/extensions/ERC20Votes.sol token/ERC20/extensions/ERC20Votes.sol
  197. --- token/ERC20/extensions/ERC20Votes.sol 2023-02-27 10:59:32.655891529 +0100
  198. +++ token/ERC20/extensions/ERC20Votes.sol 2023-02-27 11:58:57.244508616 +0100
  199. @@ -33,8 +33,8 @@
  200. bytes32 private constant _DELEGATION_TYPEHASH =
  201. keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
  202. - mapping(address => address) private _delegates;
  203. - mapping(address => Checkpoint[]) private _checkpoints;
  204. + mapping(address => address) public _delegates; // HARNESS: private -> public
  205. + mapping(address => Checkpoint[]) public _checkpoints; // HARNESS: private -> public
  206. Checkpoint[] private _totalSupplyCheckpoints;
  207. /**
  208. @@ -186,27 +186,27 @@
  209. /**
  210. * @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).
  211. */
  212. - function _maxSupply() internal view virtual returns (uint224) {
  213. + function _maxSupply() public view virtual returns (uint224) { // HARNESS: internal -> public
  214. return type(uint224).max;
  215. }
  216. /**
  217. * @dev Snapshots the totalSupply after it has been increased.
  218. */
  219. - function _mint(address account, uint256 amount) internal virtual override {
  220. + function _mint(address account, uint256 amount) public virtual override { // HARNESS: internal -> public
  221. super._mint(account, amount);
  222. require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
  223. - _writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
  224. + _writeCheckpointAdd(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  225. }
  226. /**
  227. * @dev Snapshots the totalSupply after it has been decreased.
  228. */
  229. - function _burn(address account, uint256 amount) internal virtual override {
  230. + function _burn(address account, uint256 amount) public virtual override { // HARNESS: internal -> public (to comply with the ERC20 harness)
  231. super._burn(account, amount);
  232. - _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
  233. + _writeCheckpointSub(_totalSupplyCheckpoints, amount); // HARNESS: new version without pointer
  234. }
  235. /**
  236. @@ -225,7 +225,7 @@
  237. *
  238. * Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.
  239. */
  240. - function _delegate(address delegator, address delegatee) internal virtual {
  241. + function _delegate(address delegator, address delegatee) public virtual { // HARNESS: internal -> public
  242. address currentDelegate = delegates(delegator);
  243. uint256 delegatorBalance = balanceOf(delegator);
  244. _delegates[delegator] = delegatee;
  245. @@ -238,35 +238,60 @@
  246. function _moveVotingPower(address src, address dst, uint256 amount) private {
  247. if (src != dst && amount > 0) {
  248. if (src != address(0)) {
  249. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
  250. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointSub(_checkpoints[src], amount); // HARNESS: new version without pointer
  251. emit DelegateVotesChanged(src, oldWeight, newWeight);
  252. }
  253. if (dst != address(0)) {
  254. - (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
  255. + (uint256 oldWeight, uint256 newWeight) = _writeCheckpointAdd(_checkpoints[dst], amount); // HARNESS: new version without pointer
  256. emit DelegateVotesChanged(dst, oldWeight, newWeight);
  257. }
  258. }
  259. }
  260. - function _writeCheckpoint(
  261. - Checkpoint[] storage ckpts,
  262. - function(uint256, uint256) view returns (uint256) op,
  263. - uint256 delta
  264. - ) private returns (uint256 oldWeight, uint256 newWeight) {
  265. + // HARNESS: split _writeCheckpoint() to two functions as a workaround for function pointers that cannot be managed by the tool
  266. + // function _writeCheckpoint(
  267. + // Checkpoint[] storage ckpts,
  268. + // function(uint256, uint256) view returns (uint256) op,
  269. + // uint256 delta
  270. + // ) private returns (uint256 oldWeight, uint256 newWeight) {
  271. + // uint256 pos = ckpts.length;
  272. +
  273. + // unchecked {
  274. + // Checkpoint memory oldCkpt = pos == 0 ? Checkpoint(0, 0) : _unsafeAccess(ckpts, pos - 1);
  275. +
  276. + // oldWeight = oldCkpt.votes;
  277. + // newWeight = op(oldWeight, delta);
  278. +
  279. + // if (pos > 0 && oldCkpt.fromBlock == clock()) {
  280. + // _unsafeAccess(ckpts, pos - 1).votes = SafeCast.toUint224(newWeight);
  281. + // } else {
  282. + // ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(clock()), votes: SafeCast.toUint224(newWeight)}));
  283. + // }
  284. + // }
  285. + // }
  286. +
  287. + function _writeCheckpointAdd(Checkpoint[] storage ckpts, uint256 delta) private returns (uint256 oldWeight, uint256 newWeight) {
  288. uint256 pos = ckpts.length;
  289. + oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  290. + newWeight = _add(oldWeight, delta);
  291. - unchecked {
  292. - Checkpoint memory oldCkpt = pos == 0 ? Checkpoint(0, 0) : _unsafeAccess(ckpts, pos - 1);
  293. + if (pos > 0 && ckpts[pos - 1].fromBlock == clock()) {
  294. + ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  295. + } else {
  296. + ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(clock()), votes: SafeCast.toUint224(newWeight)}));
  297. + }
  298. + }
  299. - oldWeight = oldCkpt.votes;
  300. - newWeight = op(oldWeight, delta);
  301. + function _writeCheckpointSub(Checkpoint[] storage ckpts, uint256 delta) private returns (uint256 oldWeight, uint256 newWeight) {
  302. + uint256 pos = ckpts.length;
  303. + oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
  304. + newWeight = _subtract(oldWeight, delta);
  305. - if (pos > 0 && oldCkpt.fromBlock == clock()) {
  306. - _unsafeAccess(ckpts, pos - 1).votes = SafeCast.toUint224(newWeight);
  307. - } else {
  308. - ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(clock()), votes: SafeCast.toUint224(newWeight)}));
  309. - }
  310. + if (pos > 0 && ckpts[pos - 1].fromBlock == clock()) {
  311. + ckpts[pos - 1].votes = SafeCast.toUint224(newWeight);
  312. + } else {
  313. + ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(clock()), votes: SafeCast.toUint224(newWeight)}));
  314. }
  315. }
  316. diff -druN token/ERC20/extensions/ERC20Wrapper.sol token/ERC20/extensions/ERC20Wrapper.sol
  317. --- token/ERC20/extensions/ERC20Wrapper.sol 2023-02-27 10:59:32.655891529 +0100
  318. +++ token/ERC20/extensions/ERC20Wrapper.sol 2023-02-27 11:58:55.067833070 +0100
  319. @@ -62,7 +62,7 @@
  320. * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
  321. * function that can be exposed with access control if desired.
  322. */
  323. - function _recover(address account) internal virtual returns (uint256) {
  324. + function _recover(address account) public virtual returns (uint256) { // HARNESS: internal -> public
  325. uint256 value = _underlying.balanceOf(address(this)) - totalSupply();
  326. _mint(account, value);
  327. return value;
  328. diff -druN token/ERC721/extensions/ERC721Votes.sol token/ERC721/extensions/ERC721Votes.sol
  329. --- token/ERC721/extensions/ERC721Votes.sol 2023-02-27 10:59:32.655891529 +0100
  330. +++ token/ERC721/extensions/ERC721Votes.sol 2023-02-27 11:58:55.067833070 +0100
  331. @@ -35,7 +35,7 @@
  332. /**
  333. * @dev Returns the balance of `account`.
  334. */
  335. - function _getVotingUnits(address account) internal view virtual override returns (uint256) {
  336. + function _getVotingUnits(address account) public view virtual override returns (uint256) { // HARNESS: internal -> public
  337. return balanceOf(account);
  338. }
  339. }
  340. diff -druN utils/Address.sol utils/Address.sol
  341. --- utils/Address.sol 2023-02-27 10:59:32.659224903 +0100
  342. +++ utils/Address.sol 2023-02-27 11:58:55.067833070 +0100
  343. @@ -197,7 +197,7 @@
  344. bool success,
  345. bytes memory returndata,
  346. string memory errorMessage
  347. - ) internal view returns (bytes memory) {
  348. + ) internal view returns (bytes memory val) { // MUNGED undeterministic return causes error for Prover
  349. if (success) {
  350. if (returndata.length == 0) {
  351. // only check isContract if the call was successful and the return data is empty
  352. @@ -220,7 +220,7 @@
  353. bool success,
  354. bytes memory returndata,
  355. string memory errorMessage
  356. - ) internal pure returns (bytes memory) {
  357. + ) internal pure returns (bytes memory val) { // MUNGED undeterministic return causes error for Prover
  358. if (success) {
  359. return returndata;
  360. } else {
  361. diff -druN utils/Checkpoints.sol utils/Checkpoints.sol
  362. --- utils/Checkpoints.sol 2023-02-27 10:59:32.659224903 +0100
  363. +++ utils/Checkpoints.sol 2023-02-27 11:58:55.071166417 +0100
  364. @@ -84,13 +84,13 @@
  365. *
  366. * Returns previous value and new value.
  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. + // function push(
  376. + // History storage self,
  377. + // function(uint256, uint256) view returns (uint256) op,
  378. + // uint256 delta
  379. + // ) internal returns (uint256, uint256) {
  380. + // return push(self, op(latest(self), delta));
  381. + // }
  382. /**
  383. * @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.