Skip to content

Conversation

nikgraf
Copy link
Collaborator

@nikgraf nikgraf commented Jan 29, 2025

  • add the recovery bit to space events and remove the publicKey
  • restore the publicKey before verifying

@nikgraf nikgraf force-pushed the ng/use-recovery-bit branch from 356e1b9 to 9ed05ce Compare January 29, 2025 14:29
pcarranzav
pcarranzav previously approved these changes Jan 29, 2025
Copy link
Member

@pcarranzav pcarranzav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one question/suggestion but can be addressed separately

accountId: author.accountId,
publicKey: author.signaturePublicKey,
signature,
signature: signatureResult.toCompactHex(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of grouping the hex part and recovery of the signature in a SignatureWithRecovery type like I did here? https://github.com/graphprotocol/hypergraph/pull/135/files#diff-46bf560b871193fa360550e8a148fcf76963723d89bd6252c4cfc4e729d9704eR5-R15

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, sounds good. Will update the PR

btw our addresses use 0x as prefix to indicate hex, but signatures don't. Should we add it for consistency or is it only relevant for addresses? What's the default in the Ethereum eco-system?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I think it would be good to standardize and use the 0x prefix in any hex strings, so yeah that'd include signatures. Most (if not all) ethereum tooling uses that everywhere.

signatureInstance = signatureInstance.addRecoveryBit(event.author.recovery);
const authorPublicKey = signatureInstance.recoverPublicKey(sha256(encodedTransaction));

const isValidSignature = secp256k1.verify(event.author.signature, encodedTransaction, authorPublicKey.toRawBytes(), {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, one more thing - I think this might not be necessary, as recoverPublicKey essentially verifies the signature too (it will only give the correct public key if the corresponding private key signed that message)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might even be redundant, because the public key is recovered from the signature, so it will probably always be valid - I think we should instead validate that the public key is a valid signing key for the author's accountId

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as a next step we ned to retrieve the publicKey from the author and pass it in. At the moment afaik I need to reconstruct it, since it's a required argument for the verify function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is we don't need to call the verify function. Once you retrieve the author's public key and compare it to the one you recovered, you have essentially verified the signature

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added an issue for it: #138

@pcarranzav pcarranzav dismissed their stale review January 29, 2025 14:47

Missed something important

@nikgraf nikgraf merged commit 42aad3d into main Jan 29, 2025
4 checks passed
@nikgraf nikgraf deleted the ng/use-recovery-bit branch January 29, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants