Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFP12] CToken Cleanup #152

Merged
merged 29 commits into from Jun 7, 2022

Conversation

arjun-io
Copy link
Contributor

@arjun-io arjun-io commented Aug 29, 2021

This PR Implements RFP 12:

Changes

  • Upgrades all Contracts to 0.8.10 and removes legacy contracts
  • Removes SafeMath and error codes from CToken and Interest Rate contracts, in favor of checked math and custom errors added to Solidity 0.8.x
  • Changes to Scenario tests which involve explicit behavior changes due to changing to reverts instead returning

Change Notes

Since Saddle and solc don't support multiple versions within a repo, we thought the best way forward was to upgrade all contracts and remove legacy Comptroller implementations (ComptrollerGN). In order to ensure tests still work, legacy build artifacts were added to tests/LegacyBuilds/legacy.json for usage in tests. We're open to a cleaner solution to this issue - perhaps by supporting multiple solidity versions within a single repo through Hardhat.

We introduce a new CustomError matcher in both regular JS tests and Scenarios - these work by comparing the ABI encoding of the custom error and the results field of the transaction output.

Most math errors with explicit messages (addition overflow, subtraction underflow, divide by zero, etc) have been removed and now just have a generic revert message. This is how Solidity exposes these reverts with checked math, and generally these errors can be debugged using more modern transaction tracing tooling.

@arjun-io arjun-io force-pushed the rfp12-ctoken-cleanup branch 2 times, most recently from d4d81c1 to 9703b0f Compare August 30, 2021 04:06
@jflatow
Copy link
Contributor

jflatow commented Aug 31, 2021

Cool! So what's the gas impact looking like?

@arjun-io
Copy link
Contributor Author

arjun-io commented Aug 31, 2021

@jflatow Just ran the profiler and pushed, modest savings. We can save a bit more doing another pass at the optimizations with more code changes (found that removing the localvar structs did save some memory) but wanted to get this version out first

edit: Just removed the LocalVar structs, a bit more savings

proposals[newProposal.id] = newProposal;
uint proposalId = proposalCount;
Proposal storage newProposal = proposals[proposalId];
newProposal.id = proposalCount;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be newProposal.id = proposalId to avoid discrepancies

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment applies to Governor Bravo as well.


proposals[newProposal.id] = newProposal;
uint proposalId = proposalCount;
Proposal storage newProposal = proposals[proposalId];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a revert below this line if newProposal has any data set. This should never be the case, but if so, we don't want to overwrite anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment applies to Governor Bravo as well.

contracts/CToken.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@jflatow jflatow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what broke in linting? But I guess this is the future and we need to merge 💪

@arjun-io
Copy link
Contributor Author

arjun-io commented May 2, 2022

@jflatow I think the current linter (solium) doesn't support newer syntax, it might make sense to switch to solhint

@arjun-io
Copy link
Contributor Author

arjun-io commented Jun 2, 2022

@jflatow migrated to solhint. All of the rules mapped pretty cleanly (except indentation):

"quotes" -> "quotes"
"max-len" ->  "max-line-len"
"security/no-block-members" -> "not-rely-on-block-hash" and "not-rely-on-time"
"security/no-inline-assembly" -> "no-inline-assembly"
"security/no-low-level-calls" -> "avoid-low-level-calls"
"security/no-tx-origin" ->. "avoid-tx-origin"
"imports-on-top" -> "imports-on-top"

Hopefully CI will pass now 🙏

Copy link
Contributor

@jflatow jflatow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@arjun-io
Copy link
Contributor Author

arjun-io commented Jun 7, 2022

@jflatow it seems like the failing tests are due to Circle rather than the tests themselves? What are your thoughts on merging this in and then investigating CI separately (I'm happy to help here)? I know people are developing on top of these changes so it might be nice to have it in master

@jflatow jflatow merged commit a3214f6 into compound-finance:master Jun 7, 2022
@arjun-io arjun-io deleted the rfp12-ctoken-cleanup branch June 9, 2022 00:50
@enzoferey
Copy link

Hi ! Good clean up here 💅🏻

How do you plan to use these changes ? Do you have any intention to audit them ?

@arjun-io
Copy link
Contributor Author

Hi ! Good clean up here 💅🏻

How do you plan to use these changes ? Do you have any intention to audit them ?

This change has been audited and the cTokens have been upgraded on mainnet. See the forum post for more details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants