Skip to content

Commit b5a9ba0

Browse files
authored
F/public randomness ts (#128)
1 parent be85fb1 commit b5a9ba0

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

contracts/op-finality-gadget/schema/op-finality-gadget.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@
500500
"type": "object",
501501
"required": [
502502
"commitment",
503+
"height",
503504
"num_pub_rand",
504505
"start_height"
505506
],
@@ -513,6 +514,12 @@
513514
"minimum": 0.0
514515
}
515516
},
517+
"height": {
518+
"description": "`height` defines the height that the commit was submitted",
519+
"type": "integer",
520+
"format": "uint64",
521+
"minimum": 0.0
522+
},
516523
"num_pub_rand": {
517524
"description": "`num_pub_rand` is the number of committed public randomness",
518525
"type": "integer",
@@ -552,6 +559,7 @@
552559
"type": "object",
553560
"required": [
554561
"commitment",
562+
"height",
555563
"num_pub_rand",
556564
"start_height"
557565
],
@@ -565,6 +573,12 @@
565573
"minimum": 0.0
566574
}
567575
},
576+
"height": {
577+
"description": "`height` defines the height that the commit was submitted",
578+
"type": "integer",
579+
"format": "uint64",
580+
"minimum": 0.0
581+
},
568582
"num_pub_rand": {
569583
"description": "`num_pub_rand` is the number of committed public randomness",
570584
"type": "integer",

contracts/op-finality-gadget/schema/raw/response_to_first_pub_rand_commit.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"type": "object",
1616
"required": [
1717
"commitment",
18+
"height",
1819
"num_pub_rand",
1920
"start_height"
2021
],
@@ -28,6 +29,12 @@
2829
"minimum": 0.0
2930
}
3031
},
32+
"height": {
33+
"description": "`height` defines the height that the commit was submitted",
34+
"type": "integer",
35+
"format": "uint64",
36+
"minimum": 0.0
37+
},
3138
"num_pub_rand": {
3239
"description": "`num_pub_rand` is the number of committed public randomness",
3340
"type": "integer",

contracts/op-finality-gadget/schema/raw/response_to_last_pub_rand_commit.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"type": "object",
1616
"required": [
1717
"commitment",
18+
"height",
1819
"num_pub_rand",
1920
"start_height"
2021
],
@@ -28,6 +29,12 @@
2829
"minimum": 0.0
2930
}
3031
},
32+
"height": {
33+
"description": "`height` defines the height that the commit was submitted",
34+
"type": "integer",
35+
"format": "uint64",
36+
"minimum": 0.0
37+
},
3138
"num_pub_rand": {
3239
"description": "`num_pub_rand` is the number of committed public randomness",
3340
"type": "integer",

contracts/op-finality-gadget/src/contract.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub fn execute(
6666
signature,
6767
} => handle_public_randomness_commit(
6868
deps,
69+
&env,
6970
&fp_pubkey_hex,
7071
start_height,
7172
num_pub_rand,

contracts/op-finality-gadget/src/exec/finality.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use k256::sha2::{Digest, Sha256};
2323
// Most logic copied from contracts/btc-staking/src/finality.rs
2424
pub fn handle_public_randomness_commit(
2525
deps: DepsMut,
26+
env: &Env,
2627
fp_pubkey_hex: &str,
2728
start_height: u64,
2829
num_pub_rand: u64,
@@ -62,6 +63,7 @@ pub fn handle_public_randomness_commit(
6263
let pr_commit = PubRandCommit {
6364
start_height,
6465
num_pub_rand,
66+
height: env.block.height,
6567
commitment: commitment.to_vec(),
6668
};
6769

@@ -396,28 +398,11 @@ pub(crate) mod tests {
396398
use cosmwasm_std::{from_json, testing::message_info};
397399
use std::collections::HashMap;
398400

399-
use babylon_apis::finality_api::PubRandCommit;
400-
use hex::ToHex;
401401
use test_utils::{
402-
get_add_finality_sig, get_add_finality_sig_2, get_pub_rand_commit, get_pub_rand_value,
402+
get_add_finality_sig, get_add_finality_sig_2, get_pub_rand_value,
403+
get_public_randomness_commitment,
403404
};
404405

405-
/// Get public randomness public key, commitment, and signature information
406-
///
407-
/// Signature is a Schnorr signature over the commitment
408-
pub(crate) fn get_public_randomness_commitment() -> (String, PubRandCommit, Vec<u8>) {
409-
let pub_rand_commitment_msg = get_pub_rand_commit();
410-
(
411-
pub_rand_commitment_msg.fp_btc_pk.encode_hex(),
412-
PubRandCommit {
413-
start_height: pub_rand_commitment_msg.start_height,
414-
num_pub_rand: pub_rand_commitment_msg.num_pub_rand,
415-
commitment: pub_rand_commitment_msg.commitment.to_vec(),
416-
},
417-
pub_rand_commitment_msg.sig.to_vec(),
418-
)
419-
}
420-
421406
#[test]
422407
fn verify_commitment_signature_works() {
423408
// Define test values

0 commit comments

Comments
 (0)