From 40d40bc57be288981811e41e63c51808d6e4c9f2 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sat, 18 Apr 2026 19:46:45 +0200 Subject: [PATCH] update targets --- scripts/deploy.pl | 15 +-- targets/lib.h | 11 ++ .../wasm-module/{sum.cpp => sum0_base.cpp} | 20 ++- targets/wasm-module/sum1_repl_naive_late.cpp | 58 +++++++++ .../{cored.cpp => sum2_repl_cored_late.cpp} | 26 ++-- targets/wasm-module/sum3_repl_naive_early.cpp | 58 +++++++++ targets/wasm-module/sum4_repl_cored_early.cpp | 117 ++++++++++++++++++ 7 files changed, 269 insertions(+), 36 deletions(-) rename targets/wasm-module/{sum.cpp => sum0_base.cpp} (57%) create mode 100644 targets/wasm-module/sum1_repl_naive_late.cpp rename targets/wasm-module/{cored.cpp => sum2_repl_cored_late.cpp} (89%) create mode 100644 targets/wasm-module/sum3_repl_naive_early.cpp create mode 100644 targets/wasm-module/sum4_repl_cored_early.cpp diff --git a/scripts/deploy.pl b/scripts/deploy.pl index 0299869..7e34d77 100755 --- a/scripts/deploy.pl +++ b/scripts/deploy.pl @@ -64,8 +64,6 @@ my $ssh = Net::OpenSSH->new( $ssh->error and die 'SSH connection failed: ' . $ssh->error; say 'Connected to mars.cs.tu-dortmund.de'; -# TODO: Abort if old experiments are still on the server => meaning they're not archived - # Pull changes # remote( $ssh, 'git', '-C', $remote_root, 'pull' ); # TODO: Requires auth @@ -111,18 +109,7 @@ foreach (@experiments) { or die "Failed to create database: " . $dbh->errstr; } -# Kill old screen session (don't check success as a session might not exist) -# say "Killing previous screen session with name $screen_name"; -# $ssh->system( "screen", "-XS", $screen_name, "quit" ); - -# Start new screen session -# my $invoke_runner = -# "cd " . shell_quote($remote_root) . " && perl " . shell_quote($remote_runner); -# say -# "Starting new screen session with name $screen_name and command $invoke_runner"; -# remote( $ssh, "screen", "-dmS", $screen_name, "sh", "-lc", -# "exec $invoke_runner" ); - +# Launch remote runner remote( $ssh, "nohup sh -c " . shell_quote("cd $remote_root && perl $remote_runner") . " >" diff --git a/targets/lib.h b/targets/lib.h index d34102f..2df7421 100644 --- a/targets/lib.h +++ b/targets/lib.h @@ -1,6 +1,8 @@ #ifndef _include_fail_h #define _include_fail_h +#include + #define INLINE __attribute__((always_inline)) inline #define NOINLINE __attribute__((noinline)) @@ -44,6 +46,15 @@ #define RET(val) return val; #endif +typedef uint16_t enc_t; +typedef uint8_t plain_t; +typedef int8_t sign_t; + +#define check(vc, A, B) (((vc - B) % A) == 0) +#define encode(v, A, B) ((((plain_t)v) * ((sign_t)A)) + ((sign_t)B)) +#define decode(vc, A, B) ((vc - B) / A) +#define equals(vc1, vc2, B1, B2) ((vc1 - vc2) == (B1 - B2)) + #ifdef __cplusplus extern "C" { #endif diff --git a/targets/wasm-module/sum.cpp b/targets/wasm-module/sum0_base.cpp similarity index 57% rename from targets/wasm-module/sum.cpp rename to targets/wasm-module/sum0_base.cpp index 7d972fb..b4eefe7 100644 --- a/targets/wasm-module/sum.cpp +++ b/targets/wasm-module/sum0_base.cpp @@ -1,16 +1,30 @@ #include "../lib.h" -extern "C" EXPORT("wasm_module") int wasm_module(void) { - fail_start_trace(); +#define REPLICA_COUNT 1 +static plain_t sum_out[REPLICA_COUNT]; + +#define X sum_out[0] + +template static INLINE void sum(void) { int sum = 0; for (int i = 0; i < 100; ++i) { sum += 1; } + sum_out[N] = sum; +} + +extern "C" EXPORT("wasm_module") int wasm_module(void) { + X = 0; + + fail_start_trace(); + + sum<0>(); + fail_stop_trace(); - if (sum == 100) { + if (X == 100) { fail_marker_positive(); return 0; } else { diff --git a/targets/wasm-module/sum1_repl_naive_late.cpp b/targets/wasm-module/sum1_repl_naive_late.cpp new file mode 100644 index 0000000..c85c6b4 --- /dev/null +++ b/targets/wasm-module/sum1_repl_naive_late.cpp @@ -0,0 +1,58 @@ +#include "../lib.h" + +#define REPLICA_COUNT 3 + +static plain_t vote_res; +static plain_t sum_out[REPLICA_COUNT]; + +#define XC sum_out[0] +#define YC sum_out[1] +#define ZC sum_out[2] + +// The prints here can't happen because they're disabled under test ¯\_(ツ)_/¯ + +static void naive_vote(void) { + if (XC == YC || XC == ZC) { + vote_res = XC; + } else if (YC == ZC) { + vote_res = YC; + } else { + HOST_PRINT("all replicas differ.\n"); + fail_marker_detected(); + } +} + +template static INLINE void sum(void) { + int sum = 0; + for (int i = 0; i < 100; ++i) { + sum += 1; + } + + sum_out[N] = sum; +} + +extern "C" EXPORT("wasm_module") int wasm_module(void) { + XC = 0; + YC = 0; + ZC = 0; + + sum<0>(); + sum<1>(); + sum<2>(); + + fail_start_trace(); + + naive_vote(); + + fail_stop_trace(); + + if (vote_res == 100) { + HOST_PRINT("vote success.\n"); + fail_marker_positive(); + return 0; + } else { + HOST_PRINT("undetected error.\n"); + fail_marker_negative(); + return 1; + } +} diff --git a/targets/wasm-module/cored.cpp b/targets/wasm-module/sum2_repl_cored_late.cpp similarity index 89% rename from targets/wasm-module/cored.cpp rename to targets/wasm-module/sum2_repl_cored_late.cpp index b8ad4fc..abe4edc 100644 --- a/targets/wasm-module/cored.cpp +++ b/targets/wasm-module/sum2_repl_cored_late.cpp @@ -1,19 +1,5 @@ -#include - #include "../lib.h" -typedef uint16_t enc_t; -typedef uint8_t plain_t; -typedef int8_t sign_t; - -#define REPLICA_COUNT 3 - -#define check(vc, A, B) (((vc - B) % A) == 0) -#define encode(v, A, B) ((((plain_t)v) * ((sign_t)A)) + ((sign_t)B)) -#define decode(vc, A, B) ((vc - B) / A) - -#define equals(vc1, vc2, B1, B2) ((vc1 - vc2) == (B1 - B2)) - #define THE_A 110 // CONSTANT Replica results signatures @@ -28,13 +14,15 @@ typedef int8_t sign_t; #define SIG_s_YZ (SIG_Y - SIG_Z) #define SIG_s_XZ (SIG_X - SIG_Z) -#define XC sum_out[0] -#define YC sum_out[1] -#define ZC sum_out[2] +#define REPLICA_COUNT 3 static enc_t cored_res; static enc_t sum_out[REPLICA_COUNT]; +#define XC sum_out[0] +#define YC sum_out[1] +#define ZC sum_out[2] + // The prints here can't happen because they're disabled under test ¯\_(ツ)_/¯ static INLINE enc_t apply(enc_t vc, sign_t bdyn) { @@ -81,12 +69,12 @@ extern "C" EXPORT("wasm_module") int wasm_module(void) { YC = 0; ZC = 0; - fail_start_trace(); - sum<0, SIG_X>(); sum<1, SIG_Y>(); sum<2, SIG_Z>(); + fail_start_trace(); + sign_t static_sig = cored_vote(); fail_stop_trace(); diff --git a/targets/wasm-module/sum3_repl_naive_early.cpp b/targets/wasm-module/sum3_repl_naive_early.cpp new file mode 100644 index 0000000..57c9ee2 --- /dev/null +++ b/targets/wasm-module/sum3_repl_naive_early.cpp @@ -0,0 +1,58 @@ +#include "../lib.h" + +#define REPLICA_COUNT 3 + +static plain_t vote_res; +static plain_t sum_out[REPLICA_COUNT]; + +#define XC sum_out[0] +#define YC sum_out[1] +#define ZC sum_out[2] + +// The prints here can't happen because they're disabled under test ¯\_(ツ)_/¯ + +static void naive_vote(void) { + if (XC == YC || XC == ZC) { + vote_res = XC; + } else if (YC == ZC) { + vote_res = YC; + } else { + HOST_PRINT("all replicas differ.\n"); + fail_marker_detected(); + } +} + +template static INLINE void sum(void) { + int sum = 0; + for (int i = 0; i < 100; ++i) { + sum += 1; + } + + sum_out[N] = sum; +} + +extern "C" EXPORT("wasm_module") int wasm_module(void) { + XC = 0; + YC = 0; + ZC = 0; + + fail_start_trace(); + + sum<0>(); + sum<1>(); + sum<2>(); + + naive_vote(); + + fail_stop_trace(); + + if (vote_res == 100) { + HOST_PRINT("vote success.\n"); + fail_marker_positive(); + return 0; + } else { + HOST_PRINT("undetected error.\n"); + fail_marker_negative(); + return 1; + } +} diff --git a/targets/wasm-module/sum4_repl_cored_early.cpp b/targets/wasm-module/sum4_repl_cored_early.cpp new file mode 100644 index 0000000..c0e6f87 --- /dev/null +++ b/targets/wasm-module/sum4_repl_cored_early.cpp @@ -0,0 +1,117 @@ +#include "../lib.h" + +#define THE_A 110 + +// CONSTANT Replica results signatures +#define SIG_X 32 +#define SIG_Y 23 +#define SIG_Z 67 +#define SIG_MAX SIG_Z + +// CONSTANT Voter Result Signatures +#define SIG_s_XYZ ((SIG_X - SIG_Y) + (SIG_X - SIG_Z)) +#define SIG_s_XY (SIG_X - SIG_Y) +#define SIG_s_YZ (SIG_Y - SIG_Z) +#define SIG_s_XZ (SIG_X - SIG_Z) + +#define REPLICA_COUNT 3 + +static enc_t cored_res; +static enc_t sum_out[REPLICA_COUNT]; + +#define XC sum_out[0] +#define YC sum_out[1] +#define ZC sum_out[2] + +// The prints here can't happen because they're disabled under test ¯\_(ツ)_/¯ + +static INLINE enc_t apply(enc_t vc, sign_t bdyn) { + if (bdyn > SIG_MAX) { + HOST_PRINT("signature overflow.\n"); + fail_marker_detected(); + } + return vc + bdyn; +} + +static sign_t cored_vote(void) { + if (equals(XC, YC, SIG_X, SIG_Y)) { + if (equals(XC, ZC, SIG_X, SIG_Z)) { + cored_res = apply(XC, (XC - YC) + (XC - ZC)); + return SIG_s_XYZ; + } else { + cored_res = apply(XC, (XC - YC)); + return SIG_s_XY; + } + } else if (equals(YC, ZC, SIG_Y, SIG_Z)) { + cored_res = apply(YC, (YC - ZC)); + return SIG_s_YZ; + } else if (equals(XC, ZC, SIG_X, SIG_Z)) { + cored_res = apply(XC, (XC - ZC)); + return SIG_s_XZ; + } else { + HOST_PRINT("all replicas differ.\n"); + fail_marker_detected(); + return 0; + } +} + +template static INLINE void sum(void) { + int sum = 0; + for (int i = 0; i < 100; ++i) { + sum += 1; + } + + sum_out[N] = encode(sum, THE_A, S); +} + +extern "C" EXPORT("wasm_module") int wasm_module(void) { + XC = 0; + YC = 0; + ZC = 0; + + fail_start_trace(); + + sum<0, SIG_X>(); + sum<1, SIG_Y>(); + sum<2, SIG_Z>(); + + sign_t static_sig = cored_vote(); + + fail_stop_trace(); + + sign_t vote_result_sig; + switch (static_sig) { + case SIG_s_XYZ: + case SIG_s_XY: + case SIG_s_XZ: + vote_result_sig = SIG_X; + break; + case SIG_s_YZ: + vote_result_sig = SIG_Y; + break; + default: + HOST_PRINT("unknown static_sig.\n"); + break; + } + + // Inversely apply constant program flow signature. + cored_res -= static_sig; + + /* Validate Vote result */ + if (!check(cored_res, THE_A, vote_result_sig)) { + HOST_PRINT("voted result invalid.\n"); + fail_marker_detected(); + return 2; + } + + plain_t res = decode(cored_res, THE_A, vote_result_sig); + if (res == 100) { + HOST_PRINT("cored success.\n"); + fail_marker_positive(); + return 0; + } else { + HOST_PRINT("undetected error.\n"); + fail_marker_negative(); + return 1; + } +}