unify host programs across targets

This commit is contained in:
2026-04-16 22:36:36 +02:00
parent e73ab0a788
commit 329014aada
11 changed files with 226 additions and 346 deletions

View File

@ -35,8 +35,11 @@ typedef int8_t sign_t;
static enc_t cored_res;
static enc_t sum_out[REPLICA_COUNT];
// 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;
@ -58,6 +61,7 @@ static sign_t cored_vote(void) {
cored_res = apply(XC, (XC - ZC));
return SIG_s_XZ;
} else {
HOST_PRINT("all replicas differ.\n");
fail_marker_detected();
return 0;
}
@ -72,15 +76,11 @@ template <const unsigned int N, const sign_t S> static INLINE void sum(void) {
sum_out[N] = encode(sum, THE_A, S);
}
extern "C" int wasm_module(void) {
extern "C" EXPORT("wasm_module") int wasm_module(void) {
XC = 0;
YC = 0;
ZC = 0;
// TODO: Start trace from WASM?
// - Simpler, as only a single wasm function has to be called for all
// modules
// - Doesn't inject wasm_runtime_call_wasm() setup
fail_start_trace();
sum<0, SIG_X>();
@ -102,6 +102,7 @@ extern "C" int wasm_module(void) {
vote_result_sig = SIG_Y;
break;
default:
HOST_PRINT("unknown static_sig.\n");
break;
}
@ -110,15 +111,18 @@ extern "C" int wasm_module(void) {
/* 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;
}