Bitcoin Forum
July 14, 2025, 04:00:08 PM *
News: Latest Bitcoin Core release: 29.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1] 2 3 4 5 6 »
1  Bitcoin / Development & Technical Discussion / [libsecp256k1] secp256k1_fe_set_b32_mod doesn't actually reduce anything on: November 26, 2023, 01:36:41 PM
I'm going through libsecp256k1 and noticed a new change which is strange.

secp256k1_fe_set_b32_mod method name and comment suggest that it reduces the value mod p and the result is supposed to be r ≡ a (mod p)
https://github.com/bitcoin-core/secp256k1/blob/c1b4966410a81162bf9404ec84e69a85e1e23469/src/field.h#L192

But looking at the implementations they don't actually perform any reduction. It's just a simple conversion from byte[] to uint[] in radix 26 or 52.
For example:
https://github.com/bitcoin-core/secp256k1/blob/c1b4966410a81162bf9404ec84e69a85e1e23469/src/field_10x26_impl.h#L293

How the method is called(?):
https://github.com/bitcoin-core/secp256k1/blob/c1b4966410a81162bf9404ec84e69a85e1e23469/src/field_impl.h#L258

After this commit the library seems to still use the old method (secp256k1_fe_set_b32_limit method so I don't think anything is changed there) except here
https://github.com/bitcoin-core/secp256k1/commit/5b32602295ff7ad9e1973f96b8ee8344b82f4af0#diff-6f71b0372be086d45b4f2740508c03a21835d87008840032fbb767f419fd988a
And this "assumption" that the secp256k1_fe_set_b32_mod reduces the result is new.

Am I missing something or is this a mistake?

Edit: fixed in https://github.com/bitcoin-core/secp256k1/commit/77af1da9f631fa622fb5b5895fd27be431432368
2  Bitcoin / Development & Technical Discussion / Why does secp256k1_fe_set_int enforce a <= 0x7FFF? on: July 22, 2022, 04:55:10 AM
Is there a reason why secp256k1_fe_set_int method is enforcing the integer to be this small considering the first limbs (least significant) the can have at most 26 bits (0x03ffffff) and 52 bits (0x0fffffffffffff) respectively?
https://github.com/bitcoin-core/secp256k1/blob/1253a27756540d2ca526b2061d98d54868e9177c/src/field_5x52_impl.h#L251-L252
https://github.com/bitcoin-core/secp256k1/blob/1253a27756540d2ca526b2061d98d54868e9177c/src/field_10x26_impl.h#L295-L296
3  Bitcoin / Development & Technical Discussion / Is there any benchmark results on block verification times? on: May 05, 2022, 04:33:51 AM
Has anybody done any research about how much time it takes to verify bitcoin blocks on different hardware?
I'm hoping for actual values not a benchmark that I have to run myself, something like "it takes X seconds to verify block Y on CPU with clock speed Z".

For example if I remove all IO operations it would take me 28 seconds to fully verify first 2000 blocks and update databases in memory (from block #1 to #2001) on a single core @3.7 GHz.
My current assumption is that this is slow but I don't know by how much. For example should it take 5 seconds or 20?
4  Bitcoin / Bitcoin Technical Support / Need some feedback on a search space limiter option on: April 10, 2022, 10:11:46 AM
I'm working on a new option for FinderOuter to limit the search space in each recovery option. I'm currently working on the concept and want to know what you think.
For example the mnemonic recovery looks like the following pictures.

User clicks Start to perform some basic checks and find out how many words are missing then it creates a set of "steps" to set what words can be used in that missing place and limit the search space.

For first missing word (grace) it adds words that start with "gr":


User clicks the next button (>) to move on to the next missing word.

For second missing word (cruise) it adds words that contain letters "is":


User clicks Finish button to finish up and create a SearchSpace object to be sent to the brute force service.
As a result the search space is now limited to 976 permutations instead of 4,194,304.

User can also add custom words one by one, or add all possible words.
Q 1. What do you think of how it looks and the process?
Q 2. Is there any other option you think I should add?

Q 3. I'm also not sure whether I should add this option as a new window like the picture below shows or just extend the main window's height and add the option right there under an advanced expander (I'm leaning toward the later myself although my implementation so far is using the former).


5  Bitcoin / Project Development / HandyDandy a tool to work with entropy on: November 27, 2021, 04:11:41 PM
Handy Dandy is a tool that helps visualize and work with data in different formats that are used in Bitcoin protocol such as private keys and mnemonics.

A potential use case is offline generation of private keys or mnemonics using a coin flip.
User selects what result they want to generate (eg. a 15-word BIP-39 mnemonic) by selecting the appropriate options on top of the window and the program automatically generates appropriate number of bits to be set. In this example it is 165 bits (160 bit entropy + 5 bit dynamically computed checksum).
Then the user has to flip a coin and set each bit. For example
Heads: 1
Tails: 0
Heads: 1
Heads: 1


As each bit is being set, the respective value is also printed as integer, hexadecimal and BIP-39 word.
After all bits were set the final result will be printed in the result TextBox at the bottom of the page and can be copied.



Source code and compiled binaries can be found here: https://github.com/Coding-Enthusiast/HandyDandy
This project is in beta. Please report any bugs you find here or on GitHub

If You found this tool helpful consider making a donation:
Legacy address: 1Q9swRQuwhTtjZZ2yguFWk7m7pszknkWyk
SegWit address: bc1q3n5t9gv40ayq68nwf0yth49dt5c799wpld376s

The idea for project was influenced by: https://bitcointalk.org/index.php?topic=5187401.0
6  Bitcoin / Bitcoin Technical Support / What's the expected speed for BIP39 passphrase recovery using CPU? on: June 29, 2021, 06:18:19 AM
If you have used any BIP39 passphrase (extra/extension words) recovery tools using your CPU please let me know what was the speed you got, preferably in terms of pass/second.

I recently added the BIP39 passphrase recovery option to FinderOuter and am now working on its parallelism, while testing the speed I'm getting a surprisingly low speed of 1500 pass/sec. Although my CPU is old and it is expected to see a very low speed due to the algorithm being "expensive" but I'm wondering how does this compare to other tools out there.
This is surprising because I'm already exploiting PBKDF2 weaknesses and reducing the work by almost 45% so I don't think there is that much room left for further optimization.
7  Bitcoin / Development & Technical Discussion / What's the reason for not being strict about Taproot witness program size? on: May 30, 2021, 11:28:17 AM
Witness version 0 is strict and will fail if the program size is not 20 or 32 bytes but witness version 1 will simply assume the program is undefined and passes on verification. What's the rational for keeping this loose?
https://github.com/bitcoin/bitcoin/blob/55a156fca08713b020aafef91f40df8ce4bc3cae/src/script/interpreter.cpp#L1878
Code:
if (witversion == 0) 
{
  if (program.size() == WITNESS_V0_SCRIPTHASH_SIZE){}
  else if (program.size() == WITNESS_V0_KEYHASH_SIZE){}
  else { set_error (...) }
}
else if (witversion == 1 && program.size() == WITNESS_V1_TAPROOT_SIZE && !is_p2sh)
{...}
else
   return true;
8  Bitcoin / Development & Technical Discussion / Shouldn't DNS seeds avoid returning pruned nodes? on: May 02, 2021, 07:31:09 AM
Considering the fact that nodes mainly dig DNS seeds when they start for the first time why are they returning pruned nodes (NodeNetworkLimited)?
Right now almost all IP addresses returned from DNS seeds are pruned nodes which has made downloading blocks impossible for me.

Another issue I noticed is that some of the addresses they return are not useful at all (I either get timeouts or the connection is refused or there isn't any node at all to connect to).
For example the following list is a handful of invalid IP addresses that seed.bitcoin.sipa.be returns:
Code:
95.116.33.86
15.185.229.194
34.101.110.211
68.104.65.149
52.78.217.89
34.86.209.19
9  Bitcoin / Development & Technical Discussion / [Experimental-2] Better mnemonic on: April 13, 2021, 06:56:38 AM
We're trying to address some of the problems and shortcoming with the existing mnemonic algorithms namely BIP-39 and Electrum. The idea is to add the information that the wallet needs to derive child keys to final string that the user writes down and more importantly we see mnemonic as a simple encoding and avoid modifying the entropy when deriving the BIP-32 seed (see #4).

The C# implementation can be found here: https://github.com/Autarkysoft/Denovo/blob/master/Src/Autarkysoft.Bitcoin/Experimental/BetterMnemonic.cs
Like any experimental class under Experimental namespace this is a rough idea and the code is untested.

Code:
4 bit version | 4 bit depth | 32 bit index * depth | CompactInt entropy length | entropy | checksum (pad)

1. Scalability
To make the algorithm scalable a small 4 bit version is added to the beginning of the encoding. This way we can have different definitions using the same scheme.

2. Derivation path/script type
In order to let the wallet know which BIP-32 derivation path to use, that path has to be encoded into the mnemonic. This path could also act as the script (address) type of the child keys. For instance m/84'/0'/0'/0 is for P2WPKH addresses.
The downside is increasing the length of the final mnemonic. This could be mitigated by introducing version 2 where instead of encoding the entire path a 4 bit integer is used to indicate the predefined paths. 16 hard-coded paths can be defined this way and for anything new next version could be used.
version 1: 4-bit version | 4 bit derivation path depth | each index as 32-bit unsigned integers
version 2: 4-bit version | 4 bit hard-coded path

BIP-39 doesn't have this feature.
Electrum has a partial solution by first increasing the entropy size from 128 to 132 bits then brute forcing a version that indicates the derivation paths and script types

3. Creation time
This can be useful for the full nodes to avoid re-scanning the entire blockchain when the user imports their mnemonic. The creation time (as a LockTime object) can quickly tell the client from when in the history to begin the scan. For example a mnemonic created today doesn't have to scan the 300 GB of existing history.
Since this is LockTime as used in transactions (instead of simple DateTime) it could be used by both online and offline clients generating the mnemonic as the online synced client knows the block height and can use that and the offline (cold storage) can use the DateTime (values as Unix timestamp and above 500,000,000).

The rest is implementation detail, for example the wallet UI can show the LockTime (block height or DateTime) and still give the user the option to do a full rescan.

4. No modification of the initial entropy
This is the main and biggest difference. Both BIP-39[2] and Electrum[3] are modifying the mnemonic:
A. Modifying by normalization
BIP-39 uses a Unicode normalization with full compatibility decomposition (form KD) but Electrum takes a step further and modifies the input mnemonic more by removing accents, changing Chinese words, removing spaces for word lists other than English, etc. Then the byte array representation of the string is used to derive the keys.
This can create incompatibility between different implementations and lead to losses specially for any word list other than English.

If the words are only used to look up index of each word in the word list to get the entropy out and nothing else, this problem is eliminated.
In other words if user enters a word like "aliener" instead of "aliéner" (from French word list) it still can be searched inside the word list and if the search fails (due to bad normalization) the import process fails right away instead of going ahead. While normalizing this word can give different values:
Code:
0x616c6965cc816e6572  No normalization
0x616c6965cc816e6572  NFKD
0x616c69656e6572      Electrum
0x616c69656e6572      No accent
The problem is more palpable when using Japanese word list for example (the start of the difference is marked by ^, also note the lengths):
Code:
そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかめ
e3819de381a4e38186e38080e3828ce3818de381a0e38184e38080e381bbe38293e38284e3818fe38080e3828fe3818be38199e38080e3828ae3818fe381a4e38080e381b0e38184e3818be38080e3828de3819be38293e38080e38284e381a1e38293e38080e3819de381a4e38186e38080e3828ce3818de381a0e38184e38080e381bbe38293e38284e3818fe38080e3828fe3818be38281
e3819de381a4e38186e3828ce3818de3819fe38184e381bbe38293e38284e3818fe3828fe3818be38199e3828ae3818fe381a4e381afe38184e3818be3828de3819be38293e38284e381a1e38293e3819de381a4e38186e3828ce3818de3819fe38184e381bbe38293e38284e3818fe3828fe3818be38281
e3819de381a4e3818620e3828ce3818de3819fe38299e3818420e381bbe38293e38284e3818f20e3828fe3818be3819920e3828ae3818fe381a420e381afe38299e38184e3818b20e3828de3819be3829320e38284e381a1e3829320e3819de381a4e3818620e3828ce3818de3819fe38299e3818420e381bbe38293e38284e3818f20e3828fe3818be38281
                  ^

B. Use the UTF-8 decoded bytes of the mnemonic instead of the entropy
When creating a mnemonic a random entropy with a good distribution of bits is chosen. For example in a 12 word mnemonic the entropy is an octet string with length of 16 (ie. 128 bits). Each octet can have a value between 0 and 255 inclusive which is 256 different values.
When this is converted to 12 words using English word list then UT8 decoded to be used to derive BIP-32 seed, it is a longer octet string but each octet can only have a value between 97 and 122 inclusive which is only 26 different values.
In other words a big bias is introduced in the input of PBKDF2 while the initial entropy had no bias at all (assuming it was chosen using a strong RNG).

By using the entropy itself we can eliminate this bias and also avoid the normalization bugs that could occur in different implementations while greatly simplifying the implementation.

Downside
The only disadvantage of this proposal is the longer mnemonic. For example a 12-word BIP-39/Electrum mnemonic would turn into a 26-word version 1 BetterMnemonic using BIP-84 derivation path (without locktime) or 14-word version 2+ (without locktime).

[1] Experimental-1: https://bitcointalk.org/index.php?topic=5245712.0
[2] https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#from-mnemonic-to-seed
[3] https://github.com/spesmilo/electrum/blob/392a648de5f6edf2e06620763bf0685854d0d56d/electrum/mnemonic.py
10  Bitcoin / Development & Technical Discussion / I need help understanding secp256k1_scalar_check_overflow (from secp256k1 lib.) on: April 04, 2021, 12:48:11 PM
I understand what it does and why, I just don't get how it does it.
Code:
SECP256K1_INLINE static int secp256k1_scalar_check_overflow(const secp256k1_scalar *a) {
    int yes = 0;
    int no = 0;
    no |= (a->d[7] < SECP256K1_N_7); /* No need for a > check. */
    no |= (a->d[6] < SECP256K1_N_6); /* No need for a > check. */
    no |= (a->d[5] < SECP256K1_N_5); /* No need for a > check. */
    no |= (a->d[4] < SECP256K1_N_4);
    yes |= (a->d[4] > SECP256K1_N_4) & ~no;
    no |= (a->d[3] < SECP256K1_N_3) & ~yes;
    yes |= (a->d[3] > SECP256K1_N_3) & ~no;
    no |= (a->d[2] < SECP256K1_N_2) & ~yes;
    yes |= (a->d[2] > SECP256K1_N_2) & ~no;
    no |= (a->d[1] < SECP256K1_N_1) & ~yes;
    yes |= (a->d[1] > SECP256K1_N_1) & ~no;
    yes |= (a->d[0] >= SECP256K1_N_0) & ~no;
    return yes;
}
Link
11  Bitcoin / Armory / Is there any Armory backup phrase test vectors? on: March 04, 2021, 06:47:47 AM
I'm adding a new recovery option for Armory's paper backup to FinderOuter but I need some test vectors from the project itself which I couldn't find. It also doesn't help that the repository is a fork and GitHub doesn't search within forks.

Could you help me find some, specially the process for deriving addresses from the "recovery phrase"?
12  Bitcoin / Development & Technical Discussion / Why is my block being rejected for having "high hash"? on: February 22, 2021, 10:58:31 AM
Using bitcoin core 0.21.0 on RegTest.
Block #101 with the default RegTest target of 0x207fffff
Full header is
Code:
00000020c21aa3b43d104b5db7eb46d90430308b668b4edebdd23d72ba6cfc685601f1666769ae0d507824c9b1220f02db880618240a6b5dff17c1319a443eadd4b218e7a76c3360ffff7f2000000000
Hash versus target:
Code:
6f295fbd976fd8dd1668bf4ba82b8e7b2089c3497cf3f9dc4a61beb519992958
7fffff0000000000000000000000000000000000000000000000000000000000

50279827699679515341806937817482573096355300064251967888806579886749916932440
57896037716911750921221705069588091649609539881711309849342236841432341020672

This block is being rejected by core with a short message only saying "high-hash".
13  Bitcoin / Development & Technical Discussion / Assuming block.vtx.size() return tx count why is it used for block size check? on: February 20, 2021, 09:07:07 AM
I'm trying to figure out what validations are being performed on block size and so far found this line:
https://github.com/bitcoin/bitcoin/blob/828bb776d29cbdfad3937ba100c428e3244c652f/src/validation.cpp#L3348
Code:
if (block.vtx.empty() || 
    block.vtx.size() * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT ||
    ::GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)

Google tells me that in c++ the size() method in std::vector (which is block.vtx type) returns item count which makes me wonder why is transaction count being multiplied by 4 and compared with max block weight?
14  Bitcoin / Development & Technical Discussion / How many blocks can/should I request from a node at one time? on: January 07, 2021, 07:37:59 AM
As far as I can tell the only way to download blocks from another peer is through using getdata messages (is there any other messages?) which have a limit of 50000 items; but there is also MAX_BLOCKS_IN_TRANSIT_PER_PEER (=16) which I'm not sure what it's used for.

My getdata requests with 17 inventories are ignored sometimes which has left me confused. I'm not sure if it is the limit on number of blocks I can request or if it is fPauseSend which will then erase the m_getdata_requests completely here which means the request is ignored entirely.
15  Bitcoin / Development & Technical Discussion / Is there any research on different key-value DBs suitable for bitcoin? on: December 26, 2020, 05:42:41 AM
I'm starting to look into key-value stores and I'm curious whether there has been any research and comparison between different options from a bitcoin usage point of view.
I'm looking into MongoDB, Redis, PostGres, Cassandra and of course BerkeleyDB since bitcoin core uses it. There are a lot more options which make things even harder.

The information I've found so far are for purposes different than bitcoin, for instance PostGres is used by Reddit and they claim it is the fastest based on their benchmarks.

Hopefully a comparison into their performance (speed) and scalability but also I'm also interested in concurrency and whether it could be taken advantage of using these DBs. I know that Cassandra and Redis support concurrency but BerkeleyDB doesn't seem to.
16  Bitcoin / Development & Technical Discussion / Question about ServiceFlags: None and NetworkLimited on: December 15, 2020, 09:34:58 AM
1. Why or when would a node set its ServiceFlags to NONE?
I'm probably testing "fake" nodes again but they seem to be providing me with headers without an issue.

2. Are NetworkLimited nodes capable of supplying all block headers even though they don't have most of the blocks?
17  Bitcoin / Electrum / Looking for derivation paths used for different Electrum mnemonic types on: November 06, 2020, 07:54:15 AM
I just added the recovery option for Electrum mnemonics to The FinderOuter and even though the derivation path could be set manually but it would be simpler if it were set automatically based on mnemonic type selected (or the address type entered).


However I couldn't find what derivation path is used for each mnemonic type above (eg. m/0 for standard) and need help.
I'd appreciate it if you could also include the link to code where it is defined.
18  Bitcoin / Development & Technical Discussion / Why do nodes ignore the relay=false in version and send MSG_TX inv? on: October 28, 2020, 06:45:18 AM
It is my understanding that when the relay (the last byte of a version message) is set to 0 (false) the other node is supposed to not send any inv messages containing transactions but they seem to ignore this and at the very beginning of the connection (after handshake) start sending inv messages of type MSG_TX.
Why is that?


Haven't tried all but from those that tested so far: new bitcoin core versions (0.20.1 and 0.18.0) are like this while old ones (0.12.1) aren't. In other words the new versions seem to not respect the relay flag anymore.
19  Bitcoin / Development & Technical Discussion / Why was the 6th ServiceFlags bit skipped? on: October 12, 2020, 03:41:25 PM
The ServiceFlags enum is jumping from the previously defined 5th bit (1 << 4 ie XThin) to 7th bit (1 << 6 ie CompactFilters). I couldn't find the 6th bit ever being set in the history of protocol.h file so is there any reason for this jump?

https://github.com/bitcoin/bitcoin/blob/af22322dab1a2277483b2512723491a5fad1a606/src/protocol.h#L268-L302
20  Bitcoin / Development & Technical Discussion / Why does core send its own addr message to inbound connections? on: October 01, 2020, 12:36:22 PM
Although the code seems to be sending addr message to outbound connections (ref) but in my experience it is sending it to inbound connections too.
And in both cases I can't think of why it is doing that. When the connection is made specially if it is initiated by the other node, they should know our address and sending it again seems pointless to me.
On top of that the addr message is sent after version message (hand-shake) which already contains connection information (ie. the addr message).
Pages: [1] 2 3 4 5 6 »
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!