Skip to content

Commit

Permalink
v5.0.1-RC: fix tests after merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed Oct 13, 2022
1 parent 2342414 commit 2668480
Show file tree
Hide file tree
Showing 3 changed files with 420 additions and 440 deletions.
16 changes: 6 additions & 10 deletions sigmastate/src/main/scala/sigmastate/interpreter/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,8 @@ trait Interpreter extends ScorexLogging {
*/
protected def deserializeMeasured(context: CTX, scriptBytes: Array[Byte]): (CTX, Value[SType]) = {
val r = SigmaSerializer.startReader(scriptBytes)
val (script, scriptComplexity) = if (VersionContext.current.isJitActivated) {
val script = ValueSerializer.deserialize(r) // Why ValueSerializer? read NOTE above
val cost = java7.compat.Math.multiplyExact(scriptBytes.length, CostPerByteDeserialized)
(script, cost)
} else {
r.complexity = 0
val script = ValueSerializer.deserialize(r) // Why ValueSerializer? read NOTE above
(script, r.complexity)
}
val script = ValueSerializer.deserialize(r) // Why ValueSerializer? read NOTE above
val scriptComplexity = java7.compat.Math.multiplyExact(scriptBytes.length, CostPerByteDeserialized)

val currCost = Evaluation.addCostChecked(context.initCost, scriptComplexity, context.costLimit)
val ctx1 = context.withInitCost(currCost).asInstanceOf[CTX]
Expand Down Expand Up @@ -243,7 +236,10 @@ trait Interpreter extends ScorexLogging {
env: ScriptEnv): FullReductionResult = {
implicit val vs: SigmaValidationSettings = context.validationSettings
val jitRes = VersionContext.withVersions(context.activatedScriptVersion, ergoTree.version) {
val (propTree, context2) = trySoftForkable[(SigmaPropValue, CTX)](whenSoftFork = (TrueSigmaProp, context)) {
val deserializeSubstitutionCost = java7.compat.Math.multiplyExact(ergoTree.bytes.length, CostPerTreeByte)
val currCost = Evaluation.addCostChecked(context.initCost, deserializeSubstitutionCost, context.costLimit)
val context1 = context.withInitCost(currCost).asInstanceOf[CTX]
val (propTree, context2) = trySoftForkable[(SigmaPropValue, CTX)](whenSoftFork = (TrueSigmaProp, context1)) {
applyDeserializeContextJITC(context, prop)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,36 +284,20 @@ class ErgoAddressSpecification extends SigmaDslTesting
// when limit is low
{
val deliberatelySmallLimit = 24
testPay2SHAddress(addr,
script = scriptVarId -> ByteArrayConstant(scriptBytes),
costLimit = deliberatelySmallLimit)


assertExceptionThrown(
testPay2SHAddress(addr,
script = scriptVarId -> ByteArrayConstant(scriptBytes),
costLimit = deliberatelySmallLimit),
rootCauseLike[CostLimitException](
s"Estimated execution cost 164 exceeds the limit $deliberatelySmallLimit")
s"Estimated execution cost 88 exceeds the limit $deliberatelySmallLimit")
)
}

// when limit is low
val deliberatelySmallLimit = 100

assertExceptionThrown(
{
testPay2SHAddress(addr,
script = scriptVarId -> ByteArrayConstant(scriptBytes),
costLimit = deliberatelySmallLimit)
},
rootCauseLike[CostLimitException](
s"Estimated execution cost 164 exceeds the limit $deliberatelySmallLimit")
)


// when limit is even lower than tree complexity
{
val deliberatelySmallLimit = 100
val deliberatelySmallLimit = 2

assertExceptionThrown(
{
Expand Down
Loading

0 comments on commit 2668480

Please sign in to comment.