mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-03-16 21:34:53 +00:00
Disable relative time lock by time (#1800)
* ignore type flag * Ignore type flag of relative time lock - interpret as DAA score * Split verifyLockTime to functions with and without threshold.relative lockTimes dont need threshold check * Change function name and order of the functions calls Co-authored-by: tal <tal@daglabs.com>
This commit is contained in:
@@ -1068,17 +1068,16 @@ func opcodeReturn(op *parsedOpcode, vm *Engine) error {
|
||||
return scriptError(ErrEarlyReturn, "script returned early")
|
||||
}
|
||||
|
||||
// verifyLockTime is a helper function used to validate locktimes.
|
||||
func verifyLockTime(txLockTime, threshold, lockTime uint64) error {
|
||||
// The lockTimes in both the script and transaction must be of the same
|
||||
// type.
|
||||
if !((txLockTime < threshold && lockTime < threshold) ||
|
||||
(txLockTime >= threshold && lockTime >= threshold)) {
|
||||
str := fmt.Sprintf("mismatched locktime types -- tx locktime "+
|
||||
"%d, stack locktime %d", txLockTime, lockTime)
|
||||
return scriptError(ErrUnsatisfiedLockTime, str)
|
||||
func verifyLockTimeWithThreshold(txLockTime, threshold, lockTime uint64) error {
|
||||
err := verifyLockTimeThreshold(txLockTime, threshold, lockTime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return verifyLockTime(txLockTime, lockTime)
|
||||
}
|
||||
|
||||
// checkLockTimeRequirement is a helper function used to validate locktimes.
|
||||
func verifyLockTime(txLockTime, lockTime uint64) error {
|
||||
if lockTime > txLockTime {
|
||||
str := fmt.Sprintf("locktime requirement not satisfied -- "+
|
||||
"locktime is greater than the transaction locktime: "+
|
||||
@@ -1089,6 +1088,18 @@ func verifyLockTime(txLockTime, threshold, lockTime uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// verifyLockTimeThreshold is a helper function used to verify the lockTimes in both the script and transaction have the same type.
|
||||
func verifyLockTimeThreshold(txLockTime, threshold, lockTime uint64) error {
|
||||
if !((txLockTime < threshold && lockTime < threshold) ||
|
||||
(txLockTime >= threshold && lockTime >= threshold)) {
|
||||
str := fmt.Sprintf("mismatched locktime types -- tx locktime "+
|
||||
"%d, stack locktime %d", txLockTime, lockTime)
|
||||
return scriptError(ErrUnsatisfiedLockTime, str)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// opcodeCheckLockTimeVerify compares the top item on the data stack to the
|
||||
// LockTime field of the transaction containing the script signature
|
||||
// validating if the transaction outputs are spendable yet.
|
||||
@@ -1111,12 +1122,11 @@ func opcodeCheckLockTimeVerify(op *parsedOpcode, vm *Engine) error {
|
||||
lockTimeBytes = paddedLockTimeBytes
|
||||
}
|
||||
stackLockTime := binary.LittleEndian.Uint64(lockTimeBytes)
|
||||
// The lock time field of a transaction is either a block height at
|
||||
// The lock time field of a transaction is either a DAA score at
|
||||
// which the transaction is finalized or a timestamp depending on if the
|
||||
// value is before the constants.LockTimeThreshold. When it is under the
|
||||
// threshold it is a block height.
|
||||
err = verifyLockTime(vm.tx.LockTime, constants.LockTimeThreshold,
|
||||
stackLockTime)
|
||||
// threshold it is a DAA score.
|
||||
err = verifyLockTimeWithThreshold(vm.tx.LockTime, constants.LockTimeThreshold, stackLockTime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1188,10 +1198,9 @@ func opcodeCheckSequenceVerify(op *parsedOpcode, vm *Engine) error {
|
||||
}
|
||||
|
||||
// Mask off non-consensus bits before doing comparisons.
|
||||
lockTimeMask := constants.SequenceLockTimeIsSeconds | constants.SequenceLockTimeMask
|
||||
maskedTxSequence := txSequence & lockTimeMask
|
||||
maskedStackSequence := stackSequence & lockTimeMask
|
||||
return verifyLockTime(maskedTxSequence, constants.SequenceLockTimeIsSeconds, maskedStackSequence)
|
||||
maskedTxSequence := txSequence & constants.SequenceLockTimeMask
|
||||
maskedStackSequence := stackSequence & constants.SequenceLockTimeMask
|
||||
return verifyLockTime(maskedTxSequence, maskedStackSequence)
|
||||
}
|
||||
|
||||
// opcodeToAltStack removes the top item from the main data stack and pushes it
|
||||
|
||||
Reference in New Issue
Block a user