Libbitcoin Consensus: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
Evoskuil (talk | contribs)
c++ include link
Evoskuil (talk | contribs)
 
(4 intermediate revisions by the same user not shown)
Line 27: Line 27:
   
   
     constexpr uint32_t tx_input_index = 0;
     constexpr uint32_t tx_input_index = 0;
     constexpr uint32_t flags = verify_flags_standard | verify_flags_mandatory;
     constexpr uint32_t flags = verify_flags_p2sh |
        verify_flags_checklocktimeverify | verify_flags_dersig;
   
   
     const std::string tx(VERIFY_TX);
     const std::string tx(VERIFY_TX);
Line 45: Line 46:
The consensus library exists to provide consensus validation identical in outcome to [[Bitcoind|bitcoind]]. The integral [[Libbitcoin_Common|libbitcoin]] script engine provides the same checks. However given the complexity of the validation code it is effectively impossible to prove that two implementations are identical in outcome, even with extensive testing. This effectively makes the bitcoind ''implementation'' a standard (as opposed to an RFC or BIP).
The consensus library exists to provide consensus validation identical in outcome to [[Bitcoind|bitcoind]]. The integral [[Libbitcoin_Common|libbitcoin]] script engine provides the same checks. However given the complexity of the validation code it is effectively impossible to prove that two implementations are identical in outcome, even with extensive testing. This effectively makes the bitcoind ''implementation'' a standard (as opposed to an RFC or BIP).


That has helped stifle the adoption of alternative full node implementations. While it has been argued that consensus risk from any particular implementation is a red herring<ref>[https://blog.conformal.com/the-bitcoin-consensus-red-herring The Bitcoin Consensus Red Herring]</ref> it was decided to give libbitcoin developers and users the option. Following much deliberation<ref>[https://lists.dyne.org/lurker/message/20150214.111556.61403f4c.en.html Libbitcoinconsensus Discussion on Libbitcoin Mailing List]</ref> and a recommendation by [[Peter_Todd|Peter Todd]]<ref>[https://lists.dyne.org/lurker/message/20150325.083041.77f52cd3.en.html Response to Peter Todd "Twinkle Fingers" Post on Bitcoin-Dev]</ref> it was decided to package this library independently in order to provide better consistency, a leaner dependency, and more formal isolation from bitcoind. The library is free of both libbitcoin and bitcoind dependencies.<ref>[https://github.com/libbitcoin/libbitcoin-consensus/blob/master/README.md Instructions for Building libbitcoin-consensus]</ref>
That has helped stifle the adoption of alternative full node implementations. While it has been argued that consensus risk from any particular implementation is a red herring<ref>[https://blog.conformal.com/the-bitcoin-consensus-red-herring The Bitcoin Consensus Red Herring]</ref> it was decided to give Libbitcoin developers and users the option. Following much deliberation<ref>[https://lists.dyne.org/lurker/message/20150214.111556.61403f4c.en.html Libbitcoinconsensus Discussion on Libbitcoin Mailing List]</ref> and a recommendation by [[Peter_Todd|Peter Todd]]<ref>[https://lists.dyne.org/lurker/message/20150325.083041.77f52cd3.en.html Response to Peter Todd "Twinkle Fingers" Post on Bitcoin-Dev]</ref><ref>[https://plus.google.com/u/0/+AvatarEquis/posts/JjFnTf3iY1E "Peter Todd takes the gloves off on this letter to Libbitcoin Devs" - AvatarX]</ref> it was decided to package this library independently in order to provide better consistency, a leaner dependency, and more formal isolation from bitcoind. The library is free of both libbitcoin and bitcoind dependencies.<ref>[https://github.com/libbitcoin/libbitcoin-consensus/blob/master/README.md Instructions for Building libbitcoin-consensus]</ref>


==Verification==
==Verification==
Line 57: Line 58:


==Dependencies==
==Dependencies==
* [https://www.openssl.org openssl] (optional, default)
* [https://github.com/bitcoin/secp256k1 libsecp256k1]
* [https://github.com/bitcoin/secp256k1 libsecp256k1] (optional, experimental)
* [http://www.boost.org boost test] (tests only)
* [http://www.boost.org/doc/libs/1_55_0/libs/test/doc/html/index.html boost test] (tests only)


==See Also==
==See Also==
Line 65: Line 65:


==References==
==References==
[[Category:Open Source]]
[[Category:Software‏‎]]

Latest revision as of 17:38, 8 March 2017

The libbitcoin-consensus library is an optional dependency of libbitcoin-blockchain. It is conceptually redundant with native functionality within libbitcoin.

Example

#include <cstdint>
#include <string>
#include <vector>
#include <bitcoin/consensus.hpp>

// For bc::decode_base16 utility.
#include <bitcoin/bitcoin.hpp>

#define VERIFY_TX \
    "01000000017d01943c40b7f3d8a00a2d62fa1d560bf739a2368c180615b0a793" \
    "7c0e883e7c000000006b4830450221008f66d188c664a8088893ea4ddd968902" \
    "4ea5593877753ecc1e9051ed58c15168022037109f0d06e6068b7447966f751d" \
    "e8474641ad2b15ec37f4a9d159b02af68174012103e208f5403383c77d5832a2" \
    "68c9f71480f6e7bfbdfa44904becacfad66163ea31ffffffff01c8af00000000" \
    "00001976a91458b7a60f11a904feef35a639b6048de8dd4d9f1c88ac00000000"

#define PREVOUT_SCRIPT \
    "76a914c564c740c6900b93afc9f1bdaef0a9d466adf6ee88ac"

// Validate a transaction against a single previous output script.
int main()
{
    using namespace libbitcoin::consensus;

    constexpr uint32_t tx_input_index = 0;
    constexpr uint32_t flags = verify_flags_p2sh |
       verify_flags_checklocktimeverify | verify_flags_dersig;

    const std::string tx(VERIFY_TX);
    const std::string ps(PREVOUT_SCRIPT);

    std::vector<uint8_t> tx_data, ps_data;
    /* bool */ bc::decode_base16(tx_data, tx);
    /* bool */ bc::decode_base16(ps_data, ps);

    const auto result = verify_script(&tx_data[0], tx_data.size(),
        &ps_data[0], ps_data.size(), tx_input_index, flags);

    return result == verify_result_eval_true ? 0 : 1;
}

Background

The consensus library exists to provide consensus validation identical in outcome to bitcoind. The integral libbitcoin script engine provides the same checks. However given the complexity of the validation code it is effectively impossible to prove that two implementations are identical in outcome, even with extensive testing. This effectively makes the bitcoind implementation a standard (as opposed to an RFC or BIP).

That has helped stifle the adoption of alternative full node implementations. While it has been argued that consensus risk from any particular implementation is a red herring[1] it was decided to give Libbitcoin developers and users the option. Following much deliberation[2] and a recommendation by Peter Todd[3][4] it was decided to package this library independently in order to provide better consistency, a leaner dependency, and more formal isolation from bitcoind. The library is free of both libbitcoin and bitcoind dependencies.[5]

Verification

This library incorporates the files that have been identified as "consensus critical" in bitcoind. It is straightforward to verify the implementation against bitcoind by overlaying the bitcoind sources and performing a difference option. With each tagged release of bitcoind this library is updated with the files identified in the libbitcoinconsensus build.

Bindings

The library exposes a C++ interface and includes SWIG generated bindings for other languages. Libbitcoin is a C++ toolkit, the underlying bitcoind sources are C++, and SWIG bindings are easily generated over C++. For these reasons the native interface is C++, in contrast to the libbitcoinconsensus interface which is C.

Dependencies

See Also

References