Brief History of Error Handling in the Protocol

I’ve mentioned before that there’s some history to the way we do error handling in the protocol (On Interest Rate Models). Since this question comes up from time to time, I wanted to give a brief summary.

The first batch of Compound v2 contracts were compiled and deployed using Solidity 0.5.8. Most of these contracts were immutable and are still in use today. Besides still being used, the first cTokens established conventions inherited by later contracts.

Error handling was always a big topic of discussion, even when developing the first v2 contracts. The original reason for using error codes, was that the EVM did not have revert with reason at the time. Thus if you wanted to know what went wrong, you needed to emit a log, and in order to do that the transaction needed to succeed. So in general, the contracts were written in a “Check Effects Interactions” style.

Another benefit of using logs was that anyone could look at the tx on chain and see what went wrong. This meant that as developers, if users were having issues, we could help diagnose issues after the fact. Over time, Etherscan and others added more support for being able inspect the call stack for reverts.

By the time we had become fully comfortable with the idea of using revert with reason everywhere, our contracts weren’t changing much. At some point, we finally decided that all new code would be written using reverts, and that old code could be rewritten using reverts, if and when the appropriate time ever came.

Slowly, we are moving to reverts everywhere. Eventually, it is possible all contracts using the ‘old-style’ errors will have been deprecated by the protocol.

4 Likes