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

6.0.0 candidate for testnet #1025

Closed
wants to merge 164 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
0843902
DecodeNBitsMethod definition
kushti Apr 2, 2024
49dce78
ToNBits def
kushti Apr 2, 2024
1c1049e
merging w. 6.0.0
kushti Apr 3, 2024
37bb86c
toNBits added to SigmaDsl
kushti Apr 4, 2024
6f8981f
NBitsUtils
kushti Apr 4, 2024
d0f1b7d
unused import removed
kushti Apr 5, 2024
fcc7f0f
merging latest 5.0.14 commits
kushti Apr 6, 2024
6e47167
nbits impl
kushti Apr 9, 2024
9e4e098
failing roundtrip test for deserialization roundtrip
kushti Apr 10, 2024
1016323
importing method def from i675
kushti Apr 10, 2024
93748f1
removing decode nbits
kushti Apr 10, 2024
a3cb64d
versioned nbits serialization roundtrip test
kushti Apr 12, 2024
8941a8e
nbits evaluation test
kushti Apr 15, 2024
92e2d77
close #974 : Header.bytes method implementation
kushti May 6, 2024
98e2756
moving failing test from #612 to here
kushti May 6, 2024
2c6bd15
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti May 6, 2024
624558f
executeFromVar tests are passing
kushti May 7, 2024
690a3e2
Global.deserialize method
kushti May 7, 2024
023ad09
deserialize int - test passing
kushti May 8, 2024
7648182
unused code removal
kushti May 9, 2024
79b4d11
executeFromVar is passing for SigmaProp
kushti May 9, 2024
a470406
more executeFromVar and deserialize tests, all passing
kushti May 9, 2024
c1947d4
negative test for DeserializeContext in executeFromVar, new stubs for…
kushti May 9, 2024
cec0add
long roundtrip
kushti May 9, 2024
838a617
box rouundtrip test
kushti May 10, 2024
fd589a8
bigInt test
kushti May 10, 2024
4404741
Short test
kushti May 10, 2024
7d69ebc
group elem impl & test
kushti May 10, 2024
48f112a
sigmaprop test & impl
kushti May 12, 2024
63f8ccc
non evaluated sigmaprop test
kushti May 12, 2024
516f05d
avltree test & impl
kushti May 12, 2024
5f3a1ad
removing executeFromVar from i443 and some code cleaning
kushti May 13, 2024
50f5b87
merging w. i974
kushti May 13, 2024
126bc05
header impl & test
kushti May 13, 2024
5bf4704
renaming to deserializeRaw, LangSpec.md update
kushti May 13, 2024
4004cc9
i486-toBytes: tests added to SigmaTyperTest
aslesarenko May 14, 2024
b55d336
i486-toBytes: ExactNumeric.toBytes implemented
aslesarenko May 14, 2024
9d83125
Merge branch 'develop' into i486-toBytes
aslesarenko May 14, 2024
e865264
Merge remote-tracking branch 'origin/v6.0.0-fix-tests' into i486-toBytes
aslesarenko May 14, 2024
35c9375
DataSerializer WIP #1
kushti May 16, 2024
48f11e7
coll allowed
kushti May 16, 2024
d4ff7b5
Merge remote-tracking branch 'refs/remotes/origin/v6.0.0-refactor-ir-…
aslesarenko May 16, 2024
7fd601b
.propBytes test
kushti May 16, 2024
e1873fe
merging w. i659, header option test
kushti May 17, 2024
a2ffc2d
all types rely on DataSerializer
kushti May 17, 2024
ae271cd
deserializeRaw -> deserializeTo
kushti May 17, 2024
779a9eb
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti May 17, 2024
60a111b
unused import fix
kushti May 18, 2024
d3e4040
MethodCall deserialization roundtrip for Global.deserializeTo[]
kushti May 20, 2024
727be9b
Merge remote-tracking branch 'refs/remotes/origin/i994-fix-subst-cons…
aslesarenko May 23, 2024
3ccf11e
i486-toBytes: fixes after merge
aslesarenko May 23, 2024
3d47f2a
initial raw, buggy & unversioned unsigned bit int impl
kushti May 24, 2024
b13cef6
failing schnorr sig check w. unsigned
kushti May 24, 2024
e5a32c8
i486-toBytes: Versioned.scala added
aslesarenko May 25, 2024
bba2230
i486-toBytes: ensure VersionContext.current in tests
aslesarenko May 25, 2024
dc361a1
i486-toBytes: ErgoTreeSpecification versioned and updated
aslesarenko May 25, 2024
70786a0
i486-toBytes: clarified description of demotion of SNumericType
aslesarenko May 25, 2024
c76ac1a
i486-toBytes: GraphBuilding to handle numeric methods
aslesarenko May 25, 2024
2427db3
i486-toBytes: added userDefinedInvoke handler to SMethod
aslesarenko May 25, 2024
02e2d06
i486-toBytes: toBigEndianBytes implemented
aslesarenko May 25, 2024
c8d75cd
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti May 26, 2024
c9d0889
first pow check test
kushti May 26, 2024
299fdd5
merging w. nbits encoding PR
kushti May 26, 2024
a90e7be
pow check test passing
kushti May 26, 2024
2e23a2c
v6.0-serialize: CheckMinimalErgoTreeVersion rule removed
aslesarenko May 28, 2024
fe68c66
v6.0-serialize: cleanup + ScalaDocs
aslesarenko May 28, 2024
a5321af
v6.0-serialize: added CoreByteWriter.checkCostLimit
aslesarenko May 28, 2024
37b23cd
hit <= diff
kushti May 29, 2024
69e8d9e
merging w. 6.0.0
kushti May 29, 2024
432addc
v6.0-serialize: cost accumulation in SigmaByteWriter and serialize_ev…
aslesarenko May 29, 2024
97377c2
v6.0-serialize: cleanup + ScalaDocs
aslesarenko Jun 3, 2024
767fbb4
v6.0-serialize: tests for cost trace
aslesarenko Jun 3, 2024
7ce2446
merging w. 6.0.0
kushti Jun 3, 2024
744d8a5
conversion test stub
kushti Jun 3, 2024
a30e068
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jun 3, 2024
2acc6db
more todos
kushti Jun 4, 2024
4735aed
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jun 4, 2024
0478069
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jun 6, 2024
e2faf71
merging with newfeature pr
kushti Jun 6, 2024
37ac921
BasicOpsSpecification tests for serialize
kushti Jun 6, 2024
074d609
MethodCall deserialization round trip for Global.serialize
kushti Jun 6, 2024
bf53a6b
spam tests, test for serialize(long) producing different result from …
kushti Jun 6, 2024
dd7bdc6
removing serialize
kushti Jun 7, 2024
4b27c86
merging w. 6.0-newfeature
kushti Jun 7, 2024
e1bfb1c
remove serialize from GraphBuilding and ErgoTreeSpecification
kushti Jun 7, 2024
15e21a4
importing new test for ErgoTreeSpecification from i486
kushti Jun 7, 2024
15f4f67
removing modq methods
kushti Jun 7, 2024
303f969
expUnsigned impl (test still failing)
kushti Jun 8, 2024
982f32f
schnorr sig example passed
kushti Jun 9, 2024
eb47d17
eq test, DataValueComparer
kushti Jun 9, 2024
33033fc
importing CheckMinimalErgoTreeVersion from i994
kushti Jun 10, 2024
d7fd8e1
merging w. 6.0.0
kushti Jun 10, 2024
312167b
merging w. 6.0.0
kushti Jun 10, 2024
dd62bd7
failing tests
kushti Jun 11, 2024
aaef77e
close #906: lazy evaluation of default in Option.getOrElse and Coll.g…
kushti Jun 11, 2024
ea468c9
initial stubs along first todos for bulletproofs contracts
kushti Jun 11, 2024
e9b3253
original code
kushti Jun 12, 2024
e71d7c2
modInverse
kushti Jun 13, 2024
e989665
plusMod
kushti Jun 13, 2024
d776db3
multiplyMod
kushti Jun 13, 2024
72db85b
toUnsigned & toUnsignedMod
kushti Jun 14, 2024
fc6d856
mod, toSigned, subtractMod
kushti Jun 17, 2024
a731962
simplifying the code
kushti Jul 5, 2024
cb7e262
initial toBits failing tests
kushti Jul 6, 2024
f577fd3
passing test (compilation fixed)
kushti Jul 8, 2024
cadf53d
tests for Byte and BigInt
kushti Jul 8, 2024
81ed008
Merge branch 'i486-toBytes' of github.com:ScorexFoundation/sigmastate…
kushti Jul 8, 2024
ee59083
Byte.toBits test passing
kushti Jul 8, 2024
3fde5fa
toBits tests for Long and BigInt(failing)
kushti Jul 8, 2024
9ea7597
BigInt.toBits test passing
kushti Jul 8, 2024
be77315
bitwise inversion
kushti Jul 9, 2024
a575d38
bitwiseInverse tests for Long and Byte
kushti Jul 9, 2024
7ff3542
bitwise or impl
kushti Jul 10, 2024
868fbb1
bitwiseAnd
kushti Jul 10, 2024
f21436d
bitwiseXor
kushti Jul 10, 2024
ced229f
shiftLeft
kushti Jul 11, 2024
9519ef6
shiftRight
kushti Jul 16, 2024
8f9b549
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jul 30, 2024
4c63a60
LSV5 & LSV6 tests
kushti Jul 30, 2024
61f90cd
assertEXceptionThrown
kushti Jul 31, 2024
aaa2aa9
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jul 31, 2024
a20c04f
moving to Global, finalizing costing
kushti Jul 31, 2024
2c8df31
updating collectMethods
kushti Jul 31, 2024
6981c34
fixing JS test
kushti Jul 31, 2024
26809c9
passing but improper changedFeature test
kushti Aug 2, 2024
2bf10bb
merging w. 6.0.0
kushti Aug 5, 2024
57ba522
merging w. 6.0.0
kushti Aug 8, 2024
8da3575
fixed tests in LSV6
kushti Aug 9, 2024
26b2b77
merging header.checkPoW
kushti Aug 12, 2024
65144a9
merging w. 6.0.0
kushti Aug 13, 2024
3fe6e50
merging v6.0-serialize into
kushti Aug 14, 2024
b4aa573
mmerging w. 6.0.0
kushti Aug 14, 2024
d8cc09d
deserializeCostKind
kushti Aug 14, 2024
6eba58d
deserialize merged
kushti Aug 14, 2024
fc056d8
nbits PR merged into
kushti Aug 14, 2024
57e39be
Header.bytes removed
kushti Aug 18, 2024
a8f1d66
merging deserialize PR updates into
kushti Aug 20, 2024
6bb7fe7
merging w. 6.0.0
kushti Aug 20, 2024
bcfb24d
removing unused CSigmaDslBuilder.validationSettings
kushti Aug 25, 2024
3037f1a
merging w 6.0.0, fixing ErgoTreeSpec
kushti Aug 27, 2024
016262b
removing unused SNumericTypeMethods.getMethods
kushti Aug 27, 2024
baef87f
more efficient toBits impl
kushti Sep 2, 2024
c7918ad
merging v6.0.0
kushti Sep 2, 2024
5a983b3
merging w. 6.0.0
kushti Sep 3, 2024
2e8d8f4
optimizing imports, polishing
kushti Sep 3, 2024
0c674fe
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Sep 4, 2024
ed5b8f5
fixing SigmaTyperTest
kushti Sep 4, 2024
b2de9cf
scaladoc
kushti Sep 6, 2024
9a10d17
merging w. i1006 (numeric methods)
kushti Sep 9, 2024
eccc9ca
6.0 methods for Byte in LSV6
kushti Sep 10, 2024
f566b7b
6.0 methods for Short in LSV6
kushti Sep 10, 2024
8cf4264
6.0 methods for Int in LSV6
kushti Sep 10, 2024
fa2c2df
Long tests in LSV6, shift check in shiftRight
kushti Sep 11, 2024
48db432
shiftLeft/shiftRight shift limit
kushti Sep 11, 2024
a2f3030
bigint - LSV6 tests
kushti Sep 11, 2024
297265f
arg descs, 2.11 comp fix, BOS tests fixed
kushti Sep 12, 2024
89d4477
Merge branch 'i1006' of github.com:ScorexFoundation/sigmastate-interp…
kushti Sep 12, 2024
55d03cd
addressing review comments
kushti Sep 16, 2024
343a385
Merge branch 'i1006' of github.com:ScorexFoundation/sigmastate-interp…
kushti Sep 17, 2024
1c2b99d
more polishing in UnsignedBigInt impl
kushti Sep 17, 2024
cb51ba8
removing access to type before 6.0, more tests
kushti Sep 17, 2024
3f6f8d5
merging w. 6.0.0
kushti Sep 17, 2024
c63ade1
merging with unsigned big int PR
kushti Sep 17, 2024
6c59ce0
imports fix
kushti Sep 17, 2024
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
*.fdb_latexmk
*.gz


yarn.lock
*.log
yarn.lock
docs/spec/out/
test-out/
flamegraphs/
Expand Down
1 change: 1 addition & 0 deletions core/jvm/src/main/scala/sigma/crypto/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ object Platform {
case _: Int => tpe == SInt
case _: Long => tpe == SLong
case _: BigInt => tpe == SBigInt
case _: UnsignedBigInt => tpe == SUnsignedBigInt
case _: String => tpe == SString // TODO v6.0: remove this case (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
case _: GroupElement => tpe.isGroupElement
case _: SigmaProp => tpe.isSigmaProp
Expand Down
2 changes: 2 additions & 0 deletions core/shared/src/main/scala/sigma/Evaluation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object Evaluation {
case SAny => AnyType
case SUnit => UnitType
case SBigInt => BigIntRType
case SUnsignedBigInt => UnsignedBigIntRType
case SBox => BoxRType
case SContext => ContextRType
case SGlobal => SigmaDslBuilderRType
Expand Down Expand Up @@ -67,6 +68,7 @@ object Evaluation {
case AnyType => SAny
case UnitType => SUnit
case BigIntRType => SBigInt
case UnsignedBigIntRType => SUnsignedBigInt
case GroupElementRType => SGroupElement
case AvlTreeRType => SAvlTree
case ot: OptionType[_] => SOption(rtypeToSType(ot.tA))
Expand Down
204 changes: 199 additions & 5 deletions core/shared/src/main/scala/sigma/SigmaDsl.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package sigma

import java.math.BigInteger
import sigma.ast.SType

import java.math.BigInteger
import sigma.data._

/**
* All `modQ` operations assume that Q is a global constant (an order of the only one cryptographically strong group
* which is used for all cryptographic operations).
* So it is globally and implicitly used in all methods.
* */
* Base class for signed 256-bits integers
*/
trait BigInt {
/** Convert this BigInt value to Byte.
* @throws ArithmeticException if overflow happens.
Expand Down Expand Up @@ -154,8 +153,180 @@ trait BigInt {
*/
def or(that: BigInt): BigInt
def |(that: BigInt): BigInt = or(that)

/**
* @return a big integer whose value is `this xor that`
*/
def xor(that: BigInt): BigInt

/**
* @return a 256-bit signed integer whose value is (this << n). The shift distance, n, may be negative,
* in which case this method performs a right shift. (Computes floor(this * 2n).)
*/
def shiftLeft(n: Int): BigInt

/**
* @return a 256-bit signed integer whose value is (this >> n). Sign extension is performed. The shift distance, n,
* may be negative, in which case this method performs a left shift. (Computes floor(this / 2n).)
*/
def shiftRight(n: Int): BigInt

/**
* @return unsigned representation of this BigInt, or exception if its value is negative
*/
def toUnsigned: UnsignedBigInt

/**
* @return unsigned representation of this BigInt modulo `m`. Cryptographic mod operation is done, ie result is
* non-negative always
*/
def toUnsignedMod(m: UnsignedBigInt): UnsignedBigInt
}


trait UnsignedBigInt {
/** Convert this BigInt value to Byte.
* @throws ArithmeticException if overflow happens.
*/
def toByte: Byte

/** Convert this BigInt value to Short.
* @throws ArithmeticException if overflow happens.
*/
def toShort: Short

/** Convert this BigInt value to Int.
* @throws ArithmeticException if overflow happens.
*/
def toInt: Int

/** Convert this BigInt value to Int.
* @throws ArithmeticException if overflow happens.
*/
def toLong: Long

/** Returns a big-endian representation of this BigInt in a collection of bytes.
* For example, the value {@code 0x1213141516171819} would yield the
* byte array {@code {0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19}}.
* @since 2.0
*/
def toBytes: Coll[Byte]


/** Compares this numeric with that numeric for order. Returns a negative integer, zero, or a positive integer as the
* `this` is less than, equal to, or greater than `that`.
*/
def compareTo(that: UnsignedBigInt): Int

/** Returns a BigInt whose value is {@code (this + that)}.
*
* @param that value to be added to this BigInt.
* @return { @code this + that}
*/
def add(that: UnsignedBigInt): UnsignedBigInt
def +(that: UnsignedBigInt): UnsignedBigInt = add(that)

/** Returns a BigInt whose value is {@code (this - that)}.
*
* @param that value to be subtracted from this BigInt.
* @return { @code this - that}
*/
def subtract(that: UnsignedBigInt): UnsignedBigInt

def -(that: UnsignedBigInt): UnsignedBigInt = subtract(that)

/** Returns a BigInt whose value is {@code (this * that)}.
*
* @implNote An implementation may offer better algorithmic
* performance when { @code that == this}.
* @param that value to be multiplied by this BigInt.
* @return { @code this * that}
*/
def multiply(that: UnsignedBigInt): UnsignedBigInt
def *(that: UnsignedBigInt): UnsignedBigInt = multiply(that)

/** Returns a BigInt whose value is {@code (this / that)}.
*
* @param that value by which this BigInt is to be divided.
* @return { @code this / that}
* @throws ArithmeticException if { @code that} is zero.
*/
def divide(that: UnsignedBigInt): UnsignedBigInt
def /(that: UnsignedBigInt): UnsignedBigInt = divide(that)

/**
* Returns a BigInt whose value is {@code (this mod m}). This method
* differs from {@code remainder} in that it always returns a
* <i>non-negative</i> BigInteger.
*
* @param m the modulus.
* @return { @code this mod m}
* @throws ArithmeticException { @code m} &le; 0
* @see #remainder
*/
def mod(m: UnsignedBigInt): UnsignedBigInt
def %(m: UnsignedBigInt): UnsignedBigInt = mod(m)

/**
* Returns the minimum of this BigInteger and {@code val}.
*
* @param that value with which the minimum is to be computed.
* @return the BigInteger whose value is the lesser of this BigInteger and
* { @code val}. If they are equal, either may be returned.
*/
def min(that: UnsignedBigInt): UnsignedBigInt

/**
* Returns the maximum of this BigInteger and {@code val}.
*
* @param that value with which the maximum is to be computed.
* @return the BigInteger whose value is the greater of this and
* { @code val}. If they are equal, either may be returned.
*/
def max(that: UnsignedBigInt): UnsignedBigInt

/** Returns a BigInteger whose value is `(this & that)`.
* @param that value to be AND'ed with this BigInteger.
* @return `this & that`
*/
def and(that: UnsignedBigInt): UnsignedBigInt
def &(that: UnsignedBigInt): UnsignedBigInt = and(that)

/** Returns a BigInteger whose value is `(this | that)`.
*
* @param that value to be OR'ed with this BigInteger.
* @return `this | that`
*/
def or(that: UnsignedBigInt): UnsignedBigInt
def |(that: UnsignedBigInt): UnsignedBigInt = or(that)

def modInverse(m: UnsignedBigInt): UnsignedBigInt
def plusMod(that: UnsignedBigInt, m: UnsignedBigInt): UnsignedBigInt
def subtractMod(that: UnsignedBigInt, m: UnsignedBigInt): UnsignedBigInt
def multiplyMod(that: UnsignedBigInt, m: UnsignedBigInt): UnsignedBigInt

/**
* @return a big integer whose value is `this xor that`
*/
def xor(that: UnsignedBigInt): UnsignedBigInt

/**
* @return a 256-bit signed integer whose value is (this << n). The shift distance, n, may be negative,
* in which case this method performs a right shift. (Computes floor(this * 2n).)
*/
def shiftLeft(n: Int): UnsignedBigInt

/**
* @return a 256-bit signed integer whose value is (this >> n). Sign extension is performed. The shift distance, n,
* may be negative, in which case this method performs a left shift. (Computes floor(this / 2n).)
*/
def shiftRight(n: Int): UnsignedBigInt

def toSigned(): BigInt
}



/** Base class for points on elliptic curves. */
trait GroupElement {
/** Checks if the provided element is an identity element. */
Expand All @@ -168,6 +339,8 @@ trait GroupElement {
*/
def exp(k: BigInt): GroupElement

def expUnsigned(k: UnsignedBigInt): GroupElement

/** Group operation. */
def multiply(that: GroupElement): GroupElement

Expand Down Expand Up @@ -712,6 +885,20 @@ trait SigmaDslBuilder {
*/
def groupGenerator: GroupElement

/**
* @return big integer provided as input approximately encoded using NBits,
* see (https://bitcoin.stackexchange.com/questions/57184/what-does-the-nbits-value-represent)
* for format details
*/
def encodeNbits(bi: BigInt): Long

/**
* @return big integer decoded from NBits value provided,
* see (https://bitcoin.stackexchange.com/questions/57184/what-does-the-nbits-value-represent)
* for format details
*/
def decodeNbits(l: Long): BigInt

/**
* Transforms serialized bytes of ErgoTree with segregated constants by replacing constants
* at given positions with new values. This operation allow to use serialized scripts as
Expand All @@ -738,13 +925,20 @@ trait SigmaDslBuilder {
/** Create DSL big integer from existing `java.math.BigInteger`*/
def BigInt(n: BigInteger): BigInt

def UnsignedBigInt(n: BigInteger): UnsignedBigInt

/** Extract `java.math.BigInteger` from DSL's `BigInt` type*/
def toBigInteger(n: BigInt): BigInteger

/** Construct a new authenticated dictionary with given parameters and tree root digest. */
def avlTree(operationFlags: Byte, digest: Coll[Byte], keyLength: Int, valueLengthOpt: Option[Int]): AvlTree

/** Serializes the given `value` into bytes using the default serialization format. */
def serialize[T](value: T)(implicit cT: RType[T]): Coll[Byte]

/** Returns a byte-wise XOR of the two collections of bytes. */
def xor(l: Coll[Byte], r: Coll[Byte]): Coll[Byte]

def deserializeTo[T](tpe: SType, bytes: Coll[Byte])(implicit cT: RType[T]): T
}

Loading
Loading