Skip to content
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

verifymessagewithname in SPV is insecure #482

Open
pinheadmz opened this issue Mar 11, 2022 · 1 comment
Open

verifymessagewithname in SPV is insecure #482

pinheadmz opened this issue Mar 11, 2022 · 1 comment
Labels
enhancement New feature or request security

Comments

@pinheadmz
Copy link
Contributor

pinheadmz commented Mar 11, 2022

async getCoin(hash, index) {
if (await this.getSpvMode()) {
return hapiGet(`/coin/${hash}/${index}`);
}
return this.client.getCoin(hash, index);
}
async verifyMessageWithName(name, signature, message) {
if (await this.getSpvMode()) {
const result = await this.getNameInfo(name);
const owner = result?.info?.owner;
if (!owner) {
throw new Error('Cannot find the name owner.');
}
const coin = await this.getCoin(owner.hash, owner.index);
if (!coin) {
throw new Error('Cannot find the owner\'s address.');
}
return this._execRPC('verifymessage', [coin.address, signature, message]);
}

This is (a) broken because getNameInfo() will always return null for every name in SPV mode. (rpc getnameinfo relies on the Urkel Tree, which in SPV mode is always empty). It is (b) insecure because it relies on an API server to getCoin() (even though it never will, because getnameinfo will always be null)

Verify with name is possible in SPV mode though, consider this:

  • Request Urkel proof for name from full node, which returns a complete NameState object
  • NameState contains owner which is hash and index of a UTXO
  • Bob Wallet requests the ENTIRE TX from API server with that hash
  • Bob verifies the TX from the server hashes to the hash in NameState.owner
  • Bob now has the coin that owns the name: by looking up the index in the TX it just verified
  • Bob now has the address that owns the name and everything is verified.

Update: ok I misread the code, getnameinfo is actually fetched from the API server, so its not broken its just insecure.

@pinheadmz pinheadmz changed the title verifymessagewithname in SPV is broken and insecure verifymessagewithname in SPV is insecure Mar 11, 2022
@rithvikvibhu
Copy link
Collaborator

Request Urkel proof for name from full node, which returns a complete NameState object

With handshake-org/hsd#647 it's possible to get the namestate, but it will be stale (2 hours?) so would need a warning or something I guess.

@rithvikvibhu rithvikvibhu added enhancement New feature or request security labels Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request security
Projects
None yet
Development

No branches or pull requests

2 participants