Download engine.cpp from UPNISO/apex-coin: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/UPNISO/apex-coin/resolve/main/engine.cpp
- Command line
-
hf download hf://spaces/UPNISO/apex-coin/engine.cpp
-
curl -L -o engine.cpp https://huggingface.co/spaces/UPNISO/apex-coin/resolve/main/engine.cpp
1.89 kB
| using namespace std; | |
| /* | |
| FLASKIO Math Engine (PoI Validator) | |
| - Deterministic | |
| - Session-bound | |
| - Replay-safe | |
| */ | |
| string sha256(const string& input) { | |
| unsigned char hash[SHA256_DIGEST_LENGTH]; | |
| SHA256((unsigned char*)input.c_str(), input.size(), hash); | |
| char output[65]; | |
| for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { | |
| sprintf(output + (i * 2), "%02x", hash[i]); | |
| } | |
| output[64] = 0; | |
| return string(output); | |
| } | |
| // Simulates deterministic 800-question verification | |
| bool verify_flaskio_block( | |
| const string& wallet, | |
| const string& session_nonce, | |
| const string& user_solution | |
| ) { | |
| if (user_solution.empty()) return false; | |
| if (user_solution.length() < 128) return false; | |
| // Deterministic seed (Ledger can recompute this) | |
| string seed = sha256(wallet + session_nonce); | |
| // Simulate 300 math + 500 logic checks | |
| int score = 0; | |
| for (int i = 0; i < 800; i++) { | |
| string q = sha256(seed + to_string(i)); | |
| if (user_solution.find(q.substr(0, 4)) != string::npos) { | |
| score++; | |
| } | |
| } | |
| return score >= 800; // Must solve all | |
| } | |
| int main(int argc, char* argv[]) { | |
| // Docker healthcheck | |
| if (argc == 1) { | |
| cout << "FLASKIO_ENGINE_READY" << endl; | |
| return 0; | |
| } | |
| if (argc < 4) { | |
| cerr << "Usage: ./flaskio_engine [wallet] [session_nonce] [solution]" << endl; | |
| return 1; | |
| } | |
| string wallet = argv[1]; | |
| string session_nonce = argv[2]; | |
| string solution = argv[3]; | |
| if (!verify_flaskio_block(wallet, session_nonce, solution)) { | |
| cout << "INVALID" << endl; | |
| return 1; | |
| } | |
| // Proof hash (submitted to Ledger) | |
| string proof = sha256(wallet + session_nonce + solution); | |
| cout << "VALID" << endl; | |
| cout << proof << endl; | |
| return 0; | |
| } | |