Skip to content

Commit

Permalink
start echidna tests and add to workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
darcys22 committed Dec 15, 2023
1 parent 3682ec0 commit 0ab9102
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/fuzz-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Fuzz Testing

on:
push:
branches:
- master
pull_request:

jobs:
echidna:
name: Echidna
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
testName:
- TickBitmapEchidnaTest
- TickMathEchidnaTest
- SqrtPriceMathEchidnaTest
- SwapMathEchidnaTest
- TickEchidnaTest
- TickOverflowSafetyEchidnaTest
- OracleEchidnaTest
- BitMathEchidnaTest
- LowGasSafeMathEchidnaTest
- UnsafeMathEchidnaTest
- FullMathEchidnaTest

steps:
- uses: actions/checkout@v2

- name: Set up node
uses: actions/setup-node@v1
with:
node-version: 12

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install node dependencies
run: yarn install --frozen-lockfile

- name: Install pip3
run: |
python -m pip install --upgrade pip
- name: Install slither
run: |
pip3 install slither-analyzer
- name: Install echidna
run: |
sudo wget -O /tmp/echidna-test.tar.gz https://github.com/crytic/echidna/releases/download/v1.6.0/echidna-test-v1.6.0-Ubuntu-18.04.tar.gz
sudo tar -xf /tmp/echidna-test.tar.gz -C /usr/bin
sudo chmod +x /usr/bin/echidna-test
- name: Run ${{ matrix.testName }}
run: echidna-test . --contract ${{ matrix.testName }} --config echidna.config.yml
34 changes: 34 additions & 0 deletions contracts/test/BN256G2EchidnaTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.18;

import "../BN256G2.sol";

contract BN256G2EchidnaTest {
// Test the ECTwistAdd function
function checkECTwistAdd(
uint256 pt1xx, uint256 pt1xy,
uint256 pt1yx, uint256 pt1yy,
uint256 pt2xx, uint256 pt2xy,
uint256 pt2yx, uint256 pt2yy
) public {
(uint256 sumXx, uint256 sumXy, uint256 sumYx, uint256 sumYy) = BN256G2.ECTwistAdd(
pt1xx, pt1xy, pt1yx, pt1yy,
pt2xx, pt2xy, pt2yx, pt2yy
);
assert(BN256G2.IsOnCurve(sumXx, sumXy, sumYx, sumYy));
}

// Test the ECTwistMul function
function checkECTwistMul(
uint256 s,
uint256 pt1xx, uint256 pt1xy,
uint256 pt1yx, uint256 pt1yy
) public {
(uint256 mulXx, uint256 mulXy, uint256 mulYx, uint256 mulYy) = BN256G2.ECTwistMul(
s, pt1xx, pt1xy, pt1yx, pt1yy
);
assert(BN256G2.IsOnCurve(mulXx, mulXy, mulYx, mulYy));
}

}

File renamed without changes.
74 changes: 74 additions & 0 deletions echidna.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#format can be "text" or "json" for different output (human or machine readable)
format: 'text'
#checkAsserts checks assertions
checkAsserts: true
#coverage controls coverage guided testing
coverage: false
# #psender is the sender for property transactions; by default intentionally
# #the same as contract deployer
# psender: "0x00a329c0648769a73afac7f9381e08fb43dbea70"
# #prefix is the prefix for Boolean functions that are properties to be checked
# prefix: "echidna_"
# #propMaxGas defines gas cost at which a property fails
# propMaxGas: 8000030
# #testMaxGas is a gas limit; does not cause failure, but terminates sequence
# testMaxGas: 8000030
# #maxGasprice is the maximum gas price
# maxGasprice: 100000000000
# #testLimit is the number of test sequences to run
# testLimit: 50000
# #stopOnFail makes echidna terminate as soon as any property fails and has been shrunk
# stopOnFail: false
# #estimateGas makes echidna perform analysis of maximum gas costs for functions (experimental)
# estimateGas: false
# #seqLen defines how many transactions are in a test sequence
# seqLen: 100
# #shrinkLimit determines how much effort is spent shrinking failing sequences
# shrinkLimit: 5000
# #contractAddr is the address of the contract itself
# contractAddr: "0x00a329c0648769a73afac7f9381e08fb43dbea72"
# #deployer is address of the contract deployer (who often is privileged owner, etc.)
# deployer: "0x00a329c0648769a73afac7f9381e08fb43dbea70"
# #sender is set of addresses transactions may originate from
# sender: ["0x10000", "0x20000", "0x00a329c0648769a73afac7f9381e08fb43dbea70"]
# #balanceAddr is default balance for addresses
# balanceAddr: 0xffffffff
# #balanceContract overrides balanceAddr for the contract address
# balanceContract: 0
# #solcArgs allows special args to solc
# solcArgs: ""
# #solcLibs is solc libraries
# solcLibs: []
# #cryticArgs allows special args to crytic
# cryticArgs: []
# #quiet produces (much) less verbose output
# quiet: false
# #initialize the blockchain with some data
# initialize: null
# #whether ot not to use the multi-abi mode of testing
# multi-abi: false
# #benchmarkMode enables benchmark mode
# benchmarkMode: false
# #timeout controls test timeout settings
# timeout: null
# #seed not defined by default, is the random seed
# #seed: 0
# #dictFreq controls how often to use echidna's internal dictionary vs random
# #values
# dictFreq: 0.40
# maxTimeDelay: 604800
# #maximum time between generated txs; default is one week
# maxBlockDelay: 60480
# #maximum number of blocks elapsed between generated txs; default is expected increment in one week
# # timeout:
# #campaign timeout (in seconds)
# # list of methods to filter
# filterFunctions: []
# # by default, blacklist methods in filterFunctions
# filterBlacklist: true
# #directory to save the corpus; by default is disabled
# corpusDir: null
# # constants for corpus mutations (for experimentation only)
# mutConsts: [100, 1, 1]
# # maximum value to send to payable functions
# maxValue: 100000000000000000000 # 100 eth

0 comments on commit 0ab9102

Please sign in to comment.