Skip to content

Commit b459146

Browse files
authored
F/rewards distribution send (#96)
#97 follow-up. Send rewards along with the distribution table using ICS-20 with a json payload in the Memo field
1 parent 769be78 commit b459146

File tree

4 files changed

+218
-18
lines changed

4 files changed

+218
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ babylon-btcstaking = { path = "./packages/btcstaking" }
2929
babylon-contract = { path = "./contracts/babylon" }
3030
eots = { path = "./packages/eots" }
3131
anyhow = "1.0.82"
32+
bech32 = "0.9.1"
3233
bitcoin = "0.31.1"
3334
bitvec = "1"
34-
bech32 = "0.9.1"
3535
blst = "0.3.11"
3636
cosmos-sdk-proto = { version = "0.19.0", default-features = false, features = [
3737
"cosmwasm",

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

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@
126126
},
127127
"additionalProperties": false
128128
},
129+
{
130+
"description": "Slashing message.\n\nThis message can be called by the admin only.",
131+
"type": "object",
132+
"required": [
133+
"slashing"
134+
],
135+
"properties": {
136+
"slashing": {
137+
"type": "object",
138+
"required": [
139+
"evidence",
140+
"sender"
141+
],
142+
"properties": {
143+
"evidence": {
144+
"$ref": "#/definitions/Evidence"
145+
},
146+
"sender": {
147+
"$ref": "#/definitions/Addr"
148+
}
149+
},
150+
"additionalProperties": false
151+
}
152+
},
153+
"additionalProperties": false
154+
},
129155
{
130156
"description": "Enable or disable finality gadget.\n\nThis message can be called by the admin only. If disabled, the verifier should bypass the EOTS verification logic, allowing the OP derivation derivation pipeline to pass through. Note this should be implemented in the verifier and is not enforced by the contract itself.",
131157
"type": "object",
@@ -171,10 +197,90 @@
171197
}
172198
],
173199
"definitions": {
200+
"Addr": {
201+
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
202+
"type": "string"
203+
},
174204
"Binary": {
175205
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
176206
"type": "string"
177207
},
208+
"Evidence": {
209+
"description": "Evidence is the evidence that a finality provider has signed finality signatures with correct public randomness on two conflicting Babylon headers",
210+
"type": "object",
211+
"required": [
212+
"block_height",
213+
"canonical_app_hash",
214+
"canonical_finality_sig",
215+
"fork_app_hash",
216+
"fork_finality_sig",
217+
"fp_btc_pk",
218+
"pub_rand"
219+
],
220+
"properties": {
221+
"block_height": {
222+
"description": "`block_height` is the height of the conflicting blocks",
223+
"type": "integer",
224+
"format": "uint64",
225+
"minimum": 0.0
226+
},
227+
"canonical_app_hash": {
228+
"description": "`canonical_app_hash` is the AppHash of the canonical block",
229+
"type": "array",
230+
"items": {
231+
"type": "integer",
232+
"format": "uint8",
233+
"minimum": 0.0
234+
}
235+
},
236+
"canonical_finality_sig": {
237+
"description": "`canonical_finality_sig` is the finality signature to the canonical block, where finality signature is an EOTS signature, i.e., the `s` in a Schnorr signature `(r, s)`. `r` is the public randomness already committed by the finality provider. Deserializes to `SchnorrEOTSSig`",
238+
"type": "array",
239+
"items": {
240+
"type": "integer",
241+
"format": "uint8",
242+
"minimum": 0.0
243+
}
244+
},
245+
"fork_app_hash": {
246+
"description": "`fork_app_hash` is the AppHash of the fork block",
247+
"type": "array",
248+
"items": {
249+
"type": "integer",
250+
"format": "uint8",
251+
"minimum": 0.0
252+
}
253+
},
254+
"fork_finality_sig": {
255+
"description": "`fork_finality_sig` is the finality signature to the fork block, where finality signature is an EOTS signature. Deserializes to `SchnorrEOTSSig`",
256+
"type": "array",
257+
"items": {
258+
"type": "integer",
259+
"format": "uint8",
260+
"minimum": 0.0
261+
}
262+
},
263+
"fp_btc_pk": {
264+
"description": "`fp_btc_pk` is the BTC PK of the finality provider that casts this vote",
265+
"type": "array",
266+
"items": {
267+
"type": "integer",
268+
"format": "uint8",
269+
"minimum": 0.0
270+
}
271+
},
272+
"pub_rand": {
273+
"description": "`pub_rand is` the public randomness the finality provider has committed to. Deserializes to `SchnorrPubRand`",
274+
"type": "array",
275+
"items": {
276+
"type": "integer",
277+
"format": "uint8",
278+
"minimum": 0.0
279+
}
280+
}
281+
},
282+
"additionalProperties": false
283+
},
178284
"Proof": {
179285
"description": "A `Proof` is a proof of a leaf's existence in a Merkle tree.\n\nThe convention for proofs is to include leaf hashes, but to exclude the root hash. This convention is implemented across IAVL range proofs as well. Keep this consistent unless there's a very good reason to change everything. This affects the generalized proof system as well.\n\nEquivalent to / adapted from cometbft/crypto/merkle/proof.go.",
180286
"type": "object",

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

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,32 @@
100100
},
101101
"additionalProperties": false
102102
},
103+
{
104+
"description": "Slashing message.\n\nThis message can be called by the admin only.",
105+
"type": "object",
106+
"required": [
107+
"slashing"
108+
],
109+
"properties": {
110+
"slashing": {
111+
"type": "object",
112+
"required": [
113+
"evidence",
114+
"sender"
115+
],
116+
"properties": {
117+
"evidence": {
118+
"$ref": "#/definitions/Evidence"
119+
},
120+
"sender": {
121+
"$ref": "#/definitions/Addr"
122+
}
123+
},
124+
"additionalProperties": false
125+
}
126+
},
127+
"additionalProperties": false
128+
},
103129
{
104130
"description": "Enable or disable finality gadget.\n\nThis message can be called by the admin only. If disabled, the verifier should bypass the EOTS verification logic, allowing the OP derivation derivation pipeline to pass through. Note this should be implemented in the verifier and is not enforced by the contract itself.",
105131
"type": "object",
@@ -145,10 +171,90 @@
145171
}
146172
],
147173
"definitions": {
174+
"Addr": {
175+
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
176+
"type": "string"
177+
},
148178
"Binary": {
149179
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
150180
"type": "string"
151181
},
182+
"Evidence": {
183+
"description": "Evidence is the evidence that a finality provider has signed finality signatures with correct public randomness on two conflicting Babylon headers",
184+
"type": "object",
185+
"required": [
186+
"block_height",
187+
"canonical_app_hash",
188+
"canonical_finality_sig",
189+
"fork_app_hash",
190+
"fork_finality_sig",
191+
"fp_btc_pk",
192+
"pub_rand"
193+
],
194+
"properties": {
195+
"block_height": {
196+
"description": "`block_height` is the height of the conflicting blocks",
197+
"type": "integer",
198+
"format": "uint64",
199+
"minimum": 0.0
200+
},
201+
"canonical_app_hash": {
202+
"description": "`canonical_app_hash` is the AppHash of the canonical block",
203+
"type": "array",
204+
"items": {
205+
"type": "integer",
206+
"format": "uint8",
207+
"minimum": 0.0
208+
}
209+
},
210+
"canonical_finality_sig": {
211+
"description": "`canonical_finality_sig` is the finality signature to the canonical block, where finality signature is an EOTS signature, i.e., the `s` in a Schnorr signature `(r, s)`. `r` is the public randomness already committed by the finality provider. Deserializes to `SchnorrEOTSSig`",
212+
"type": "array",
213+
"items": {
214+
"type": "integer",
215+
"format": "uint8",
216+
"minimum": 0.0
217+
}
218+
},
219+
"fork_app_hash": {
220+
"description": "`fork_app_hash` is the AppHash of the fork block",
221+
"type": "array",
222+
"items": {
223+
"type": "integer",
224+
"format": "uint8",
225+
"minimum": 0.0
226+
}
227+
},
228+
"fork_finality_sig": {
229+
"description": "`fork_finality_sig` is the finality signature to the fork block, where finality signature is an EOTS signature. Deserializes to `SchnorrEOTSSig`",
230+
"type": "array",
231+
"items": {
232+
"type": "integer",
233+
"format": "uint8",
234+
"minimum": 0.0
235+
}
236+
},
237+
"fp_btc_pk": {
238+
"description": "`fp_btc_pk` is the BTC PK of the finality provider that casts this vote",
239+
"type": "array",
240+
"items": {
241+
"type": "integer",
242+
"format": "uint8",
243+
"minimum": 0.0
244+
}
245+
},
246+
"pub_rand": {
247+
"description": "`pub_rand is` the public randomness the finality provider has committed to. Deserializes to `SchnorrPubRand`",
248+
"type": "array",
249+
"items": {
250+
"type": "integer",
251+
"format": "uint8",
252+
"minimum": 0.0
253+
}
254+
}
255+
},
256+
"additionalProperties": false
257+
},
152258
"Proof": {
153259
"description": "A `Proof` is a proof of a leaf's existence in a Merkle tree.\n\nThe convention for proofs is to include leaf hashes, but to exclude the root hash. This convention is implemented across IAVL range proofs as well. Keep this consistent unless there's a very good reason to change everything. This affects the generalized proof system as well.\n\nEquivalent to / adapted from cometbft/crypto/merkle/proof.go.",
154260
"type": "object",

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -519,28 +519,16 @@ pub(crate) mod tests {
519519
let attrs: HashMap<_, _> = event
520520
.attributes
521521
.iter()
522-
.map(|a| (&a.key, &a.value))
522+
.map(|a| (a.key.clone(), a.value.clone()))
523523
.collect();
524+
assert_eq!(attrs.get("module").unwrap(), "finality");
525+
assert_eq!(attrs.get("finality_provider").unwrap(), &pk_hex);
524526
assert_eq!(
525-
attrs.get(&"module".to_string()).unwrap().as_str(),
526-
"finality"
527-
);
528-
assert_eq!(
529-
attrs
530-
.get(&"finality_provider".to_string())
531-
.unwrap()
532-
.as_str(),
533-
&pk_hex
534-
);
535-
assert_eq!(
536-
attrs.get(&"block_height".to_string()).unwrap().as_str(),
527+
attrs.get("block_height").unwrap(),
537528
&block_height.to_string()
538529
);
539530
assert_eq!(
540-
attrs
541-
.get(&"canonical_app_hash".to_string())
542-
.unwrap()
543-
.as_str(),
531+
attrs.get("canonical_app_hash").unwrap(),
544532
&hex::encode(&evidence.canonical_app_hash)
545533
);
546534
}

0 commit comments

Comments
 (0)