mirror of
https://github.com/fluencelabs/fluence-VRF
synced 2025-04-24 14:52:13 +00:00
add reveal method
This commit is contained in:
parent
119c421e39
commit
b68d2e08e4
36
bls/main.cpp
36
bls/main.cpp
@ -53,12 +53,28 @@ struct pub_key_type {
|
||||
int len;
|
||||
};
|
||||
|
||||
struct signature_type {
|
||||
char *data;
|
||||
int len;
|
||||
};
|
||||
|
||||
struct hash_type {
|
||||
char *data;
|
||||
int len;
|
||||
};
|
||||
|
||||
|
||||
struct Game {
|
||||
bool new_game(int n) {
|
||||
len = 0;
|
||||
players = (char**)malloc(sizeof(char*) * n);
|
||||
stakes = (int*)malloc(sizeof(int) * n);
|
||||
game_id = game_id_autoinc++;
|
||||
signs = (signature_type*)malloc(sizeof(signature_type) * n);
|
||||
reveals = 0;
|
||||
threshold = n * 2 / 3 + 1;
|
||||
winner = -1;
|
||||
|
||||
|
||||
state = STATE_GATHERING_STAKES;
|
||||
return true;
|
||||
@ -107,6 +123,26 @@ struct Game {
|
||||
return state;
|
||||
}
|
||||
|
||||
bool reveal(pub_key_type pub_key, hash_type game_id_hash, signature_type sign) {
|
||||
blsSignature s;
|
||||
blsPublicKey pk;
|
||||
|
||||
mclBnG1_setStr(&s.v, sign.data, sign.len, 512);
|
||||
mclBnG2_setStr(&pk.v, pub_key.data, pub_key.len, 0);
|
||||
|
||||
if (!blsVerify(&s, &pk, game_id_hash.data, game_id_hash.len)) {
|
||||
return;
|
||||
}
|
||||
|
||||
signs[reveals++] = sign;
|
||||
|
||||
if (reveals == threshold) {
|
||||
winner = players[blsAggregate(signs, reveals)];
|
||||
}
|
||||
|
||||
state = STATE_DONE;
|
||||
}
|
||||
|
||||
private:
|
||||
bool compare(char *a, char *b, int len) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user