Conditions
When a coin is spent, its puzzle is executed on the Chialisp Virtual Machine (CLVM). If the program does not fail, it returns a list of conditions. These conditions determine what the outcome of the spend is, and whether or not the spend is valid.
Puzzles have no access to the outside world, or even to blockchain parameters like block height. Therefore, to interact with the outside environment, they return a list of conditions, each of which must be valid in order for the spend itself to be valid.
There are two kinds of conditions. Some require something to be true (such as time passing) in order for the spend to be valid. And others cause something to happen if the spend is valid (such as the creation of new coins).
Condition List
Be vigilant when using ASSERT_MY_COIN_ID
as a shortcut for validating the parent coin ID, puzzle hash, and amount. If they are passed into the solution separately, then validated all at once by hashing them together, it is possible to shift the bytes to the left or right and manipulate the values. If they are passed into the solution separately, then validated all at once by hashing them together, it is possible to shift the bytes to the left or right and manipulate the values.
You are recommended to use the coinid
operator when computing coin IDs. This operator was introduced with CHIP-11. It verifies that hashes are indeed 32 bytes in length, at no extra CLVM cost versus verifying the parent ID, puzzle hash, and amount individually. The coinid
operator, as well as the other CHIP-11 operators, are described on the Chialisp operators page. This operator was introduced with CHIP-11. It verifies that hashes are indeed 32 bytes in length, at no extra CLVM cost versus verifying the parent ID, puzzle hash, and amount individually. The coinid
operator, as well as the other CHIP-11 operators, are described on the Chialisp operators page.
ASSERT_COIN_ANNOUNCEMENT
and ASSERT_PUZZLE_ANNOUNCEMENT
should typically only be used in a puzzle's solution, and not in the puzzle itself. This is especially important when using ASSERT_COIN_ANNOUNCEMENT
, because it refers to a specific coin. This is especially important when using ASSERT_COIN_ANNOUNCEMENT
, because it refers to a specific coin.
To illustrate the danger, let's say coin A
uses this condition in its puzzle, and it asserts a coin announcement from coin B
. In this case, coin A
requires coin B
to be spent in the same block as it is spent. If coin B
is spent before coin A
, then coin A
can never be spent.
However, if this condition is instead used in the solution for coin A
, and coin B
has already been spent, then coin A
can still be spent later, albeit with a different solution.
It is somewhat less dangerous to use ASSERT_PUZZLE_ANNOUNCEMENT
in a coin's puzzle because it only relies on a coin with a specific puzzle, and many such coins might exist. However, it is still best practice to only use this condition in a coin's solution.
1 REMARK
Format: (1)
This condition is always considered valid by the mempool.
This condition has no parameters.
43 AGG_SIG_PARENT
This condition is part of CHIP-0011, and will be available at block height 5,496,000.
:::
This condition adds an additional CLVM cost of 1,200,000.
:::
Format: (43 public_key message)
Verifies a signature for a given message which is concatenated with the following values:
- The parent coin id of the coin being spent.
- The domain string,
sha256(genesis_id + 43)
.
The following parameters are expected:
Name | Type |
---|---|
public_key | G1Element |
message | Bytes |
44 AGG_SIG_PUZZLE
This condition is part of CHIP-0011, and will be available at block height 5,496,000.
:::
This condition adds an additional CLVM cost of 1,200,000.
:::
Format: (44 public_key message)
Verifies a signature for a given message which is concatenated with the following values:
- The puzzle hash of the coin being spent.
- The domain string,
sha256(genesis_id + 44)
.
The following parameters are expected:
Name | Type |
---|---|
public_key | G1Element |
message | Bytes |
45 AGG_SIG_AMOUNT
This condition is part of CHIP-0011, and will be available at block height 5,496,000.
:::
This condition adds an additional CLVM cost of 1,200,000.
:::
Format: (45 public_key message)
Verifies a signature for a given message which is concatenated with the following values:
- The amount of the coin being spent.
- The domain string,
sha256(genesis_id + 45)
.
The following parameters are expected:
Name | Type |
---|---|
public_key | G1Element |
message | Bytes |
46 AGG_SIG_PUZZLE_AMOUNT
This condition is part of CHIP-0011, and will be available at block height 5,496,000.
:::
This condition adds an additional CLVM cost of 1,200,000.
:::
Format: (46 public_key message)
Verifies a signature for a given message which is concatenated with the following values:
- The puzzle hash of the coin being spent.
- The amount of the coin being spent.
- The domain string,
sha256(genesis_id + 46)
.
The following parameters are expected:
Name | Type |
---|---|
public_key | G1Element |
message | Bytes |
47 AGG_SIG_PARENT_AMOUNT
This condition is part of CHIP-0011, and will be available at block height 5,496,000.
:::
This condition adds an additional CLVM cost of 1,200,000.
:::
Format: (47 public_key message)
Verifies a signature for a given message which is concatenated with the following values:
- The parent coin id of the coin being spent.
- The amount of the coin being spent.
- The domain string,
sha256(genesis_id + 47)
.
The following parameters are expected:
Name | Type |
---|---|
public_key | G1Element |
message | Bytes |