Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions C/bitcoin/bitcoinJets.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,26 @@ static uint_fast32_t lockTime(const bitcoinTransaction* tx) {
return !tx->isFinal && 500000000U <= tx->lockTime ? tx->lockTime : 0;
}

static uint_fast16_t lockDistance(const bitcoinTransaction* tx) {
return 2 <= tx->version ? tx->lockDistance : 0;
static uint_fast16_t lockDistance(const bitcoinTransaction* tx, uint_fast32_t ix) {
simplicity_assert(ix < tx->numInputs);
if (2 <= tx->version &&
tx->input[ix].sequence < 0x80000000 &&
!(tx->input[ix].sequence & ((uint_fast32_t)1 << 22))) {
return tx->input[ix].sequence & 0xffff;
} else {
return 0;
}
}

static uint_fast16_t lockDuration(const bitcoinTransaction* tx) {
return 2 <= tx->version ? tx->lockDuration : 0;
static uint_fast16_t lockDuration(const bitcoinTransaction* tx, uint_fast32_t ix) {
simplicity_assert(ix < tx->numInputs);
if (2 <= tx->version &&
tx->input[ix].sequence < 0x80000000 &&
!!(tx->input[ix].sequence & ((uint_fast32_t)1 << 22))) {
return tx->input[ix].sequence & 0xffff;
} else {
return 0;
}
}

/* version : ONE |- TWO^32 */
Expand Down Expand Up @@ -312,14 +326,16 @@ bool simplicity_bitcoin_tx_lock_time(frameItem* dst, frameItem src, const txEnv*
/* tx_lock_distance : ONE |- TWO^16 */
bool simplicity_bitcoin_tx_lock_distance(frameItem* dst, frameItem src, const txEnv* env) {
(void) src; // src is unused;
simplicity_write16(dst, lockDistance(env->tx));
if (env->tx->numInputs <= env->ix) return false;
simplicity_write16(dst, lockDistance(env->tx, env->ix));
return true;
}

/* tx_lock_duration : ONE |- TWO^16 */
bool simplicity_bitcoin_tx_lock_duration(frameItem* dst, frameItem src, const txEnv* env) {
(void) src; // src is unused;
simplicity_write16(dst, lockDuration(env->tx));
if (env->tx->numInputs <= env->ix) return false;
simplicity_write16(dst, lockDuration(env->tx, env->ix));
return true;
}

Expand All @@ -340,15 +356,17 @@ bool simplicity_bitcoin_check_lock_time(frameItem* dst, frameItem src, const txE
/* check_lock_distance : TWO^16 |- ONE */
bool simplicity_bitcoin_check_lock_distance(frameItem* dst, frameItem src, const txEnv* env) {
(void) dst; // dst is unused;
if (env->tx->numInputs <= env->ix) return false;
uint_fast16_t x = simplicity_read16(&src);
return x <= lockDistance(env->tx);
return x <= lockDistance(env->tx, env->ix);
}

/* check_lock_duration : TWO^16 |- ONE */
bool simplicity_bitcoin_check_lock_duration(frameItem* dst, frameItem src, const txEnv* env) {
(void) dst; // dst is unused;
if (env->tx->numInputs <= env->ix) return false;
uint_fast16_t x = simplicity_read16(&src);
return x <= lockDuration(env->tx);
return x <= lockDuration(env->tx, env->ix);
}

/* build_tapleaf_simplicity : TWO^256 |- TWO^256 */
Expand Down
8 changes: 0 additions & 8 deletions C/bitcoin/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ extern bitcoinTransaction* simplicity_bitcoin_mallocTransaction(const rawBitcoin
copyInput(&input[i], &rawTx->input[i]);
tx->totalInputValue += input[i].txo.value;
if (input[i].sequence < 0xffffffff) { tx->isFinal = false; }
if (input[i].sequence < 0x80000000) {
const uint_fast16_t maskedSequence = input[i].sequence & 0xffff;
if (input[i].sequence & ((uint_fast32_t)1 << 22)) {
if (tx->lockDuration < maskedSequence) tx->lockDuration = maskedSequence;
} else {
if (tx->lockDistance < maskedSequence) tx->lockDistance = maskedSequence;
}
}
sha256_hash(&ctx_inputOutpointsHash, &input[i].prevOutpoint.txid);
sha256_u32be(&ctx_inputOutpointsHash, input[i].prevOutpoint.ix);
sha256_u64be(&ctx_inputValuesHash, input[i].txo.value);
Expand Down
8 changes: 4 additions & 4 deletions C/bitcoin/primitiveJetNode.inc
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@
,[CHECK_LOCK_DISTANCE] =
{ .tag = JET
, .jet = simplicity_bitcoin_check_lock_distance
, .cmr = {{0xdbaa6fedu, 0xb73b2e31u, 0xa80ccbd1u, 0x4daaa5b8u, 0xce212cdeu, 0x0cbfd96du, 0x5db9715fu, 0xd19f8899u}}
, .cmr = {{0x38fdf7ddu, 0x28538670u, 0xfb34c1bfu, 0xe72f17e2u, 0xca5784f8u, 0x7fed88eau, 0xb584792bu, 0x3974bd18u}}
, .sourceIx = ty_w16
, .targetIx = ty_u
, .cost = 84 /* milli weight units */
}
,[CHECK_LOCK_DURATION] =
{ .tag = JET
, .jet = simplicity_bitcoin_check_lock_duration
, .cmr = {{0xdde93f33u, 0xf9b9d1d3u, 0xa3f2b3e8u, 0xb90f6d8bu, 0xeffccb45u, 0x81210eeau, 0xf06bd32fu, 0x6319df6eu}}
, .cmr = {{0x77503832u, 0x6eae25c7u, 0x209b2443u, 0x06eaa9f9u, 0x204c7eceu, 0x2dd63b45u, 0x2e10017fu, 0xa4ea53cfu}}
, .sourceIx = ty_w16
, .targetIx = ty_u
, .cost = 78 /* milli weight units */
Expand Down Expand Up @@ -3298,15 +3298,15 @@
,[TX_LOCK_DISTANCE] =
{ .tag = JET
, .jet = simplicity_bitcoin_tx_lock_distance
, .cmr = {{0x8c0b0c44u, 0x2bc20978u, 0xfa4c2b3du, 0x52a7fe7cu, 0x3f86e3d2u, 0x1b42130eu, 0xbb8dba45u, 0xe0f5e64bu}}
, .cmr = {{0xb6fbaac2u, 0x10a306beu, 0x8b58d0d7u, 0xb1563f62u, 0x2336d2aeu, 0xb56c393du, 0x276445a9u, 0xa22cc4a7u}}
, .sourceIx = ty_u
, .targetIx = ty_w16
, .cost = 72 /* milli weight units */
}
,[TX_LOCK_DURATION] =
{ .tag = JET
, .jet = simplicity_bitcoin_tx_lock_duration
, .cmr = {{0x09b18d5cu, 0x2f08402bu, 0xbcf8c31eu, 0xa43435efu, 0xffd9ea0eu, 0xf8758f76u, 0xbb27272bu, 0x4d60dc62u}}
, .cmr = {{0x53572818u, 0xe7e5b98fu, 0x968c9da7u, 0xdf5090d9u, 0x826f9bcfu, 0x84b63639u, 0x5eea321bu, 0x6909ece9u}}
, .sourceIx = ty_u
, .targetIx = ty_w16
, .cost = 66 /* milli weight units */
Expand Down
5 changes: 0 additions & 5 deletions C/bitcoin/txEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ typedef struct bitcoinTransaction {
uint_fast32_t numOutputs;
uint_fast32_t version;
uint_fast32_t lockTime;
/* lockDuration and lockDistance values are set even when the version is 0 or 1.
* This is similar to lockTime whose value is also set, even when the transaction is final.
*/
uint_fast16_t lockDistance;
uint_fast16_t lockDuration; /* Units of 512 seconds */
bool isFinal;
} bitcoinTransaction;

Expand Down
8 changes: 4 additions & 4 deletions C/elements/decodeElementsJets.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
switch (code) {
case 1: *result = CHECK_LOCK_HEIGHT; return SIMPLICITY_NO_ERROR;
case 2: *result = CHECK_LOCK_TIME; return SIMPLICITY_NO_ERROR;
case 3: *result = CHECK_LOCK_DISTANCE; return SIMPLICITY_NO_ERROR;
case 4: *result = CHECK_LOCK_DURATION; return SIMPLICITY_NO_ERROR;
case 3: *result = BROKEN_DO_NOT_USE_CHECK_LOCK_DISTANCE; return SIMPLICITY_NO_ERROR;
case 4: *result = BROKEN_DO_NOT_USE_CHECK_LOCK_DURATION; return SIMPLICITY_NO_ERROR;
case 5: *result = TX_LOCK_HEIGHT; return SIMPLICITY_NO_ERROR;
case 6: *result = TX_LOCK_TIME; return SIMPLICITY_NO_ERROR;
case 7: *result = TX_LOCK_DISTANCE; return SIMPLICITY_NO_ERROR;
case 8: *result = TX_LOCK_DURATION; return SIMPLICITY_NO_ERROR;
case 7: *result = BROKEN_DO_NOT_USE_TX_LOCK_DISTANCE; return SIMPLICITY_NO_ERROR;
case 8: *result = BROKEN_DO_NOT_USE_TX_LOCK_DURATION; return SIMPLICITY_NO_ERROR;
case 9: *result = TX_IS_FINAL; return SIMPLICITY_NO_ERROR;
}
break;
Expand Down
24 changes: 12 additions & 12 deletions C/elements/elementsJets.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ static uint_fast32_t lockTime(const elementsTransaction* tx) {
return !tx->isFinal && 500000000U <= tx->lockTime ? tx->lockTime : 0;
}

static uint_fast16_t lockDistance(const elementsTransaction* tx) {
return 2 <= tx->version ? tx->lockDistance : 0;
static uint_fast16_t obsolete_lockDistance(const elementsTransaction* tx) {
return 2 <= tx->version ? tx->obsolete_lockDistance : 0;
}

static uint_fast16_t lockDuration(const elementsTransaction* tx) {
return 2 <= tx->version ? tx->lockDuration : 0;
static uint_fast16_t obsolete_lockDuration(const elementsTransaction* tx) {
return 2 <= tx->version ? tx->obsolete_lockDuration : 0;
}

static bool isFee(const sigOutput* output) {
Expand Down Expand Up @@ -733,16 +733,16 @@ bool simplicity_tx_lock_time(frameItem* dst, frameItem src, const txEnv* env) {
}

/* tx_lock_distance : ONE |- TWO^16 */
bool simplicity_tx_lock_distance(frameItem* dst, frameItem src, const txEnv* env) {
bool simplicity_broken_do_not_use_tx_lock_distance(frameItem* dst, frameItem src, const txEnv* env) {
(void) src; // src is unused;
simplicity_write16(dst, lockDistance(env->tx));
simplicity_write16(dst, obsolete_lockDistance(env->tx));
return true;
}

/* tx_lock_duration : ONE |- TWO^16 */
bool simplicity_tx_lock_duration(frameItem* dst, frameItem src, const txEnv* env) {
bool simplicity_broken_do_not_use_tx_lock_duration(frameItem* dst, frameItem src, const txEnv* env) {
(void) src; // src is unused;
simplicity_write16(dst, lockDuration(env->tx));
simplicity_write16(dst, obsolete_lockDuration(env->tx));
return true;
}

Expand All @@ -761,17 +761,17 @@ bool simplicity_check_lock_time(frameItem* dst, frameItem src, const txEnv* env)
}

/* check_lock_distance : TWO^16 |- ONE */
bool simplicity_check_lock_distance(frameItem* dst, frameItem src, const txEnv* env) {
bool simplicity_broken_do_not_use_check_lock_distance(frameItem* dst, frameItem src, const txEnv* env) {
(void) dst; // dst is unused;
uint_fast16_t x = simplicity_read16(&src);
return x <= lockDistance(env->tx);
return x <= obsolete_lockDistance(env->tx);
}

/* check_lock_duration : TWO^16 |- ONE */
bool simplicity_check_lock_duration(frameItem* dst, frameItem src, const txEnv* env) {
bool simplicity_broken_do_not_use_check_lock_duration(frameItem* dst, frameItem src, const txEnv* env) {
(void) dst; // dst is unused;
uint_fast16_t x = simplicity_read16(&src);
return x <= lockDuration(env->tx);
return x <= obsolete_lockDuration(env->tx);
}

/* calculate_issuance_entropy : TWO^256 * TWO^32 * TWO^256 |- TWO^256 */
Expand Down
8 changes: 4 additions & 4 deletions C/elements/elementsJets.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ bool simplicity_num_outputs(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_tx_is_final(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_tx_lock_height(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_tx_lock_time(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_tx_lock_distance(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_tx_lock_duration(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_broken_do_not_use_tx_lock_distance(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_broken_do_not_use_tx_lock_duration(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_check_lock_height(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_check_lock_time(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_check_lock_distance(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_check_lock_duration(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_broken_do_not_use_check_lock_distance(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_broken_do_not_use_check_lock_duration(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_calculate_issuance_entropy(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_calculate_asset(frameItem* dst, frameItem src, const txEnv* env);
bool simplicity_calculate_explicit_token(frameItem* dst, frameItem src, const txEnv* env);
Expand Down
12 changes: 6 additions & 6 deletions C/elements/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,12 @@ extern elementsTransaction* simplicity_elements_mallocTransaction(const rawEleme
copyInput(&input[i], &rawTx->input[i]);
if (input[i].sequence < 0xffffffff) { tx->isFinal = false; }
if (input[i].sequence < 0x80000000) {
const uint_fast16_t maskedSequence = input[i].sequence & 0xffff;
if (input[i].sequence & ((uint_fast32_t)1 << 22)) {
if (tx->lockDuration < maskedSequence) tx->lockDuration = maskedSequence;
} else {
if (tx->lockDistance < maskedSequence) tx->lockDistance = maskedSequence;
}
const uint_fast16_t maskedSequence = input[i].sequence & 0xffff;
if (input[i].sequence & ((uint_fast32_t)1 << 22)) {
if (tx->obsolete_lockDuration < maskedSequence) tx->obsolete_lockDuration = maskedSequence;
} else {
if (tx->obsolete_lockDistance < maskedSequence) tx->obsolete_lockDistance = maskedSequence;
}
}
if (input[i].isPegin) {
sha256_uchar(&ctx_inputOutpointsHash, 1);
Expand Down
8 changes: 4 additions & 4 deletions C/elements/primitiveEnumJet.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ AND_8,
ANNEX_HASH,
ASSET_AMOUNT_HASH,
BIP_0340_VERIFY,
BROKEN_DO_NOT_USE_CHECK_LOCK_DISTANCE,
BROKEN_DO_NOT_USE_CHECK_LOCK_DURATION,
BROKEN_DO_NOT_USE_TX_LOCK_DISTANCE,
BROKEN_DO_NOT_USE_TX_LOCK_DURATION,
BUILD_TAPBRANCH,
BUILD_TAPLEAF_SIMPLICITY,
BUILD_TAPTWEAK,
Expand All @@ -27,8 +31,6 @@ CH_16,
CH_32,
CH_64,
CH_8,
CHECK_LOCK_DISTANCE,
CHECK_LOCK_DURATION,
CHECK_LOCK_HEIGHT,
CHECK_LOCK_TIME,
CHECK_SIG_VERIFY,
Expand Down Expand Up @@ -454,8 +456,6 @@ TOTAL_FEE,
TRANSACTION_ID,
TX_HASH,
TX_IS_FINAL,
TX_LOCK_DISTANCE,
TX_LOCK_DURATION,
TX_LOCK_HEIGHT,
TX_LOCK_TIME,
VERIFY,
Expand Down
64 changes: 32 additions & 32 deletions C/elements/primitiveJetNode.inc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,38 @@
, .targetIx = ty_u
, .cost = 49087 /* milli weight units */
}
,[BROKEN_DO_NOT_USE_CHECK_LOCK_DISTANCE] =
{ .tag = JET
, .jet = simplicity_broken_do_not_use_check_lock_distance
, .cmr = {{0x7f78c7a7u, 0x7a25ada2u, 0x23267d23u, 0x9a5922f7u, 0x64b8ac0cu, 0x2fcef68eu, 0xb93c0d92u, 0xda4af515u}}
, .sourceIx = ty_w16
, .targetIx = ty_u
, .cost = 105 /* milli weight units */
}
,[BROKEN_DO_NOT_USE_CHECK_LOCK_DURATION] =
{ .tag = JET
, .jet = simplicity_broken_do_not_use_check_lock_duration
, .cmr = {{0x73dac8e2u, 0x5d87eaf3u, 0x82c2a772u, 0x06ad38b9u, 0x384361e7u, 0xd0dc87c0u, 0xfa7af7eau, 0x524597b7u}}
, .sourceIx = ty_w16
, .targetIx = ty_u
, .cost = 102 /* milli weight units */
}
,[BROKEN_DO_NOT_USE_TX_LOCK_DISTANCE] =
{ .tag = JET
, .jet = simplicity_broken_do_not_use_tx_lock_distance
, .cmr = {{0x4c7773b8u, 0x18cb7ee5u, 0xf54f925au, 0xad015677u, 0xa043a72fu, 0x316a187cu, 0xc28c696cu, 0xfcb90807u}}
, .sourceIx = ty_u
, .targetIx = ty_w16
, .cost = 91 /* milli weight units */
}
,[BROKEN_DO_NOT_USE_TX_LOCK_DURATION] =
{ .tag = JET
, .jet = simplicity_broken_do_not_use_tx_lock_duration
, .cmr = {{0xcc9c64c8u, 0xb6eb4bf0u, 0x9694af5au, 0x35d957a4u, 0x05e66c1bu, 0x35224ed6u, 0x75878918u, 0x452440b2u}}
, .sourceIx = ty_u
, .targetIx = ty_w16
, .cost = 84 /* milli weight units */
}
,[BUILD_TAPBRANCH] =
{ .tag = JET
, .jet = simplicity_build_tapbranch
Expand Down Expand Up @@ -223,22 +255,6 @@
, .targetIx = ty_w8
, .cost = 77 /* milli weight units */
}
,[CHECK_LOCK_DISTANCE] =
{ .tag = JET
, .jet = simplicity_check_lock_distance
, .cmr = {{0x7f78c7a7u, 0x7a25ada2u, 0x23267d23u, 0x9a5922f7u, 0x64b8ac0cu, 0x2fcef68eu, 0xb93c0d92u, 0xda4af515u}}
, .sourceIx = ty_w16
, .targetIx = ty_u
, .cost = 105 /* milli weight units */
}
,[CHECK_LOCK_DURATION] =
{ .tag = JET
, .jet = simplicity_check_lock_duration
, .cmr = {{0x73dac8e2u, 0x5d87eaf3u, 0x82c2a772u, 0x06ad38b9u, 0x384361e7u, 0xd0dc87c0u, 0xfa7af7eau, 0x524597b7u}}
, .sourceIx = ty_w16
, .targetIx = ty_u
, .cost = 102 /* milli weight units */
}
,[CHECK_LOCK_HEIGHT] =
{ .tag = JET
, .jet = simplicity_check_lock_height
Expand Down Expand Up @@ -3639,22 +3655,6 @@
, .targetIx = ty_b
, .cost = 71 /* milli weight units */
}
,[TX_LOCK_DISTANCE] =
{ .tag = JET
, .jet = simplicity_tx_lock_distance
, .cmr = {{0x4c7773b8u, 0x18cb7ee5u, 0xf54f925au, 0xad015677u, 0xa043a72fu, 0x316a187cu, 0xc28c696cu, 0xfcb90807u}}
, .sourceIx = ty_u
, .targetIx = ty_w16
, .cost = 91 /* milli weight units */
}
,[TX_LOCK_DURATION] =
{ .tag = JET
, .jet = simplicity_tx_lock_duration
, .cmr = {{0xcc9c64c8u, 0xb6eb4bf0u, 0x9694af5au, 0x35d957a4u, 0x05e66c1bu, 0x35224ed6u, 0x75878918u, 0x452440b2u}}
, .sourceIx = ty_u
, .targetIx = ty_w16
, .cost = 84 /* milli weight units */
}
,[TX_LOCK_HEIGHT] =
{ .tag = JET
, .jet = simplicity_tx_lock_height
Expand Down
8 changes: 3 additions & 5 deletions C/elements/txEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,9 @@ typedef struct elementsTransaction {
uint_fast32_t numFees;
uint_fast32_t version;
uint_fast32_t lockTime;
/* lockDuration and lockDistance values are set even when the version is 0 or 1.
* This is similar to lockTime whose value is also set, even when the transaction is final.
*/
uint_fast16_t lockDistance;
uint_fast16_t lockDuration; /* Units of 512 seconds */
/* These two fields are used to implement broken jets and only remain here for consensus purposes. */
uint_fast16_t obsolete_lockDistance;
uint_fast16_t obsolete_lockDuration;
bool isFinal;
} elementsTransaction;

Expand Down
Loading
Loading