Skip to content

Commit

Permalink
doc and test: fuzzing VoteWeighting
Browse files Browse the repository at this point in the history
  • Loading branch information
AL committed Apr 17, 2024
1 parent 39af7cd commit b7bea8d
Show file tree
Hide file tree
Showing 11 changed files with 4,785 additions and 0 deletions.
18 changes: 18 additions & 0 deletions audits/internal11/fuzzing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Fuzzing VoteWeighting

## Prepare contracts for fuzzing
contracts/test/VoteWeightingFuzzing.sol <br>
contracts/test/EchidnaVoteWeightingAssert.sol <br>

## Fuzzing
```sh
# Move the script to the root of the project
cp start_echidna.sh ../../../
# Move config file to the root of the project
cp echidna_assert.yaml ../../../
cd ../../../
# Run
./start_echidna.sh
```
result overflow: [fuzzing-overflow.PNG](fuzzing-overflow.PNG) <br>
result assert: [fuzzing-assert.PNG](fuzzing-assert.PNG)
2,072 changes: 2,072 additions & 0 deletions audits/internal11/fuzzing/corpusEchidna/covered.1713373564.html

Large diffs are not rendered by default.

2,073 changes: 2,073 additions & 0 deletions audits/internal11/fuzzing/corpusEchidna/covered.1713373572.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions audits/internal11/fuzzing/crytic-export/combined_solc.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions audits/internal11/fuzzing/echidna_assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#testMode: overflow
testMode: assertion
coverage: true
corpusDir: corpusEchidna
coverageFormats: ["html"]
# maxBlockDelay: 12
# provide solc remappings to crytic-compile
# https://www.justinsilver.com/technology/programming/slither-echidna-remappings/
cryticArgs: ['--solc-remaps', '@=node_modules/@']

10 changes: 10 additions & 0 deletions audits/internal11/fuzzing/echidna_overflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
testMode: overflow
#testMode: assertion
coverage: true
corpusDir: corpusEchidna
coverageFormats: ["html"]
# maxBlockDelay: 12
# provide solc remappings to crytic-compile
# https://www.justinsilver.com/technology/programming/slither-echidna-remappings/
cryticArgs: ['--solc-remaps', '@=node_modules/@']

Binary file added audits/internal11/fuzzing/fuzzing-assert.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added audits/internal11/fuzzing/fuzzing-overflow.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions audits/internal11/fuzzing/start_echidna.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

rm -rf corpusEchidna/
echidna contracts/test/EchidnaVoteWeightingAssert.sol --contract EchidnaVoteWeightingAssert --config echidna_assert.yaml
74 changes: 74 additions & 0 deletions contracts/test/EchidnaVoteWeightingAssert.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "../OLAS.sol";
import "../veOLAS.sol";
import "./VoteWeightingFuzzing.sol";


contract EchidnaVoteWeightingAssert {
OLAS olas;
veOLAS ve;
VoteWeightingFuzzing vw;
uint160 constant FAKE_OLAS = 7;

uint256 constant oneOLASBalance = 1 ether;
uint256 constant fourYear = 4 * 365 * 86400;
uint256 constant oneYear = 1 * 365 * 86400;
uint256 constant maxVoteWeight = 10000;
uint64 constant WEEK = 1 weeks;
uint256 constant oneOLAS = 1 ether;
uint256 constant oneMLN = 1_000_000;
uint256 ts;

// msg.sender in Echidna
address[3] private senders = [ address(0x10000), address(0x20000), address(0x30000) ];

constructor() payable {
olas = new OLAS();
address aolas = address(olas);
ve = new veOLAS(aolas, "Voting Escrow OLAS", "veOLAS");
address ave = address(ve);
vw = new VoteWeightingFuzzing(ave);
olas.mint(address(this),oneOLAS*oneMLN);
}

// voteForNomineeWeights_assert(0xdeadbeef,1,0,4495678220902361,1124857)
function voteForNomineeWeights_assert(address nominee, uint32 chainId, uint16 weight, uint256 amount, uint32 unlockTime) external {
require(block.timestamp > 0);
require(block.timestamp > ts);
require(unlockTime < fourYear);
require(weight < maxVoteWeight);
require(amount < 100 * oneOLAS);
uint256 balanceOf = olas.balanceOf(address(this));
assert(balanceOf > amount);
(uint128 initialAmount,) = ve.mapLockedBalances(address(this));
if (initialAmount == 0) {
olas.approve(address(ve), amount);
ve.createLock(amount, unlockTime);
(uint128 lockedAmount,) = ve.mapLockedBalances(address(this));
assert(lockedAmount > 0);
} else {
(uint128 lockedAmount,) = ve.mapLockedBalances(address(this));
assert(lockedAmount > 0);
}
vw.addNominee(nominee, chainId);
uint256 id = vw.getNomineeId(nominee, chainId);
uint256 num = vw.getNumNominees();
assert(id > 0);
assert(num > 0);
vw.setCallVoteForNomineeWeights(false);
bool beforeAfterCall = vw.callVoteForNomineeWeights();
assert(beforeAfterCall == false);
vw.voteForNomineeWeights(nominee, chainId, weight);
bool stateAfterCall = vw.callVoteForNomineeWeights();
if(stateAfterCall == true) {
uint256 lts = vw.getlastUserVote(nominee,chainId);
assert(lts > 0);
}
ts = block.timestamp; // next timestamp > timestamp
vw.checkpointNominee(nominee, chainId);
}

}

Loading

0 comments on commit b7bea8d

Please sign in to comment.