-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
60a62a4
to
fa32192
Compare
frame/im-online/src/lib.rs
Outdated
_signature: <T::AuthorityId as RuntimeAppPublic>::Signature | ||
_signature: <T::AuthorityId as RuntimeAppPublic>::Signature, | ||
// checked in `validate_unsigned` | ||
_keys_len: u32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here keys_len isn't part of the signed heartbeat but I think its fine, though one can double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since imonline transactions have to be propagated to other authorities (since the ones that send it didn't have a chance to produce a block), there is a potential attack, where other authorities change the key_len
inside the payload making the transaction invalid.
This is not super bad, since they can also change say session_index
or simply censor the transactions, but with key_len
we can't be sure what happened - we don't know if the authority is misbehaving or it was maliciously modified. The possible cases are:
- The hearbeat is incorrect, but has correct signature (i.e. the authority is misbehaving).
- The heartbeat is incorrect and has incorrect signature (i.e. was modified).
- The heartbeat was not seen (i.e. either not sent or censored).
Key_len
invalid (i.e. either modified or authority misbehaving).
I'd be for putting that into Heartbeat
payload for simplicity, unless there are any reasons why we should not do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re discussions in benchmarking channel, we should probably use saturating ops here, since key_len
is coming from the user.
Even though the transaction should be rejected, I think the overflow may have some unforseen consequences (for instance it will panic in debug mode), so better have saturating ops for everything here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok for the saturation, params should have been checked in validate_unsigned but better be safe anyway.
I updated to put key_len part of heartbeat. 👍
fa32192
to
352a63e
Compare
352a63e
to
bd9aa1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good besides the possible improvement with key_len
being signed as well.
Changing offchain workers does not require updating the nodes. Indeed old transactions will fail in case runtime update is performed in unlucky moment, but also as Gui mentioned, the OCW code will attempt to send another one after the grace period is over and the previous transaction was not included.
frame/im-online/src/lib.rs
Outdated
_signature: <T::AuthorityId as RuntimeAppPublic>::Signature | ||
_signature: <T::AuthorityId as RuntimeAppPublic>::Signature, | ||
// checked in `validate_unsigned` | ||
_keys_len: u32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since imonline transactions have to be propagated to other authorities (since the ones that send it didn't have a chance to produce a block), there is a potential attack, where other authorities change the key_len
inside the payload making the transaction invalid.
This is not super bad, since they can also change say session_index
or simply censor the transactions, but with key_len
we can't be sure what happened - we don't know if the authority is misbehaving or it was maliciously modified. The possible cases are:
- The hearbeat is incorrect, but has correct signature (i.e. the authority is misbehaving).
- The heartbeat is incorrect and has incorrect signature (i.e. was modified).
- The heartbeat was not seen (i.e. either not sent or censored).
Key_len
invalid (i.e. either modified or authority misbehaving).
I'd be for putting that into Heartbeat
payload for simplicity, unless there are any reasons why we should not do that.
The weight must consider all the cost of executing the extrinsic, validate_unsigned included.
To confirm formula a benchmark has been added.
In order to have the length of
Keys
it is added as argument of the dispatchable.Thus the offchain worker is also changed. AFAIK changing the offchain worker doesn't require validators to update their nodes.
But old unsigned transaction submitted will fail, but if I understand the code correctly the offchain worker will try at every block if it is not online yet. @tomusdrw