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

Verify mulWad functions correctness #1

Merged
merged 48 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2fa01ac
Make mulWad specs exhaustive
JuanCoRo Sep 21, 2023
dfd4e6a
Update run script and add `smt-timeout` flag
JuanCoRo Sep 21, 2023
9828668
Add lemmas for mulWad proofs
JuanCoRo Sep 21, 2023
4a30438
Update run script comptibility with `kontrol` tool
JuanCoRo Sep 26, 2023
b50af47
Update verification summary for `wadMul` and `wadMulUp`
JuanCoRo Sep 26, 2023
e999f9a
Merge branch 'master' into mulWad-proofs
F-WRunTime Sep 27, 2023
a113156
Re-push to rebuild with CI changes
F-WRunTime Sep 29, 2023
2ff5a86
Merge branch 'master' into mulWad-proofs
F-WRunTime Sep 29, 2023
cdf27d2
Update action.yml
F-WRunTime Oct 4, 2023
303be37
login to pull private image form docker
F-WRunTime Oct 4, 2023
199a501
Define the ubuntu user
F-WRunTime Oct 4, 2023
aa4162b
WRong path
F-WRunTime Oct 4, 2023
20ec144
Run direct
F-WRunTime Oct 4, 2023
05b4ae7
Check copy directory
F-WRunTime Oct 4, 2023
850d31e
call just the script
F-WRunTime Oct 4, 2023
28d558a
Remove interactive shell
F-WRunTime Oct 4, 2023
ad9eea1
List directory
F-WRunTime Oct 4, 2023
0f88bd4
Fix user chown
F-WRunTime Oct 4, 2023
bfc204f
Change permissions
F-WRunTime Oct 4, 2023
1c847c3
Wrong workspace
F-WRunTime Oct 4, 2023
53a4892
Matching release version used in docker iamge
F-WRunTime Oct 5, 2023
f00e822
Test env
F-WRunTime Oct 5, 2023
7a740e7
Test env
F-WRunTime Oct 5, 2023
d15f2cc
Test env
F-WRunTime Oct 5, 2023
366fa4b
Test env
F-WRunTime Oct 5, 2023
1af256a
Test env
F-WRunTime Oct 5, 2023
6eaea5b
Transition to use docker images at build time based on a base image w…
F-WRunTime Oct 5, 2023
e6488b0
mount syntax
F-WRunTime Oct 5, 2023
7c63d41
Misplanned user permissions post start container
F-WRunTime Oct 5, 2023
dc8992c
updating dockerfile to force foundry binaries to path
F-WRunTime Oct 5, 2023
cf55942
Final clean up of test code
F-WRunTime Oct 5, 2023
2c26e45
Missing v in control version
F-WRunTime Oct 5, 2023
19cd2e8
Go to altest kontrol release, revert docker kup usage to kontrol image
F-WRunTime Oct 6, 2023
02ab5a1
Wrong image name
F-WRunTime Oct 6, 2023
546d04a
Docker login method update creds
F-WRunTime Oct 6, 2023
40f433e
Wrong registry
F-WRunTime Oct 6, 2023
0e93fd8
missed revert user to 'user'
F-WRunTime Oct 6, 2023
49e0b50
Remove tweaks that are now part of Kontrol's default behavior
JuanCoRo Oct 6, 2023
67328fb
Adding dockerfile if we need to control z3 install, cleaning docker b…
F-WRunTime Oct 6, 2023
e02a0ca
--name > --tag
F-WRunTime Oct 6, 2023
e115991
Kontrol version does not resolve
F-WRunTime Oct 6, 2023
19f3c4c
need to set variable name
F-WRunTime Oct 6, 2023
1b65597
Do not build Image
F-WRunTime Oct 6, 2023
ca2291c
Remove dockerfile
F-WRunTime Oct 6, 2023
e234dc3
Return to kontrol-kup
F-WRunTime Oct 10, 2023
c456c41
Revert "Return to kontrol-kup"
F-WRunTime Oct 10, 2023
e6a2ef0
Fix working solc version
JuanCoRo Oct 10, 2023
e2889c8
Replace KevmUtil in favor of KontrolCheats library
JuanCoRo Oct 10, 2023
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
26 changes: 12 additions & 14 deletions .github/actions/with-docker/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: 'With Docker'
description: 'Run a given stage with Docker Image'
inputs:
container-version:
description: 'Docker Image Version'
required: true
container-name:
description: 'Docker Container Name'
required: true
Expand All @@ -16,17 +13,18 @@ runs:
set -euxo pipefail

CONTAINER_NAME=${{inputs.container-name}}
CONTAINER_VERSION=${{inputs.container-version}}

docker run \
--name ${CONTAINER_NAME} \
--rm \
--interactive \
--tty \
--detach \
--user root \
--workdir /home/user/workspace \
runtimeverificationinc/kontrol:ubuntu-jammy-${CONTAINER_VERSION}
CONTAINER_VERSION=$(cat deps/kontrol_release)
KONTROL_RELEASE=$(cat deps/kontrol_release)

docker run \
--name ${CONTAINER_NAME} \
--rm \
--interactive \
--tty \
--detach \
--user root \
--workdir /home/user/workspace \
runtimeverificationinc/kontrol:ubuntu-jammy-${KONTROL_RELEASE}

# Copy the current Checkout direcotry into the container
docker cp . ${CONTAINER_NAME}:/home/user/workspace
Expand Down
26 changes: 12 additions & 14 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,23 @@ jobs:
# Get Repository Base name
echo "repository_basename=$(basename ${{ github.repository }})" >> $GITHUB_ENV

- name: Docker Login w/ Github Token
uses: docker/login-action@v1
with:
username: rvdockerhub
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: "Start Docker Container"
uses: ./.github/actions/with-docker
with:
container-name: '${{ env.repository_basename }}-ci'
container-version: '${{ env.kontrol-version }}'

- name: 'Test New Tool Versions'
run: |
# Run the following in the running docker container
docker exec -u user ${{ env.repository_basename }}-ci bash -c '
set -euo pipefail
# If all scripts in test.sh pass then the test is successful, else fail
# and print the name of the script that failed
for script in ./test/*.sh; do
if ! bash "$script"; then
echo "Test failed: $script"
exit 1
else
echo "Test passed: $script"
fi
done
'
docker exec -u user ${{ env.repository_basename }}-ci bash -c './test/run-kevm.sh'

- name: 'Stop Docker Container'
if: always()
run: |
docker stop --time=0 ${{ env.repository_basename }}-ci
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/vectorized/solady
[submodule "lib/kontrol-cheatcodes"]
path = lib/kontrol-cheatcodes
url = https://github.com/runtimeverification/kontrol-cheatcodes
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ We employ two different types of specification for function verification: functi

### Verified functions

| Name | Location | Equivalence | Property |
|------------------|--------------------|-----------------------|--------------------|
| FooName : string | FooLocation : path | FooEquivalence : Bool | FooProperty : Bool |
| Name | Location | Equivalence | Property |
|------------|--------------------------------------------------------------------------------------------------------------------------|-------------|----------|
| `wadMul` | [solady/src/utils/FixedPointMathLib.sol](https://github.com/Vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol) | No | Yes |
| `wadMulUp` | [solady/src/utils/FixedPointMathLib.sol](https://github.com/Vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol) | No | Yes |


## Repository Structure

Expand Down
2 changes: 1 addition & 1 deletion deps/kontrol_release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.11
0.1.20
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ out = 'out'
libs = ['lib']
test = 'test/'
cache_path = 'forge-cache'
solc-version = "0.8.16"

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions lib/kontrol-cheatcodes
Submodule kontrol-cheatcodes added at 2c48ae
39 changes: 39 additions & 0 deletions tatus
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git a/.github/actions/with-docker/action.yml b/.github/actions/with-docker/action.yml
index 94d499e..ad90341 100644
--- a/.github/actions/with-docker/action.yml
+++ b/.github/actions/with-docker/action.yml
@@ -18,7 +18,7 @@ runs:
CONTAINER_NAME=${{inputs.container-name}}
CONTAINER_VERSION=${{inputs.container-version}}

- docker build --tag kontrol-kup-ci .
+ docker build --tag kontrol-kup-ci --build-arg=KONTROL_RELEASE=$(cat deps/kontrol_release) .

docker run \
--name ${CONTAINER_NAME} \
@@ -34,4 +34,3 @@ runs:
# Copy the current Checkout direcotry into the container
docker cp . ${CONTAINER_NAME}:/home/ubuntu/workspace
docker exec ${CONTAINER_NAME} chown -R ubuntu:ubuntu /home/ubuntu
- # docker exec ${CONTAINER_NAME} chown -R ubuntu:ubuntu /nix/store
diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml
index 35814eb..88deacb 100644
--- a/.github/workflows/test-pr.yml
+++ b/.github/workflows/test-pr.yml
@@ -13,7 +13,7 @@ concurrency:
jobs:
new-version-test:
name: 'Test Proofs'
- runs-on: [self-hosted, linux, normal, github-runner-13]
+ runs-on: [self-hosted, linux, normal, fast]
steps:
- name: 'Check out code'
uses: actions/checkout@v3
@@ -45,7 +45,6 @@ jobs:
- name: 'Test New Tool Versions'
run: |
# Run the following in the running docker container
- docker exec -u ubuntu ${{ env.repository_basename }}-ci bash -c 'export PATH=/home/ubuntu/.foundry/bin:$PATH && which forge'
docker exec -u ubuntu ${{ env.repository_basename }}-ci bash -c './test/run-kevm.sh'

- name: 'Stop Docker Container'
39 changes: 20 additions & 19 deletions test/FixedPointMathLib.k.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@ pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import "solady/src/utils/FixedPointMathLib.sol";
import "kontrol-cheatcodes/KontrolCheats.sol";

import "./KevmUtil.sol";

contract FixedPointMathLibVerification is Test, KevmUtil {
contract FixedPointMathLibVerification is Test, KontrolCheats {

// Constants
uint256 constant WAD = 1e18;

function setUp() public {
// Make KEVM abstract gas computations
kevm.infiniteGas();
}
function testMulWad(uint256 x, uint256 y) public {

function testMulWadInRange(uint256 x, uint256 y) public {
// Assume x * y won't overflow
vm.assume(y == 0 || x <= type(uint256).max / y);
if(y == 0 || x <= type(uint256).max / y) {
uint256 zSpec = (x * y) / WAD;
uint256 zImpl = FixedPointMathLib.mulWad(x, y);

uint256 zSpec = (x * y) / WAD;
uint256 zImpl = FixedPointMathLib.mulWad(x, y);
assertEq(zImpl, zSpec);
} else {
vm.expectRevert(); // FixedPointMathLib.MulWadFailed.selector
FixedPointMathLib.mulWad(x, y);
}

assertEq(zImpl, zSpec);
}

function testMulWadUpInRange(uint256 x, uint256 y) public {
// Assume x * y + WAD/2 won't overflow
vm.assume(y == 0 || x <= (type(uint256).max)/y);
function testMulWadUp(uint256 x, uint256 y) public {

uint256 zSpec = ((x * y)/WAD)*WAD < x * y ? (x * y)/WAD + 1 : (x * y)/WAD;
uint256 zImpl = FixedPointMathLib.mulWadUp(x, y);
if(y == 0 || x <= (type(uint256).max)/y) {
uint256 zSpec = ((x * y)/WAD)*WAD < x * y ? (x * y)/WAD + 1 : (x * y)/WAD;
uint256 zImpl = FixedPointMathLib.mulWadUp(x, y);

assertEq(zImpl, zSpec);
assertEq(zImpl, zSpec);
} else {
vm.expectRevert(); // FixedPointMathLib.MulWadFailed.selector
FixedPointMathLib.mulWadUp(x, y);
}
}
}
96 changes: 40 additions & 56 deletions test/run-kevm.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,55 @@ forge_build() {
forge build
}

foundry_kompile() {
kevm foundry-kompile --verbose \
--require ${lemmas} \
--module-import ${module} \
${rekompile} \
${regen} \
${llvm_library}
kontrol_kompile() {
kontrol build \
--verbose \
--require ${lemmas} \
--module-import ${module} \
${rekompile}
}

foundry_prove() {
kevm foundry-prove \
--max-depth ${max_depth} \
--max-iterations ${max_iterations} \
--bmc-depth ${bmc_depth} \
--workers ${workers} \
--verbose \
${reinit} \
${debug} \
${simplify_init} \
${implication_every_block} \
${break_every_step} \
${break_on_calls} \
${auto_abstract} \
${bug_report} \
${tests} \
${use_booster} \
# --kore-rpc-command "${kore_rpc_command}"
kontrol_prove() {
kontrol prove \
--max-depth ${max_depth} \
--max-iterations ${max_iterations} \
--smt-timeout ${smt_timeout} \
--workers ${workers} \
--verbose \
${reinit} \
${debug} \
${bug_report} \
${simplify_init} \
${implication_every_block} \
${break_every_step} \
${break_on_calls} \
${tests} \
${use_booster}
}

foundry_claim() {
kevm prove ${lemmas} \
--claim ${base_module}-SPEC.${claim} \
kontrol_claim() {
kevm prove \
${lemmas} \
--claim ${base_module}-SPEC.${claim} \
--definition out/kompiled \
--spec-module ${base_module}-SPEC
--spec-module ${base_module}-SPEC \
--smt-timeout ${smt_timeout}
}

lemmas=test/solady-lemmas.k
base_module=SOLADY-LEMMAS
module=FixedPointMathLibVerification:${base_module}

claim=first-roadblock

max_depth=10000
max_iterations=10000

bmc_depth=3
smt_timeout=100000

# Number of processes run by the prover in parallel
# Should be at most (M - 8) / 8 in a machine with M GB of RAM
workers=16
workers=12

# Switch the options below to turn them on or off
# TODO: Describe this thoroughly
regen=--regen # Regenerates all of the K definition files
regen=

rekompile=--rekompile # Rekompiles
rekompile=--rekompile
#rekompile=

# Progress is saved automatically so an unfinished proof can be resumed from where it left off
Expand All @@ -85,33 +77,25 @@ break_every_step=
break_on_calls=
break_on_calls=--no-break-on-calls

auto_abstract=--auto-abstract
auto_abstract=
auto_abstract=--auto-abstract-gas

bug_report=--bug-report
bug_report=

# For running the booster
llvm_library=
llvm_library=--with-llvm-library

# For running the booster
use_booster=
use_booster=--use-booster

kore_rpc_command=
kore_rpc_command=kore-rpc-booster\ --simplify-after-exec\ --llvm-backend-library\ out/kompiled/llvm-library/interpreter.so
#use_booster=

# List of tests to symbolically execute

tests=""
tests+="--test FixedPointMathLibVerification.testMulWadInRange "
#tests+="--test FixedPointMathLibVerification.testMulWadUpInRange "
tests+="--test FixedPointMathLibVerification.testMulWad(uint256,uint256) "
tests+="--test FixedPointMathLibVerification.testMulWadUp "

# Name of the claim to execute
claim=mulWadUp-first-roadblock

# Comment these lines as needed
pkill kore-rpc || true
forge_build
foundry_kompile
foundry_prove
#foundry_claim
kontrol_kompile
kontrol_prove
#kontrol_claim
Loading
Loading