Skip to content

Commit 924072b

Browse files
committed
generate execution graphs
1 parent f18c689 commit 924072b

11 files changed

+80
-26
lines changed

.github/workflows/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
with:
3232
install: true
3333
cache: false
34+
- name: install graphviz
35+
run: |
36+
sudo apt-get -qy install graphviz
3437
- name: slangroom tests
3538
run: |
3639
ln -s `mise which slangroom-exec` bin/slangroom-exec

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# bin/slexfe
22
bin/slangroom-exec
33
src/*.json
4+
src/*.svg
45
*.orig
56
*.rdf
67
*.slang

bats/setup

+46-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ slexe() {
4242
}
4343
# run bats_pipe bash bin/slexfe -F $1 \| slangroom-exec
4444
>&3 echo " 🔥 `basename ${1}.slang`"
45+
local start_time_s=$(date +%s)
46+
local start_time_ns=$(date +%N)
4547
bash bin/slexfe -F $1 \
4648
| slangroom-exec \
4749
1>$TMP/out 2> >(tee $TMP/err | grep -v 'J64 ' >&2)
4850
local res=$?
51+
local end_time_s=$(date +%s)
52+
local end_time_ns=$(date +%N)
4953
export output=`cat $TMP/out`
5054
[ "$res" != 0 ] && {
5155
>&2 echo "TRACE:"
@@ -60,11 +64,52 @@ slexe() {
6064
_err "Output is missing, no result from previous computation" | tee -a $TMP/err
6165
exit 1
6266
}
67+
# Avoid leading zero issues by normalizing inputs
68+
start_time_s=$((10#$start_time_s))
69+
start_time_ns=$((10#$start_time_ns))
70+
end_time_s=$((10#$end_time_s))
71+
end_time_ns=$((10#$end_time_ns))
72+
# Convert and calculate elapsed time in milliseconds
73+
local start_time_ms=$((start_time_s * 1000 + start_time_ns / 1000000))
74+
local end_time_ms=$((end_time_s * 1000 + end_time_ns / 1000000))
75+
local execution_time_ms=$((end_time_ms - start_time_ms))
6376
rm -f "${1}.out.json"
6477
echo "$output" > "${1}.out.json"
6578
>&3 echo " 💾 `basename ${1}.out.json`"
6679
>&3 echo ""
6780
set -e
81+
if [ -L $1.data.json ]; then
82+
idata=`readlink $1.data.json`
83+
local size=$(stat --format="%s" "$idata") # Get file size in bytes
84+
idata="`basename $idata`\n\n$size bytes"
85+
else
86+
idata="null\n\n0 bytes"
87+
fi
88+
if [ -L $1.keys.json ]; then
89+
ikeys=`readlink $1.keys.json`
90+
local size=$(stat --format="%s" "$ikeys") # Get file size in bytes
91+
ikeys="`basename $ikeys`\n\n$size bytes"
92+
else
93+
ikeys="null\n\n0 bytes"
94+
fi
95+
# size_kilobytes=$(echo "scale=2; $size / 1024" | bc)
96+
iout="`basename $1`\n\n$(stat --format="%s" "$1.out.json") bytes"
97+
cat <<EOF | dot -Tsvg -o ${1}.svg
98+
digraph G {
99+
rankdir=LR;
100+
node [shape=box, style=rounded, fontname="Arial", fontsize=12, color=black, fillcolor=lightgray, margin=0.2];
101+
bgcolor=transparent;
102+
edge [arrowsize=0.8];
103+
Input1 [label="$idata"];
104+
Input2 [label="$ikeys"];
105+
Script [shape=ellipse, label="zencode_exec\n\ntime: $execution_time_ms ms"];
106+
Output [label="$iout"];
107+
Input1 -> Script;
108+
Input2 -> Script;
109+
Script -> Output;
110+
edge [color=black, arrowsize=0.7];
111+
}
112+
EOF
68113
}
69114

70115
save_output() {
@@ -78,7 +123,7 @@ save_output() {
78123
>&3 echo " 💾 > `basename $1`"
79124
}
80125

81-
prepare() {
126+
input() {
82127
[ -r "$2" ] || {
83128
_err "Input file not found: $2" | tee -a $TMP/err
84129
exit 1

sign_ecdsa-rdfc-2019.bats

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ EOF
5858
}
5959
EOF
6060
export contract="ecdsa_rdf-canon-objects"
61-
prepare data $SRC/unsecuredDocument.data.json
62-
prepare keys $SRC/${algo}_keyring.out.json
61+
input data $SRC/unsecuredDocument.data.json
62+
input keys $SRC/${algo}_keyring.out.json
6363
cat <<EOF > $SRC/${contract}.slang
6464
rule unknown ignore
6565
Given I have a 'string dictionary' named 'unsecuredDocument'
@@ -89,8 +89,8 @@ EOF
8989

9090
@test "Create the signature" {
9191
export contract=${algo}_hash-and-sign
92-
prepare data $SRC/${algo}_rdf-canon-objects.out.json
93-
prepare keys $SRC/${algo}_keyring.out.json
92+
input data $SRC/${algo}_rdf-canon-objects.out.json
93+
input keys $SRC/${algo}_keyring.out.json
9494
cat <<EOF > $SRC/${contract}.slang
9595
Scenario es256
9696
Given I have a 'keyring'

sign_eddsa-rdfc-2022.bats

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ EOF
6060
}
6161
EOF
6262
export contract=${algo}_rdf-canon-objects
63-
prepare data $SRC/unsecuredDocument.data.json
64-
prepare keys $SRC/${algo}_keyring.out.json
63+
input data $SRC/unsecuredDocument.data.json
64+
input keys $SRC/${algo}_keyring.out.json
6565
cat <<EOF > $SRC/${algo}_rdf-canon-objects.slang
6666
rule unknown ignore
6767
Given I have a 'string dictionary' named 'unsecuredDocument'
@@ -91,8 +91,8 @@ EOF
9191

9292
@test "Create the signature" {
9393
export contract=${algo}_hash-and-sign
94-
prepare data $SRC/${algo}_rdf-canon-objects.out.json
95-
prepare keys $SRC/${algo}_keyring.out.json
94+
input data $SRC/${algo}_rdf-canon-objects.out.json
95+
input keys $SRC/${algo}_keyring.out.json
9696
cat <<EOF > $SRC/${algo}_hash-and-sign.slang
9797
Scenario eddsa
9898
Given I have a 'keyring'

sign_mldsa-rdfc-2025.bats

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ EOF
5757
}
5858
EOF
5959
export contract="${algo}_rdf-canon-objects"
60-
prepare data $SRC/unsecuredDocument.data.json
61-
prepare keys $SRC/${algo}_keyring.out.json
60+
input data $SRC/unsecuredDocument.data.json
61+
input keys $SRC/${algo}_keyring.out.json
6262
cat <<EOF > $SRC/${contract}.slang
6363
rule unknown ignore
6464
Given I have a 'string dictionary' named 'unsecuredDocument'
@@ -88,8 +88,8 @@ EOF
8888

8989
@test "Create the signature" {
9090
export contract=${algo}_hash-and-sign
91-
prepare data $SRC/${algo}_rdf-canon-objects.out.json
92-
prepare keys $SRC/${algo}_keyring.out.json
91+
input data $SRC/${algo}_rdf-canon-objects.out.json
92+
input keys $SRC/${algo}_keyring.out.json
9393
cat <<EOF > $SRC/${contract}.slang
9494
Scenario qp
9595
Given I have a 'keyring'

src/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ hero:
1111
alt: Hands-on, Dyne.org style
1212
actions:
1313
- theme: brand
14-
text: 💥 MLDSA (Post-Quantum)
14+
text: MLDSA (Post-Quantum)
1515
link: /mldsa-w3c-vc
1616
- theme: alt
1717
text: ECDSA (P256)

src/mldsa-w3c-vc.md

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Conforming to:
1313
## Generate keys
1414

1515
<<< @/mldsa_keyring.slang{gherkin}
16+
![](mldsa_keyring.svg)
1617

1718
### Output
1819

@@ -37,6 +38,7 @@ Results in both private and public keys, which can also be generated in two sepa
3738
### Zencode
3839

3940
<<< @/mldsa_rdf-canon-objects.slang{gherkin}
41+
![](mldsa_rdf-canon-objects.svg)
4042

4143
### Output
4244

@@ -57,6 +59,7 @@ Results in seralized canonical RDF versions of the document and signature settin
5759
### Zencode
5860

5961
<<< @/mldsa_hash-and-sign.slang{gherkin}
62+
![](mldsa_hash-and-sign.svg)
6063

6164
### 💾 Output
6265

@@ -73,6 +76,7 @@ Results in seralized canonical RDF versions of the document and signature settin
7376
### Zencode
7477

7578
<<< @/mldsa_prepare-verification-signed-doc.slang{gherkin}
79+
![](mldsa_prepare-verification-signed-doc.svg)
7680

7781
### Output
7882

@@ -89,6 +93,7 @@ Results again in serialized canonical RDF version of the document and signature
8993
### Zencode
9094

9195
<<< @/mldsa_verify-prepared-signed-doc.slang{gherkin}
96+
![](mldsa_verify-prepared-signed-doc.svg)
9297

9398
### Output
9499

verify_ecdsa-rdfc-2019.bats

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ setup() {
2525

2626
@test "Prepare the document signature verification" {
2727
export contract=${algo}_prepare-verification-signed-doc
28-
prepare data $SRC/${algo}_hash-and-sign.out.json
29-
prepare keys $SRC/${algo}_keyring.out.json
28+
input data $SRC/${algo}_hash-and-sign.out.json
29+
input keys $SRC/${algo}_keyring.out.json
3030
cat <<EOF > $SRC/${contract}.slang
3131
rule output encoding base64
3232
Scenario es256
@@ -57,8 +57,8 @@ EOF
5757

5858
@test "Verify the signature" {
5959
export contract=${algo}_verify-prepared-signed-doc
60-
prepare data $SRC/${algo}_prepare-verification-signed-doc.out.json
61-
prepare keys /dev/null
60+
input data $SRC/${algo}_prepare-verification-signed-doc.out.json
61+
input keys /dev/null
6262
cat <<EOF > ${SRC}/${contract}.slang
6363
Scenario es256
6464
Given I have a 'base64' named 'document rdf-canon'

verify_eddsa-rdfc-2022.bats

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ setup() {
2525

2626
@test "Prepare the document signature verification" {
2727
export contract=${algo}_prepare-verification-signed-doc
28-
prepare data $SRC/${algo}_hash-and-sign.out.json
29-
prepare keys $SRC/${algo}_keyring.out.json
28+
input data $SRC/${algo}_hash-and-sign.out.json
29+
input keys $SRC/${algo}_keyring.out.json
3030
cat <<EOF > $SRC/${contract}.slang
3131
Scenario eddsa
3232
Given I have a 'keyring'
@@ -56,8 +56,8 @@ EOF
5656

5757
@test "Verify the signature" {
5858
export contract=${algo}_verify-prepared-signed-doc
59-
prepare data $SRC/${algo}_prepare-verification-signed-doc.out.json
60-
prepare keys /dev/null
59+
input data $SRC/${algo}_prepare-verification-signed-doc.out.json
60+
input keys /dev/null
6161
cat <<EOF > ${SRC}/${contract}.slang
6262
Scenario eddsa
6363
Given I have a 'base64' named 'document rdf-canon'

verify_mldsa-rdfc-2025.bats

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ setup() {
2424

2525
@test "Prepare the document signature verification" {
2626
export contract=${algo}_prepare-verification-signed-doc
27-
prepare data $SRC/${algo}_hash-and-sign.out.json
28-
prepare keys $SRC/${algo}_keyring.out.json
27+
input data $SRC/${algo}_hash-and-sign.out.json
28+
input keys $SRC/${algo}_keyring.out.json
2929
cat <<EOF > $SRC/${contract}.slang
3030
rule output encoding base64
3131
Scenario qp
@@ -56,8 +56,8 @@ EOF
5656

5757
@test "Verify the signature" {
5858
export contract=${algo}_verify-prepared-signed-doc
59-
prepare data $SRC/${algo}_prepare-verification-signed-doc.out.json
60-
prepare keys /dev/null
59+
input data $SRC/${algo}_prepare-verification-signed-doc.out.json
60+
input keys /dev/null
6161
cat <<EOF > ${SRC}/${contract}.slang
6262
Scenario qp
6363
Given I have a 'base64' named 'document rdf-canon'

0 commit comments

Comments
 (0)