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

Multisig: same order of public keys produces different address (vs coinb.in/#newMultiSig) #32

Open
ramontayag opened this issue May 26, 2018 · 0 comments

Comments

@ramontayag
Copy link
Contributor

ramontayag commented May 26, 2018

Not sure if this is a bug or I'm missing something.

I'm attempting to generate the same addresses as a multisig Electrum wallet using this library. When I enter the public keys into coinb.in of each address generated in Electrum, I get the same address as the one in Electrum, as long as I lexicographically order the public keys.

Using this library, I am not able to generate the same addresses. Here's the script I'm using:

require "btcruby"

# For context, not actually used in the script below.
cosigners = [
  {
    electrum_seed: "hotel congress unable service silver wool fabric ski buffalo orbit damp enjoy",
    master_public_key: "xpub661MyMwAqRbcGHY2QrfyiUyvSv93zCQN8Cv3eXFB3ivnq7SQ6TLUJueJnGZKR8r8CQ5cLsGrr9D71uwAW9RLKqFyUybARtbbqg1kiHopBsZ",
  },
  {
    electrum_seed: "trust diary skull hidden album awesome lady zoo polar gorilla alley credit",
    master_public_key: "xpub6D4K8Hb6sMZwwtbk6p94RnRewTb6PykJc1zZwB3GUozGSNXLnTdL2T8uXRehiD9d5Dis3bDpJCvR3pFZcYUu2xpPj5Z73oFNUUQKwkFTewo",
  },
]

# Copied from electrum 1-of-2 multisig wallet using the keys above. public_keys order is as shown in the address' "details" window of Electrum.
addresses = {
  0 => {
    address: "3GbE5Hn5NNfAbkk33AquoZqtoehkDDBEZn",
    public_keys: [
      "02c71e2fd1793943296f2c708ee44d0c7df113b3d9f6808180801835d510beb794",
      "036822f8013573775f7cb0c9aa1cbf7fba9b59480af59415685328a334b5f5c369",
    ],
    redeem_script: "512102c71e2fd1793943296f2c708ee44d0c7df113b3d9f6808180801835d510beb79421036822f8013573775f7cb0c9aa1cbf7fba9b59480af59415685328a334b5f5c36952ae",
  },
  4 => {
    address: "35gx2GzbtVy116Ai2kop8u95xWVHYfFPne",
    public_keys: [
      "03b064e3adf933622eff9b33e7dbc881e1bc9ec3030f96bf0ddd53cabd862adf7c",
      "0228f4d23588f5dd93ad64c1d1502f43c779e9d3811fcbe8af5f54faf585f68ece",
    ],
    redeem_script: "51210228f4d23588f5dd93ad64c1d1502f43c779e9d3811fcbe8af5f54faf585f68ece2103b064e3adf933622eff9b33e7dbc881e1bc9ec3030f96bf0ddd53cabd862adf7c52ae",
  },
  9 => {
    address: "3C1KyYDMg8woFnZZXqfmkdvUEJuLMuajCV",
    public_keys: [
      "03b84384cd966c8554ddc2303101fd416f5b4f260161c788d6c62d6c6d293b4880",
      "0336e728be1b9370565204b5de4050d418704cc9c5c2db47f13be30173f7f5bd46",
    ],
    redeem_script: "51210336e728be1b9370565204b5de4050d418704cc9c5c2db47f13be30173f7f5bd462103b84384cd966c8554ddc2303101fd416f5b4f260161c788d6c62d6c6d293b488052ae",
  },
}

addresses.each do |idx, addr_details|
  public_keys = addr_details[:public_keys].sort
  multisig_script = BTC::Script.
    multisig(public_keys: public_keys, signatures_required: 1)
  p2sh_script = multisig_script.p2sh_script
  generated_addr = p2sh_script.standard_address.to_s
  if generated_addr == addr_details[:address]
    puts "YES MATCH:"
    puts "We generated the same one for address #{idx}: #{addr_details}"
  else
    puts "NO MATCH:"
    puts " - Generated address from lexicographically ordered keys: #{generated_addr}"
    puts " - Expected address: #{addr_details[:address]}"
  end
end

puts "Done"

Links to coinbin:

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

No branches or pull requests

1 participant