Skip to content

Commit

Permalink
Merge branch 'dev' into feature-trusted-macros
Browse files Browse the repository at this point in the history
  • Loading branch information
d10r authored Feb 12, 2024
2 parents 7e9a023 + d3d602f commit 93c778c
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 217 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/call.test-hot-fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ jobs:
- name: Run tests
run: |
cd packages/hot-fuzz
echo "testLimit: 1000" >> echidna.yaml
./hot-fuzz contracts/superfluid-tests/SuperHotFuzz.yaml
env:
ECHIDNA_TEST_LIMIT: 10000
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ package-lock.json
.DS_Store
.idea


.vscode/
*-workspace
.npmrc

# echidna litters
crytic-export
corpus
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
shellcheck
# used by some scripts
jq
yq
# test utilities
lcov
actionlint
Expand Down
1 change: 1 addition & 0 deletions packages/hot-fuzz/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/crytic-export
/artifacts
/packages
/echidna.yaml
19 changes: 5 additions & 14 deletions packages/hot-fuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,14 @@ yarn add --dev 'https://gitpkg.now.sh/api/pkg?url=superfluid-finance/protocol-mo
> - https://github.com/yarnpkg/yarn/issues/4725
> - https://gitpkg.vercel.app/
Also make sure the dependency `@superfluid-finance/ethereum-contracts` is at least version 1.2.2.
Also make sure the dependency `@superfluid-finance/ethereum-contracts` is from the latest dev branch, since it is still
under active development.

3. Extend your `truffle-config.js`
3. Make sure you use foundry and configure it properly:

It is required to link external libraries correctly during the testing. The workaround is provided, all you need to do
is to slightly change your `truffle-config.js`:
(TODO.)

```js
const M = (module.exports = {
// networks, compilers, ...
}
require("@superfluid-finance/hot-fuzz").hotfuzzPatchTruffleConfig(M);
```
> :warning: hardhat-config support is currently missing, pull request appreciated!
>
> Note that there is no harm just to create a minimal truffle-config.js in your project if that helps for now!
> :warning: there is no truffle or hardhat support at the moment
:star: Congrats! Now you should be all set!

Expand Down
2 changes: 1 addition & 1 deletion packages/hot-fuzz/contracts/HotFuzzBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract HotFuzzBase {
uint private constant INIT_SUPER_TOKEN_BALANCE = type(uint128).max;

// immutables
SuperfluidFrameworkDeployer private immutable _sfDeployer;
SuperfluidFrameworkDeployer internal immutable _sfDeployer;
TestToken internal immutable token;
SuperToken internal immutable superToken;
uint internal immutable nTesters;
Expand Down
36 changes: 0 additions & 36 deletions packages/hot-fuzz/echidna.yaml

This file was deleted.

119 changes: 76 additions & 43 deletions packages/hot-fuzz/hot-fuzz
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,113 @@

# In all seriousness, this script should be written in perl. To the dearest leader Tim Toady.

D="$(dirname "$0")"
L="$(readlink "$0")" # do not use -f since mac BSD coreutils does not like it

ECHIDNA=${ECHIDNA:-echidna}
HOTFUZZ_DIR=$D/"$(dirname "$L")"
HOTFUZZ_DIR="$(readlink -f "$(dirname "$0")")"
set -xe

function apply_crytic_workaround() {
# SEE https://github.com/crytic/echidna/issues/738
[ -e "node_modules" ] || mkdir -p node_modules
ln -sf ../../../node_modules/\@superfluid-finance node_modules/
ln -sf ../../../node_modules/\@openzeppelin node_modules/
ln -sf ../../packages .
}

function cleanup_crytic_workaround() {
rm -f "node_modules/@superfluid-finance" || true
rm -f "node_modules/@openzeppelin" || true
rm -f packages || true
}

function digest_last_corpus() {
sleep 2 # wait for corpus dumped, just in case
$HOTFUZZ_DIR/tasks/digest-corpus $(ls corpus/covered.*.txt | tail -n1)
}

function digests() {
digest_last_corpus
}
trap digests SIGINT

function cleanup() {
cleanup_crytic_workaround
}
trap cleanup EXIT
# trap cleanup EXIT

function oops() {
echo "$@" >&2
exit 1
}

# TODO: have a commandline option
mode=${HOT_FUZZ_MODE:-truffle}
DIGESTED=
function digest_last_corpus() {
sleep 2 # wait for corpus dumped, just in case
"$HOTFUZZ_DIR"/scripts/digest-corpus "$(find "$PROJECT_DIR"/corpus -name "covered.*.txt" | tail -n1)"
}

function build_echidna_yaml() {
# to generate --compile-libraries
# $ (j=$((0xf01));tasks/list-all-linked-libraries.sh | while read i;do echo -n "($i,$(printf "0x%x" "$j")),";j=$((j+1));done)
# to generate deployContracts
# $ (j=$((0xf01));tasks/list-all-linked-libraries.sh | while read i;do echo "[\"$(printf "0x%x" "$j")\", \"$i\"],";j=$((j+1));done)

echo "# This file is auto-generated"

echo "# Taken from $TEST_CONTRACT_CONFIG"
cat "$TEST_CONTRACT_CONFIG"

echo "# Generated by build_echidna_yaml"
cat <<EOF
# format: "json"
testLimit: ${ECHIDNA_TEST_LIMIT:-50000}
corpusDir: "${PROJECT_DIR}/corpus"
cryticArgs: [
"--compile-force-framework=${CRYTIC_COMPILE_FRAMEWORK}",
"--foundry-out-directory=${FOUNDRY_ROOT}/${FOUNDRY_OUT:-out}",
# "--export-dir=${PROJECT_DIR}/crytic-export", TODO unfortunately this doesn't work
"--compile-libraries=(CFAv1ForwarderDeployerLibrary,0xf01),(GDAv1ForwarderDeployerLibrary,0xf02),(IDAv1ForwarderDeployerLibrary,0xf03),(ProxyDeployerLibrary,0xf04),(SlotsBitmapLibrary,0xf05),(SuperfluidCFAv1DeployerLibrary,0xf06),(SuperfluidFlowNFTLogicDeployerLibrary,0xf07),(SuperfluidGDAv1DeployerLibrary,0xf08),(SuperfluidGovDeployerLibrary,0xf09),(SuperfluidHostDeployerLibrary,0xf0a),(SuperfluidIDAv1DeployerLibrary,0xf0b),(SuperfluidPeripheryDeployerLibrary,0xf0c),(SuperfluidPoolDeployerLibrary,0xf0d),(SuperfluidPoolLogicDeployerLibrary,0xf0e),(SuperfluidPoolNFTLogicDeployerLibrary,0xf0f),(SuperTokenDeployerLibrary,0xf10),(SuperTokenFactoryDeployerLibrary,0xf11),(TokenDeployerLibrary,0xf12)"
]
deployContracts: [
["0xf01", "CFAv1ForwarderDeployerLibrary"],
["0xf02", "GDAv1ForwarderDeployerLibrary"],
["0xf03", "IDAv1ForwarderDeployerLibrary"],
["0xf04", "ProxyDeployerLibrary"],
["0xf05", "SlotsBitmapLibrary"],
["0xf06", "SuperfluidCFAv1DeployerLibrary"],
["0xf07", "SuperfluidFlowNFTLogicDeployerLibrary"],
["0xf08", "SuperfluidGDAv1DeployerLibrary"],
["0xf09", "SuperfluidGovDeployerLibrary"],
["0xf0a", "SuperfluidHostDeployerLibrary"],
["0xf0b", "SuperfluidIDAv1DeployerLibrary"],
["0xf0c", "SuperfluidPeripheryDeployerLibrary"],
["0xf0d", "SuperfluidPoolDeployerLibrary"],
["0xf0e", "SuperfluidPoolLogicDeployerLibrary"],
["0xf0f", "SuperfluidPoolNFTLogicDeployerLibrary"],
["0xf10", "SuperTokenDeployerLibrary"],
["0xf11", "SuperTokenFactoryDeployerLibrary"],
["0xf12", "TokenDeployerLibrary"],
]
deployBytecodes: [
["0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24", "608060405234801561001057600080fd5b506109c5806100206000396000f3fe608060405234801561001057600080fd5b50600436106100a5576000357c010000000000000000000000000000000000000000000000000000000090048063a41e7d5111610078578063a41e7d51146101d4578063aabbb8ca1461020a578063b705676514610236578063f712f3e814610280576100a5565b806329965a1d146100aa5780633d584063146100e25780635df8122f1461012457806365ba36c114610152575b600080fd5b6100e0600480360360608110156100c057600080fd5b50600160a060020a038135811691602081013591604090910135166102b6565b005b610108600480360360208110156100f857600080fd5b5035600160a060020a0316610570565b60408051600160a060020a039092168252519081900360200190f35b6100e06004803603604081101561013a57600080fd5b50600160a060020a03813581169160200135166105bc565b6101c26004803603602081101561016857600080fd5b81019060208101813564010000000081111561018357600080fd5b82018360208201111561019557600080fd5b803590602001918460018302840111640100000000831117156101b757600080fd5b5090925090506106b3565b60408051918252519081900360200190f35b6100e0600480360360408110156101ea57600080fd5b508035600160a060020a03169060200135600160e060020a0319166106ee565b6101086004803603604081101561022057600080fd5b50600160a060020a038135169060200135610778565b61026c6004803603604081101561024c57600080fd5b508035600160a060020a03169060200135600160e060020a0319166107ef565b604080519115158252519081900360200190f35b61026c6004803603604081101561029657600080fd5b508035600160a060020a03169060200135600160e060020a0319166108aa565b6000600160a060020a038416156102cd57836102cf565b335b9050336102db82610570565b600160a060020a031614610339576040805160e560020a62461bcd02815260206004820152600f60248201527f4e6f7420746865206d616e616765720000000000000000000000000000000000604482015290519081900360640190fd5b6103428361092a565b15610397576040805160e560020a62461bcd02815260206004820152601a60248201527f4d757374206e6f7420626520616e204552433136352068617368000000000000604482015290519081900360640190fd5b600160a060020a038216158015906103b85750600160a060020a0382163314155b156104ff5760405160200180807f455243313832305f4143434550545f4d4147494300000000000000000000000081525060140190506040516020818303038152906040528051906020012082600160a060020a031663249cb3fa85846040518363ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004018083815260200182600160a060020a0316600160a060020a031681526020019250505060206040518083038186803b15801561047e57600080fd5b505afa158015610492573d6000803e3d6000fd5b505050506040513d60208110156104a857600080fd5b5051146104ff576040805160e560020a62461bcd02815260206004820181905260248201527f446f6573206e6f7420696d706c656d656e742074686520696e74657266616365604482015290519081900360640190fd5b600160a060020a03818116600081815260208181526040808320888452909152808220805473ffffffffffffffffffffffffffffffffffffffff19169487169485179055518692917f93baa6efbd2244243bfee6ce4cfdd1d04fc4c0e9a786abd3a41313bd352db15391a450505050565b600160a060020a03818116600090815260016020526040812054909116151561059a5750806105b7565b50600160a060020a03808216600090815260016020526040902054165b919050565b336105c683610570565b600160a060020a031614610624576040805160e560020a62461bcd02815260206004820152600f60248201527f4e6f7420746865206d616e616765720000000000000000000000000000000000604482015290519081900360640190fd5b81600160a060020a031681600160a060020a0316146106435780610646565b60005b600160a060020a03838116600081815260016020526040808220805473ffffffffffffffffffffffffffffffffffffffff19169585169590951790945592519184169290917f605c2dbf762e5f7d60a546d42e7205dcb1b011ebc62a61736a57c9089d3a43509190a35050565b600082826040516020018083838082843780830192505050925050506040516020818303038152906040528051906020012090505b92915050565b6106f882826107ef565b610703576000610705565b815b600160a060020a03928316600081815260208181526040808320600160e060020a031996909616808452958252808320805473ffffffffffffffffffffffffffffffffffffffff19169590971694909417909555908152600284528181209281529190925220805460ff19166001179055565b600080600160a060020a038416156107905783610792565b335b905061079d8361092a565b156107c357826107ad82826108aa565b6107b85760006107ba565b815b925050506106e8565b600160a060020a0390811660009081526020818152604080832086845290915290205416905092915050565b6000808061081d857f01ffc9a70000000000000000000000000000000000000000000000000000000061094c565b909250905081158061082d575080155b1561083d576000925050506106e8565b61084f85600160e060020a031961094c565b909250905081158061086057508015155b15610870576000925050506106e8565b61087a858561094c565b909250905060018214801561088f5750806001145b1561089f576001925050506106e8565b506000949350505050565b600160a060020a0382166000908152600260209081526040808320600160e060020a03198516845290915281205460ff1615156108f2576108eb83836107ef565b90506106e8565b50600160a060020a03808316600081815260208181526040808320600160e060020a0319871684529091529020549091161492915050565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff161590565b6040517f01ffc9a7000000000000000000000000000000000000000000000000000000008082526004820183905260009182919060208160248189617530fa90519096909550935050505056fea165627a7a72305820377f4a2d4301ede9949f163f319021a6e9c687c292a5e2b2c4734c126b524e6c0029"],
]
EOF
}

function hott() {
TEST_CONTRACT_CONFIG=$1
TEST_CONTRACT=$(basename $TEST_CONTRACT_CONFIG)
TEST_CONTRACT=${TEST_CONTRACT%%.yaml}
PROJECT_DIR=$PWD
TEST_CONTRACT_CONFIG="$(readlink -f "$1")"
TEST_CONTRACT="$(basename "$TEST_CONTRACT_CONFIG")"
TEST_CONTRACT="${TEST_CONTRACT%%.yaml}"
[ ! -f "$TEST_CONTRACT_CONFIG" ] && oops "No $TEST_CONTRACT_CONFIG provided."

rm -rf crytic-export/
rm -rf build/hot-fuzz-contracts/

apply_crytic_workaround

mode=${HOT_FUZZ_MODE:-foundry}
case $mode in
truffle)
export CRYTIC_COMPILE_FRAMEWORK=truffle
;;
foundry)
FOUNDRY_TOML="$PROJECT_DIR"/foundry.toml
[ -f "$FOUNDRY_TOML" ] || oops "$FOUNDRY_TOML not found."
export CRYTIC_COMPILE_FRAMEWORK=foundry
;;
*)
echo "Unknown mode: $mode"
;;
esac

"$ECHIDNA" . \
--config <(cat "${HOTFUZZ_DIR}"/echidna.yaml "${TEST_CONTRACT_CONFIG}") \
--workers 6 \
--contract $TEST_CONTRACT \
FOUNDRY_ROOT=$(tomlq -r ".profile.default.root // \"\"" "$FOUNDRY_TOML")
FOUNDRY_OUT=$(tomlq -r ".profile.default.out // \"\"" "$FOUNDRY_TOML")

if [ -n "$FOUNDRY_ROOT" ];then
cd "$FOUNDRY_ROOT"
fi
FOUNDRY_ROOT=$PWD

build_echidna_yaml > "$PROJECT_DIR"/echidna.yaml

"$ECHIDNA" "$PROJECT_DIR" \
--config "$PROJECT_DIR"/echidna.yaml \
--contract "$TEST_CONTRACT" \
&& digests
}

TEST_CONTRACT_CONFIG=$1
[ -z "$TEST_CONTRACT_CONFIG" ] && oops "No contract specified."
hott $TEST_CONTRACT_CONFIG
hott "$TEST_CONTRACT_CONFIG"
File renamed without changes.
Loading

0 comments on commit 93c778c

Please sign in to comment.