Skip to content

Commit a2b2869

Browse files
committed
.
1 parent f8d0d23 commit a2b2869

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

DEFI/ConstantProductPool/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Refer to `certora/conf/runBroken.conf` and `certora/conf/runFixed.conf` for more
2828
To check this version, run:
2929
```certoraRun runBroken.conf```
3030

31-
[The report of the run](https://prover.certora.com/output/15800/fa11484d63054f79a199c8620af33bdb?anonymousKey=1cdcdf2c4cf2cd17157ecb1290dc726e15ba8de4)
31+
[The report of the run](https://prover.certora.com/output/15800/2987524d197447f4944e13ed519390f9?anonymousKey=d09bc4f46c5bab5a51296938fbffeb9fcac03252)
3232

3333
## Correct Code
3434

@@ -37,4 +37,4 @@ To check this version, run:
3737
This contract can be verified by running:
3838
```certoraRun runFixed.conf```
3939

40-
[The report of the run](https://prover.certora.com/output/15800/1fe898be7fc242909c043bac5b8c67e7?anonymousKey=ca1719a1a7ee64b224160d5ebf0b02fa69b20e28)
40+
[The report of the run](https://prover.certora.com/output/15800/b1ed0c02f9d0409fbaed4485f5b23a56?anonymousKey=a48319976eedda3ebf0e7c3eabe1ead2e02c809f)

DEFI/ConstantProductPool/certora/spec/ConstantProductPool.spec

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ See https://docs.certora.com for a complete guide.
66
// reference from the spec to additional contracts used in the verification
77
using DummyERC20A as _token0;
88
using DummyERC20B as _token1;
9+
using ConstantProductPool as _pool;
910

1011

1112
/*
@@ -25,6 +26,8 @@ methods{
2526
//calls to external contracts
2627
function _token0.balanceOf(address account) external returns (uint256) envfree;
2728
function _token1.balanceOf(address account) external returns (uint256) envfree;
29+
function _token0.allowance(address owner, address spender) external returns (uint256) envfree;
30+
function _token1.allowance(address owner, address spender) external returns (uint256) envfree;
2831
function _token0.transfer(address, uint) external;
2932
function _token1.transfer(address, uint) external;
3033

@@ -127,17 +130,32 @@ invariant balanceGreaterThanReserve()
127130

128131
// This preserved is safe because transferFrom is called from the currentContract whose code is known and
129132
// it is not msg.sender. It would not be safe to do if the call was to a function of an unresolved contract.
130-
preserved transferFrom(address sender, address recipient,uint256 amount) with (env e1) {
133+
preserved _.transferFrom(address sender, address recipient,uint256 amount) with (env e1) {
134+
requireInvariant allowanceOfPoolAlwaysZero(e1.msg.sender);
131135
require e1.msg.sender != currentContract;
132136
}
133137

134-
// This preserved is safe because transfer is called from the currentContract whose code is known and
138+
// This preserved is safe because transfer is called from the currentContract whose code is known and
135139
// it is not msg.sender.
136-
preserved transfer(address recipient, uint256 amount) with (env e2) {
140+
preserved _.transfer(address recipient, uint256 amount) with (env e2) {
137141
require e2.msg.sender != currentContract;
138142
}
139143
}
140144

145+
invariant allowanceOfPoolAlwaysZero(address a)
146+
_token0.allowance(_pool, a) == 0 && _token1.allowance(_pool, a) == 0
147+
{
148+
// This preserved is safe because we know the code in the pool contract.
149+
preserved _.approve(address spender, uint256 amount) with (env e1) {
150+
require e1.msg.sender != _pool;
151+
}
152+
153+
// This preserved is safe because we know the code in the pool contract.
154+
preserved _.increaseAllowance(address spender, uint256 addedValue) with (env e2) {
155+
require e2.msg.sender != _pool;
156+
}
157+
}
158+
141159

142160
/*
143161
Property: Integrity of totalSupply with respect to the amount of reserves.

0 commit comments

Comments
 (0)