54 const bool bit = (std::to_integer<uint8_t>(bytes[
bitpos / 8]) >> (
bitpos % 8)) & 1;
65 const bool bit = (std::to_integer<uint8_t>(bytes[
bitpos / 8]) >> (7 - (
bitpos % 8))) & 1;
165constexpr uint8_t JUMP_BIT_SIZES[]{5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
189 if (
opcode == Instruction::RETURN) {
194 }
else if (
opcode == Instruction::JUMP) {
204 }
else if (
opcode == Instruction::MATCH) {
213 for (
int bit = 0; bit <
matchlen; bit++) {
219 }
else if (
opcode == Instruction::DEFAULT) {
241 std::vector<std::pair<uint32_t, int>>
jumps;
248 if (!
jumps.empty() && pos >=
jumps.back().first)
return false;
251 if (
opcode == Instruction::RETURN) {
253 if (
prevopcode == Instruction::DEFAULT)
return false;
258 if (
endpos - pos > 7)
return false;
265 if (pos !=
jumps.back().first)
return false;
266 bits =
jumps.back().second;
270 }
else if (
opcode == Instruction::JUMP) {
274 if (bits == 0)
return false;
280 }
else if (
opcode == Instruction::MATCH) {
291 }
else if (
opcode == Instruction::DEFAULT) {
293 if (
prevopcode == Instruction::DEFAULT)
return false;
311 LogWarning(
"Sanity check of asmap data failed\n");
325 LogWarning(
"Failed to open asmap file from disk");
332 std::vector<std::byte> buffer(length);
348 if (
data.empty())
return {};
Non-refcounted RAII wrapper for FILE*.
A writer stream (for serialization) that computes a 256-bit hash.
uint256 GetSHA256()
Compute the SHA256 hash of all data written to this object.
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
static CService ip(uint32_t i)
static auto quoted(const std::string &s)
static std::string PathToString(const path &path)
Convert path object to a byte string.
FILE * fopen(const fs::path &p, const char *mode)
bool SanityCheckAsmap(const std::span< const std::byte > asmap, int bits)
Validates ASMap structure by simulating all possible execution paths.
bool CheckStandardAsmap(const std::span< const std::byte > data)
Provides a safe interface for validating ASMap data before use.
std::vector< std::byte > DecodeAsmap(fs::path path)
Loads an ASMap file from disk and validates it.
uint32_t Interpret(const std::span< const std::byte > asmap, const std::span< const std::byte > ip)
Execute the ASMap bytecode to find the ASN for an IP.
uint256 AsmapVersion(const std::span< const std::byte > data)
Computes SHA256 hash of ASMap data for versioning and consistency checks.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.