Comments (3)
Here is the way I went about it, I saw that about the signatures being in the same order of the pubkeys.
But, I'm not quite sure why that is necessary so long as:
- Each signature can be verified against one of the pubkeys successfully, and
- The pubkey is removed from the list once it is matched with a signature
I solved it using list .remove(). I don't think things necessarily have to be in order. It seems to cover all the test cases I've tried. Am I missing something or would this work just as well?
try:
pubkeys_parsed = [S256Point.parse(p) for p in sec_pubkeys]
signatures_parsed = [Signature.parse(p) for p in signatures]
for sig in signatures_parsed:
if len(pubkeys_parsed) == 0:
return False
signature_verified = False
for pubkey in pubkeys_parsed:
if pubkey.verify(z, sig):
print(f'Verified point: {pubkey} with signature: {sig}')
signature_verified = True
pubkeys_parsed.remove(pubkey)
break
if not signature_verified:
return False # Signature did not match a pubkey
stack.append(encode_num(1))
from programmingbitcoin.
@mattacus From my understanding, the actual implementation of op_checkmultisig
in Bitcoin requires the signatures and pubkeys to be in the same order. At least according to these sources:
- https://bitcoin.stackexchange.com/questions/113425/order-of-signatures-in-multisig-scheme
- https://en.bitcoin.it/wiki/OP_CHECKMULTISIG
from programmingbitcoin.
Right, I saw that, in the docs:
Because public keys are not checked again if they fail any signature comparison, signatures must be placed in the scriptSig using the same order as their corresponding public keys
After thinking about it some more it makes more sense to do it that way since signature verification time could add up if you have, say, 100s of signature that each node must verify, and you don't pop each pubkey each time it is visited. (In my case I am removing them, but only if the signature is verified, so there could be more iterations). So it seems like they chose that approach for efficiency reasons.
from programmingbitcoin.
Related Issues (20)
- Chapter 4 Exercise 9 Code returns invalid testnet address HOT 3
- Chapter 11: Exercise 6 & 7 HOT 2
- Openssl removed ripemd160 support. Code using hashlib's 'ripemd160' algorithm may fail. HOT 4
- mainnet.programmingbitcoin.com not responding for getheaders message HOT 1
- Chapter 7: help me understand decode_base58 HOT 1
- rmul method inside FieldElement Class to be added before completing ex 4 chapter 3 HOT 1
- Chapter 3, Exercise 3 self.assertEqual() error HOT 1
- Chapter 3, Explanation of why doubling SHA-256 is more secure seems wrongs
- "virtualenv -p python3 .venv" does not work
- How to setup environment in Google Colab
- How to generate P2TR address? HOT 1
- Chapter 5: Varint sidebar example
- Chapter 4 return value for decode_base58 function HOT 1
- Chapter 3 sign method s or N - s works as part of the sig? HOT 1
- Chapter 5: In function encode_varint - Why use < 0xfd instead of < 0x100 for one byte strings, similar to the larger options? HOT 1
- Invalid ScriptSig found on mainnet HOT 1
- Chapter 4 - checksum should be double hashed? HOT 1
- Can not visit the link https://faucet.programmingbitcoin.com HOT 4
- Multiplying two points
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from programmingbitcoin.