do fail interactions inside wasm module + unify host modules + fix cored module

This commit is contained in:
2026-04-13 23:03:54 +02:00
parent fe6c2f5b99
commit 550ce0b079
13 changed files with 283 additions and 370 deletions

View File

@ -1,5 +1,4 @@
#include "../lib.h"
#include "../lib_cored.h"
void fail_start_trace(void) {}
void fail_stop_trace(void) {}
@ -7,47 +6,6 @@ void fail_marker_positive(void) {}
void fail_marker_negative(void) {}
void fail_marker_detected(void) {}
void init_outputs(plain_t x_c, plain_t y_c, plain_t z_c);
int wasm_module(void);
enc_t get_cored_res(void);
void os_main(void) {
init_outputs(100, 142, 100);
fail_start_trace();
sign_t static_sig = wasm_module();
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:
break;
}
// Inversely apply constant program flow signature.
enc_t cored_res = get_cored_res();
cored_res -= static_sig;
/* Validate Vote result */
if (!check(cored_res, THE_A, vote_result_sig)) {
fail_marker_detected();
return;
}
plain_t res = decode(cored_res, THE_A, vote_result_sig);
if (res == 100) {
fail_marker_positive();
return;
} else {
fail_marker_negative();
return;
}
}
void os_main(void) { wasm_module(); }

View File

@ -1,56 +1,16 @@
#include "../lib_cored.h"
#include "../lib.h"
#include <stdio.h>
void init_outputs(plain_t x_c, plain_t y_c, plain_t z_c);
int wasm_module(void);
enc_t get_cored_res(void);
void fail_start_trace(void) {}
void fail_stop_trace(void) {}
void fail_marker_positive(void) {}
void fail_marker_negative(void) {}
void fail_marker_detected(void) {}
int wasm_module(void);
int main(int argc, char *argv[]) {
init_outputs(100, 142, 100);
sign_t static_sig = wasm_module();
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:
// printf("ERROR: Unknown static_sig %d\n", static_sig);
break;
}
// Inversely apply constant program flow signature.
enc_t cored_res = get_cored_res();
printf("Inversely apply: cored_res=%d static_sig=%d\n", cored_res,
static_sig);
cored_res -= static_sig;
/* Validate Vote result */
printf(
"Validating vote result: cored_res=%d THE_A=%d vote_result_sig = % d\n ",
cored_res, THE_A, vote_result_sig);
if (!check(cored_res, THE_A, vote_result_sig)) {
printf("Validation failed :(\n");
// fail_marker_detected();
return 1;
}
plain_t res = decode(cored_res, THE_A, vote_result_sig);
// printf("Decoded result: %d (%f)\n", res, q_to_float(res));
if (res == 100) {
// fail_marker_positive();
printf("Marker Positive\n");
return 0;
} else {
printf("Marker Negative\n");
// fail_marker_negative();
return 1;
}
int retval = wasm_module();
printf("Function returned %d.\n", retval);
return retval;
}