Skip to content

Commit

Permalink
feat: partial restore of knuth vm
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni committed Jan 9, 2025
1 parent 557cd8a commit 3c5a946
Show file tree
Hide file tree
Showing 18 changed files with 1,788 additions and 659 deletions.
18 changes: 14 additions & 4 deletions include/kth/domain/chain/script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ class KD_API script : public script_basis {
//-------------------------------------------------------------------------

static
hash_digest generate_signature_hash(transaction const& tx,
std::pair<hash_digest, size_t> generate_signature_hash(transaction const& tx,
uint32_t input_index,
script const& script_code,
uint8_t sighash_type,
script_version version = script_version::unversioned,
uint64_t value = max_uint64);

static
bool check_signature(ec_signature const& signature,
std::pair<bool, size_t> check_signature(ec_signature const& signature,
uint8_t sighash_type,
data_chunk const& public_key,
script const& script_code,
Expand Down Expand Up @@ -231,6 +231,16 @@ class KD_API script : public script_basis {

bool is_pay_to_script_hash(uint32_t forks) const;

// Validation.
//-----------------------------------------------------------------------------

//TODO: move to script_basis (?)
static
code verify(transaction const& tx, uint32_t input_index, uint32_t forks, script const& input_script, script const& prevout_script, uint64_t /*value*/);

static
code verify(transaction const& tx, uint32_t input, uint32_t forks);

private:
static
size_t serialized_size(operation::list const& ops);
Expand All @@ -239,10 +249,10 @@ class KD_API script : public script_basis {
data_chunk operations_to_data(operation::list const& ops);

static
hash_digest generate_unversioned_signature_hash(transaction const& tx, uint32_t input_index, script const& script_code, uint8_t sighash_type);
std::pair<hash_digest, size_t> generate_unversioned_signature_hash(transaction const& tx, uint32_t input_index, script const& script_code, uint8_t sighash_type);

static
hash_digest generate_version_0_signature_hash(transaction const& tx,
std::pair<hash_digest, size_t> generate_version_0_signature_hash(transaction const& tx,
uint32_t input_index,
script const& script_code,
uint64_t value,
Expand Down
2 changes: 1 addition & 1 deletion include/kth/domain/chain/script_basis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class KD_API script_basis {
// hash_digest generate_unversioned_signature_hash(transaction const& tx, uint32_t input_index, script_basis const& script_code, uint8_t sighash_type);

static
hash_digest generate_version_0_signature_hash(transaction const& tx, uint32_t input_index, script_basis const& script_code, uint64_t value, uint8_t sighash_type);
std::pair<hash_digest, size_t> generate_version_0_signature_hash(transaction const& tx, uint32_t input_index, script_basis const& script_code, uint64_t value, uint8_t sighash_type);

void find_and_delete_(data_chunk const& endorsement);

Expand Down
7 changes: 6 additions & 1 deletion include/kth/domain/config/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ kth::infrastructure::config::checkpoint::list default_checkpoints(config::networ
checkpoints.emplace_back("00000000e4627a1a0bf9aaae007af5cea32720fb54cf2ccf0aa20b02a18392ab", 16869); //mediantime: 1605444236. New rules activated in this block.

} else if (network == domain::config::network::chipnet) {
checkpoints.reserve(12);
checkpoints.reserve(17);

checkpoints.emplace_back("000000001dd410c49a788668ce26751718cc797474d3152a5fc073dd44fd9f7b", 0);

Expand Down Expand Up @@ -208,6 +208,11 @@ kth::infrastructure::config::checkpoint::list default_checkpoints(config::networ

// A block significantly after Upgrade 10 activated (which activated on Nov. 15, 2023)
checkpoints.emplace_back("000000003c37cc0372a5b9ccacca921786bbfc699722fc41e9fdbb1de4146ef1", 178140);
checkpoints.emplace_back("00000000146a073b9d4e172adbee5252014a8b4d75c56cce36858311565ae251", 206364);

// A block after Upgrade 11 activated (Nov. 15, 2024), first block after upgrade: 227229
checkpoints.emplace_back("00000000144b00db5736b33bd572b3a3a52aa9b4c26ba59fc212aeb68a9b7a20", 228000);
checkpoints.emplace_back("0000000017d92f88ed2c81885c57f999184860a042250510be06b3edd12e0dc5", 232000);

} else if (network == domain::config::network::mainnet) {
checkpoints.reserve(60);
Expand Down
17 changes: 16 additions & 1 deletion include/kth/domain/constants/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,27 @@ constexpr size_t max_counted_ops = 201;
constexpr size_t max_stack_size = 1000;
constexpr size_t max_script_size = 10000;
// constexpr size_t max_push_data_size = 520;
constexpr size_t max_push_data_size_legacy = 520;
constexpr size_t max_script_public_keys = 20;
constexpr size_t multisig_default_sigops = 20;
constexpr size_t max_number_size = 4;
constexpr size_t max_number_size_32_bits = 4;
constexpr size_t max_number_size_64_bits = 8;
constexpr size_t max_check_locktime_verify_number_size = 5;
constexpr size_t max_check_sequence_verify_number_size = 5;

// The below constants are used after activation of the May 2025 upgrade (Targeted VM Limits CHIP)
namespace may2025 {

// Maximum number of bytes pushable to the stack
constexpr size_t max_push_data_size = max_script_size; // BCHN: MAX_SCRIPT_ELEMENT_SIZE
// Base cost for each executed opcode; no opcodes incur a cost less than this, but some may incur more.
constexpr size_t opcode_cost = 100u; // BCHN: OPCODE_COST
// Conditional stack depth limit (max depth of OP_IF and friends)
constexpr size_t max_conditional_stack_depth = 100u; // BCHN: MAX_CONDITIONAL_STACK_DEPTH
// Each sigcheck done by an input adds this amount to the total op cost
constexpr uint64_t sig_check_cost_factor = 26'000u; // BCHN: SIG_CHECK_COST_FACTOR
}

// Policy.
constexpr size_t max_null_data_size = 80;

Expand Down
Loading

0 comments on commit 3c5a946

Please sign in to comment.