Skip to content

Commit 40ddfa0

Browse files
committed
generated execution logs
1 parent a7937c8 commit 40ddfa0

12 files changed

+261
-505
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
bin/slangroom-exec
33
src/*.json
44
src/*.svg
5+
src/*exec_log.md
56
*.orig
67
*.rdf
78
*.slang
9+
*.dot
10+
*.png
811
.vitepress/dist
912
.vitepress/cache
1013
node_modules

GNUmakefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
all:
44
@rm -f src/*.json src/*.slang
5-
@bats/bin/bats sign*bats
6-
@bats/bin/bats verify*bats
5+
@bats/bin/bats mldsa-rdfc-2025.bats
6+
@bats/bin/bats eddsa-rdfc-2022.bats
7+
@bats/bin/bats ecdsa-rdfc-2019.bats
78

89
check:
910
bats/bin/bats test.bats

bats/setup

+59-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ slexe() {
3030
set +e
3131
[ -r bin/slexfe ] || {
3232
_err "Error: bin/slexfe not found." | tee -a $TMP/err
33-
exit 1 }
33+
exit 1; }
3434
command -v slangroom-exec > /dev/null || {
3535
_err "Error: slangroom-exec not found." | tee -a $TMP/err
36-
exit 1 }
36+
exit 1; }
3737
[ -r "${1}.slang" ] || {
3838
_err "Error: script not found: $1" | tee -a $TMP/err
39-
exit 1 }
39+
exit 1; }
4040
# EXECUTION (timed)
4141
>&3 echo " 🔥 `basename ${1}.slang`"
4242
local start_time_s=$(date +%s)
@@ -56,10 +56,10 @@ slexe() {
5656
>&2 echo "HEAP:"
5757
awk '/J64 HEAP/ {print $3}' $TMP/err | \
5858
cut -d\" -f1 | base64 -d | jq .
59-
exit 1 }
59+
exit 1; }
6060
[ "$output" == "" ] && {
6161
_err "Output is missing, no result from previous computation" | tee -a $TMP/err
62-
exit 1 }
62+
exit 1; }
6363
# Calculate execution timing:
6464
# avoid leading zero issues in shell by normalizing inputs
6565
start_time_s=$((10#$start_time_s))
@@ -92,7 +92,7 @@ slexe() {
9292
ikeys="null\n\n0 bytes"
9393
fi
9494
iout="`basename $1`\n\n$(stat --format="%s" "$1.out.json") bytes"
95-
cat <<EOF | dot -Tsvg -o ${1}.svg
95+
cat <<EOF | dot -Tsvg -o ${1}.svg
9696
digraph G {
9797
rankdir=LR;
9898
node [shape=box, style=rounded, fontname="Arial", fontsize=12, color=black, fillcolor=lightgray, margin=0.2];
@@ -108,7 +108,7 @@ digraph G {
108108
edge [color=black, arrowsize=0.7];
109109
}
110110
EOF
111-
# add entry to execution log
111+
execlog $1
112112
}
113113

114114
save_output() {
@@ -137,3 +137,55 @@ input() {
137137
ln -s "$2" "${SRC}/${contract}.${ft}.json"
138138
>&3 echo " 🔌 $ft `basename $2`"
139139
}
140+
141+
execlog() {
142+
# add entry to execution log
143+
local input_found=0
144+
local out="${SRC}/${algo}_exec_log.md"
145+
input_temp=`mktemp`
146+
echo "## ${contract}" >> "$out"
147+
cat <<EOF >> $input_temp
148+
149+
### Input
150+
EOF
151+
local idata_file
152+
if [ -L $1.data.json ]; then
153+
idata_file=`readlink $1.data.json`
154+
if [ -r $idata_file ] && [ "$idata_file" != "/dev/null" ]; then
155+
idata="`basename $idata_file|cut -d. -f1`"
156+
input_found=1
157+
cat <<EOF >> $input_temp
158+
$idata
159+
160+
<<< @/$contract.data.json
161+
162+
EOF
163+
fi
164+
fi
165+
local ikeys_file
166+
if [ -L $1.keys.json ]; then
167+
ikeys_file=`readlink $1.keys.json`
168+
if [ -r $ikeys_file ] && [ "$ikeys_file" != "/dev/null" ]; then
169+
ikeys="`basename $ikeys_file|cut -d. -f1`"
170+
input_found=1
171+
cat <<EOF >> $input_temp
172+
$ikeys
173+
174+
<<< @/$contract.keys.json
175+
176+
EOF
177+
fi
178+
fi
179+
if [ $input_found == 1 ]; then cat $input_temp >> $out; fi
180+
rm -f $input_temp
181+
182+
cat <<EOF >> $out
183+
### Zencode
184+
<<< @/${contract}.slang{gherkin}
185+
![]($contract.svg)
186+
187+
### Output
188+
<<< @/${contract}.out.json
189+
190+
EOF
191+
}

sign_ecdsa-rdfc-2019.bats renamed to ecdsa-rdfc-2019.bats

+64-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020

2121
setup() {
2222
load bats/setup
23-
algo=ecdsa
23+
}
24+
25+
setup_file() {
26+
export algo=ecdsa
27+
rm -f src/${algo}_exec_log.md
2428
}
2529

2630
@test "Create the keyring and document" {
@@ -135,3 +139,62 @@ EOF
135139
slexe $SRC/${contract}
136140
# cat $SRC/${contract}.out.json | >&3 jq .
137141
}
142+
143+
144+
@test "Prepare the document signature verification" {
145+
export contract=${algo}_prepare-verification-signed-doc
146+
input data $SRC/${algo}_hash-and-sign.out.json
147+
input keys $SRC/${algo}_keyring.out.json
148+
cat <<EOF > $SRC/${contract}.slang
149+
rule output encoding base64
150+
Scenario es256
151+
Given I have a 'keyring'
152+
and I have a 'dictionary' named 'document'
153+
and I have a 'base58' part of path 'document.proof.proofValue' after string prefix 'z'
154+
and I have a 'dictionary' in path 'document.proof'
155+
156+
When I rename 'proofValue' to 'es256 signature'
157+
and I remove 'proofValue' from 'proof'
158+
and I remove 'proof' from 'document'
159+
and I create copy of '@context' from 'document'
160+
and I rename 'copy' to '@context'
161+
and I move '@context' in 'proof'
162+
and I create the es256 public key
163+
164+
Then print the 'es256 signature' as 'base64'
165+
and print the 'proof'
166+
and print the 'document'
167+
and print the 'es256 public key'
168+
169+
Compute 'proof rdf-canon': generate serialized canonical rdf with dictionary 'proof'
170+
Compute 'document rdf-canon': generate serialized canonical rdf with dictionary 'document'
171+
EOF
172+
slexe $SRC/${contract}
173+
# cat $TMP/out | >&3 jq .
174+
}
175+
176+
@test "Verify the signature" {
177+
export contract=${algo}_verify-prepared-signed-doc
178+
input data $SRC/${algo}_prepare-verification-signed-doc.out.json
179+
input keys /dev/null
180+
cat <<EOF > ${SRC}/${contract}.slang
181+
Scenario es256
182+
Given I have a 'base64' named 'document rdf-canon'
183+
and I have a 'base64' named 'proof rdf-canon'
184+
and I have a 'es256 public key'
185+
and I have a 'es256 signature'
186+
187+
When I create the hash of 'proof rdf-canon'
188+
and rename 'hash' to 'proof hash'
189+
and I create the hash of 'document rdf-canon'
190+
and rename 'hash' to 'document hash'
191+
and I append 'document hash' to 'proof hash'
192+
193+
When I verify 'proof hash' has a es256 signature in 'es256 signature' by 'es256 public key'
194+
195+
Then print the string 'VALID DOC PROOF'
196+
EOF
197+
slexe ${SRC}/${contract}
198+
cat $TMP/out | >&3 jq .
199+
200+
}

sign_eddsa-rdfc-2022.bats renamed to eddsa-rdfc-2022.bats

+64-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020

2121
setup() {
2222
load bats/setup
23-
algo=eddsa
23+
}
24+
25+
setup_file() {
26+
export algo=eddsa
27+
rm -f src/${algo}_exec_log.md
2428
}
2529

2630
@test "Create the keyring and document" {
31+
export contract=eddsa_keyring
2732
cat <<EOF > $SRC/eddsa_keyring.keys.json
2833
{ "w3c test key": "c96ef9ea10c5e414c471723aff9de72c35fa5b70fae97e8832ecac7d2e2b8ed6" }
2934
EOF
@@ -141,3 +146,61 @@ Then print 'document' as 'string'
141146
EOF
142147
slexe $SRC/${algo}_hash-and-sign
143148
}
149+
150+
151+
@test "Prepare the document signature verification" {
152+
export contract=${algo}_prepare-verification-signed-doc
153+
input data $SRC/${algo}_hash-and-sign.out.json
154+
input keys $SRC/${algo}_keyring.out.json
155+
cat <<EOF > $SRC/${contract}.slang
156+
Scenario eddsa
157+
Given I have a 'keyring'
158+
and I have a 'dictionary' named 'document'
159+
and I have a 'eddsa signature' part of path 'document.proof.proofValue' after string prefix 'z'
160+
and I have a 'dictionary' in path 'document.proof'
161+
162+
When I rename 'proofValue' to 'eddsa signature'
163+
and I remove 'proofValue' from 'proof'
164+
and I remove 'proof' from 'document'
165+
and I create copy of '@context' from 'document'
166+
and I rename 'copy' to '@context'
167+
and I move '@context' in 'proof'
168+
and I create the eddsa public key
169+
170+
Then print the 'eddsa signature'
171+
and print the 'proof'
172+
and print the 'document'
173+
and print the 'eddsa public key'
174+
175+
Compute 'proof rdf-canon': generate serialized canonical rdf with dictionary 'proof'
176+
Compute 'document rdf-canon': generate serialized canonical rdf with dictionary 'document'
177+
EOF
178+
slexe $SRC/${contract}
179+
# cat $TMP/out | >&3 jq .
180+
}
181+
182+
@test "Verify the signature" {
183+
export contract=${algo}_verify-prepared-signed-doc
184+
input data $SRC/${algo}_prepare-verification-signed-doc.out.json
185+
input keys /dev/null
186+
cat <<EOF > ${SRC}/${contract}.slang
187+
Scenario eddsa
188+
Given I have a 'base64' named 'document rdf-canon'
189+
and I have a 'base64' named 'proof rdf-canon'
190+
and I have a 'eddsa public key'
191+
and I have a 'eddsa signature'
192+
193+
When I create the hash of 'proof rdf-canon'
194+
and rename 'hash' to 'proof hash'
195+
and I create the hash of 'document rdf-canon'
196+
and rename 'hash' to 'document hash'
197+
and I append 'document hash' to 'proof hash'
198+
199+
When I verify 'proof hash' has a eddsa signature in 'eddsa signature' by 'eddsa public key'
200+
201+
Then print the string 'VALID DOC PROOF'
202+
EOF
203+
slexe ${SRC}/${contract}
204+
cat $TMP/out | >&3 jq .
205+
206+
}

sign_mldsa-rdfc-2025.bats renamed to mldsa-rdfc-2025.bats

+65-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
# A.1 Representation: mldsa-rdfc-2025, with fips203 (dilithium2)
1919

20-
setup() {
20+
function setup() {
2121
load bats/setup
22-
algo=mldsa
22+
}
23+
24+
function setup_file() {
25+
export algo=mldsa
26+
rm -f src/${algo}_exec_log.md
2327
}
2428

2529
@test "Create the keyring and document" {
@@ -122,3 +126,62 @@ EOF
122126
slexe $SRC/${contract}
123127
# cat $SRC/${contract}.out.json | >&3 jq .
124128
}
129+
130+
131+
@test "Prepare the document signature verification" {
132+
export contract=${algo}_prepare-verification-signed-doc
133+
input data $SRC/${algo}_hash-and-sign.out.json
134+
input keys $SRC/${algo}_keyring.out.json
135+
cat <<EOF > $SRC/${contract}.slang
136+
rule output encoding base64
137+
Scenario qp
138+
Given I have a 'keyring'
139+
and I have a 'dictionary' named 'document'
140+
and I have a 'base58' part of path 'document.proof.proofValue' after string prefix 'z'
141+
and I have a 'dictionary' in path 'document.proof'
142+
143+
When I rename 'proofValue' to 'mldsa44 signature'
144+
and I remove 'proofValue' from 'proof'
145+
and I remove 'proof' from 'document'
146+
and I create copy of '@context' from 'document'
147+
and I rename 'copy' to '@context'
148+
and I move '@context' in 'proof'
149+
and I create the mldsa44 public key
150+
151+
Then print the 'mldsa44 signature' as 'base64'
152+
and print the 'proof'
153+
and print the 'document'
154+
and print the 'mldsa44 public key'
155+
156+
Compute 'proof rdf-canon': generate serialized canonical rdf with dictionary 'proof'
157+
Compute 'document rdf-canon': generate serialized canonical rdf with dictionary 'document'
158+
EOF
159+
slexe $SRC/${contract}
160+
# cat $TMP/out | >&3 jq .
161+
}
162+
163+
@test "Verify the signature" {
164+
export contract=${algo}_verify-prepared-signed-doc
165+
input data $SRC/${algo}_prepare-verification-signed-doc.out.json
166+
input keys /dev/null
167+
cat <<EOF > ${SRC}/${contract}.slang
168+
Scenario qp
169+
Given I have a 'base64' named 'document rdf-canon'
170+
and I have a 'base64' named 'proof rdf-canon'
171+
and I have a 'mldsa44 public key'
172+
and I have a 'mldsa44 signature'
173+
174+
When I create the hash of 'proof rdf-canon'
175+
and rename 'hash' to 'proof hash'
176+
and I create the hash of 'document rdf-canon'
177+
and rename 'hash' to 'document hash'
178+
and I append 'document hash' to 'proof hash'
179+
180+
When I verify 'proof hash' has a mldsa44 signature in 'mldsa44 signature' by 'mldsa44 public key'
181+
182+
Then print the string 'VALID DOC PROOF'
183+
EOF
184+
slexe ${SRC}/${contract}
185+
cat $TMP/out | >&3 jq .
186+
187+
}

0 commit comments

Comments
 (0)