Skip to content

Commit c6bdfd6

Browse files
authored
f/TODOs annotation (#135)
Closes #116
1 parent b5a9ba0 commit c6bdfd6

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn execute(
7878
height,
7979
pub_rand,
8080
proof,
81-
block_hash,
81+
block_hash: block_app_hash,
8282
signature,
8383
} => handle_finality_signature(
8484
deps,
@@ -88,7 +88,7 @@ pub fn execute(
8888
height,
8989
&pub_rand,
9090
&proof,
91-
&block_hash,
91+
&block_app_hash,
9292
&signature,
9393
),
9494
ExecuteMsg::Slashing { sender, evidence } => handle_slashing(&sender, &evidence),

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ pub fn handle_finality_signature(
123123
height: u64,
124124
pub_rand: &[u8],
125125
proof: &Proof,
126-
block_hash: &[u8],
126+
block_app_hash: &[u8],
127127
signature: &[u8],
128128
) -> Result<Response<BabylonMsg>, ContractError> {
129129
// Ensure the finality provider exists
130130
check_fp_exist(deps.as_ref(), fp_btc_pk_hex)?;
131131

132-
// TODO: Ensure the finality provider is not slashed at this time point
132+
// TODO: Ensure the finality provider is not slashed at this time point (#82)
133133
// NOTE: It's possible that the finality provider equivocates for height h, and the signature is
134134
// processed at height h' > h. In this case:
135135
// - We should reject any new signature from this finality provider, since it's known to be adversarial.
@@ -177,12 +177,12 @@ pub fn handle_finality_signature(
177177
pub_rand,
178178
proof,
179179
&pr_commit,
180-
block_hash,
180+
block_app_hash,
181181
signature,
182182
)?;
183183

184184
// The public randomness value is good, save it.
185-
// TODO?: Don't save public randomness values, to save storage space
185+
// TODO?: Don't save public randomness values, to save storage space (#122)
186186
PUB_RAND_VALUES.save(deps.storage, (fp_btc_pk_hex, height), &pub_rand.to_vec())?;
187187

188188
// Build the response
@@ -192,9 +192,10 @@ pub fn handle_finality_signature(
192192
// extracting its secret key, and emit an event
193193
let canonical_sig: Option<Vec<u8>> =
194194
SIGNATURES.may_load(deps.storage, (height, fp_btc_pk_hex))?;
195-
let canonical_block_hash: Option<Vec<u8>> =
195+
let canonical_block_app_hash: Option<Vec<u8>> =
196196
BLOCK_HASHES.may_load(deps.storage, (height, fp_btc_pk_hex))?;
197-
if let (Some(canonical_sig), Some(canonical_block_hash)) = (canonical_sig, canonical_block_hash)
197+
if let (Some(canonical_sig), Some(canonical_block_app_hash)) =
198+
(canonical_sig, canonical_block_app_hash)
198199
{
199200
// the finality provider has voted for a fork before!
200201
// If this evidence is at the same height as this signature, slash this finality provider
@@ -204,10 +205,9 @@ pub fn handle_finality_signature(
204205
fp_btc_pk: hex::decode(fp_btc_pk_hex)?,
205206
block_height: height,
206207
pub_rand: pub_rand.to_vec(),
207-
// TODO: we use block hash in place of app hash for now, to define new interface if needed
208-
canonical_app_hash: canonical_block_hash,
208+
canonical_app_hash: canonical_block_app_hash,
209209
canonical_finality_sig: canonical_sig,
210-
fork_app_hash: block_hash.to_vec(),
210+
fork_app_hash: block_app_hash.to_vec(),
211211
fork_finality_sig: signature.to_vec(),
212212
};
213213

@@ -223,23 +223,27 @@ pub fn handle_finality_signature(
223223

224224
// This signature is good, save the vote to the store
225225
SIGNATURES.save(deps.storage, (height, fp_btc_pk_hex), &signature.to_vec())?;
226-
BLOCK_HASHES.save(deps.storage, (height, fp_btc_pk_hex), &block_hash.to_vec())?;
226+
BLOCK_HASHES.save(
227+
deps.storage,
228+
(height, fp_btc_pk_hex),
229+
&block_app_hash.to_vec(),
230+
)?;
227231

228-
// Check if the key (height, block_hash) exists
232+
// Check if the key (height, block_app_hash) exists
229233
let mut block_votes_fp_set = BLOCK_VOTES
230-
.may_load(deps.storage, (height, block_hash))?
234+
.may_load(deps.storage, (height, block_app_hash))?
231235
.unwrap_or_else(HashSet::new);
232236

233237
// Add the fp_btc_pk_hex to the set
234238
block_votes_fp_set.insert(fp_btc_pk_hex.to_string());
235239

236240
// Save the updated set back to storage
237-
BLOCK_VOTES.save(deps.storage, (height, block_hash), &block_votes_fp_set)?;
241+
BLOCK_VOTES.save(deps.storage, (height, block_app_hash), &block_votes_fp_set)?;
238242

239243
let event = Event::new("submit_finality_signature")
240244
.add_attribute("fp_pubkey_hex", fp_btc_pk_hex)
241245
.add_attribute("block_height", height.to_string())
242-
.add_attribute("block_hash", hex::encode(block_hash));
246+
.add_attribute("block_app_hash", hex::encode(block_app_hash));
243247

244248
res = res.add_event(event);
245249

@@ -289,10 +293,10 @@ pub(crate) fn verify_finality_signature(
289293

290294
/// `msg_to_sign` returns the message for an EOTS signature.
291295
///
292-
/// The EOTS signature on a block will be (block_height || block_hash)
293-
fn msg_to_sign(height: u64, block_hash: &[u8]) -> Vec<u8> {
296+
/// The EOTS signature on a block will be (block_height || block_app_hash)
297+
fn msg_to_sign(height: u64, block_app_hash: &[u8]) -> Vec<u8> {
294298
let mut msg: Vec<u8> = height.to_be_bytes().to_vec();
295-
msg.extend_from_slice(block_hash);
299+
msg.extend_from_slice(block_app_hash);
296300
msg
297301
}
298302

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum QueryMsg {
4141
IsEnabled {},
4242
}
4343

44-
// Note: copied from packages/apis/src/btc_staking_api.rs
44+
// Note: Adapted from packages/apis/src/btc_staking_api.rs / packages/apis/src/finality_api.rs
4545
#[cw_serde]
4646
pub enum ExecuteMsg {
4747
CommitPublicRandomness {
@@ -73,6 +73,7 @@ pub enum ExecuteMsg {
7373
height: u64,
7474
pub_rand: Binary,
7575
proof: Proof,
76+
// FIXME: Rename to block_app_hash for consistency / clarity
7677
block_hash: Binary,
7778
signature: Binary,
7879
},

0 commit comments

Comments
 (0)