applyHarness.patch 19 KB

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