When compile bitcoin by the toolchain(riscv32-unknown-elf-g++
) from risc0 , the compiler argument is -march=rv32i, -mabi=ilp32
, which will get the error which due to not serialize the value of type int .
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);
Reason
“The toolchain from RISC Zero defines int and int32_t as different types, although they have the same width. This means that src/compat/assumptions.h
compiles fine; however, the templated serialization code cannot accept values of type int. Fix the compilation on RISC Zero by serializing int32_t instead of int values.
This patch will explicitly use the int32_t
type instead of int
to avoid errors when compiling with the risc0 toolchain. Additionally, this patch will not change any behavior on platforms where compilation was previously successful.
Fixes #30747