stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3k stars 659 forks source link

[stacks-signer] Public Keys Don't Match - Signer Not Registered #4761

Open BowTiedDevOps opened 2 months ago

BowTiedDevOps commented 2 months ago

The public keys generated by generate-stacking-signature and check-config don't match. I've used the public key generated by stacking signature command in stack-aggregation-commit contract calls and the signer is not registered for cycle 84. The private/public keys are generated directly off secp256k1 package in node:

const EC = require("elliptic").ec;
const secp256k1 = new EC("secp256k1");
const enc = require("@stacks/encryption");
const process = require("process");
const key = secp256k1.genKeyPair();

while (true) {
  const key_hex = key.getPrivate().toString("hex");
  if (key_hex.length != 64) {
    continue;
  }
  break;
}
try {
  const privateKey = key.getPrivate().toString("hex");
  const publicKey = enc.getPublicKeyFromPrivate(privateKey);
  process.stdout.write([publicKey, ":", privateKey].join(""));
} catch {
  return process.exit(1);
}
return process.exit(0);

generate-stacking-signature response:

$ ./stacks-signer generate-stacking-signature --pox-address <> --reward-cycle 84 --config ./signer.toml --method agg-commit --period 1 --max-amount 500000000000 --auth-id 0

Signer Public Key: 0x0303144ba518fe7a0fb56a8a7d488f950307a4330f146e1e1458fc63fb33defe96
Signer Key Signature: <>

check-config response:

$ ./stacks-signer check-config --config signer.toml 
Config: 
Stacks node host: 127.0.0.1:30443
Signer endpoint: 0.0.0.0:30000
Stacks address: SPYQ2Q584Y5059SEVN695YREBZ3RPJ68GJBQTPV8
Public key: 0403144ba518fe7a0fb56a8a7d488f950307a4330f146e1e1458fc63fb33defe96193e4d30f75dc540cc29c27de85a0233bd084628d430add9c2229cdebe55a997
Network: mainnet
Database path: /stacks-blockchain/signer/signer.sqlite
DKG transaction fee: 0.01 uSTX

Using stx get_address <privKey>, @stacks/transactions package and check-config all point to the address SPYQ2Q584Y5059SEVN695YREBZ3RPJ68GJBQTPV8, while the public key generated from generate-stacking-signature matches the address SP2H1N2V9S7PEBC0120S3WMEAT32B9N7CGMPSGF16 (checked by @hstove).

On another note, the public key generated by generate-stacking-signature is the same one that is being generated in the node script (process.stdout.write([publicKey, ":", privateKey].join(""));).

I haven't seen other signers run into this issue, so that makes me think if it's because of the way the private key is being generated.

BowTiedDevOps commented 2 months ago

Update: After trying with Hank's implementation of compressed key in the check-config function (https://github.com/stacks-network/stacks-core/pull/4762), the public keys match, but the signer is still unregistered:

$ ./stacks-signer-fix-signer-pk-hex generate-stacking-signature -p bc1p8vg588hldsnv4a558apet4e9ff3pr4awhqj2hy8gy6x2yxzjpmqsvvpta4 -r 22 --method stack-stx --max-amount 340282366920938463463374607431768211455 --auth-id 1 --period 10 --config signer.toml
Signer Public Key: 0x0303144ba518fe7a0fb56a8a7d488f950307a4330f146e1e1458fc63fb33defe96
Signer Key Signature: 0xd47d49ef4eed1917c3d4d5d1df2f0069b65f88c59b760b1fe26043630956885549b192e78af4c0526468b3872fb1838d4c6cf697f5eb626ef8eefdde28f4343700

$ ./stacks-signer-fix-signer-pk-hex check-config --config signer.toml 
Config: 
Stacks node host: 127.0.0.1:30443
Signer endpoint: 0.0.0.0:30000
Stacks address: SPYQ2Q584Y5059SEVN695YREBZ3RPJ68GJBQTPV8
Public key: 0303144ba518fe7a0fb56a8a7d488f950307a4330f146e1e1458fc63fb33defe96
Network: mainnet
Database path: /stacks-blockchain/signer/signer.sqlite
DKG transaction fee: 0.01 uSTX
Metrics endpoint: None

The link to the stack-aggregate-commit transaction, which is made with the same signer key as the one shared above: