94 lines
3.5 KiB
C++
94 lines
3.5 KiB
C++
/*
|
|
* This file is part of the Flowee project
|
|
* Copyright (C) 2009-2010 Satoshi Nakamoto
|
|
* Copyright (C) 2009-2015 The Bitcoin Core developers
|
|
* Copyright (C) 2021 Tom Zander <tom@flowee.org>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef FLOWEE_SCRIPT_DEFINES_H
|
|
#define FLOWEE_SCRIPT_DEFINES_H
|
|
|
|
#include <cstdint>
|
|
|
|
// Maximum number of bytes pushable to the stack before CHIP-2025-05 VM limits.
|
|
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE_LEGACY = 520;
|
|
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = MAX_SCRIPT_ELEMENT_SIZE_LEGACY;
|
|
|
|
// Maximum number of non-push operations per script before CHIP-2021-05 VM limits.
|
|
static const int MAX_OPS_PER_SCRIPT_LEGACY = 201;
|
|
static const int MAX_OPS_PER_SCRIPT = MAX_OPS_PER_SCRIPT_LEGACY;
|
|
|
|
// Maximum script length in bytes.
|
|
static const int MAX_SCRIPT_SIZE = 10000;
|
|
|
|
// Maximum number of values on the stack plus altstack plus function table.
|
|
static const int MAX_STACK_SIZE = 1000;
|
|
|
|
// Maximum number of public keys per multisig
|
|
static const int MAX_PUBKEYS_PER_MULTISIG = 20;
|
|
|
|
// Threshold for nLockTime: below this value it is interpreted as block number,
|
|
// otherwise as UNIX timestamp.
|
|
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
|
|
|
|
namespace may2025 {
|
|
|
|
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = MAX_SCRIPT_SIZE;
|
|
static const unsigned int OPCODE_COST = 100;
|
|
static const unsigned int MAX_CONDITIONAL_STACK_DEPTH = 100;
|
|
static const unsigned int SIG_CHECK_COST_FACTOR = 26000;
|
|
|
|
namespace detail {
|
|
static const unsigned int HASH_ITER_BONUS_FOR_NONSTD_TXNS = 7;
|
|
static const unsigned int OP_COST_BUDGET_PER_INPUT_BYTE = 800;
|
|
static const unsigned int HASH_COST_PENALTY_FOR_STD_TXNS = 3;
|
|
static const unsigned int HASH_BLOCK_SIZE = 64;
|
|
static const unsigned int INPUT_SCRIPT_SIZE_FIXED_CREDIT = 41;
|
|
|
|
inline int64_t GetInputHashItersLimit(bool standard, uint64_t scriptSigSize) noexcept
|
|
{
|
|
const unsigned int factor = standard ? 1 : HASH_ITER_BONUS_FOR_NONSTD_TXNS;
|
|
return static_cast<int64_t>((scriptSigSize + INPUT_SCRIPT_SIZE_FIXED_CREDIT) * factor / 2);
|
|
}
|
|
|
|
inline int64_t GetInputOpCostLimit(uint64_t scriptSigSize) noexcept
|
|
{
|
|
return static_cast<int64_t>(scriptSigSize + INPUT_SCRIPT_SIZE_FIXED_CREDIT) * OP_COST_BUDGET_PER_INPUT_BYTE;
|
|
}
|
|
} // namespace detail
|
|
|
|
inline int64_t GetHashIterOpCostFactor(bool standard) noexcept
|
|
{
|
|
return standard ? detail::HASH_BLOCK_SIZE * detail::HASH_COST_PENALTY_FOR_STD_TXNS
|
|
: detail::HASH_BLOCK_SIZE;
|
|
}
|
|
|
|
inline int64_t CalcHashIters(uint32_t messageLength, bool isTwoRoundHashOp) noexcept
|
|
{
|
|
return static_cast<int64_t>(isTwoRoundHashOp) + 1 +
|
|
((static_cast<uint64_t>(messageLength) + 8) / detail::HASH_BLOCK_SIZE);
|
|
}
|
|
|
|
} // namespace may2025
|
|
|
|
namespace may2026 {
|
|
static const unsigned int MAX_FUNCTION_IDENTIFIER_SIZE = 7;
|
|
static const unsigned int MAX_CONTROL_STACK_DEPTH = may2025::MAX_CONDITIONAL_STACK_DEPTH;
|
|
} // namespace may2026
|
|
|
|
|
|
#endif
|