Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for soft-forked acceptance of Ergoscript containing unknown methods (after 6.0 activation) #2146

Merged
merged 10 commits into from
May 15, 2024
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.ergoplatform.modifiers.history.header

import cats.syntax.either._
import cats.syntax.either._ // needed for Scala 2.11
import sigmastate.utils.Helpers._
import io.circe.syntax._
import io.circe.{Decoder, Encoder, HCursor}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import sigma.validation.SigmaValidationSettings
import scala.util.Try

/**
* Ergo configuration of validation.
*
* Specifies the strategy to be used (fail-fast) and validation rules with their statuses.
* Container for validation rules along with their statuses.
* Contains delta from the initial validation rules `updateFromInitial` as well as calculated current rules,
* that might also be computed by applying `updateFromInitial` to `ErgoValidationSettings.initial`
*
Expand All @@ -29,6 +27,9 @@ case class ErgoValidationSettings(rules: Map[Short, RuleStatus],

override type M = ErgoValidationSettings

/**
* In regards with consensus rules, it is worth to fail fast to avoid spam issues.
*/
override val isFailFast: Boolean = true

override def getError(id: Short, invalidMod: InvalidModifier): ValidationResult.Invalid = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class ErgoTransactionSpec extends ErgoCorePropertyTest {
txTry.toEither.left.get.isInstanceOf[NegativeArraySizeException] shouldBe true
}


property("context extension with neg and pos ids") {
val negId: Byte = -20

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@ import org.ergoplatform.nodeView.state.{ErgoStateContext, VotingData}
import org.ergoplatform.settings._
import org.ergoplatform.utils.ErgoCorePropertyTest
import org.ergoplatform.wallet.interpreter.ErgoInterpreter
import org.ergoplatform.{ErgoBox, ErgoBoxCandidate}
import org.ergoplatform.{ErgoBox, ErgoBoxCandidate, Input}
import scorex.util.{ModifierId, bytesToId}
import sigmastate.eval.Extensions._
import org.ergoplatform.nodeView.ErgoContext
import org.ergoplatform.sdk.wallet.protocol.context.TransactionContext
import org.ergoplatform.settings.Parameters.MaxBlockCostIncrease
import org.ergoplatform.settings.ValidationRules.{bsBlockTransactionsCost, txAssetsInOneBox}
import org.ergoplatform.validation.ValidationRules.CheckAndGetMethod
import org.ergoplatform.wallet.boxes.ErgoBoxAssetExtractor
import org.ergoplatform.wallet.interpreter.TransactionHintsBag
import org.ergoplatform.wallet.protocol.context.InputContext
import org.scalacheck.Gen
import sigma.util.BenchmarkUtil
import scorex.crypto.hash.Blake2b256
import scorex.util.encode.Base16
import sigma.Colls
import sigma.ast.ErgoTree.ZeroHeader
import sigma.ast.{AND, ErgoTree, TrueLeaf}
import sigma.interpreter.{ContextExtension, ProverResult}
import sigma.serialization.ErgoTreeSerializer.DefaultSerializer
import sigma.validation.ReplacedRule
import sigmastate.helpers.TestingHelpers._

import scala.util.{Random, Try}
Expand Down Expand Up @@ -478,4 +484,45 @@ class ErgoNodeTransactionSpec extends ErgoCorePropertyTest {
txCost shouldBe (accInitCost + initialCost + inputCost(tx, from) * inputsNum)
}
}

/**
* In this test we check how current version of the node (block protocol v3, at the moment of writing this test) will
* execute a script which contains a method added in next version of the protocol (namely, BigInt.nbits), which
* is unknown to the node.
*
* As shown in the test, rule #1110 (CheckAndGetMethod) should be replaced for new methods to be passed by the node
* not recognizing it.
*/
property("Soft-forked execution of Ergoscript containing unknown methods") {

val activatedVersion = 3.toByte
val params = new Parameters(0, LaunchParameters.parametersTable.updated(123, activatedVersion + 1), ErgoValidationSettingsUpdate.empty)

// for next version, rule 1011 should be replaced , otherwise transaction validation will fail
// in this test, the rule is replaced with self, but for real activation this choice should be revised
val ruleId = CheckAndGetMethod.id
val updVs = ErgoValidationSettings.initial.updated(ErgoValidationSettingsUpdate(Seq(), Seq(ruleId -> ReplacedRule(ruleId))))

val stateContext = emptyStateContext.copy(currentParameters = params, validationSettings = updVs)(chainSettings)
stateContext.blockVersion shouldBe activatedVersion + 1

// the following ergo tree contains SBigInt.nbits method which is not supported by this client (as of 5.x version)
// ergo tree version is 3, less value (e.g. version = 2 which gives 1a130206022edf0580fcf622d193db060873007301)
// also works
val ergoTree = DefaultSerializer.deserializeErgoTree(Base16.decode("1b130206022edf0580fcf622d193db060873007301").get)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ergoTree is UnparsedErgoTree? Maybe add the assertion.


ergoTree.root.isLeft shouldBe true // unparsed

val b = new ErgoBox(1000000000L, ergoTree, Colls.emptyColl,
Map.empty, ModifierId @@ "c95c2ccf55e03cac6659f71ca4df832d28e2375569cec178dcb17f3e2e5f7742",
0, 0)
val input = Input(b.id, ProverResult(Array.emptyByteArray, ContextExtension.empty))

val oc = new ErgoBoxCandidate(b.value, b.ergoTree, b.creationHeight)

val utx = new ErgoTransaction(IndexedSeq(input), IndexedSeq.empty, IndexedSeq(oc))

utx.statefulValidity(IndexedSeq(b), IndexedSeq.empty, stateContext, 0)(defaultProver).isSuccess shouldBe true
}

}
Loading