Skip to content

Komodo Consensus Specification Draft

dimxy edited this page Aug 23, 2023 · 295 revisions

Draft Inventory for Komodo Consensus Rules and Non-consensus P2P Message Checks

The purpose of this doc is to list all Komodo chain consensus rules to refer to them in code and docs, f.e. to help to find out missed or unimplemented rules in new rust-based Komodo Zebra (Kebra) codebase.
Look for links to rules in the Komodod C++ or Komodo Zebra code by using search by rule identifiers (like 'kmd-0001', in lowercase).

KMD Mainnet Rules

The rules in this section are for KMD Main network chain (excluding rules specific for dPoW, PoS and asset chains).
The rule categories:

KMD Mainnet Block Rules
KMD Mainnet Block-level contextual rules
KMD Mainnet Block Connect Rules
KMD Mainnet Legacy Z-transaction rules
KMD Mainnet DPoW Block-Level Rules
KMD Mainnet Checkpoint Level rules
KMD Mainnet Mempool-level transaction rules
KMD Mainnet Non-consensus checks in P2P Message Processing
KMD Mainnet Non-consensus run chain rules
Zebra-only rules

NOTE:

  • MultiSig is not supported
  • Cryptoconditions framework (disabled in the Komodo Mainnet) currently is not supported in Zebra.

KMD Mainnet Block Rules

Non-contextual block rules for the KMD Mainnet

KMD-0001 Target is valid

If the difficulty target is negative or zero or is over the PoW limit the block is invalid. The PoW limit is set to either the chain parameters' powLimit (if height <= 1 or ASSETCHAINS_ALGO is equal to ASSETCHAINS_EQUIHASH) or to the powLimitAlternate value. Note that using ASSETCHAINS_ALGO var probably was not intended for KMD mainnet (it is asset chain param actually) but nonetheless this parameter should not be changed in the komodo.conf or komodod start command line.

KMD-0002 Block Hash is not over Target

if block hash is over the Target the block is invalid. The Target is calculated according to zcash rules. This rule is activated after block 792000

KMD-0003 Check Equihash Solution

The Equihash Solution in the block header must be valid

KMD-0003-2 Check Equihash Solution 2

This rule duplicates the rule KMD-0003 but this check can be skipped (see the rule KMD-0007 description about skipping rules). This rule may be eliminated.

KMD-0004 For height 0 PoW is not checked

KMD-0005 Fail known block with BLOCK_FAILED_MASK set

Fail already known block with BLOCK_FAILED_MASK set.
TODO: check if this is probably not a part of the consensus but validation optimisation.

KMD-0006 Already known block is accepted

TODO: check if this is a consensus part. Looks like this is not a consensus rule but block processing optimisation

KMD-0007 Block too far in future

If block time is equal or greater than the current time + 300 sec the block is invalid
If block time is equal or greater than the current time + 60 sec and less than current time + 300 then skip rules KMD-0008 and KMD-0003-2 Note for Komodo Zebra: this rule is not implemented yet and KMD-0076 rule is implemented instead. Probably just change of the max future time to 300 sec would suffice to fix it in Zebra.

KMD-0008 Block version too low

For height > 0 if block version less than 4 the block is invalid
Note that this check may be skipped - see rule KMD-0007
Duplicates KMD-0080 and may be eliminated.
Not for Komodo Zebra: not implemented, see KMD-0080.

KMD-0009 Check Merkle Root

Calculate the Merkle Root and check it is equal to the value in the block header

KMD-0010 Check Merkle Tree malleability

While calculating the Merkle Root get the mutated flag. If it is true the block is invalid (CVE-2012-2459)

KMD-0011 Block size limits

Check that the block transaction count is not zero or over MAX_BLOCK_SIZE. Check that the block serialised size is not over MAX_BLOCK_SIZE. MAX_BLOCK_SIZE is set for block height. Note that this rule must be checked before transaction validations.
Note for Komodo Zebra: this rule is not correctly implemented yet. See the latest zcash zebra code for the MAX_BLOCK_BYTES var use.

KMD-0012 First transaction in block is coinbase

KMD-0013 Second transaction and next in block are not coinbase

KMD-0014 Transaction does not spend banned transactions

Check that transaction does not spend any transaction from the banned set. Take into account that first 15 txns from the banned set have only vout1 banned and the rest 2 txns have all vouts banned.

KMD-0015 No-overwinter transaction version is not too low

For transaction with fOverwintered false its version is not less than SPROUT_MIN_TX_VERSION.
Note for Komodo zebra: this rule is not implemented at the consensus level (transactions before Sapling are not supported and should be covered with checkpoints). However version check is done at serialization: see ZcashDeserialize for Transaction

KMD-0016 Overwinter transaction version is not too low

For transaction with fOverwintered true its version is not less than OVERWINTER_MIN_TX_VERSION.
Note for Komodo zebra: this rule is not implemented at the consensus level (transactions before Sapling are not supported and should be covered with checkpoints). However version check is done at serialization: see ZcashDeserialize for Transaction

KMD-0017 Overwinter transaction version Group Id is valid

Overwinter transaction version Group Id is OVERWINTER_VERSION_GROUP_ID or SAPLING_VERSION_GROUP_ID.
Note that this rule is overridden by KMD-0042 and KMD-0046

KMD-0018 Transaction expiry height is not too high

Transaction expiry height is not equal or more than TX_EXPIRY_HEIGHT_THRESHOLD

KMD-0019 Transaction cannot have empty transparent inputs and private spends

If transaction has empty vins it cannot have empty both vjoinsplit and vShieldedSpend.

KMD-0020 Transaction cannot have empty transparent and private outputs

If transaction has empty vouts it cannot have empty vjoinsplit and vShieldedOutput.

KMD-0021 Transaction size limits after Sapling

Transaction serialised size after Sapling upgrade must not be over MAX_TX_SIZE_AFTER_SAPLING.
Note for Komodo Zebra: this rule is not implemented yet

KMD-0022 Transaction output value is not negative

Note for Komodo Zebra: implemented at serialization: see ZcashDeserialize for Transaction

KMD-0023 Transaction output value is not over MAX_MONEY

Note for Komodo Zebra: implemented at serialization: see ZcashDeserialize for Transaction

KMD-0024 Transaction output script pubkey size is not over IGUANA_MAXSCRIPTSIZE

Every transaction output script pubkey size (including opreturn and non-opreturn) cannot exceed IGUANA_MAXSCRIPTSIZE Note for Komodo Zebra: apparently not implemented yet

KMD-0025 Transaction total transparent output value is within Money Range

For each transaction transparent output, the total value of this output and outputs with lower indexes is calculated and checked that it is within the 'Money Range' (non-negative and not greater than MAX_MONEY)

KMD-0026 Transaction valueBalance should be zero if vShieldedSpend and vShieldedOutput are empty

Note for Komodo Zebra: I did not find any dedicated code for this rule but I believe it should be checked in the general sapling shield data validation (see the link in the zebra code)

KMD-0027 Disable Sapling shielded spends and outputs for public chain

Transaction's vShieldedSpend and vShieldedOutput list should be both empty for public chains (var acpublic is not zero). For KMD Mainnet var acpublic is set to 1 since blocktime is KOMODO_SAPLING_DEADLINE. (This rule disables Sapling shielded transactions. Note that we cannot also spend Sapling commitments created before this deadline).
Notes for Komodo zebra: TODO: to be implemented

KMD-0028 Transaction valueBalance must be within MAX_MONEY

Transaction's shielded valueBalance must be equal or over -MAX_MONEY and below or equal to MAX_MONEY

KMD-0029 Transaction total output value is within Money Range with account of valueBalance

If transaction's shielded valueBalance is less or equal than zero (takes money from the tx transparent value pool) then transaction's total value plus -valueBalance must be within the 'Money Range' (non negative and not greater than MAX_MONEY).
Note for Komodo Zebra: it looks like there is no such dedicated rule in zebra code. It is similar to the conversion to ValueBalance but not exactly. TODO: to be implemented

KMD-0030 Disable Sprout non-empty JoinSplits for public chains

Transaction vjoinsplit list should be empty for public chains (var acpublic is not zero). For KMD Mainnet var acpublic is set to 1 since blocktime reaches KOMODO_SAPLING_DEADLINE. (This rule disables Sprout transfers in transactions. Note that we also cannot spend Sprout commitments created before this deadline).
Note for Komodo zebra: TODO: to be implemented

KMD-0031 Transaction does not have duplicate inputs

Note for Komodo Zebra: I did not find this rule implementation. There is the check_for_duplicates helper function that may be used for that but it's not.

KMD-0032 Minted transaction input 0 ScriptSig size is valid

Minted transaction is either coinbase or coin import transaction. For such transactions input 0 ScriptSig size must be greater or equal to 2 and less or equal to 100 bytes

KMD-0033 Non-minted transaction inputs are not null

KMD-0034 Transaction Legacy signature count does not exceed MAX_BLOCK_SIGOPS



KMD Mainnet Block-level contextual rules

In this section there are rules for the block in context with the whole chain

KMD-0036 Fix komodo limit lock time calculation

The var cmptime, limiting the lock time, is increased by 777 secs. Activated since S6 Hardfork.
Note for Komodo Zebra: cmp_time is calculated only by after S6 rules

KMD-0037 Transaction lock time is within komodo limits

For each transaction in the block transaction lock time must be not too old to prevent cheating with interest value.

KMD-0038 Transaction is final

Transaction is final if its lock time is set to 0, or its lock time is less than the current block height or tip block time, or its inputs marked as final, or if some inputs are not marked as final then the transaction lock time must not exceed the current block height or tip block time.

KMD-0039 Coinbase input scriptSig is valid

Coinbase input 0 must contain serialised this block height. Activated since height 1.

KMD Mainnet Block-level Contextual Transaction Rules

Rules for each transaction in the block in context with other transactions in the chain

KMD-0040 Disable overwinter transactions for Sprout upgrade

For the Sprout upgrade it is too early for transactions with overwinter flag.
Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade)

KMD-0041 Min transaction version and Overwintered flag must be valid for Sapling

For transaction version set for Sapling upgrade the Overwintered flag should be set.
Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade)

KMD-0042 Transaction Overwintered flag and version GroupId must be valid for Sapling

For Overwintered flag set the transaction version GroupId must be set to SAPLING_VERSION_GROUP_ID if Sapling upgrade is active. Overrides KMD-0017.
Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade)

KMD-0043 Transaction version must not be too low when Overwintered flag is on for Sapling

Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade). The transaction version is checked in zcash_deserialize but current network upgrade is not checked

KMD-0044 Transaction version must not be too high when Overwintered flag is on for Sapling

Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade). The transaction version is checked in zcash_deserialize but current network upgrade is not checked

KMD-0045 When transaction version is valid Overwintered flag must be on for Overwinter

Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade). The transaction version is checked in zcash_deserialize but current network upgrade is not checked

KMD-0046 When transaction Overwintered flag is on transaction version GroupId must be valid for Overwinter

Overrides KMD-0017.
Note for Komodo zebra: this rule is implemented at serialization: see impl ZcashDeserialize for Transaction

KMD-0047 When transaction Overwintered flag is on transaction version must be valid for Overwinter

Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade). The transaction version is checked in zcash_deserialize but current network upgrade is not checked

KMD-0048 Transaction Overwintered flag must be on for Overwinter

Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade). The transaction version is checked in zcash_deserialize but current network upgrade is not checked

KMD-0049 Transaction must not expire for Overwinter

Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade). The transaction version is checked in zcash_deserialize but current network upgrade is not checked

KMD-0050 If Sapling not active transaction size must be within limits

If the Sapling upgrade is not active the transaction size must not be over MAX_TX_SIZE_BEFORE_SAPLING.
Note for Komodo Zebra: not implemented (there is no rules before the Canopy upgrade). The transaction version is checked in zcash_deserialize but current network upgrade is not checked

KMD-0051 If private transfers not empty signature hash must be valid

If transaction is not minted and JoinSplit or ShieldedSpend or ShieldedOutput are not empty the signature hash must be valid.
Note for Komodo Zebra: the implementation is different with the Komodo C++: in the Komodo C++ this rule is checked for non-minted txns.

KMD Mainnet Block Connect Rules

Additional consensus rules applied when a block is connected

KMD-0053 Contextual Block Rules are active after time 1547510400

Note for Komodo Zebra: not implemented yet

KMD-0054 When best chain activated previous block hash must point to current best block

TODO: not sure if this is a consensus rule or a sanity check

KMD-0055 Do not allow to overwrite older transactions

If a new block's transaction already exists in the chain and was not pruned such block is invalid
Note for Komodo Zebra: I did not find code for this rule. Apparently it is covered by the double-spend rule. It looks like it is possible to have another tx with the same txid if the first tx was pruned (in such a case the double-spend rule would not cover this rule), but I did not find possibility of tx pruning in zebra.

KMD-0056 Legacy SigOps count must not exceed MAX_BLOCK_SIGOPS

This rule seems to duplicate the KMD-0034 rule.

KMD-0057 Transaction must have inputs in chain

Transactions, to which a block non-coinbase transaction refers to, must exist in the chain and be unspent

KMD-0058 Komodo transaction output value valid

Check komodo rules for max output value (not greater than 10000000001*COIN).
Note for Komodo Zebra: not implemented yet

KMD-0059 Add komodo interest to transaction input value

If a transaction is not a coinbase then calculate the komodo interest value and add it to the transaction input value. There are several paths to calculate the komodo interest depending on the spent utxo's height and value.

KMD-0060 Validate coinbase maturity

KMD-0061 Protect coinbase if enabled

If this option enabled for a network, disable spending coinbase outputs to transparent outputs. This rule is disabled for the KMD Mainnet.

KMD-0062 Transaction input value with interest within Money Range

Transaction each input value and current total input value, including komodo interest, is within Money Range

KMD-0063 Transaction input value with interest and shielded value within Money Range

Transaction total input value, with added komodo interest and shielded value, is within Money Range.
Note for Komodo Zebra: I could not find exactly such a rule in the zebra code (which calculates the tx total input value and checks it against the Money Range, i.e. 0..MAX_MONEY) but value_balance() gets the tx total input value and places it into Amount which validates against -MAX_MONEY..MAX_MONEY what should suffice

KMD-0064 Transaction input value not less than output value

Transaction total input value, with added komodo interest and shielded value, is not less than total output value

KMD-0065 Transaction fee is not negative

Transaction fee, equal to total input minus total output value, is not negative. Seems duplicate the previous rule.

KMD-0066 Transaction fee within Money Range

KMD-0067 SCRIPT_VERIFY_P2SH enabled

KMD-0068 SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY enabled

KMD-0069 Execute standard script

If transaction is not a coinbase run the standard script (with the passed option flags) for each transaction input. This rule is evaluated if expensive checks are enabled (see rule KMD-0082).
Note for Komodo Zebra: the script interpreter is implemented in legacy zcash C++ code (see zcash_script lib). TODO: check difference with the Komodo C++ interpreter

KMD-0070 Block header Final Sapling Tree Root hash is valid

Activated in the Sapling upgrade

KMD-0071 Remove komodo interest from block reward

Remove komodo interest from block reward, apparently added by mistake. Activated since KOMODO_NOTARIES_HEIGHT2

KMD-0072 Coinbase does not pay too much

The block is invalid if the coinbase total value is greater than calculated block reward plus extra satoshi and any of the following is true:

  • the block height is greater or equal to KOMODO_NOTARIES_HEIGHT1,
  • the coinbase output 0 value is greater that the calculated block reward.
    It looks like before KOMODO_NOTARIES_HEIGHT1 it was allowed to generate extra unchecked reward in coinbase outputs with indexes over 0.

KMD-0073 Prevent chain reorganisation over 99 blocks

If the chain reorganises for the depth more than MAX_REORG_LENGTH (99 blocks) stop the chain

KMD-0074 Header nBits field valid

Block header nBits field must be equal to the calculated next work required

KMD-0075 BlockTime not too early

Block header blocktime field must be greater than the median time past

KMD-0076 BlockTime not too far in future 2

Yet another rule for the block time that should not be greater than current time plus nMaxFutureBlockTime (7 * 60).
This rule actually does not work as the KMD-0007 rule is more restrictive.
Note for Komodo Zebra: currently only this rule is implemented although the acting rule is KMD-0007

KMD-0077 Block hash validated by built-in checkpoint

If for the block height a checkpoint is found the block hash must be equal to the checkpoint hash.

KMD-0078 Do not allow to change block of height 1

If checkpoints are enabled check that new block's hash at height 1 is not changed.
Note for Komodo Zebra: there is no such a rule found, it looks like it is not needed and covered by checkpoints.

KMD-0079 Invalidate block of height less than last checkpoint height

KMD-0080 Block version is not less than 4

This rule duplicates the rule KMD-0008.
Note for Komodo Zebra: implemented at block deserialisation

KMD-0081 Execute KOMODO_REWIND

If KOMODO_REWIND is set, when the previous best chain is deactivated disconnect blocks until KOMODO_REWIND. It is not completely clear how this option is used though.
Note for Komodo Zebra: not implemented

KMD-0082 Disable expensive checks

Disable expensive checks if the block is an ancestor of the last checkpoint block. By default expensive checks are enabled.
Apparently this is an optimisation feature and not a consensus rule.
Note for Komodo Zebra: checkpoint-based block validation is executed by a different code path, with only minimum checks

KMD-0083 Activate Sapling network upgrade

Note for Komodo Zebra: the current upgrade set to Sapling, but in Zebra most rules for private txns are fully implemented only for Canopy+ upgrades (lower upgrades are covered by checkpoints). In Komodo we disabled private txns since Dec 2019, so only minimum private txns rules are actually needed (like to ensure tx integrity for empty private transfers).
In Komodo C++ the Sapling upgrade is activated for the Mainnet by KOMODO_SAPLING_ACTIVATION timestamp (15 Dec 2018).<br< Note for Komodo Zebra: the Sapling upgrade is activated by Zebra's standard NetworkUpgrade object, by setting the Sapling block height at which it was activated in the KMD Mainnet

KMD-0084 Check if transaction is coinbase

A transaction is coinbase if it has 1 input and the input's previous tx hash is null

KMD-0085 Transaction total output with account of sprout value within Money Range

This rule is deactivated in the Komodo C++ codebase after KOMODO_SAPLING_DEADLINE

KMD-0086 Transaction Sprout value balance is within Money Range

KMD-0087 Transaction Sprout pub value is within Money Range

Transaction Sprout old pub value (taken from the tx transparent value pool) is within the Money Range

KMD-0088 Transaction Sapling value balance is within Money Range

KMD-0089 Transaction Sapling pub value is within Money Range

Transaction Sapling old pub value (taken from the tx transparent value pool) is within the Money Range

KMD-0090 Calculate Komodo Subsidy

KMD-0091 Transaction Sprout vpub_old and vpub_new must be within Money Range

KMD-0092 Transaction Sprout vpub_old and vpub_new cannot be both non-zero

KMD-0093 PayToPubKey scriptPubKey well-formed

Note for Komodo Zebra: this check is not implemented but scripts will be checked when executed

KMD-0094 PayToPubKeyHash scriptPubKey well-formed

Note for Komodo Zebra: this check is not implemented but scripts will be checked when executed

KMD-0095 PayToScriptHash scriptPubKey well-formed

Note for Komodo Zebra: this check is not implemented but scripts will be checked when executed

KMD-0096 MultiSig scriptPubKey well-formed

Note for Komodo Zebra: this check is not implemented but scripts will be checked when executed

KMD-0097 OpReturn scriptPubKey well-formed

Note for Komodo Zebra: this check is not implemented but scripts will be checked when executed

KMD-0098 Non-standard scriptPubKey disabled

Note for Komodo Zebra: this check is not implemented but scripts will be checked when executed

KMD-0099 Disable Sprout joinsplits for all chains

Note for Komodo Zebra: not implemented (but for Komodo Mainnet the rule KMD-0030 would suffice)

KMD-0100 Cryptoconditions scriptPubKey well-formed

Note for Komodo Zebra: this check is not implemented

KMD-0101 Coinbase cannot have JoinSplits

KMD-0102 Coinbase cannot have ShieldedSpends

KMD-0103 Coinbase cannot have ShieldedOutputs

Note for Komodo Zebra: this check is not implemented. This rule should be covered for Mainnet if we disable z-transactions and use checkpoints for earlier blocks

KMD-0104 Duplicate sprout nullifiers in transaction

KMD-0105 Duplicate sapling nullifiers in transaction

KMD-0106 Sprout input value and transaction total input value within Money Range

Note for Komodo Zebra: I could not find exactly the same rule which checks for the Money Range but value_balance places the total tx input value into Amount which checks for -MAX_MONEY..MOX_MONEY what should suffice

KMD-0107 Sapling value balance non-negative and transaction total input value within Money Range

This rule is similar or identical to KMD-0029.
Note for Komodo Zebra: I could not find exactly the same rule but I think the value_balance constraint Amount should suffice

KMD Mainnet Legacy Z-transaction rules

Rules for zcash private transactions. Those rules are currently disabled in the KMD Mainnet.
WARNING: we probably should never use those rules in Komodo Zebra as we are going to cover the chain part, where those rules were used, with checkpoints. But if we want to use them (f.e. for the PIRATE chain or else), be aware of that: for the original Zebra code it is claimed that the private transaction rules are fully implemented only since the Canopy upgrade, so we cannot be sure that the Zebra code for the Sapling upgrade or before (periods in Komodo mainnet when private txns were used) is valid and fully implements the same rules in Komodo C++.

KMD-ZK-0001 Sapling Spend descriptions valid

If Sapling Spend are non empty Sapling Spend descriptions must be valid

KMD-ZK-0002 Sapling Output descriptions valid

If Sapling Outputs are non empty Sapling Output descriptions must be valid

KMD-ZK-0003 JoinSplit signature must be valid

If transaction is not minted and JoinSplit is not empty the signature must be valid Note for Komodo Zebra: the implementation is different: in komodo cpp this rule is checked for non-minted txns

KMD-ZK-0004 Sapling binding signature valid

If Sapling Spend or Outputs are non empty Sapling binding signature must be valid

KMD-ZK-0005 Sprout and Sapling transaction spends valid

Several rules are evaluated both for Sprout and Sapling: nullifiers do not exist to prevent double spends, anchors exists. This rule is deactivated after KOMODO_SAPLING_DEADLINE.

KMD Mainnet DPoW Block-Level Rules

Block-level rules specific for DPoW protocol

KMD-DPOW-0001 Check special block OpReturn

Check that a special block (easy mined by a notary) must have the correct OpReturn output in the last transaction: it should contain the Merkle Root for the previous block hash and all transactions in the current block (this is to prevent special block last transaction reuse). This rule is activated since Season5.

KMD-DPOW-0002 Second and next coinbase output values do not overflow

The block's second and next coinbase output values should not be negative or exceed MAX_MONEY. Total of second and next coinbase output values should not exceed COIN/10. Activated since height 235300.

KMD-DPOW-0003 Do not allow total of second and next coinbase output values over zero for min diff blocks

If the block's nBits is KOMODO_MINDIFF_NBITS then the total of 2nd+ coinbase output values must be zero. Activated since height 814000. Also, this is activated only if the total is not overflowed (see rule KMD-DPOW-0002).

KMD-DPOW-0004 No strange coinbase outputs for block with possible notary proof

If the block coinbase pays to the same scriptPubKey as the block's last transaction vin 0 then this block possibly has a notary proof (a special block). For such coinbase we do not allow outputs with an OpReturn and small amount less 5000 sat, for output indexes > 1. This is activated since height 1000000.

KMD-DPOW-0005 If notary proof is invalid then coinbase must not pay to notary

If the block coinbase pays to the same scriptPubKey as the block last transaction vin 0 then this block possibly has a notary proof (a special block). If it does not, then coinbase scriptPubKey must not pay to a valid notary and if height is over 1000000. If this condition is not true the special block is invalid. This rule is activated since height 814000.

KMD-DPOW-0006 Update last notarisation if found valid

Looks for a notarisation transaction by making sure all of the following checks are true for a transaction:

  • the tx output must be an opreturn
  • if the opreturn data in position 68 contains "KMD\0" then this is a back notarisation. The output index must be 1 and the opreturn data size must be sufficient to have the source txid and the destination txid (if this is a back notarisation) and last notarised height
  • the number of signed notaries is calculated as a mask (var 'signedmask'). If the current height < 91400 'signedmask is initialised to 1 otherwise 0. The 'signedmask' must be equal or greater than KOMODO_MINRATIFY. KOMODO_MINRATIFY is 7 if the current height < 90000 or 11
  • the opreturn data length must be sufficient to include the MoM (merkle of merkle roots) and MoM depth If a notarisation tx is found and valid then collect the notarisation data from it: flag if this is a back notarisation, source txid, destination chain, destination txid (if a back notarisation), last notarised height, MoM and MoM depth, and update it in the memory as the current last notarisation.

KMD-DPOW-0007 Prevent forks below last notarised height

Komodo dPoW protocol requires that in case of chain reorganisation forks are not allowed below the last notarised height stored in the current last notarisation, signed by current season notaries (at least of MIN_RATIFY quantity)

KMD-DPOW-0008 Disable to disconnect block if its hash equals to last notarised block hash

This rule appears to be always valid because the KMD-DPOW-0007 rule would not allow forks below the last notarised height

KMD-DPOW-0009 Invalidate block connected below last notarised height

Blocks could not be connected to heights below the last notarised height. To check this:

  • ensure that the last notarised height equals to the height of the block index element found by the last notarised block hash (I am not sure how this could not be true). If that is not true stop the validation with the result of true
  • if the block height is below the last notarised height the block is invalid
  • if the block height equals to the last notarised height check that the block hash equals to the last notarised hash. If that is not true the block is invalid.
    This rule complements the KMD-DPOW-0007 rule:
    the KMD-DPOW-0007 rule prevents activation of a longest chain fork if it does not have the last notarisation (if a chain with the last notarisation was received after the longest chain was created)
    this rule prevents connecting new blocks at heights below the last notarised height.

KMD-DPOW-0010 Notary special block is valid

If block is created by a valid notary, has the valid last special block transaction (see rules KMD-DPOW-0001, KMD-DPOW-0004, KMD-DPOW-0005, KMD-DPOW-0012) and there was no any blocks already created by this notary within recent 65 blocks, then the block target is allowed to be minimal (easy mining). Otherwise the block target must be for the normal PoW block

KMD-DPOW-0011 Notary second special block is allowed

If there is a big time gap after the last mined normal pow block then notary is allowed to create a second special block. Notaries allowed to create a second special block are ordered in a priority list according to their first created special block order. The rule is activated since S6 season.

KMD-DPOW-0012 Notary special block difficulty must be over KOMODO_MINDIFF_NBITS

Special block hash must be over KOMODO_MINDIFF_NBITS.
Note that KOMODO_MINDIFF_NBITS is the Mainnet target limit.
Note that special block's target (block header field nBits) must also conform to the calculated PoW difficulty for this block, although the special block hash does not need to conform to this rule.

KMD Mainnet Checkpoint Level rules

Rules that are evaluated when blocks are within the static checkpoint range.
TODO...

KMD Mainnet Mempool-level transaction rules

Rules to evaluate when a transaction is placed to the mempool.

KMD-MEM-0001 Transaction inputs quantity within limits

If the limit is set the transaction inputs quantity should not exceed it
This is not a consensus rule as any node may not set this limit

KMD-MEM-0002 Transaction locktime is within komodo limits for mempool

The transaction locktime value must be not too old to prevent cheating with interest value. Similar to the KMD-0037 rule but adjusted for mempool

Evaluate Transaction Rules in Mempool

Evaluate rules implemented in CheckTransaction function when a tx is placed in mempool. The same code for several rules is called when tx in a block is validated and when a transaction is placed in mempool. There is no special links in the code for these rules for mempool so here is a list of those rules here with a mark whether it is called in Komodo C++ and Zebra for mempool validation:

Rule used for mempool Komodo Zebra
kmd-0014-transaction-does-not-spend-banned-transactions yes yes
kmd-0015-no-overwinter-transaction-version-is-not-too-low yes no
kmd-0016-overwinter-transaction-version-is-not-too-low yes no
kmd-0017-overwinter-transaction-version-group-id-is-valid yes no
kmd-0018-transaction-expiry-height-is-not-too-high yes yes
kmd-0019-transaction-cannot-have-empty-vins-and-private-spends yes yes
kmd-0020-transaction-cannot-have-empty-vouts-and-private-spends yes yes
kmd-0021-transaction-size-limits-after-sapling yes no
kmd-0022-transaction-output-value-is-not-negative yes yes
kmd-0023-transaction-output-value-is-not-over-max_money yes yes
kmd-0024-transaction-output-script-pubkey-size-is-not-over-iguana_maxscriptsize yes no
kmd-0025-transaction-total-output-value-is-within-money-range yes yes
kmd-0026-transaction-valuebalance-should-be-zero-if-vshieldedspend-and-vshieldedoutput-are-empty yes yes
kmd-0027-disable-sapling-shielded-spends-and-outputs-for-public-chain yes no
kmd-0028-transaction-valuebalance-must-be-within-max_money yes yes
kmd-0029-transaction-total-output-value-is-within-money-range-with-account-of-valuebalance yes no
kmd-0030-disable-sprout-non-empty-joinsplits-for-public-chains yes no
kmd-0031-transaction-does-not-have-duplicate-inputs yes no
kmd-0032-minted-transaction-input-0-scriptsig-size-is-valid yes yes
kmd-0033-non-minted-transaction-inputs-are-not-null yes yes

If any rule is not implemented see the rule description.

Evaluate Contextual Transaction Rules in Mempool

Evaluate rules implemented in ContextualCheckTransaction function. Those rules are used both for tx in mempool and block validation. There is no special links in the code for these rules for mempool so here is a list whether those rules are called in Komodo C++ and Zebra for tx in mempool validation:

Rule used for mempool Komodo Zebra
kmd-0040-disable-overwinter-transactions-for-sprout-upgrade yes no
kmd-0041-min-transaction-version-and-overwintered-flag-must-be-valid-for-sapling yes no
kmd-0042-transaction-overwintered-flag-and-version-groupid-must-be-valid-for-sapling yes no
kmd-0043-transaction-version-must-not-be-too-low-when-overwintered-flag-is-on-for-sapling yes no
kmd-0044-transaction-version-must-not-be-too-high-when-overwintered-flag-is-on-for-sapling yes no
kmd-0045-when-transaction-version-is-valid-overwintered-flag-must-be-on-for-overwinter yes no
kmd-0046-when-transaction-overwintered-flag-is-on-transaction-version-groupid-must-be-valid-for-overwinter yes yes
kmd-0047-when-transaction-overwintered-flag-is-on-transaction-version-must-be-valid-for-overwinter yes no
kmd-0048-transaction-overwintered-flag-must-be-on-for-overwinter yes no
kmd-0049-transaction-must-not-expire-for-overwinter partially partially
kmd-0050-if-sapling-not-active-transaction-size-must-be-within-limits yes no
kmd-0051-if-private-transfers-not-empty-signature-hash-must-be-valid different different
kmd-0052-if-joinsplit-signature-must-be-valid yes no
kmd-zk-0001-sapling-spend-description-valid yes ?
kmd-zk-0002-sapling-output-descriptions-valid yes ?
kmd-zk-0003-sapling-binding-signature-valid yes ?

If any rule is not implemented see the rule description.

KMD-MEM-0005 Do not allow coinbase in mempool

KMD-MEM-0006 Do not allow non-standard transactions in mempool

Note for Komodo Zebra: there is no similar function like IsStandardTx in Komodo C++. TODO: check if deserialize function does this right

KMD-MEM-0007 Check if Transaction is Final

Defines the next block time as the Median Time Past and the next height as the tip height plus one and performs the validation as in the KMD-0038 Transaction is final rule.
Note for Komodo Zebra: not implemented

KMD-MEM-0008 Transaction already exists in mempool

KMD-MEM-0009 Disable transaction replacement in mempool

For all transaction inputs check if any previous output is not spent already in mempool

KMD-MEM-0010 Transaction Sprout nullifiers do not exist already in mempool

KMD-MEM-0011 Transaction Sapling nullifiers do not exist already in mempool

KMD-MEM-0012 Transaction does not exist in chain and mempool

Check if a transaction does not exists in both the mempool and coin cache.
Partially overlaps with KMD-MEM-0008.
Note for Komodo Zebra: apparently there is no check if a transaction hash exists in the chain in Zebra but the rule that prevents double-spends (KMD-0057) should cover it.

KMD-MEM-0013 Previous outputs exist in chain or mempool

KMD-MEM-0014 Previous outputs are not spent already in chain or mempool

KMD-MEM-0015 Sprout and Sapling transaction spends valid

KMD-MEM-0016 Do not allow non-standard transaction inputs

Note for Komodo Zebra: there is no similar function like AreInputsStandard() in Komodo C++. TODO: check maybe the script interpreter covers this rule

KMD-MEM-0017 Transaction legacy signature count does not exceed MAX_STANDARD_TX_SIGOPS

Note for Komodo Zebra: not implemented

KMD-MEM-0018 Transaction total output value within komodo limits

The transaction total output value does not exceed 777,777 multiplied by COIN satoshi For difference of the transaction total output value and 777,777 multiplied by COIN the KOMODO_VALUETOOBIG condition is not true Note for Komodo Zebra: not implemented

KMD-MEM-0019 If transaction does not fit priority size it has minimum tx fee

If limiting transactions with low fee is on and the transaction does not fit the block priority size or has zero user priority the transaction fee must not be less that the minimum relay tx fee.
Note for Komodo Zebra: not implemented

KMD-MEM-0020 Low fee transaction has sufficient calculated priority

If the relay priority option is on and the transaction fee is less than the minimum relay tx fee the transaction calculated priority should be greater than the free tx priority threshold. The calculated priority is obtained from transaction inputs and transaction output values increased by the tx depth. For private transactions it is always set to the max priority value.
Note for Komodo Zebra: not implemented

KMD-MEM-0021 Low fee transaction rate constrained

If limiting transactions with low fee is on use a rate limiter to constrain throughput of low fee transactions data.

KMD-MEM-0022 Transactions with absurd fee rejected

If rejecting absurd tx fee is on then reject transactions which have too big tx fee, when the tx fee is greater than the minimum relay tx fee multiplied by 1000 and total tx outputs value divided by 19

Evaluate Contextual Transaction Inputs Rules in Mempool

Evaluate the following rules for contextual transaction inputs when a tx is placed in mempool The same code for several rules is called when tx in a block is validated and when a transaction is placed in mempool. There is no special links in the code for these rules for mempool so here is a list of those rules here with a mark whether it is called in Komodo C++ and Zebra for mempool validation:

Rule used for mempool Komodo Zebra
kmd-0057-transaction-must-have-inputs-in-chain yes yes
kmd-zk-0004-sprout-and-sapling-transaction-spends-valid yes yes
kmd-0059-add-komodo-interest-to-transaction-input-value yes yes
kmd-0060-validate-coinbase-maturity yes yes
kmd-0061-protect-coinbase-if-enabled yes yes
kmd-0062-transaction-input-value-with-interest-within-money-range yes yes
kmd-0063-transaction-input-value-with-interest-and-shielded-value-within-money-range yes no
kmd-0064-transaction-input-value-not-less-output-value yes yes
kmd-0065-transaction-fee-is-not-negative yes no
kmd-0066-transaction-fee-within-money-range yes yes

If any rule is not implemented see the rule description.

KMD-MEM-0024 Evaluate mandatory transaction scripts

Evaluate transaction scripts with MANDATORY_SCRIPT_VERIFY_FLAGS.
This is probably not a consensus-important call but error determination, because there is another script executing call with all needed flags.
Note for Komodo Zebra: there is no a separate call to script interpreter with MANDATORY_SCRIPT_VERIFY_FLAGS only. It looks like we need two dedicated calls to script verification: with standard and mandatory only flags: with CC modules enabled, if any consensus error in a cc module the error was generated by the call to the script interpreter with the mandatory flags (the call with standard flags did not return any error for that case). TODO: check and implement if necessary.

KMD-MEM-0025 Max input script size

Max input scriptSig size is no more than 1560 bytes.
Note for Komodo Zebra: not implemented

KMD-MEM-0026 Only One OpReturn

Multiple OpReturns are not permitted.
Note for Komodo Zebra: not implemented

KMD-MEM-0027 OpReturn size no more than IGUANA_MAXSCRIPTSIZE

Note for Komodo Zebra: not implemented

KMD-MEM-0028 Remove transactions added in block

Remove from mempool transactions that were just added to the new connected block

KMD-MEM-0029 Remove expired transactions

Remove from mempool transactions whose nExpiryHeight value became less than the new connected block height. Also remove transactions whose locktime value violates the too-long-in-mempool rule (KMD-MEM-0002)

KMD Mainnet Non-consensus checks in P2P Message Processing

Checks are made when a message with a block or header or transaction is received. In progress..

to be continued...

KMD Mainnet Non-consensus run chain rules

KMD-RUN-0001 Do not add blocks after KOMODO_STOPAT

If KOMODO_STOPAT is set and height is over then the block is invalid.

KMD-RUN-0002 Chain deprecates at height

For non-upgraded nodes they will deprecate and stop after a certain height

Zebra-only rules

These rules are found in the zebra code but they look like not implemented in Komodod C++. TODO: study their implementation and disable them in Zebra, if needed.

ZEBRA-0002 Coinbase nSequence equals to 0xffffffff

I did not find if this is checked in the Komodo C++ codebase.

ZEBRA-0003 Early transparent spend invalid

When a tx input spends another tx output and both txns are in the same block and the spent tx index in the block is greater than the first tx index, such spends are invalid.
I did not find such a rule in the Komodo C++ code.

ZEBRA-0004 Total chain transparent unspent value within Money Range

Zebra maintains the transparent chain value pool which must be within the Money Range. Apparently we do not have such a rule in Komodo and this pool should be disabled. This transparent value pool in zcash may potentially go negative as value from it may be taken to private value pool. In Komodo we disabled private transactions and this is not an issue anymore.

ZEBRA-0005 Block Time is valid future 2 hours

Block time should be go for more than 2 h in future

ZEBRA-0006 Evict mempool transaction by zip-0401



TODO: there is a certain number of more zebra rules regarding Canopy+ upgrade. Currently the Canopy height is set to the max height in our Komodo Zebra code but better to remove these rules at all.

PoS Chain Block-Level Rules

to be continued...

Asset Chains Rules

to be continued...

Clone this wiki locally