Here is another example using a puzzle for addressing the same issue (DoS attacks). The idea works assuming that DEPTH is available.
{
val x = OUTPUTS(0).R4[Coll[Byte]].get
val y = OUTPUTS(0).R5[Coll[Byte]].get
val commitmentBox = CONTEXT.dataInputs(0) // can also be input
val commitmentX = commitmentBox.R4[Coll[Byte]].get
val commitmentY = commitmentBox.R5[Coll[Byte]].get
val commitmentOwnerPubKey = commitmentBox.R6[Coll[Byte]].get
val validCommitment = blakeb256(x) == commitmentX &&
blakeB256(y) == commitmentY
val validReward = OUTPUTS(0).value = SELF.value &&
OUTPUTS(0).propositionBytes == commitmentOwnerPubKey
// puzzle's goal is to find x != y such that sha256(x) == sha256(y)
sha256(x) == sha256(y) && x != y &&
validCommitment &&
commitmentBox.DEPTH > 100 &&
validReward
}
If DEPTH is not available (it isn’t yet unfortunately), there are other workarounds such as those suggested in the thread: “A trustless timestamping service for boxes”