-
Notifications
You must be signed in to change notification settings - Fork 113
Submit Fiat-Shamir #1462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Submit Fiat-Shamir #1462
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1462 +/- ##
==========================================
- Coverage 80.21% 79.82% -0.39%
==========================================
Files 20 20
Lines 854 917 +63
Branches 120 160 +40
==========================================
+ Hits 685 732 +47
- Misses 146 159 +13
- Partials 23 26 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I believe you also need some mechanism to reset the interactive BEEFY protocol if it was in progress when a Fiat-Shamir-based BEEFY submission is accepted by the light-client. also, make sure to do security audit for this feature :) |
Though I'm not sure the reset is nessessary, as we won't accept an obsolete commitment anyway. snowbridge/contracts/src/BeefyClient.sol Lines 773 to 776 in 2d55aa0
|
Gas cost of PreRandao submission with 28 signatures across 3 calls: Gas cost of |
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.
overall LGTM. Probably we write some tests for scenario when the relayers are calling fiatShamir and interactive random sampling concurrently. In theory, the staleCommitment check in the verifier should suffice.
contracts/src/BeefyClient.sol
Outdated
|
||
bytes32 bitFieldHash = keccak256(abi.encodePacked(bitfield)); | ||
bytes32 commitmentHash = keccak256(encodeCommitment(commitment)); | ||
bytes32 fiatShamirHash = keccak256(bytes.concat(commitmentHash, bitFieldHash, vset.root)); |
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.
if we are to rely on relative security to bitcoin mining then we have to use the same hash function sha256 when generating the fiatshamir hash (instead of keccak256 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.
using keccak256 for bitFieldHash and commitmentHash is fine
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.
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.
@yrong just realised that bitcoin mining uses double-SHA256 (sha256d), and there is no sha256d precompile for evm. Hence, to compute fiatShamirHash, we need to hash the output of the first hash again, i.e., sha256(sha256(concatenated_bytes)).
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.
Good to know! Fixed in b94851e
bytes32 commitmentHash = keccak256(encodeCommitment(commitment)); | ||
bytes32 fiatShamirHash = keccak256(bytes.concat(commitmentHash, bitFieldHash, vset.root)); | ||
uint256 requiredSignatures = | ||
Math.min(fiatShamirRequiredSignatures, computeQuorum(vset.length)); |
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.
we have 2/3rd +1 honesty assumption on polkadot validators. Hence it is sufficient to check 1/3rd +1 validator signatures to ensure at least 1 honest validator signed the payload. We can get away with min(fiatShamirRequiredSignature, n/3 +1) here. This also sufficient for the random sampling protocol.
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.
contracts/src/BeefyClient.sol
Outdated
@@ -195,6 +195,8 @@ contract BeefyClient { | |||
*/ | |||
uint256 public immutable minNumRequiredSignatures; | |||
|
|||
uint256 constant fiatShamirRequiredSignatures = 101; |
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.
This should be immutable and initialized via the constructor.
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.
A prototype implementation based on the spec from Bhargav. Great thanks for that.
Resolves: https://linear.app/snowfork/issue/SNO-1489
Requires: #1457