Skip to content

Multisig.new #331

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

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4d68503
Protocol semantics
Jan 11, 2021
8542fbe
tmp
Apr 1, 2021
623af47
Invariant
Jan 17, 2021
e755897
Optimize perform
Apr 1, 2021
b42a219
Functions optimization
Apr 1, 2021
007c7d5
tmp
Apr 1, 2021
0d3ebc0
tmp
Apr 2, 2021
cb9c8ed
tmp
Apr 2, 2021
7947881
tmp
Apr 2, 2021
3787c76
Map properties
Mar 16, 2021
1d10319
Can always add and execute action
Mar 16, 2021
36c0e83
Fix sign-for proofs.
Apr 1, 2021
c23dec2
tmp
Apr 1, 2021
fdf2459
tmp
Apr 1, 2021
24a7423
tmp
Apr 5, 2021
d0e08b7
Speed refactoring
Apr 7, 2021
6921ba4
Prepare actions for malicious user proofs
Apr 8, 2021
9009962
Refactor proofs in order to reuse them for malicious user properties.
Apr 8, 2021
b87588f
Add performed actions logging
Apr 2, 2021
3f79466
Malicious user properties
Apr 5, 2021
e0cb558
Invariant
Apr 12, 2021
ac6f310
Fix merge errors
Apr 13, 2021
3a2db25
Perform proofs
Apr 12, 2021
2733131
Convert proofs to tests
Apr 13, 2021
40e8580
Proofs for performActionFromId.
Apr 13, 2021
3f2eedf
Proof for the perform action endpoint checks
Apr 13, 2021
bed9e57
Fix proofs and cleanup
Apr 14, 2021
26a673d
Some of the proofs for perform-action-enpoint
Apr 14, 2021
7b71500
Proofs for the perform action endpoint function
Apr 15, 2021
99ef051
More function proofs
Apr 16, 2021
a540334
Partial perform action proof
Apr 20, 2021
9729ba7
Fix add board member subproof
Apr 20, 2021
c28b5ba
Several perform action parts
Apr 23, 2021
5ee9edb
Perform parts remove and malicious user
Apr 23, 2021
8fa8c13
Debug labels
Apr 26, 2021
a3f579b
Propose add board member
Apr 26, 2021
f9c43fc
Improve compilation times.
Apr 27, 2021
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
3 changes: 3 additions & 0 deletions multisig/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kompile_tool/k
kompile_tool/k.old
bazel-*
Empty file added multisig/BUILD
Empty file.
Empty file added multisig/WORKSPACE.bazel
Empty file.
63 changes: 63 additions & 0 deletions multisig/kompile_tool/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
sh_binary(
name = "kompile_tool",
srcs = ["kompile.sh"],
deps = [":k_release"],
data = [":k_release"],
visibility = ["//visibility:public"],
)

sh_binary(
name = "kompile_e_tool",
srcs = ["kompile-e.sh"],
deps = [":k_release"],
data = [":k_release"],
visibility = ["//visibility:public"],
)

sh_binary(
name = "kprove_tool",
srcs = ["kprove.sh"],
deps = [":k_release"],
data = [":k_release"],
visibility = ["//visibility:public"],
)

sh_binary(
name = "kprove_kompile_tool",
srcs = ["kprove-kompile.sh"],
deps = [":k_release"],
data = [":k_release"],
visibility = ["//visibility:public"],
)

sh_binary(
name = "kore_tool",
srcs = ["kore.sh"],
deps = [":k_release"],
data = [":k_release"],
visibility = ["//visibility:public"],
)

sh_binary(
name = "ktrusted_tool",
srcs = ["make-trusted.py"],
visibility = ["//visibility:public"],
)

sh_binary(
name = "kmerge_tool",
srcs = ["kmerge.sh"],
visibility = ["//visibility:public"],
)

sh_library(
name = "k_release",
data = glob(["k/**"]),
visibility = ["//visibility:public"],
)

sh_library(
name = "kast_script",
srcs = ["kast.kscript"],
visibility = ["//visibility:public"],
)
18 changes: 18 additions & 0 deletions multisig/kompile_tool/kast.kscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
alias kclaim = claim | kast -i kore -o pretty -d . /dev/stdin
alias kclaim-d x = claim | kast -i kore -o pretty -d x /dev/stdin
alias kclaim-n x = claim x | kast -i kore -o pretty -d . /dev/stdin
alias kclaim-nd x y = claim x | kast -i kore -o pretty -d y /dev/stdin
alias kaxiom x = axiom x | kast -i kore -o pretty -d . /dev/stdin
alias kaxiom-d x y = axiom x | kast -i kore -o pretty -d y /dev/stdin
alias konfig = config | kast -i kore -o pretty -d . /dev/stdin
alias konfig-d x = config | kast -i kore -o pretty -d x /dev/stdin
alias konfig-n x = config x | kast -i kore -o pretty -d . /dev/stdin
alias konfig-nd x y = config x | kast -i kore -o pretty -d y /dev/stdin
alias ktry x = try x | kast -i kore -o pretty -d . /dev/stdin
alias ktry-d x y = try x | kast -i kore -o pretty -d y /dev/stdin
alias ktryf x = tryf x | kast -i kore -o pretty -d . /dev/stdin
alias ktryf-d x y = tryf x | kast -i kore -o pretty -d y /dev/stdin
alias krule = rule | kast -i kore -o pretty -d . /dev/stdin
alias krule-d x = rule | kast -i kore -o pretty -d x /dev/stdin
alias krule-n x = rule x | kast -i kore -o pretty -d . /dev/stdin
alias krule-nd x y = rule x | kast -i kore -o pretty -d y /dev/stdin
18 changes: 18 additions & 0 deletions multisig/kompile_tool/kmerge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -e

OUTPUT=$1
shift

FIRST=$1
shift

cat $FIRST | sed 's/^.*\/\/@ Bazel remove\s*$/\/\/ Removed by Bazel + kmerge./' > $OUTPUT
echo >> $OUTPUT

for f in "$@"
do
cat "$f" | sed 's/^.*\/\/@ Bazel remove\s*$/\/\/ Removed by Bazel + kmerge./' >> $OUTPUT
echo >> $OUTPUT
done
8 changes: 8 additions & 0 deletions multisig/kompile_tool/kompile-e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

PARENT_DIR=`dirname $0`

KOMPILE=$PARENT_DIR/kompile_e_tool.runfiles/__main__/kompile_tool/k/bin/kompile
$KOMPILE --backend haskell -I `pwd` -E "$@" > /dev/null
12 changes: 12 additions & 0 deletions multisig/kompile_tool/kompile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -e

PARENT_DIR=`dirname $0`

OUTPUT_DIR=`dirname $1`
OUTPUT_DIR=`dirname $OUTPUT_DIR`
shift

KOMPILE=$PARENT_DIR/kompile_tool.runfiles/__main__/kompile_tool/k/bin/kompile
$KOMPILE --backend haskell -I `pwd` --directory $OUTPUT_DIR "$@"
59 changes: 59 additions & 0 deletions multisig/kompile_tool/kore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -e

SPEC_MODULE_NAME=$1
shift

KOMPILE_DIR=`dirname $1`
shift

DEFINITION=$(realpath $1)
shift

SPEC=$(realpath $1)
shift

COMMAND=$1
shift

OUTPUT=$(realpath $1)
shift

BREADTH=$1
shift

MODULE_NAME=$(cat $COMMAND | sed 's/^.*--module \([^ ]*\) .*$/\1/')

# SPEC_MODULE_NAME=$(cat $COMMAND | sed 's/^.*--spec-module \([^ ]*\) .*$/\1/')

KOMPILE_TOOL_DIR=kompile_tool

REPL_SCRIPT=$(realpath $KOMPILE_TOOL_DIR/kast.kscript)

KORE_EXEC="$(realpath $KOMPILE_TOOL_DIR/k/bin/kore-exec) --breadth $BREADTH"
KORE_REPL="$(realpath $KOMPILE_TOOL_DIR/k/bin/kore-repl) --repl-script $REPL_SCRIPT"

BACKEND_COMMAND=$KORE_EXEC
if [ $# -eq 0 ]; then
BACKEND_COMMAND=$KORE_EXEC
else
if [ "$1" == "--debug" ]; then
BACKEND_COMMAND=$KORE_REPL
else
echo "Unknown argument: '$1'"
exit 1
fi
fi

PATH=$(realpath $KOMPILE_TOOL_DIR/k/bin):$PATH

cd $(dirname $KOMPILE_DIR)

$BACKEND_COMMAND \
--smt-timeout 4000 \
$DEFINITION \
--prove $SPEC \
--module $MODULE_NAME \
--spec-module $SPEC_MODULE_NAME \
--output $OUTPUT
61 changes: 61 additions & 0 deletions multisig/kompile_tool/kprove-kompile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

set -e

KOMPILE_DIR=`dirname $1`
shift

ORIGINAL_FILE=$1
shift

PROOF_FILE=$(realpath $1)
shift

SPEC_OUTPUT=$1
shift

DEFINITION_OUTPUT=$1
shift

COMMAND_OUTPUT=$1
shift

KOMPILE_OUTPUT=$(dirname $1)
shift

MODULE_NAME=$(basename "$ORIGINAL_FILE" | sed 's/\.[^\.]*$//' | tr [:lower:] [:upper:])

KOMPILE_TOOL_DIR=kompile_tool

KPROVE=$(realpath $KOMPILE_TOOL_DIR/k/bin/kprove)

TMP_DIR=$(mktemp -d)
trap 'rm -rf -- "$TMP_DIR"' EXIT

cp -rL $KOMPILE_DIR $TMP_DIR
chmod -R a+w $TMP_DIR/*

pushd $TMP_DIR > /dev/null

nice -n 10 \
$KPROVE \
--spec-module "$MODULE_NAME" \
--dry-run \
"$PROOF_FILE" > output

SPEC_FILE=$(cat output | grep kore-exec | sed 's/^.*--prove \([^ ]*\) .*$/\1/')
COMMAND=$(cat output | grep kore-exec)

popd > /dev/null

cp $SPEC_FILE $SPEC_OUTPUT

DEFINITION_FILE=$(dirname $SPEC_FILE)/vdefinition.kore

cp $DEFINITION_FILE $DEFINITION_OUTPUT

echo $COMMAND > $COMMAND_OUTPUT

mkdir -p $KOMPILE_OUTPUT

cp $TMP_DIR/$(basename $KOMPILE_DIR)/* $KOMPILE_OUTPUT
60 changes: 60 additions & 0 deletions multisig/kompile_tool/kprove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash

set -e

PARENT_DIR=$(dirname $0)

KOMPILE_DIR=$(dirname $1)
shift

TMP_DIR=$(mktemp -d)
trap 'rm -rf -- "$TMP_DIR"' EXIT

ORIGINAL_FILE=$1
shift

PROOF_FILE=$(realpath $1)
shift

BREADTH=$1
shift

#KOMPILE_PARENT = $(dirname $KOMPILE_DIR)
#
MODULE_NAME=$(basename "$ORIGINAL_FILE" | sed 's/\.[^\.]*$//' | tr [:lower:] [:upper:])

cp -rL $KOMPILE_DIR $TMP_DIR
chmod -R a+w $TMP_DIR/*

KOMPILE_TOOL_DIR=kompile_tool

KPROVE=$(realpath $KOMPILE_TOOL_DIR/k/bin/kprove)
REPL_SCRIPT=$(realpath $KOMPILE_TOOL_DIR/kast.kscript)

#PROOF_FILE_PATH=$(realpath $PROOF_FILE)
#REPL_SCRIPT_PATH=$(realpath $REPL_SCRIPT)
#
KORE_EXEC="kore-exec --breadth $BREADTH"
KORE_REPL="kore-repl --repl-script $REPL_SCRIPT"

BACKEND_COMMAND=$KORE_EXEC
if [ $# -eq 0 ]; then
BACKEND_COMMAND=$KORE_EXEC
else
if [ "$1" == "--debug" ]; then
BACKEND_COMMAND=$KORE_REPL
else
echo "Unknown argument: '$1'"
exit 1
fi
fi

cd $TMP_DIR
echo $TMP_DIR

$KPROVE \
--haskell-backend-command "$BACKEND_COMMAND --smt-timeout 4000" \
--spec-module "$MODULE_NAME" \
"$PROOF_FILE"

# --directory "$TMP_DIR" \
65 changes: 65 additions & 0 deletions multisig/kompile_tool/make-trusted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
import sys

def naturalNumbers():
i = 1
while True:
yield i
i += 1

DEFAULT = 0
PROOF = 1
TRUSTED = 2

def makeTrusted(file_name, lines):
state = DEFAULT
for (line_number, line) in lines:
normalized = line.strip()
if normalized.startswith('//@'):
if state == DEFAULT:
if normalized == '//@ proof':
state = PROOF
else:
raise Exception(
"Unexpected trusted directive, only '//@ proof' allowed here.\n%s:%d"
% (file_name, line_number))
elif state == PROOF:
if normalized == '//@ trusted':
state = TRUSTED
else:
raise Exception(
"Unexpected trusted directive, only '//@ trusted' allowed here.\n%s:%d"
% (file_name, line_number))
elif state == TRUSTED:
if normalized == '//@ end':
state = DEFAULT
else:
raise Exception(
"Unexpected trusted directive, only '//@ end' allowed here.\n%s:%d"
% (file_name, line_number))
else:
if state == DEFAULT:
pass
else:
unindented = line.lstrip()
indentation = ' ' * (len(line) - len(unindented))
if state == PROOF:
line = indentation + '// ' + unindented
elif state == TRUSTED:
if unindented.startswith('// '):
line = indentation + unindented[3:]
else:
raise Exception(
"Expected trusted lines to be commented.\n%s:%d"
% (file_name, line_number))
yield line

def main(argv):
if len(argv) != 2:
raise Exception('Wrong number of arguments, expected an input and an output file name.')
with open(argv[0], 'r') as f:
with open(argv[1], 'w') as g:
g.writelines(makeTrusted(argv[0], zip(naturalNumbers(), f)))

if __name__ == '__main__':
main(sys.argv[1:])
9 changes: 9 additions & 0 deletions multisig/kompile_tool/prepare-k.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

KOMPILE=`which kompile`
BIN=`dirname $KOMPILE`
RELEASE=`dirname $BIN`

mkdir k

cp -r $RELEASE/* k
Loading