ERC1155Burnable.spec 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. methods {
  2. balanceOf(address, uint256) returns uint256 envfree
  3. isApprovedForAll(address,address) returns bool envfree
  4. }
  5. /// If a method call reduces account balances, the caller must be either the
  6. /// holder of the account or approved to act on the holder's behalf.
  7. rule onlyHolderOrApprovedCanReduceBalance {
  8. address holder; uint256 token; uint256 amount;
  9. uint256 balanceBefore = balanceOf(holder, token);
  10. method f; env e; calldataarg args;
  11. f(e, args);
  12. uint256 balanceAfter = balanceOf(holder, token);
  13. assert balanceAfter < balanceBefore => e.msg.sender == holder || isApprovedForAll(holder, e.msg.sender),
  14. "An account balance may only be reduced by the holder or a holder-approved agent";
  15. }
  16. /// Burning a larger amount of a token must reduce that token's balance more
  17. /// than burning a smaller amount.
  18. rule burnAmountProportionalToBalanceReduction {
  19. storage beforeBurn = lastStorage;
  20. env e;
  21. address holder; uint256 token;
  22. mathint startingBalance = balanceOf(holder, token); // 10
  23. uint256 smallBurn; uint256 largeBurn; // 4, 7
  24. require smallBurn < largeBurn;
  25. // smaller burn amount
  26. burn(e, holder, token, smallBurn) at beforeBurn;
  27. mathint smallBurnBalanceChange = startingBalance - balanceOf(holder, token); // 4
  28. // larger burn amount
  29. burn(e, holder, token, largeBurn) at beforeBurn;
  30. mathint largeBurnBalanceChange = startingBalance - balanceOf(holder, token); // 7
  31. assert smallBurnBalanceChange < largeBurnBalanceChange,
  32. "A larger burn must lead to a larger decrease in balance";
  33. }
  34. /// This rule should always fail.
  35. rule sanity {
  36. method f; env e; calldataarg args;
  37. f(e, args);
  38. assert false,
  39. "This rule should always fail";
  40. }