Ante Test Examples
Sample Ante Tests to dissect for explanation
A Note on Writing Ante Tests
Example: WBTC Supply Doesn't Exceed 21 Million
In this test (AnteWBTCSupplyTest.sol
) we write an Ante Test that checks the total outstanding supply of wrapped Bitcoin (WBTC) does not exceed 21 million, which is the known "maximum supply" of Bitcoin.
For more information on what wrapped Bitcoin is, please see https://wbtc.network/ (external link).
AnteWBTCSupplyTest.sol
as of 2021-11-26
This example outlines a sample Ante Test that uses the AnteTest.sol
abstract contract that inherits IAnteTest.sol
for use.
An explanation for the various lines are as follows:
(Line 15) - Importing the contract
AnteTest.sol
Future work: Will be packaged to a library for importing for ease of use
(Line 19) - Contract inherits from AnteTest using
... is AnteTest(...)
. It is here where the test name will be decided.Recommended to have a human-readable description passed as in
AnteTest()
(e.g. "Wrapped BTC (WBTC) supply ...")
(Lines 21-26) - Implement the variables and logic as needed for the test.
In this example, we define the variable for the WBTC address, it is set in the constructor (Line 33), and for clarity we wrote it in the comments (Line 20).
Following which, we set our threshold limit which is 21M, the maximum total Bitcoin supply.
Using the IERC20 interface provided by @openzeppelin, we define WBTC from the address.
(Lines 30-31) - The part of the constructor that tells Ante the name of the tested protocol and the tested contracts (for front-end convenience).
(Lines 33-34) - Defines the WBTC address from the constructor, and then uses the IERC20 interface defined earlier to read the WBTC.
(Line 39) - The
checkTestPasses()
function here does the final return on whether the test passes or not, which should be expected to be true, as the "guarantee" behind the Ante Test.In this example, the wrapped BTC total supply should not exceed the threshold we set earlier (21M)
This should be assumed true, unless something extraordinary happens.
In this example above, the Ante Test guarantees that the WBTC circulation never exceeds 21 million.
Example: WETH9 Minted WETH equals ETH Balance
In this test (AnteWETH9Test.sol
) we check that the ETH deposited into the wrapped ETH (WETH9) contract does in fact equal the total number of WETH tokens (ERC20 compliant "ETH") circulating.
For more background around what is wrapped Ether we recommend reading https://weth.io/ (external link).
AnteWETH9Test.sol as of 2021-11-26
Building on the previous example, note the important lines in the WETH9 Ante Test:
(Line 15) - Import the
AnteTest.sol
abstract class(Line 19) - Name the test with a human-readable string "Checks WETH9..."
(Line 21-23) - We define the needed variables here
(Line 21) - Defines the
address
of the WETH9 contract to be set later in the constructor, additionally, added for clarity into the comments (Line 20).(Line 23) - We define the
IERC20
interface asWETH9Token
to later interact with it
(Lines 27-28) - Defines the WETH9 address from the constructor, and then uses the IERC20 interface defined earlier to read the WETH9.
(Lines 30-31) - The part of the constructor that tells Ante the name of the tested protocol and the tested contracts (for front-end convenience).
(Line 37) - We define the invariant for WETH9 with a boolean check
Left side: we get the ETH balance of the address of the created WETH9 ERC20 token
Right side: we get the outstanding supply of WETH9Token
Invariant: the ETH deposited into WETH9 should always equal the WETH supply
Example: ETH2DepositContract Balance "Rugs"
For context, in the lead-up to the launch of Ethereum2's beacon chain in late 2020, the Ethereum Foundation helped put together a "deposit contract" (with the ENS name DEPOSITCONTRACT.ETH that was paid for for 150 years and then had ownership burned) where people could, following a set of instructions, deposit ETH in multiples of 32 to spin up ETH2 validator nodes that earn Proof-of-Stake rewards for correctly helping to secure the Beacon Chain. For more information, please see https://ethereum.org/en/eth2/
In this test, we tongue-in-cheek check that the balance in DepositContract.eth does not drop by 99.99% (indicating that it is likely it has been compromised and a thief has stolen all of the funds).
Note that it is possible for a clever thief to steal all but 501 ETH, in which case this Ante Test would still pass. While that is clearly a failure case of this Ante Test, we hope that for illustrative purposes this example shows a way to use Ante.
AnteETH2DepositTest.sol
as of 2021-11-26
Breakdown of key lines:
(Lines 3-10) - ASCII Art we are very proud of that we definitely didn't rip off of DepositContract.eth :)
(Lines 22-25) - We define key state variables
(Line 22) - We define the variable for the address, this is set when deploying the Ante Test as defined in the constructor, additionally, we write it for clarity in the comments (Line 21)
(Line 25) - We define the "Threshold" at which we consider a "failure" to have happened (500 ETH)
(Lines 29-31) - The constructor that tells Ante the name of the tested protocol, sets the ETH2 contract address, and sets the tested contracts. Note we only set the tested contract address here!
(Line 37) - We check that the Deposit Contract still has greater than or equal to
THRESHOLD_BALANCE
.
Example: EthDev Doesn't "Rug" Test
(Note: we use the term "rug" here casually -- as in, some large fraction of the balance in the contract vanishes from the address.)
The address described below is often labeled publicly as an "EthDev" (Ethereum Foundation's developer fund) address. Many online joke during market downturns that it is due to "EthDev" selling ETH or "EthDev Rugging." We do not support such rumors, but we figured it could make for an amusing illustrative example of what is possible with Ante.
This test checks that at least 1% of the ETH sitting in the "EthDev" address is still there. (Note: this is not meant to be an extremely robust Ante Test because EthDev's controlling parties could, for perfectly legitimate reasons, decide to move any or all of their ETH to a new address at any time.) Please view this as an Ante Test written purely for educational purposes.
AnteEthDevRugTest.sol
as of 2021-11-26
(Line 20) - Defines the EthDev address variable, this is set when deploying the Ante Test as defined in the constructor, additionally, we write it for clarity in the comments (Line 19)
(Line 23) - Defines the
RUG_THRESHOLD
which we've set to approximately 1% of the ETH of the total amount in the address as of 2021-05-24.(Line 25-27) - The constructor that tells Ante the name of the tested protocol, sets the EthDev contract address, and sets the tested contracts.
(Line 29) - Check the inequality holds using the threshold defined earlier.
Last updated