Skip to main content
Share Your Experience: Take the 2024 Developer Survey
22 votes
Accepted

What are the DER signature and SEC format

DER The Distinguished Encoding Rules (DER) format is used to encode ECDSA signatures in Bitcoin. An ECDSA signature is generated using a private key and a hash of the signed message. It consists of ...
Murch's user avatar
  • 75.8k
6 votes

How to parse a raw transaction field by field?

This is one method to parse a bitcoin transaction manually, one level above the script level. Parsing a Bitcoin Transaction By Hand This tutorial follows the lessons taught by Base58 Bitcoin ...
Luciana Ferreira's user avatar
6 votes
Accepted

allowed DER encoding format violations for signatures in bitcoin: implications for libraries?

It isn't clear to me from your question what your goal is. If you want to accept all transactions and only transactions that Bitcoin would accept, libsecp256k1 alone is what you want. (You may need ...
G. Maxwell's user avatar
  • 7,727
4 votes
Accepted

Why does P2SH-P2WPKH use DER encoded signatures?

Segregated Witness was already a large collection of changes that impacted several parts of Bitcoin (P2P, validation, fee estimation, sighashing, script execution, ...). Many small improvements could ...
Pieter Wuille's user avatar
4 votes
Accepted

Why are indexes in cmpctblock and getblocktxn messages calculated as differences?

Numbers up to 252 are encoded as a single byte, while larger numbers take 3 bytes. Differential encoding is effectively a form of compression, reducing the size of the data without losing information (...
Pieter Wuille's user avatar
4 votes
Accepted

Why doesn't bitcoin use bech32 encoding for transaction_id and block hash?

Bitcoin has used the same hex encoding for hashes since the very beginning. Any software written since then therefore also expects that same hex encoding. Bech32 was introduced nearly a decade into ...
Ava Chow's user avatar
  • 70.8k
3 votes
Accepted

Understanding Script's number encoding, CScriptNum

Numbers in Script are represented as byte vectors of up to 4 bytes and interpreted as signed integers between -2^31+1 and 2^31-1. This is with the exception of OP_0, OP_1NEGATE and OP_1 through OP_16 ...
Antoine Poinsot's user avatar
3 votes

What are the DER signature and SEC format

There are different formats used to encode public keys and signatures into binary (octet-streams). They are defined in Standards for Efficient Cryptography 1 (SEC). A public key is a point on an ...
Mark H's user avatar
  • 3,334
3 votes
Accepted

CVarint serialization format

The CVarInt format is implemented in serialize.h As the comment is extensive, I'll just quote it here: Variable-length integers: bytes are a MSB base-128 encoding of the number. The high bit in ...
Pieter Wuille's user avatar
2 votes

In which Block was Len Sassaman memorialised?

Find it yourself with my preprocessed ASCII strings data At https://github.com/cirosantilli/bitcoin-strings-with-txids I have uploaded a dump of all ASCII strings of length 20 or greater, including ...
Ciro Santilli OurBigBook.com's user avatar
2 votes

How much can be stripped of a base58 address in a recoverable way?

The checksum of Base58Check encoding is simply a truncated hash of the rest of the bytes. This means there is no recovery algorithm other than just brute-forcing until the hash matches. That is one of ...
meshcollider's user avatar
  • 11.8k
2 votes

Compress transaction hex string

Compressing a more-or-less random number is futile. Your best option is simply to use a more compact encoding. Base64 is better than Hex but there exists may other encodings that prform better ...
RedGrittyBrick's user avatar
1 vote
Accepted

Mixing some concepts with encodings

So before broadcast to the network what a wallet do internally is encode the psbt string to hex format and after broadcast. Is it that correct? The network format is binary, not hex. That means the ...
RedGrittyBrick's user avatar
1 vote
Accepted

Electrum's custom Base43 - looking for a 2-way deterministic hex converter

This seemed like an interesting thing to do. So I created a tool to do it. https://github.com/redgrittybrick/base43 C> type example.base43.txt 71OUKK$VH33.J1Y/K8Q8T3-F8X59N/YIO*LXY.7320F/5.KN$...
RedGrittyBrick's user avatar
1 vote

What is encoded in the first taproot enabled block?

I don't know so alternative answers are welcome! If you look at the coinbase transaction in the block 709632 (mined by F2Pool) where full nodes started enforcing Taproot rules there is a scriptSig and ...
Michael Folkson's user avatar
1 vote

what are private keys (essentially) how can i make them using any given data?

right?! Wrong. I think you have misunderstood what a private key is. Bitcoin's private keys are part of a pair of keys that are used for Public-key cryptography. The private key is randomly ...
Adam Millerchip's user avatar
1 vote
Accepted

what are private keys (essentially) how can i make them using any given data?

Bitcoin private keys (secp256k1) are just a random 256bits "number" (256 random zero and ones), or say 32byte random data. The only constraints are, that the random number must be between 0x1 and ...
Jonas Schnelli's user avatar
1 vote

allowed DER encoding format violations for signatures in bitcoin: implications for libraries?

It was the case that python-bitcoinlib's script evaluation code did not handle SCRIPT_VERIFY_STRICTENC flag. I had to create additional method, verify_nonstrict(), and make the scripteval use it ...
Dmitry Petukhov's user avatar
1 vote

allowed DER encoding format violations for signatures in bitcoin: implications for libraries?

If you want to guarantee strict DER encoded signatures which are accepted by Bitcoind then they need to be bip66 compliant(low s values(ecdsa malleability), remove leading nulls (encoding malleability)...
James C.'s user avatar
  • 2,521
1 vote
Accepted

ScriptSig Conversion in Python

0x30 is there it's '0' in ascii (second character in your bytes1) >>> b'\x30' b'0' You also want to extract the signature from the scriptSig before passing it to a decoder, right now it ...
Mike D's user avatar
  • 3,569
1 vote
Accepted

from b58check to hex and back

The second case is a P2SH address. You must supply the version number/magic byte for the address, which is 5 for P2SH. >>> bitcoin.b58check_to_hex('3BRu7EhouApLkW1EZ64T9o9yMuX5Rexz6f') '...
Nick ODell's user avatar
  • 29.4k
1 vote

Compact integer in Scripts

CompactSize Unsigned Integers are not used in Script, they are used on the Bitcoin protocol to signify the amount of bytes that the next data structure contains. You are confusing these with ...
Chris Stewart's user avatar
1 vote

How are transaction hashes calculated?

I've come across this several times when trying to come up with an easy way to calculate a txid, and I finally decided to try and write a little script to do the same. I used built-in libraries and ...
rpseu's user avatar
  • 111

Only top scored, non community-wiki answers of a minimum length are eligible