MyHush / hush3

Hush: Speak And Transact Freely
https://myhush.org
Other
15 stars 13 forks source link

Avoid Undefined Behavior in arith_uint256 #77

Closed leto closed 4 years ago

leto commented 4 years ago

Fixed in BTC one way: https://github.com/bitcoin/bitcoin/pull/14510

And in ZEC a slightly different way: https://github.com/zcash/zcash/pull/4056

oDinZu commented 4 years ago

What are the differences between the two implementations?

From what I have researched, it comes down to blocking and non-blocking algorithm. Anything undefined in the programming world creates possible challenges in the future.

https://github.com/zcash/zcash/issues/3792

What does arith_uint.cpp do? Is there a glossary to aid in learning various pieces in bitcoin cpp that create the whole application using the English language :smile: ? My conversion ratio of cpp and English are rusty.

Assigning a U defines a 'unsigned' integer in Cpp.

In programming Cpp, the difference between a signed short int and unsigned short int is one allows negative numbers, while the other begins from 0 to positive numbers. https://en.cppreference.com/w/cpp/language/types

leto commented 4 years ago

@csharpee close, but not quite. Undefined Behavior = UB means that a compiler can do anything it wants, there is no standard. It could core dump and still "follow the spec". We must avoid UB so that our code compiles anywhere and works correctly. This is not about blocking (synchronous) and non-blocking (asynchronous) : https://en.wikipedia.org/wiki/Undefined_behavior

You will need to read source code and comments to understand things about a lot of BTC internals. Sometimes the book "Mastering Bitcoin" can help, I haven't read any others. arith_uint256 are 256 bit integers with arithmetic operations, uint256 objects are just 256 bit blobs with no arithmetic operators.

leto commented 4 years ago

Fixed