-
Notifications
You must be signed in to change notification settings - Fork 121
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
Add challenge to proof ownership flows #1077
Add challenge to proof ownership flows #1077
Conversation
Pull Request Test Coverage Report for Build 10405979240Details
💛 - Coveralls |
Needs rebase after merging #1075 |
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 very good, thanks a lot!
Have a couple of improvements and nits, nothing major.
25caeae
to
c5d1d5b
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.
Very nice, LGTM 🎉
Oh, linter is unhappy. A line is too long. |
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.
LGTM 💫
Nice n clean!
Left one comment re a simplification we can make:
- We don't need to obtain
G
, to then create the pointG*challenge
- Instead, we can just do
G*challenge
, which is known as a scalar base mult
asset.NUMSPubKey.AsJacobian(&nums) | ||
|
||
// Multiply G by 1 to get G as a Jacobian point. | ||
secp256k1.ScalarBaseMultNonConst( |
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.
I think we can simplify slightly: we can just do: challenge*G
here, which is the same operations as creating a new EC point from a private scalar. Under the hood it handles obtaining the generator as a Jacobian point: https://github.com/decred/dcrd/blob/9aba0ced85c954fb3bff07eb2e9af7688fa21c94/dcrec/secp256k1/curve.go#L1235-L1238
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.
In other words, we only need to do:
var challengePoint btcec.JacobianPoint
secp256k1.ScalarBaseMultNonConst(challenge, challengePoint)
@@ -370,7 +373,7 @@ func CreateOwnershipProofAsset( | |||
} | |||
|
|||
outputAsset := ownedAsset.Copy() | |||
outputAsset.ScriptKey = asset.NUMSScriptKey | |||
outputAsset.ScriptKey = address.GenChallengeNUMS(challengeBytes) |
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.
👍
return asset.NUMSScriptKey | ||
} | ||
|
||
var challengeBytes [32]byte |
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.
Can can also further bind the challenge if we use h(nums || challenge)
instead of just challenge
.
Description
Currently, our
ProveAssetOwnership
/VerifyAssetOwnership
calls create an ownership proof by creating a vPSBT that spends the asset to a NUMS key, and that challenge witness would be appended to the proof for the verifier to check.In this PR we add a new
[32]byte challenge
field on both methods.ProveAssetOwnership
: if a challenge is defined we instead spend it toNUMS + challenge*G
, otherwise justNUMS
(noop)VerifyAssetOwnership
: if a challenge is defined we will construct a virtual tx that spends toNUMS +challenge*G
and verify that state transition, otherwise justNUMS
(noop)Comment
In the original issue there's the expectation to encode the challenge in the proof. Since the verifier is supposed to have knowledge of the challenge, we instead add the challenge as a parameter to the
VerifyAssetOwnership
. This way we don't have to change theProof
TLV encoders to accept an optional[32]byte
challenge, which significantly reduces code pollution and minimizes diff.Closes #819