|
| 1 | +/* |
| 2 | + This is a Specification File for Smart Contract Verification with the Certora Prover. |
| 3 | + Contract name: UpgradeableLockReleaseTokenPool |
| 4 | +*/ |
| 5 | + |
| 6 | +using SimpleERC20 as erc20; |
| 7 | + |
| 8 | +methods { |
| 9 | + function getCurrentBridgedAmount() external returns (uint256) envfree; |
| 10 | + function getBridgeLimit() external returns (uint256) envfree; |
| 11 | + function owner() external returns (address) envfree; |
| 12 | +} |
| 13 | + |
| 14 | + |
| 15 | +rule sanity { |
| 16 | + env e; |
| 17 | + calldataarg arg; |
| 18 | + method f; |
| 19 | + f(e, arg); |
| 20 | + satisfy true; |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +/* ============================================================================== |
| 26 | + invariant: currentBridge_LEQ_bridgeLimit. |
| 27 | + Description: The value of s_currentBridged is LEQ than the value of s_bridgeLimit. |
| 28 | + Note: this may be violated if one calls to setBridgeLimit(newBridgeLimit) with |
| 29 | + newBridgeLimit < s_currentBridged. |
| 30 | + ============================================================================*/ |
| 31 | +invariant currentBridge_LEQ_bridgeLimit() |
| 32 | + getCurrentBridgedAmount() <= getBridgeLimit() |
| 33 | + filtered { f -> |
| 34 | + !f.isView && |
| 35 | + f.selector != sig:setBridgeLimit(uint256).selector && |
| 36 | + f.selector != sig:setCurrentBridgedAmount(uint256).selector} |
| 37 | + { |
| 38 | + preserved initialize(address owner, address[] allowlist, address router, uint256 bridgeLimit) with (env e2) { |
| 39 | + require getCurrentBridgedAmount()==0; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | +/* ============================================================================== |
| 45 | + rule: withdrawLiquidity_correctness |
| 46 | + description: The rule checks that the balance of the contract is as expected. |
| 47 | + ============================================================================*/ |
| 48 | +rule withdrawLiquidity_correctness(env e) { |
| 49 | + uint256 amount; |
| 50 | + |
| 51 | + require e.msg.sender != currentContract; |
| 52 | + uint256 bal_before = erc20.balanceOf(e, currentContract); |
| 53 | + withdrawLiquidity(e, amount); |
| 54 | + uint256 bal_after = erc20.balanceOf(e, currentContract); |
| 55 | + |
| 56 | + assert (to_mathint(bal_after) == bal_before - amount); |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | +/* ============================================================================== |
| 61 | + rule: provideLiquidity_correctness |
| 62 | + description: The rule checks that the balance of the contract is as expected. |
| 63 | + ============================================================================*/ |
| 64 | +rule provideLiquidity_correctness(env e) { |
| 65 | + uint256 amount; |
| 66 | + |
| 67 | + require e.msg.sender != currentContract; |
| 68 | + uint256 bal_before = erc20.balanceOf(e, currentContract); |
| 69 | + provideLiquidity(e, amount); |
| 70 | + uint256 bal_after = erc20.balanceOf(e, currentContract); |
| 71 | + |
| 72 | + assert (to_mathint(bal_after) == bal_before + amount); |
| 73 | +} |
| 74 | + |
| 75 | +definition filterSetter(method f) returns bool = f.selector != sig:setCurrentBridgedAmount(uint256).selector; |
| 76 | + |
| 77 | +/* ============================================================================== |
| 78 | + rule: only_lockOrBurn_can_increase_currentBridged |
| 79 | + ============================================================================*/ |
| 80 | +rule only_lockOrBurn_can_increase_currentBridged(env e, method f) |
| 81 | + filtered { f -> filterSetter(f) } |
| 82 | +{ |
| 83 | + calldataarg args; |
| 84 | + |
| 85 | + uint256 curr_bridge_before = getCurrentBridgedAmount(); |
| 86 | + f (e,args); |
| 87 | + uint256 curr_bridge_after = getCurrentBridgedAmount(); |
| 88 | + |
| 89 | + assert |
| 90 | + curr_bridge_after > curr_bridge_before => |
| 91 | + f.selector==sig:lockOrBurn(Pool.LockOrBurnInV1).selector; |
| 92 | +} |
| 93 | + |
| 94 | + |
| 95 | +/* ============================================================================== |
| 96 | + rule: only_releaseOrMint_currentBridged |
| 97 | + ============================================================================*/ |
| 98 | +rule only_releaseOrMint_currentBridged(env e, method f) |
| 99 | + filtered { f -> filterSetter(f) } |
| 100 | +{ |
| 101 | + calldataarg args; |
| 102 | + |
| 103 | + uint256 curr_bridge_before = getCurrentBridgedAmount(); |
| 104 | + f (e,args); |
| 105 | + uint256 curr_bridge_after = getCurrentBridgedAmount(); |
| 106 | + |
| 107 | + assert |
| 108 | + curr_bridge_after < curr_bridge_before => |
| 109 | + f.selector==sig:releaseOrMint(Pool.ReleaseOrMintInV1).selector; |
| 110 | +} |
| 111 | + |
| 112 | + |
| 113 | +/* ============================================================================== |
| 114 | + rule: only_bridgeLimitAdmin_or_owner_can_call_setBridgeLimit |
| 115 | + ============================================================================*/ |
| 116 | +rule only_bridgeLimitAdmin_or_owner_can_call_setBridgeLimit(env e) { |
| 117 | + uint256 newBridgeLimit; |
| 118 | + |
| 119 | + setBridgeLimit(e, newBridgeLimit); |
| 120 | + |
| 121 | + assert e.msg.sender==getBridgeLimitAdmin(e) || e.msg.sender==owner(); |
| 122 | +} |
| 123 | + |
| 124 | +/* ============================================================================== |
| 125 | + rule: only_owner_can_call_setCurrentBridgedAmount |
| 126 | + ============================================================================*/ |
| 127 | +rule only_owner_can_call_setCurrentBridgedAmount(env e) { |
| 128 | + uint256 newBridgedAmount; |
| 129 | + |
| 130 | + setCurrentBridgedAmount(e, newBridgedAmount); |
| 131 | + |
| 132 | + assert e.msg.sender==owner(); |
| 133 | +} |
0 commit comments