Skip to content

Commit

Permalink
feat: tweak to conform to diff
Browse files Browse the repository at this point in the history
  • Loading branch information
QGarchery committed Dec 9, 2024
1 parent f14e8d2 commit 1ee1291
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 56 deletions.
27 changes: 27 additions & 0 deletions certora/specs/ERC20.spec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ use invariant totalSupplyIsSumOfBalances;

use invariant zeroAddressNoBalance;

/*
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Rules: only the token holder or an approved third party can reduce an account's balance
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
*/
rule onlyAuthorizedCanTransfer(env e) {
requireInvariant totalSupplyIsSumOfBalances();
requireInvariant balancesLTEqTotalSupply();
requireInvariant twoBalancesLTEqTotalSupply();

method f;
calldataarg args;
address account;

uint256 allowanceBefore = allowance(account, e.msg.sender);
uint256 balanceBefore = balanceOf(account);
f(e, args);
uint256 balanceAfter = balanceOf(account);

assert (
balanceAfter < balanceBefore
) => (
e.msg.sender == account ||
f.selector == sig:transferFrom(address, address, uint256).selector && balanceBefore - balanceAfter <= to_mathint(allowanceBefore)
);
}

/*
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Rules: only the token holder (or a permit) can increase allowance. The spender can decrease it by using it
Expand Down
31 changes: 4 additions & 27 deletions certora/specs/MintBurnEthereum.spec
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
import "Delegation.spec";
// This is spec is taken from the Open Zeppelin repositories at https://github.com/OpenZeppelin/openzeppelin-contracts/blob/448efeea6640bbbc09373f03fbc9c88e280147ba/certora/specs/ERC20.spec, and patched to support the DelegationToken.

/*
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Rules: only the token holder or an approved third party can reduce an account's balance
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
*/
rule onlyAuthorizedCanTransfer(env e, method f) {
requireInvariant totalSupplyIsSumOfBalances();
requireInvariant balancesLTEqTotalSupply();
requireInvariant twoBalancesLTEqTotalSupply();

calldataarg args;
address account;

uint256 allowanceBefore = allowance(account, e.msg.sender);
uint256 balanceBefore = balanceOf(account);
f(e, args);
uint256 balanceAfter = balanceOf(account);

assert (
balanceAfter < balanceBefore
) => (
e.msg.sender == account ||
f.selector == sig:transferFrom(address, address, uint256).selector && balanceBefore - balanceAfter <= to_mathint(allowanceBefore)
);
}
import "Delegation.spec";

/*
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Rules: only mint and burn can change total supply
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
*/
rule noChangeTotalSupply(env e, method f) {
rule noChangeTotalSupply(env e) {
requireInvariant totalSupplyIsSumOfBalances();
requireInvariant balancesLTEqTotalSupply();

method f;
calldataarg args;

uint256 totalSupplyBefore = totalSupply();
Expand Down
34 changes: 5 additions & 29 deletions certora/specs/MintBurnOptimism.spec
Original file line number Diff line number Diff line change
@@ -1,41 +1,17 @@
import "Delegation.spec";
// This is spec is taken from the Open Zeppelin repositories at https://github.com/OpenZeppelin/openzeppelin-contracts/blob/448efeea6640bbbc09373f03fbc9c88e280147ba/certora/specs/ERC20.spec, and patched to support the DelegationToken.

/*
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Rules: only the token holder or an approved third party can reduce an account's balance
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
*/
rule onlyAuthorizedCanTransfer(env e, method f) {
requireInvariant totalSupplyIsSumOfBalances();
requireInvariant balancesLTEqTotalSupply();
requireInvariant twoBalancesLTEqTotalSupply();

calldataarg args;
address account;

uint256 allowanceBefore = allowance(account, e.msg.sender);
uint256 balanceBefore = balanceOf(account);
f(e, args);
uint256 balanceAfter = balanceOf(account);

assert (
balanceAfter < balanceBefore
) => (
f.selector == sig:burn(address, uint256).selector ||
e.msg.sender == account ||
f.selector == sig:transferFrom(address, address, uint256).selector && balanceBefore - balanceAfter <= to_mathint(allowanceBefore)
);
}
import "Delegation.spec";

/*
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Rules: only mint and burn can change total supply
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
*/
rule noChangeTotalSupply(env e, method f) {
rule noChangeTotalSupply(env e) {
requireInvariant totalSupplyIsSumOfBalances();
requireInvariant balancesLTEqTotalSupply();

method f;
calldataarg args;

uint256 totalSupplyBefore = totalSupply();
Expand Down Expand Up @@ -119,7 +95,7 @@ rule burn(env e) {

// check outcome
if (lastReverted) {
assert e.msg.sender == 0x0 || fromBalanceBefore < amount || fromVotingPowerBefore < amount
assert e.msg.sender == 0x0 || fromBalanceBefore < amount || fromVotingPowerBefore < amount
|| e.msg.sender != currentContract.bridge;
} else {
// updates balance and totalSupply
Expand Down

0 comments on commit 1ee1291

Please sign in to comment.