Risczero Fit #30747

issue ludete openend this issue on August 29, 2024
  1. ludete commented at 7:55 am on August 29, 2024: none

    Please describe the feature you’d like to see added.

    Support the risczero platfrom by riscv32-unknown-elf-g++. which will bring more prove system for bitcoin.

    when i compile by riscv32-unknown-elf-g++ compiler, get the below error:

    0blockbody-guest:   cargo:warning=In file included from depend/bitcoin/src/hash.h:14,
    1blockbody-guest:   cargo:warning=                 from depend/bitcoin/src/script/interpreter.h:9,
    2blockbody-guest:   cargo:warning=                 from depend/bitcoin/src/script/interpreter.cpp:6:
    3blockbody-guest:   cargo:warning=depend/bitcoin/src/serialize.h: In instantiation of 'void Serialize(Stream&, const T&) [with Stream = HashWriter; T = int]':
    4blockbody-guest:   cargo:warning=depend/bitcoin/src/hash.h:144:20:   required from 'HashWriter& HashWriter::operator<<(const T&) [with T = int]'
    5blockbody-guest:   cargo:warning=depend/bitcoin/src/script/interpreter.cpp:1613:12:   required from 'uint256 SignatureHash(const CScript&, const T&, unsigned int, int, const CAmount&, SigVersion, const PrecomputedTransactionData*) [with T = CTransaction; CAmount = long long int]'
    6blockbody-guest:   cargo:warning=depend/bitcoin/src/script/interpreter.cpp:1664:36:   required from 'bool GenericTransactionSignatureChecker<T>::CheckECDSASignature(const std::vector<unsigned char>&, const std::vector<unsigned char>&, const CScript&, SigVersion) const [with T = CTransaction]'
    7blockbody-guest:   cargo:warning=depend/bitcoin/src/script/interpreter.cpp:1785:16:   required from here
    8blockbody-guest:   cargo:warning=depend/bitcoin/src/serialize.h:776:7: error: request for member 'Serialize' in 'a', which is of non-class type 'const int'
    9blockbody-guest:   cargo:warning=  776 |     a.Serialize(os);
    

    This error is caused by the logic in the SignatureHash function within src/script/interpreter.cpp. The function serializes the data to obtain a hash value, but it fails to find a serialization method for the int type.

    0// Sighash type
    1ss << nHashType;
    

    This behavior is particularly strict in environments like RISC-V, where the ABI (Application Binary Interface) might enforce more rigid type distinctions, leading to errors during compilation.

    The -march=rv32i -mabi=ilp32 for the compiler(riscv32-unknown-elf-g++).

    Describe the solution you’d like

    This issue was temporarily bypassed by adding serialization/deserialization code for the int type. Supporting R0 will allow the BTC L2 prover to extend to more proof systems.

    Add methods temporarily in the PR
    https://github.com/rust-bitcoin/rust-bitcoinconsensus/pull/97/files; Maybe best solution from the commiunity.

    Describe any alternatives you’ve considered

    No response

    Please leave any additional context

    No response

  2. ludete added the label Feature on Aug 29, 2024
  3. maflcko commented at 8:15 am on August 29, 2024: member

    This issue was temporarily bypassed by adding serialization/deserialization code for the int type. Supporting R0 will allow the BTC L2 prover to extend to more proof systems.

    Interesting. All int widths should already be possible to serialize, according to the code:

    0template<typename Stream> inline void Serialize(Stream& s, int16_t a ) { ser_writedata16(s, a); }
    1template<typename Stream> inline void Serialize(Stream& s, uint16_t a) { ser_writedata16(s, a); }
    2template<typename Stream> inline void Serialize(Stream& s, int32_t a ) { ser_writedata32(s, a); }
    3template<typename Stream> inline void Serialize(Stream& s, uint32_t a) { ser_writedata32(s, a); }
    4template<typename Stream> inline void Serialize(Stream& s, int64_t a ) { ser_writedata64(s, a); }
    5template<typename Stream> inline void Serialize(Stream& s, uint64_t a) { ser_writedata64(s, a); }
    

    I guess int is somehow a distinct type in your environment?

    Please be aware that violations in src/compat/assumptions.h may lead to incorrectly compiled code.

    I see that https://github.com/rust-bitcoin/rust-bitcoinconsensus/blob/0fcec269c6c7fee11b163c6800c998eee9b64df6/depend/bitcoin/src/serialize.h lacks that include, whereas in current master in this repo, it is present.

    Can you try to compile static_assert(std::is_same_v<int, int32_t>); on your system, as well as assumptions.h?

    (Godbolt: https://godbolt.org/z/T9bY9PrPx)

  4. maflcko added the label Build system on Aug 29, 2024
  5. maflcko added the label Consensus on Aug 29, 2024
  6. maflcko added the label Questions and Help on Aug 29, 2024
  7. nicholas-1vbw commented at 9:00 am on August 30, 2024: none

    Using toolchain from risc0, main.cpp that includes assumptions.h compiles successfully, but fails with static_assert(std::is_same_v<int, int32_t>);

    Actually, the toolchain from risc0 does have different type of “int” and “int32_t”, see https://github.com/risc0/toolchain/releases/tag/2024.01.05

    int32_t is defined in “riscv32-unknown-elf/include/sys/_stdint.h”

     0#ifdef ___int32_t_defined
     1#ifndef _INT32_T_DECLARED
     2typedef __int32_t int32_t ;
     3#define _INT32_T_DECLARED
     4#endif
     5#ifndef _UINT32_T_DECLARED
     6typedef __uint32_t uint32_t ;
     7#define _UINT32_T_DECLARED
     8#endif
     9#define __int32_t_defined 1
    10#endif /* ___int32_t_defined */
    

    Maybe, we should static_cast/reinterpret_cast to int32_t on all “int” types, such as nHashType.

  8. maflcko commented at 5:59 am on September 3, 2024: member

    assumptions.h compiles successfully, but fails with static_assert(std::is_same_v<int, int32_t>);

    Ok, that means int has the correct width and thus the correct behavior, apart from being a separate type that the serialization templates can’t deal with.

  9. achow101 closed this on Sep 20, 2024

  10. kashifs referenced this in commit 48c20dbd86 on Sep 20, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-03 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me