Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code4rena deploy #139

Merged
merged 114 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
5f9b435
c4-001 Wrong decimal conversion in liquidation protocol split
aviggiano Jul 3, 2024
2fbe578
c4-002 Wrong crLiquidation cap in overdue liquidation
aviggiano Jul 3, 2024
554ed8f
c4-003 Wrong fragmentationFee check in Compensate means it is never c…
aviggiano Jul 3, 2024
2575e9f
c4-tests (#121)
aviggiano Jul 3, 2024
e590625
Add Spearbit audit
aviggiano Jul 3, 2024
04c865c
c4-004 Chainlink heartbeats are different on Base and Ethereum mainnet
aviggiano Jul 3, 2024
bf49b8b
Remove old code
aviggiano Jul 3, 2024
ea65c6d
Add updated scripts
aviggiano Jul 3, 2024
831233e
c4-005 Users below crOpening cannot withdraw cash
aviggiano Jul 3, 2024
dbb4410
c4-006 DoS in market orders due to incorrect params.amount comparison…
aviggiano Jul 3, 2024
5d91267
c4-007 Supply caps can be bypassed due to incorrect balanceOf
aviggiano Jul 3, 2024
978f258
c4-008 Variable Pool liquidity check should validate balance of aToke…
aviggiano Jul 3, 2024
148e726
c4-009 Variable Pool liquidity check can be bypassed with a sandwitch…
aviggiano Jul 3, 2024
807880b
c4-010 Compensate is prevented if user is underwater
aviggiano Jul 3, 2024
0666e7e
Add missing import
aviggiano Jul 3, 2024
b78cbc0
c4-011 Compensate ignores forSale after credit split
aviggiano Jul 3, 2024
928bea4
forge fmt
aviggiano Jul 3, 2024
3fb7236
c4-012 getCreditPositionProRataAssignedCollateral can be simplified t…
aviggiano Jul 3, 2024
675bb69
c4-013 Liquidate does not have deadline protection
aviggiano Jul 3, 2024
65636ba
Add deadline from Liquidate to tests
aviggiano Jul 3, 2024
86184b6
c4-014 BuyCreditMarket returns incorrect value for liquidity check
aviggiano Jul 3, 2024
a870159
c-015 SelfLiquidation check can be simplified
aviggiano Jul 3, 2024
dc1fad6
Remove unused error
aviggiano Jul 3, 2024
5cadd4f
c4-016 Documentation fixes
aviggiano Jul 3, 2024
fa055b4
Remove old code
aviggiano Jul 3, 2024
c215a6a
c4-017 BorrowOffers do not have a maxDueDate
aviggiano Jul 3, 2024
f90fae4
c4-018 Wrong fee calculation in SellCreditMarket + exactAmountOut
aviggiano Jul 4, 2024
7b3426a
Minor documentation/error fixes
aviggiano Jul 4, 2024
3ba0e3c
c4-019 Refactor fee calculation in AccountingLibrary.getCashAmountOut
aviggiano Jul 4, 2024
b9c6973
Improve docs for swap fee
aviggiano Jul 4, 2024
8f0a021
Add base and mainnet parameters
aviggiano Jul 4, 2024
ab8f158
Add base sequencer uptime
aviggiano Jul 4, 2024
d21f018
Merge branch 'c4-001' into code4rena-deploy
aviggiano Jul 5, 2024
ae55c36
Merge branch 'c4-002' into code4rena-deploy
aviggiano Jul 5, 2024
75d8e52
Merge branch 'c4-003' into code4rena-deploy
aviggiano Jul 5, 2024
5db5078
Merge branch 'c4-004' into code4rena-deploy
aviggiano Jul 5, 2024
fef1eb4
Merge branch 'c4-005' into code4rena-deploy
aviggiano Jul 5, 2024
1077044
Merge branch 'c4-006' into code4rena-deploy
aviggiano Jul 5, 2024
78ba5f2
Merge branch 'c4-007' into code4rena-deploy
aviggiano Jul 5, 2024
9868803
Merge branch 'c4-008' into code4rena-deploy
aviggiano Jul 5, 2024
388f0aa
Merge branch 'c4-009' into code4rena-deploy
aviggiano Jul 5, 2024
3f70f1d
Merge branch 'c4-010' into code4rena-deploy
aviggiano Jul 5, 2024
0a085fc
Merge branch 'c4-011' into code4rena-deploy
aviggiano Jul 5, 2024
c6f67c4
Merge branch 'c4-012' into code4rena-deploy
aviggiano Jul 5, 2024
f7b945f
Merge branch 'c4-013' into code4rena-deploy
aviggiano Jul 5, 2024
f1f692c
Merge branch 'c4-014' into code4rena-deploy
aviggiano Jul 5, 2024
6de9a28
Merge branch 'c4-015' into code4rena-deploy
aviggiano Jul 5, 2024
34ce900
Merge branch 'c4-016' into code4rena-deploy
aviggiano Jul 5, 2024
223294c
Merge branch 'c4-017' into code4rena-deploy
aviggiano Jul 5, 2024
8d928c5
Merge branch 'c4-018' into code4rena-deploy
aviggiano Jul 5, 2024
92ba77b
Merge branch 'c4-019' into code4rena-deploy
aviggiano Jul 5, 2024
ac05f7a
Update tests with latest changes
aviggiano Jul 5, 2024
5bb8df5
Merge branch 'code4rena-audit-fixes' into code4rena-deploy
aviggiano Jul 5, 2024
043b734
Deploy to sepolia
aviggiano Jul 5, 2024
0597b2a
Update workflow to publish ABI on PRs
aviggiano Jul 5, 2024
fcf2c76
Minor fix ExpectedErrors
aviggiano Jul 5, 2024
4440e81
Minor change in GrantRole script
aviggiano Jul 5, 2024
f789da9
Grant roles
aviggiano Jul 5, 2024
8c4728c
Add Deploy tests back
aviggiano Jul 5, 2024
c641488
Move Setup to its own contract
aviggiano Jul 5, 2024
4c921fd
Add onchain fuzzing with foundry
aviggiano Jul 5, 2024
c4111b1
Add onchain properties
aviggiano Jul 8, 2024
24862bb
Fix property_UNDERWATER
aviggiano Jul 8, 2024
dc923a9
Update test
aviggiano Jul 8, 2024
e62cb1a
Chainlink sequencer feed returns startedAt 0 if down
aviggiano Jul 8, 2024
052e712
Merge branch 'c4-020' into code4rena-deploy
aviggiano Jul 8, 2024
58e64cd
Remove params.amount > credit comparison
aviggiano Jul 8, 2024
40d24b2
Merge branch 'c4-006' into code4rena-deploy
aviggiano Jul 8, 2024
bf64565
Fix property
aviggiano Jul 8, 2024
0efa457
Update LIQUIDATE_01 for self liquidation
aviggiano Jul 9, 2024
1f61c78
Add one more test
aviggiano Jul 9, 2024
f08695f
c4-021 Add borrower to RepayStruct to avoid MEV
aviggiano Jul 9, 2024
3524e53
Merge branch 'c4-021' into code4rena-deploy
aviggiano Jul 9, 2024
01f0697
Fix typo
aviggiano Jul 9, 2024
e62e820
Update tests
aviggiano Jul 9, 2024
e749e70
Merge branch 'code4rena-audit-fixes' into code4rena-deploy
aviggiano Jul 9, 2024
20d87fc
Merge branch 'c4-021' into code4rena-deploy
aviggiano Jul 9, 2024
0b2366a
Add base-sepolia
aviggiano Jul 9, 2024
bc50f7d
Update README
aviggiano Jul 9, 2024
6d9a33e
Update deployment scripts
aviggiano Jul 9, 2024
1c16b0e
Fix deploy scripts
aviggiano Jul 9, 2024
5ac5311
Deploy to Base sepolia
aviggiano Jul 9, 2024
6a06661
Update getCommitHash
aviggiano Jul 10, 2024
715c91b
Add maxDueDate to LiquidateWithReplacement
aviggiano Jul 10, 2024
10832ba
Merge branch 'c4-017' into code4rena-deploy
aviggiano Jul 10, 2024
58d7876
Fix test_LiquidateWithReplacement_validation test
aviggiano Jul 10, 2024
8ed52a5
Merge branch 'code4rena-audit-fixes' into code4rena-deploy
aviggiano Jul 10, 2024
1cc4b03
Upgrade script
aviggiano Jul 10, 2024
97b6673
Upgrade script
aviggiano Jul 10, 2024
ba90b0c
Upgrade script
aviggiano Jul 10, 2024
537da1f
Create validateLimitOrder function
aviggiano Jul 11, 2024
1d411d4
Merge branch 'c4-017' into code4rena-deploy
aviggiano Jul 11, 2024
21708c7
pure -> view
aviggiano Jul 11, 2024
7c66206
Merge branch 'c4-017' into code4rena-deploy
aviggiano Jul 11, 2024
8178fde
Fix docs
aviggiano Jul 11, 2024
04f4c95
Validate WETH
aviggiano Jul 11, 2024
e92524b
Merge branch 'c4-019' into code4rena-deploy
aviggiano Jul 11, 2024
940211f
Upgrade contract with latest commits
aviggiano Jul 11, 2024
d69e05f
Add SHOULD_UPGRADE to Upgrade.s.sol script
aviggiano Jul 11, 2024
74b64ae
GrantRole PAUSER_ROLE to testnet multisig
aviggiano Jul 11, 2024
4afde0c
Update Repay.s.sol script
aviggiano Jul 12, 2024
775fb36
Fix tests
aviggiano Jul 12, 2024
c383bfd
Add more tests
aviggiano Jul 12, 2024
77f9820
Fix invariant tests
aviggiano Jul 15, 2024
d496889
Code4rena Tests/Scripts Updates (#122)
aviggiano Jul 15, 2024
6b8b6de
Update CI
aviggiano Jul 15, 2024
c3d2308
Fix CI test names
aviggiano Jul 15, 2024
67d8ad1
Update CI names
aviggiano Jul 15, 2024
d3a0338
Update CI
aviggiano Jul 15, 2024
578d4a9
Update CI
aviggiano Jul 15, 2024
1beba09
Change fragmentation fee to 1 USDC
aviggiano Jul 15, 2024
51199c1
Update foundry.toml
aviggiano Jul 15, 2024
86432cd
Deploy to Base
aviggiano Jul 15, 2024
0ed16e4
Base deployment
aviggiano Jul 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .env-example

This file was deleted.

129 changes: 102 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ concurrency:
cancel-in-progress: true

jobs:
test:
sizes:
strategy:
fail-fast: true

name: Foundry
name: Contract sizes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -28,23 +28,79 @@ jobs:
with:
version: nightly

- name: Format
run: |
forge fmt --check
id: fmt

- name: Contract sizes
run: |
forge --version
forge build --sizes --skip CryticTester
id: build

fmt:
strategy:
fail-fast: true

name: Forge Fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Format
run: |
forge fmt --check
id: fmt

test:
strategy:
fail-fast: true

name: Forge Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Test
run: |
forge test -vvv
id: test

testFork:
strategy:
fail-fast: true

name: Forge Fork Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Test Fork
run: |
forge test -vvv
id: test
env:
API_KEY_INFURA: ${{ secrets.API_KEY_INFURA }}
API_KEY_INFURA: ${{ secrets.API_KEY_INFURA }}
FOUNDRY_INVARIANT_RUNS: 0
FOUNDRY_INVARIANT_DEPTH: 0
FOUNDRY_PROFILE: fork

slither:
strategy:
Expand Down Expand Up @@ -87,8 +143,9 @@ jobs:
run: npm run solhint

invariants:
needs: [test, slither, solhint]
needs: [sizes, fmt, test, testFork, slither, solhint]
strategy:
fail-fast: true
matrix:
mode: [assertion, property]

Expand Down Expand Up @@ -124,13 +181,12 @@ jobs:
./script/prepare_crytic.sh
./echidna . --contract CryticTester --config echidna.yaml --test-mode ${{ matrix.mode }} --corpus-dir corpus --test-limit 10000

abi-coverage:
abi:
strategy:
fail-fast: true

name: ABI/Coverage
name: ABI
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -144,35 +200,54 @@ jobs:
- name: Install dependencies
run: npm install

- name: Setup git config
run: |
git config --local user.email "dev@size.cash"
git config --local user.name "Size"

- name: Coverage
run: |
./script/update_readme_coverage.sh
git add README.md
git commit -m "Update coverage [skip ci]" || true

- name: ABI
run: |
forge build --build-info

- name: Archive production artifacts
- name: Archive ABI
uses: actions/upload-artifact@v4
with:
name: abi
path: |
out/Size.sol/Size.json
out/PriceFeed.sol/PriceFeed.json
out/VariablePoolBorrowRateFeed.sol/VariablePoolBorrowRateFeed.json
out/PoolMock.sol/PoolMock.json
out/IPriceFeed.sol/IPriceFeed.json
out/IPool.sol/IPool.json
out/WETH.sol/WETH.json
out/USDC.sol/USDC.json
out/Errors.sol/Errors.json
out/Events.sol/Events.json

coverage:
strategy:
fail-fast: true

name: Coverage
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install dependencies
run: npm install

- name: Setup git config
run: |
git config --local user.email "dev@size.cash"
git config --local user.name "Size"

- name: Coverage
run: |
./script/update_readme_coverage.sh
git add README.md
git commit -m "Update coverage [skip ci]" || true

- name: Push
run: |
git push https://${{ env.token }}@github.com/${{ github.event.repository.full_name }}.git
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ out/
# Docs
docs/

# Dotenv file
.env
# Dotenv files
.env*

# plots
plots/*.csv
Expand Down
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ Supported pair:
Target networks:

- Ethereum mainnet
- Base
- [Base](./deployments/8453.json)

## Audits

- [2024-03-19 - LightChaserV3](./audits/2024-03-19-LightChaserV3.md)
- [2024-06-10 - Code4rena (WIP)](https://code4rena.com/reports/2024-06-size)
- [2024-06-08 - Spearbit](./audits/2024-06-08-Spearbit.pdf)
- [2024-03-26 - Solidified](./audits/2024-03-26-Solidified.pdf)
- [2024-05-30 - Spearbit (draft)](./audits/2024-05-30-Spearbit-draft.pdf)
- [2024-03-19 - LightChaserV3](./audits/2024-03-19-LightChaserV3.md)

For bug reports, please refer to our [Bug Bounty Program](https://size.credit/)

## Documentation

Expand Down Expand Up @@ -175,6 +178,13 @@ yarn echidna-property
yarn echidna-assertion
```

### Onchain fuzzing

```bash
source .env
FOUNDRY_PROFILE=fork FOUNDRY_INVARIANT_RUNS=0 FOUNDRY_INVARIANT_DEPTH=0 forge test --mc FoundryForkTester -vvvvv --ffi
```

Check the coverage report with

```bash
Expand Down Expand Up @@ -215,6 +225,20 @@ for i in {0..5}; do halmos --loop $i; done
## Deployment

```bash
source .env
CHAIN_NAME=$CHAIN_NAME DEPLOYER_ADDRESS=$DEPLOYER_ADDRESS yarn deploy-sepolia-mocks --broadcast
source .env.base_sepolia
forge script script/Deploy.s.sol --rpc-url $RPC_URL --gas-limit 30000000 --sender $DEPLOYER_ADDRESS --account $DEPLOYER_ACCOUNT --ffi --verify
```

### Deployment checklist

1. Deploy
2. Grant `KEEPER_ROLE` to keeper bot
3. Grant `BORROW_RATE_UPDATER_ROLE` to updater bot
4. Grant `PAUSER_ROLE` to pauser bot

## Upgrade

```bash
source .env.sepolia
forge script script/Upgrade.s.sol --rpc-url $RPC_URL --gas-limit 30000000 --sender $DEPLOYER_ADDRESS --account $DEPLOYER_ACCOUNT --ffi --verify
```
Binary file not shown.
Loading
Loading