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

Fix for Box.getReg v6 - different ids used now #1048

Open
wants to merge 1 commit into
base: v6.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ case object SBoxMethods extends MonoTypeMethods {
| identifier followed by box index in the transaction outputs.
""".stripMargin ) // see ExtractCreationInfo

lazy val getRegMethodV5 = SMethod(this, "getReg",
lazy val getRegMethodV5 = SMethod(this, "getRegV5",
SFunc(Array(SBox, SInt), SOption(tT), Array(paramT)), 7, ExtractRegisterAs.costKind)
.withInfo(ExtractRegisterAs,
""" Extracts register by id and type.
Expand All @@ -1427,7 +1427,7 @@ case object SBoxMethods extends MonoTypeMethods {
ArgInfo("regId", "zero-based identifier of the register."))

lazy val getRegMethodV6 = SMethod(this, "getReg",
SFunc(Array(SBox, SInt), SOption(tT), Array(paramT)), 7, ExtractRegisterAs.costKind, Seq(tT))
SFunc(Array(SBox, SInt), SOption(tT), Array(paramT)), 19, ExtractRegisterAs.costKind, Seq(tT))
Copy link
Member

Choose a reason for hiding this comment

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

Why 19 and not 9?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why 19 and not 9?

It is occupied by R0, see ErgoTreeSpecification for method ids checks :

{ import SBoxMethods._
      (SBox.typeId,  Seq(
        MInfo(1, ValueMethod),
        MInfo(2, PropositionBytesMethod),
        MInfo(3, BytesMethod),
        MInfo(4, BytesWithoutRefMethod),
        MInfo(5, IdMethod),
        MInfo(6, creationInfoMethod),
        MInfo(8, tokensMethod)
      ) ++ (if (isV6Activated) {
        Seq(MInfo(19, getRegMethodV6))
      } else {
        Seq(MInfo(7, getRegMethodV5))
      }) ++ registers(idOfs = 8)
        .zipWithIndex
        .map { case (m,i) => MInfo((8 + i + 1).toByte, m) }, true)
    }

.withIRInfo(MethodCallIrBuilder,
javaMethodOf[Box, Int, RType[_]]("getReg"),
{ mtype => Array(mtype.tRange.asOption[SType].elemType) })
Expand All @@ -1449,12 +1449,11 @@ case object SBoxMethods extends MonoTypeMethods {
BytesWithoutRefMethod, // see ExtractBytesWithNoRef
IdMethod, // see ExtractId
creationInfoMethod,
tokensMethod
tokensMethod,
getRegMethodV5
) ++ registers(8)

lazy val v5Methods = commonBoxMethods ++ Array(
getRegMethodV5
)
lazy val v5Methods = commonBoxMethods

lazy val v6Methods = commonBoxMethods ++ Array(
getRegMethodV6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,12 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit with C
MInfo(4, BytesWithoutRefMethod),
MInfo(5, IdMethod),
MInfo(6, creationInfoMethod),
MInfo(7, getRegMethodV5),
MInfo(8, tokensMethod)
) ++ (if (isV6Activated) {
Seq(MInfo(7, getRegMethodV6))
Seq(MInfo(19, getRegMethodV6))
} else {
Seq(MInfo(7, getRegMethodV5))
Seq()
}) ++ registers(idOfs = 8)
.zipWithIndex
.map { case (m,i) => MInfo((8 + i + 1).toByte, m) }, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3088,7 +3088,7 @@ class BasicOpsSpecification extends CompilerTestingCommons
if (VersionContext.current.isV6SoftForkActivated) {
getRegTest()
} else {
an[sigma.exceptions.ConstraintFailed] should be thrownBy getRegTest()
an[sigma.validation.ValidationException] should be thrownBy getRegTest()
}
}

Expand All @@ -3109,7 +3109,7 @@ class BasicOpsSpecification extends CompilerTestingCommons
if (VersionContext.current.isV6SoftForkActivated) {
getRegTest()
} else {
an[java.nio.BufferUnderflowException] should be thrownBy getRegTest()
an[sigma.validation.ValidationException] should be thrownBy getRegTest()
}
}

Expand Down
Loading