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

Upgrade sigma to v5.0.8 #2003

Merged
merged 8 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ val circeVersion = "0.13.0"
val akkaVersion = "2.6.10"
val akkaHttpVersion = "10.2.4"

val sigmaStateVersion = "5.0.7"
val sigmaStateVersion = "5.0.7-186-21c924e4-SNAPSHOT"

// for testing current sigmastate build (see sigmastate-ergo-it jenkins job)
val effectiveSigmaStateVersion = Option(System.getenv().get("SIGMASTATE_VERSION")).getOrElse(sigmaStateVersion)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.ergoplatform.contracts

import org.ergoplatform.ErgoBox.{R2, STokensRegType}
import org.ergoplatform.ErgoScriptPredef.{boxCreationHeight, expectedMinerOutScriptBytesVal}
import org.ergoplatform.{Height, MinerPubkey, Outputs, Self}
import org.ergoplatform.ErgoTreePredef.{boxCreationHeight, expectedMinerOutScriptBytesVal}
import org.ergoplatform.mining.emission.EmissionRules.CoinsInOneErgo
import org.ergoplatform.settings.MonetarySettings
import sigmastate.{AND, EQ, GE, GT, LE, Minus, OR, SBox, SCollection, STuple}
import org.ergoplatform.{Height, MinerPubkey, Outputs, Self}
import sigmastate.Values.{ByteArrayConstant, ErgoTree, IntConstant, LongConstant, SigmaPropValue, Value}
import sigmastate.utxo.{ByIndex, ExtractAmount, ExtractRegisterAs, ExtractScriptBytes, OptionGet, SelectField, SizeOf}
import org.ergoplatform.mining.emission.EmissionRules.CoinsInOneErgo
import sigmastate.utxo._
import sigmastate._
import special.collection.Coll

/**
* Container for re-emission related contracts. Contains re-emission contract and pay-to-reemission contract.
Expand All @@ -22,7 +23,7 @@ trait ReemissionContracts {
/**
* @return - ID of NFT token associated with re-emission contract
*/
def reemissionNftIdBytes: Array[Byte]
def reemissionNftIdBytes: Coll[Byte]

/**
* @return - height when reemission starts
Expand Down
26 changes: 0 additions & 26 deletions ergo-wallet/src/main/scala/org/ergoplatform/utils/ArithUtils.scala

This file was deleted.

This file was deleted.

40 changes: 0 additions & 40 deletions ergo-wallet/src/main/scala/org/ergoplatform/wallet/Constants.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
package org.ergoplatform.wallet

import org.ergoplatform.wallet.secrets.DerivationPath
import supertagged.TaggedType

object Constants {
object ScanId extends TaggedType[Short]
type ScanId = ScanId.Type

/** part of the protocol, do not change */
val SecretKeyLength = 32

/** part of the protocol, do not change */
val ModifierIdLength = 32

val Encoding = "UTF-8"

val BitcoinSeed: Array[Byte] = "Bitcoin seed".getBytes(Encoding)

// Identifiers for system applications of Ergo node
// Ids below 9 are reserved. Ids from 11 (inclusive) are for user scans

Expand All @@ -26,33 +15,4 @@ object Constants {
/** Scan which is checking mining rewards */
val MiningScanId: ScanId = ScanId @@ 9.toShort


/**
* [See EIP-3 https://github.com/ergoplatform/eips/blob/master/eip-0003.md ]
*
* For coin type, we suggest consider "ergo" word in ASCII and calculate coin_type number as
*
* 101 + 114 + 103 + 111 = 429
*
* Following this idea we should use next scheme
*
* m / 44' / 429' / account' / change / address_index
*/
val CoinType = 429

/**
* There needs to be reasonable amount of tokens in a box due to a byte size limit for ergo box
* */
val MaxAssetsPerBox = 100

/**
* Pre - EIP3 derivation path
*/
val preEip3DerivationPath: DerivationPath = DerivationPath.fromEncoded("m/1").get

/**
* Post - EIP3 derivation path
*/
val eip3DerivationPath: DerivationPath = DerivationPath.fromEncoded("m/44'/429'/0'/0/0").get

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.ergoplatform.wallet.boxes

import org.ergoplatform.{ErgoBoxAssets, ErgoBoxAssetsHolder}
import org.ergoplatform.SigmaConstants.MaxBoxSize
import org.ergoplatform.wallet.TokensMap
import org.ergoplatform.sdk.wallet.TokensMap
import org.ergoplatform.wallet.boxes.BoxSelector.{BoxSelectionError, BoxSelectionResult}
import org.ergoplatform.{ErgoBoxAssets, ErgoBoxAssetsHolder}
import scorex.util.ScorexLogging


Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.ergoplatform.wallet.boxes

import org.ergoplatform.contracts.ReemissionContracts
import org.ergoplatform.sdk.wallet.{AssetUtils, TokensMap}
import org.ergoplatform.sdk.wallet.Constants.MaxAssetsPerBox
import org.ergoplatform.wallet.boxes.BoxSelector.BoxSelectionError
import org.ergoplatform.wallet.transactions.TransactionBuilder._
import org.ergoplatform.{ErgoBoxAssets, ErgoBoxAssetsHolder}
import scorex.util.ModifierId
import org.ergoplatform.{ErgoBoxAssets, ErgoBoxAssetsHolder, ErgoBoxCandidate}
import org.ergoplatform.wallet.Constants.MaxAssetsPerBox
import org.ergoplatform.wallet.{AssetUtils, TokensMap}

import scala.annotation.tailrec
import scala.collection.mutable
import org.ergoplatform.wallet.transactions.TransactionBuilder._
import org.ergoplatform.wallet.boxes.BoxSelector.BoxSelectionError

/**
* Default implementation of the box selector. It simply picks boxes till sum of their monetary values
Expand All @@ -19,9 +19,8 @@ import org.ergoplatform.wallet.boxes.BoxSelector.BoxSelectionError
*/
class DefaultBoxSelector(override val reemissionDataOpt: Option[ReemissionData]) extends BoxSelector {

import DefaultBoxSelector._
import BoxSelector._
import scorex.util.idToBytes
import DefaultBoxSelector._

// helper function which returns count of assets in `initialMap` not fully spent in `subtractor`
private def diffCount(initialMap: mutable.Map[ModifierId, Long], subtractor: TokensMap): Int = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.ergoplatform.wallet.boxes

import org.ergoplatform.ErgoBoxCandidate
import sigmastate.eval.Extensions._
import java7.compat.Math
import org.ergoplatform.ErgoBoxCandidate
import special.collection.Extensions._

import scala.collection.compat.immutable.ArraySeq
import scala.collection.mutable
Expand Down Expand Up @@ -31,7 +31,7 @@ object ErgoBoxAssetExtractor {
)
box.additionalTokens.foreach {
case (assetId, amount) =>
val aiWrapped = ArraySeq.unsafeWrapArray(assetId)
val aiWrapped = ArraySeq.unsafeWrapArray(assetId.toArray)
val total = map.getOrElse(aiWrapped, 0L)
map.put(aiWrapped, Math.addExact(total, amount))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.ergoplatform.wallet.boxes

import org.ergoplatform.wallet.boxes.BoxSelector.BoxSelectionResult
import org.ergoplatform.wallet.boxes.BoxSelector.BoxSelectionError
import org.ergoplatform.ErgoBoxAssets
import org.ergoplatform.wallet.{AssetUtils, TokensMap}
import scorex.util.ModifierId
import org.ergoplatform.sdk.wallet.{AssetUtils, TokensMap}
import org.ergoplatform.wallet.boxes.BoxSelector.{BoxSelectionError, BoxSelectionResult}
import org.ergoplatform.wallet.transactions.TransactionBuilder._
import scorex.util.ModifierId

import scala.annotation.tailrec
import scala.collection.mutable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.ergoplatform.wallet.boxes

import org.ergoplatform.sdk.wallet
import org.ergoplatform.sdk.wallet.TokensMap
import org.ergoplatform.wallet.Constants
import org.ergoplatform.wallet.Constants.ScanId
import org.ergoplatform.wallet.{Constants, TokensMap}
import org.ergoplatform.wallet.serialization.ErgoWalletSerializer
import org.ergoplatform.{ErgoBox, ErgoLikeTransaction}
import org.ergoplatform.{ErgoBox, ErgoBoxAssets, ErgoLikeTransaction}
import scorex.util.serialization.{Reader, Writer}
import scorex.util.{ModifierId, bytesToId, idToBytes}
import org.ergoplatform.ErgoBoxAssets
import special.collection.Extensions._

/**
* A box tracked by a wallet that contains Ergo box itself as well as
Expand Down Expand Up @@ -67,7 +69,7 @@ case class TrackedBox(creationTxId: ModifierId,
def isSpent: Boolean = spendingHeightOpt.isDefined

lazy val tokens: TokensMap = box.additionalTokens.toArray.map {
case (id, amt) => bytesToId(id) -> amt
case (id, amt) => id.toModifierId -> amt
}.toMap

override def equals(obj: Any): Boolean = obj match {
Expand Down Expand Up @@ -121,10 +123,10 @@ object TrackedBoxSerializer extends ErgoWalletSerializer[TrackedBox] {
}

override def parse(r: Reader): TrackedBox = {
val creationTxId = bytesToId(r.getBytes(Constants.ModifierIdLength))
val creationTxId = bytesToId(r.getBytes(wallet.Constants.ModifierIdLength))
val creationOutIndex = r.getShort()
val inclusionHeightOpt = r.getOption(r.getInt())
val spendingTxIdOpt = r.getOption(r.getBytes(Constants.ModifierIdLength)).map(bytesToId)
val spendingTxIdOpt = r.getOption(r.getBytes(wallet.Constants.ModifierIdLength)).map(bytesToId)
val spendingHeightOpt = r.getOption(r.getInt())

val appsCount = r.getShort()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.ergoplatform.wallet.crypto

import org.ergoplatform.sdk.wallet.settings.EncryptionSettings

import javax.crypto.spec.{GCMParameterSpec, PBEKeySpec, SecretKeySpec}
import javax.crypto.{Cipher, SecretKeyFactory}
import org.ergoplatform.wallet.settings.EncryptionSettings

import scala.util.Try

object AES {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.ergoplatform.wallet.crypto
import org.bouncycastle.util.BigIntegers
import scorex.crypto.hash.Blake2b256
import scorex.util.encode.Base16
import sigmastate.interpreter.CryptoConstants
import sigmastate.basics.CryptoConstants
import sigmastate.serialization.GroupElementSerializer

import scala.annotation.tailrec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.ergoplatform.wallet.interpreter

import org.ergoplatform.ErgoLikeContext.Height
import org.ergoplatform.sdk.wallet.protocol.context.ErgoLikeParameters
import org.ergoplatform.wallet.protocol.Constants
import org.ergoplatform.wallet.protocol.context.ErgoLikeParameters
import org.ergoplatform.{ErgoBox, ErgoBoxCandidate, ErgoLikeContext, ErgoLikeInterpreter}
import scorex.crypto.authds.ADDigest
import scorex.util.ScorexLogging
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package org.ergoplatform.wallet.interpreter

import java.util

import org.ergoplatform._
import org.ergoplatform.utils.ArithUtils.{addExact, multiplyExact}
import org.ergoplatform.validation.SigmaValidationSettings
import org.ergoplatform.sdk.utils.ArithUtils.{addExact, multiplyExact}
import org.ergoplatform.sdk.wallet.protocol.context.{ErgoLikeParameters, ErgoLikeStateContext}
import org.ergoplatform.sdk.wallet.secrets.{ExtendedPublicKey, ExtendedSecretKey, SecretKey}
import org.ergoplatform.validation.{SigmaValidationSettings, ValidationRules}
import org.ergoplatform.wallet.boxes.ErgoBoxAssetExtractor
import scorex.crypto.authds.ADDigest
import scorex.util.encode.Base16
import sigmastate.AvlTreeData
import sigmastate.Values.SigmaBoolean
import sigmastate.interpreter.{ContextExtension, ProverInterpreter}
import org.ergoplatform.validation.ValidationRules
import org.ergoplatform.wallet.boxes.ErgoBoxAssetExtractor
import org.ergoplatform.wallet.protocol.context.{ErgoLikeParameters, ErgoLikeStateContext}
import org.ergoplatform.wallet.secrets.SecretKey
import sigmastate.basics.SigmaProtocolPrivateInput
import org.ergoplatform.wallet.secrets.{ExtendedPublicKey, ExtendedSecretKey}
import scorex.util.encode.Base16
import sigmastate.interpreter.{ContextExtension, ProverInterpreter}
import special.collection.Coll
import special.sigma.{Header, PreHeader}

import java.util
import scala.util.{Failure, Success, Try}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package org.ergoplatform.wallet.mnemonic

import java.text.Normalizer.Form.NFKD
import java.text.Normalizer.normalize

import javax.crypto.SecretKeyFactory
import javax.crypto.spec.PBEKeySpec
import org.ergoplatform.wallet.Constants
import org.ergoplatform.wallet.interface4j.SecretString
import scodec.bits.BitVector
import sigmastate.crypto.CryptoFacade

import scala.util.{Failure, Try}

Expand Down Expand Up @@ -73,7 +72,7 @@ object Mnemonic {

val spec = new PBEKeySpec(
normalizedMnemonic,
normalizedPass.getBytes(Constants.Encoding),
normalizedPass.getBytes(CryptoFacade.Encoding),
Pbkdf2Iterations,
Pbkdf2KeyLength
)
Expand Down

This file was deleted.