Skip to content

Commit 44ff79f

Browse files
Mark depricated parts of the TxEnv as obsolete
These fields are only used to implement broken jets. They only remain here because they are not part of consensus and cannot be removed.
1 parent fc466a8 commit 44ff79f

7 files changed

Lines changed: 45 additions & 45 deletions

File tree

C/elements/elementsJets.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ static uint_fast32_t lockTime(const elementsTransaction* tx) {
153153
return !tx->isFinal && 500000000U <= tx->lockTime ? tx->lockTime : 0;
154154
}
155155

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

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

164164
static bool isFee(const sigOutput* output) {
@@ -735,14 +735,14 @@ bool simplicity_tx_lock_time(frameItem* dst, frameItem src, const txEnv* env) {
735735
/* tx_lock_distance : ONE |- TWO^16 */
736736
bool simplicity_broken_do_not_use_tx_lock_distance(frameItem* dst, frameItem src, const txEnv* env) {
737737
(void) src; // src is unused;
738-
simplicity_write16(dst, lockDistance(env->tx));
738+
simplicity_write16(dst, obsolete_lockDistance(env->tx));
739739
return true;
740740
}
741741

742742
/* tx_lock_duration : ONE |- TWO^16 */
743743
bool simplicity_broken_do_not_use_tx_lock_duration(frameItem* dst, frameItem src, const txEnv* env) {
744744
(void) src; // src is unused;
745-
simplicity_write16(dst, lockDuration(env->tx));
745+
simplicity_write16(dst, obsolete_lockDuration(env->tx));
746746
return true;
747747
}
748748

@@ -764,14 +764,14 @@ bool simplicity_check_lock_time(frameItem* dst, frameItem src, const txEnv* env)
764764
bool simplicity_broken_do_not_use_check_lock_distance(frameItem* dst, frameItem src, const txEnv* env) {
765765
(void) dst; // dst is unused;
766766
uint_fast16_t x = simplicity_read16(&src);
767-
return x <= lockDistance(env->tx);
767+
return x <= obsolete_lockDistance(env->tx);
768768
}
769769

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

777777
/* calculate_issuance_entropy : TWO^256 * TWO^32 * TWO^256 |- TWO^256 */

C/elements/env.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,12 @@ extern elementsTransaction* simplicity_elements_mallocTransaction(const rawEleme
408408
copyInput(&input[i], &rawTx->input[i]);
409409
if (input[i].sequence < 0xffffffff) { tx->isFinal = false; }
410410
if (input[i].sequence < 0x80000000) {
411-
const uint_fast16_t maskedSequence = input[i].sequence & 0xffff;
412-
if (input[i].sequence & ((uint_fast32_t)1 << 22)) {
413-
if (tx->lockDuration < maskedSequence) tx->lockDuration = maskedSequence;
414-
} else {
415-
if (tx->lockDistance < maskedSequence) tx->lockDistance = maskedSequence;
416-
}
411+
const uint_fast16_t maskedSequence = input[i].sequence & 0xffff;
412+
if (input[i].sequence & ((uint_fast32_t)1 << 22)) {
413+
if (tx->obsolete_lockDuration < maskedSequence) tx->obsolete_lockDuration = maskedSequence;
414+
} else {
415+
if (tx->obsolete_lockDistance < maskedSequence) tx->obsolete_lockDistance = maskedSequence;
416+
}
417417
}
418418
if (input[i].isPegin) {
419419
sha256_uchar(&ctx_inputOutpointsHash, 1);

C/elements/txEnv.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,9 @@ typedef struct elementsTransaction {
224224
uint_fast32_t numFees;
225225
uint_fast32_t version;
226226
uint_fast32_t lockTime;
227-
/* lockDuration and lockDistance values are set even when the version is 0 or 1.
228-
* This is similar to lockTime whose value is also set, even when the transaction is final.
229-
*/
230-
uint_fast16_t lockDistance;
231-
uint_fast16_t lockDuration; /* Units of 512 seconds */
227+
/* These two fields are used to implement broken jets and only remain here for consensus purposes. */
228+
uint_fast16_t obsolete_lockDistance;
229+
uint_fast16_t obsolete_lockDuration;
232230
bool isFinal;
233231
} elementsTransaction;
234232

Haskell/Elements/Simplicity/Elements/DataTypes.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Simplicity.Elements.DataTypes
2323
, SigTx(SigTx), sigTxVersion, sigTxIn, sigTxOut, sigTxLock
2424
, putNoWitnessTx, txid
2525
, TapEnv(..)
26-
, txIsFinal, txLockDistance, txLockDuration
26+
, txIsFinal, txLockBrokenDistance, txLockBrokenDuration
2727
, calculateIssuanceEntropy, calculateAsset, calculateToken
2828
, outputAmountsHash, outputNoncesHash, outputScriptsHash
2929
, outputRangeProofsHash, outputSurjectionProofsHash, outputsHash, outputHash
@@ -322,17 +322,19 @@ txIsFinal tx = all finalSequence (sigTxIn tx)
322322
where
323323
finalSequence sigin = sigTxiSequence sigin == maxBound
324324

325-
txLockDistance :: SigTx -> Word16
326-
txLockDistance tx | sigTxVersion tx < 2 = 0
325+
-- | This function is used in a specification of broken relative timelock jets and should not be used other than for previous consensus reasons.
326+
txLockBrokenDistance :: SigTx -> Word16
327+
txLockBrokenDistance tx | sigTxVersion tx < 2 = 0
327328
| otherwise = getMax . foldMap distance $ sigTxIn tx
328329
where
329330
distance sigin = case parseSequence (sigTxiSequence sigin) of
330331
Just (Left x) -> Max x
331332
_ -> mempty
332333

333-
txLockDuration :: SigTx -> Word16
334-
txLockDuration tx | sigTxVersion tx < 2 = 0
335-
| otherwise = getMax . foldMap duration $ sigTxIn tx
334+
-- | This function is used in a specification of broken relative timelock jets and should not be used other than for previous consensus reasons.
335+
txLockBrokenDuration :: SigTx -> Word16
336+
txLockBrokenDuration tx | sigTxVersion tx < 2 = 0
337+
| otherwise = getMax . foldMap duration $ sigTxIn tx
336338
where
337339
duration sigin = case parseSequence (sigTxiSequence sigin) of
338340
Just (Right x) -> Max x

Haskell/Simplicity/Elements/Jets.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ specificationSigHash BuildTaptweak = Prog.buildTaptweak
249249
specificationTimeLock :: (Assert term, Primitive term) => TimeLockJet a b -> term a b
250250
specificationTimeLock CheckLockHeight = TimeLock.checkLockHeight
251251
specificationTimeLock CheckLockTime = TimeLock.checkLockTime
252-
specificationTimeLock BrokenDoNotUseCheckLockDistance = TimeLock.checkLockDistance
253-
specificationTimeLock BrokenDoNotUseCheckLockDuration = TimeLock.checkLockDuration
252+
specificationTimeLock BrokenDoNotUseCheckLockDistance = TimeLock.brokenCheckLockDistance
253+
specificationTimeLock BrokenDoNotUseCheckLockDuration = TimeLock.brokenCheckLockDuration
254254
specificationTimeLock TxLockHeight = TimeLock.txLockHeight
255255
specificationTimeLock TxLockTime = TimeLock.txLockTime
256-
specificationTimeLock BrokenDoNotUseTxLockDistance = TimeLock.txLockDistance
257-
specificationTimeLock BrokenDoNotUseTxLockDuration = TimeLock.txLockDuration
256+
specificationTimeLock BrokenDoNotUseTxLockDistance = TimeLock.brokenTxLockDistance
257+
specificationTimeLock BrokenDoNotUseTxLockDuration = TimeLock.brokenTxLockDuration
258258
specificationTimeLock TxIsFinal = TimeLock.txIsFinal
259259

260260
specificationIssuance :: (Assert term, Primitive term) => IssuanceJet a b -> term a b
@@ -420,9 +420,9 @@ implementationTimeLock CheckLockTime env x | txIsFinal (envTx env) = guard $ fro
420420
| otherwise = guard $ fromWord32 x <= 0
421421
where
422422
lock = fromIntegral . sigTxLock . envTx $ env
423-
implementationTimeLock BrokenDoNotUseCheckLockDistance env x | fromWord16 x <= fromIntegral (txLockDistance (envTx env)) = Just ()
423+
implementationTimeLock BrokenDoNotUseCheckLockDistance env x | fromWord16 x <= fromIntegral (txLockBrokenDistance (envTx env)) = Just ()
424424
| otherwise = Nothing
425-
implementationTimeLock BrokenDoNotUseCheckLockDuration env x | fromWord16 x <= fromIntegral (txLockDuration (envTx env)) = Just ()
425+
implementationTimeLock BrokenDoNotUseCheckLockDuration env x | fromWord16 x <= fromIntegral (txLockBrokenDuration (envTx env)) = Just ()
426426
| otherwise = Nothing
427427
implementationTimeLock TxLockHeight env () | txIsFinal (envTx env) = Just (toWord32 0)
428428
| Left l <- parseLock lock = Just . toWord32 $ fromIntegral l
@@ -434,8 +434,8 @@ implementationTimeLock TxLockTime env () | txIsFinal (envTx env) = Just (toWord3
434434
| otherwise = Just (toWord32 0)
435435
where
436436
lock = fromIntegral . sigTxLock . envTx $ env
437-
implementationTimeLock BrokenDoNotUseTxLockDistance env () = Just . toWord16 . fromIntegral $ txLockDistance (envTx env)
438-
implementationTimeLock BrokenDoNotUseTxLockDuration env () = Just . toWord16 . fromIntegral $ txLockDuration (envTx env)
437+
implementationTimeLock BrokenDoNotUseTxLockDistance env () = Just . toWord16 . fromIntegral $ txLockBrokenDistance (envTx env)
438+
implementationTimeLock BrokenDoNotUseTxLockDuration env () = Just . toWord16 . fromIntegral $ txLockBrokenDuration (envTx env)
439439
implementationTimeLock TxIsFinal env () = Just $ toBit (txIsFinal (envTx env))
440440

441441
implementationIssuance :: IssuanceJet a b -> PrimEnv -> a -> Maybe b

Haskell/Simplicity/Elements/Programs/TimeLock.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
module Simplicity.Elements.Programs.TimeLock
33
( txIsFinal
44
, txLockHeight, txLockTime
5-
, txLockDistance, txLockDuration
5+
, brokenTxLockDistance, brokenTxLockDuration
66
, checkLockHeight, checkLockTime
7-
, checkLockDistance, checkLockDuration
7+
, brokenCheckLockDistance, brokenCheckLockDuration
88
, module Simplicity.Programs.TimeLock
99
, Bit
1010
) where
@@ -43,16 +43,16 @@ bip68VersionCheck :: (Core term, Primitive term) => term () Bit
4343
bip68VersionCheck = scribe (toWord32 2) &&& primitive Version >>> le word32
4444

4545
-- | Implements 'Simplicity.Elements.DataTypes.txLockDistance'.
46-
txLockDistance :: (Core term, Primitive term) => term () Distance
47-
txLockDistance = bip68VersionCheck &&& zero word16
46+
brokenTxLockDistance :: (Core term, Primitive term) => term () Distance
47+
brokenTxLockDistance = bip68VersionCheck &&& zero word16
4848
>>> match ih (forWhile word32 body >>> copair iden iden)
4949
where
5050
body = take (drop (primitive InputSequence)) &&& ih
5151
>>> match (injl ih) (injr (take parseSequence &&& ih >>> match ih (match (max word16) ih)))
5252

5353
-- | Implements 'Simplicity.Elements.DataTypes.txLockDuration'.
54-
txLockDuration :: (Core term, Primitive term) => term () Duration
55-
txLockDuration = bip68VersionCheck &&& zero word16
54+
brokenTxLockDuration :: (Core term, Primitive term) => term () Duration
55+
brokenTxLockDuration = bip68VersionCheck &&& zero word16
5656
>>> match ih (forWhile word32 body >>> copair iden iden)
5757
where
5858
body = take (drop (primitive InputSequence)) &&& ih
@@ -67,9 +67,9 @@ checkLockTime :: (Assert term, Primitive term) => term Time ()
6767
checkLockTime = assert (iden &&& (unit >>> txLockTime) >>> le word32)
6868

6969
-- | Asserts that the input is less than or equal to the value returned by 'txLockDistance'.
70-
checkLockDistance :: (Assert term, Primitive term) => term Distance ()
71-
checkLockDistance = assert (iden &&& (unit >>> txLockDistance) >>> le word16)
70+
brokenCheckLockDistance :: (Assert term, Primitive term) => term Distance ()
71+
brokenCheckLockDistance = assert (iden &&& (unit >>> brokenTxLockDistance) >>> le word16)
7272

7373
-- | Asserts that the input is less than or equal to the value returned by 'txLockDuration'.
74-
checkLockDuration :: (Assert term, Primitive term) => term Duration ()
75-
checkLockDuration = assert (iden &&& (unit >>> txLockDuration) >>> le word16)
74+
brokenCheckLockDuration :: (Assert term, Primitive term) => term Duration ()
75+
brokenCheckLockDuration = assert (iden &&& (unit >>> brokenTxLockDuration) >>> le word16)

Haskell/Tests/Simplicity/Elements/Tests.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ prop_check_lock_time = checkJet (ElementsJet (TimeLockJet CheckLockTime))
207207

208208
prop_check_lock_distance :: Property
209209
prop_check_lock_distance = checkJet (ElementsJet (TimeLockJet BrokenDoNotUseCheckLockDistance))
210-
$ \check -> forallPrimEnv $ \env -> forAll (genBoundaryCases . txLockDistance $ envTx env)
210+
$ \check -> forallPrimEnv $ \env -> forAll (genBoundaryCases . txLockBrokenDistance $ envTx env)
211211
$ \w -> check env (toW16 w)
212212

213213
prop_check_lock_duration :: Property
214214
prop_check_lock_duration = checkJet (ElementsJet (TimeLockJet BrokenDoNotUseCheckLockDuration))
215-
$ \check -> forallPrimEnv $ \env -> forAll (genBoundaryCases . txLockDuration $ envTx env)
215+
$ \check -> forallPrimEnv $ \env -> forAll (genBoundaryCases . txLockBrokenDuration $ envTx env)
216216
$ \w -> check env (toW16 w)
217217

218218
prop_calculate_issuance_entropy :: Outpoint -> HashElement -> Bool

0 commit comments

Comments
 (0)