Skip to content

Commit 771a5bb

Browse files
core: add allow-list to instantiate arg (#108)
## Description This PR adds additional attribute to instantiation event. Argument list all FP which are set on isntantiation. cc @gusin13 @SebastianElvis I’m skeptical about the costs, since the list can get quite large (20 to 30 BTC keys). How much of an impact do you think this will have? Fixes #104 ## Checklist - [x] I have updated the [docs/SPEC.md](https://github.com/babylonlabs-io/rollup-bsn-contracts/blob/main/docs/SPEC.md) file if this change affects the specification - [x] I have updated the schema by running `cargo gen-schema`
1 parent 29b9166 commit 771a5bb

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3939

4040
### State and API breaking
4141

42-
* [82](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/82) feat: add
43-
bsn_activation_height and finality_signature_interval for spam protection
42+
* [82](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/108) core:
43+
add allow-list to instantiate arg
4444
* [97](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/97) feat:
4545
versioning of FP allowlist
4646
* [100](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/100) chore:
4747
add query to fetch highest voted height
4848

4949
### Improvements
5050

51+
* [#108](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/91) feat:
52+
optimize public key handling by using bytes instead of hex
5153
* [#91](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/91) feat:
5254
optimize public key handling by using bytes instead of hex
5355
* [#98](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/98) feat:

contracts/finality/src/contract.rs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub fn instantiate(
4646
};
4747
set_config(deps.storage, &config)?;
4848

49+
let mut response = Response::new().add_attribute("action", "instantiate");
50+
4951
// Add initial allowed finality providers if provided
5052
if let Some(fp_list) = msg.allowed_finality_providers {
5153
// Validate all public keys are not empty
@@ -67,9 +69,11 @@ pub fn instantiate(
6769
&fp_btc_pk_bytes_list,
6870
env.block.height,
6971
)?;
72+
73+
response = response.add_attribute("allow-list", fp_list.join(","));
7074
}
7175

72-
Ok(Response::new().add_attribute("action", "instantiate"))
76+
Ok(response)
7377
}
7478

7579
pub fn query(
@@ -1528,4 +1532,61 @@ pub(crate) mod tests {
15281532
assert!(current_fps.contains(fp));
15291533
}
15301534
}
1535+
1536+
#[test]
1537+
fn test_instantiate_allowlist_event() {
1538+
let mut deps = mock_deps_babylon();
1539+
let admin = deps.api.addr_make(INIT_ADMIN);
1540+
let bsn_id = "op-stack-l2-11155420".to_string();
1541+
let min_pub_rand = 100;
1542+
1543+
// Test 1: Instantiate with allowed finality providers - should have allow-list attribute
1544+
let fp_list = vec![
1545+
"02a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7".to_string(),
1546+
"03b0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c8".to_string(),
1547+
];
1548+
let expected_allowlist = fp_list.join(",");
1549+
1550+
let instantiate_msg = InstantiateMsg {
1551+
admin: admin.to_string(),
1552+
bsn_id: bsn_id.clone(),
1553+
min_pub_rand,
1554+
max_msgs_per_interval: MAX_MSGS_PER_INTERVAL,
1555+
rate_limiting_interval: RATE_LIMITING_INTERVAL,
1556+
bsn_activation_height: 1000,
1557+
finality_signature_interval: 100,
1558+
allowed_finality_providers: Some(fp_list),
1559+
};
1560+
1561+
let info = message_info(&deps.api.addr_make(CREATOR), &[]);
1562+
let res = instantiate(deps.as_mut(), mock_env(), info, instantiate_msg).unwrap();
1563+
1564+
// Verify response has both action and allow-list attributes
1565+
assert_eq!(res.attributes.len(), 2);
1566+
assert_eq!(res.attributes[0].key, "action");
1567+
assert_eq!(res.attributes[0].value, "instantiate");
1568+
assert_eq!(res.attributes[1].key, "allow-list");
1569+
assert_eq!(res.attributes[1].value, expected_allowlist);
1570+
1571+
// Test 2: Instantiate without allowed finality providers - should not have allow-list attribute
1572+
let mut deps2 = mock_deps_babylon();
1573+
let instantiate_msg2 = InstantiateMsg {
1574+
admin: admin.to_string(),
1575+
bsn_id,
1576+
min_pub_rand,
1577+
max_msgs_per_interval: MAX_MSGS_PER_INTERVAL,
1578+
rate_limiting_interval: RATE_LIMITING_INTERVAL,
1579+
bsn_activation_height: 1000,
1580+
finality_signature_interval: 100,
1581+
allowed_finality_providers: None,
1582+
};
1583+
1584+
let info2 = message_info(&deps2.api.addr_make(CREATOR), &[]);
1585+
let res2 = instantiate(deps2.as_mut(), mock_env(), info2, instantiate_msg2).unwrap();
1586+
1587+
// Verify response has only action attribute
1588+
assert_eq!(res2.attributes.len(), 1);
1589+
assert_eq!(res2.attributes[0].key, "action");
1590+
assert_eq!(res2.attributes[0].value, "instantiate");
1591+
}
15311592
}

0 commit comments

Comments
 (0)