From fff394ff28ec5530a6535effedd927f2eb297fc0 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Tue, 5 Sep 2023 14:49:25 +0200 Subject: [PATCH 1/9] v5.0.11: added TypeScript definitions --- .../ergoplatform/sdk/js/ProverBuilder.scala | 14 ++ .../sdk/js/ReducedTransaction.scala | 2 +- .../org/ergoplatform/sdk/js/SigmaProver.scala | 8 +- sigma-js/sigmastate-js.d.ts | 211 ++++++++++++++++++ 4 files changed, 230 insertions(+), 5 deletions(-) diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/ProverBuilder.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/ProverBuilder.scala index 8d3b3cd2e3..2c27a177d4 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/ProverBuilder.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/ProverBuilder.scala @@ -94,3 +94,17 @@ class ProverBuilder(parameters: BlockchainParameters, network: Byte) extends js. new SigmaProver(p) } } + +@JSExportTopLevel("ProverBuilderObj") +object ProverBuilder extends js.Object { + /** Creates a new [[ProverBuilder]] instance with the given blockchain parameters + * and network prefix. + * + * @param parameters Blockchain parameters re-adjustable via miners voting and + * voting-related data. All of them are included into extension + * section of a first block of a voting epoch. + * @param network Network prefix to use for addresses. + */ + def create(parameters: BlockchainParameters, network: Byte): ProverBuilder = + new ProverBuilder(parameters, network) +} \ No newline at end of file diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/ReducedTransaction.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/ReducedTransaction.scala index 66c5ce7f38..a27c61d261 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/ReducedTransaction.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/ReducedTransaction.scala @@ -9,7 +9,7 @@ import scala.scalajs.js.annotation.JSExportTopLevel @JSExportTopLevel("ReducedTransaction") class ReducedTransaction(val _tx: sdk.ReducedTransaction) extends js.Object { /** Serialized bytes of this transaction in hex format. */ - def toHex: String = _tx.toHex + def toHex(): String = _tx.toHex } @JSExportTopLevel("ReducedTransactionObj") diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/SigmaProver.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/SigmaProver.scala index b7ca33b1de..6aedecf2e9 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/SigmaProver.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/SigmaProver.scala @@ -17,17 +17,17 @@ class SigmaProver(_prover: sdk.SigmaProver) extends js.Object { * The returned address corresponds to the master secret derived from the mnemonic * phrase configured in the [[ProverBuilder]]. */ - def getP2PKAddress: String = { + def getP2PKAddress(): String = { val addr = _prover.getP2PKAddress addr.toString } /** Returns the prover's secret key. */ - def getSecretKey: js.BigInt = + def getSecretKey(): js.BigInt = isoBigInt.from(_prover.getSecretKey) - /** Returns a sequence of EIP-3 addresses associated with the prover's secret keys. */ - def getEip3Addresses: js.Array[String] = { + /** Returns an array of EIP-3 addresses associated with the prover's secret keys. */ + def getEip3Addresses(): js.Array[String] = { val addresses = _prover.getEip3Addresses js.Array(addresses.map(_.toString): _*) } diff --git a/sigma-js/sigmastate-js.d.ts b/sigma-js/sigmastate-js.d.ts index 34eef4df12..775f585570 100644 --- a/sigma-js/sigmastate-js.d.ts +++ b/sigma-js/sigmastate-js.d.ts @@ -1,4 +1,12 @@ declare module "sigmastate-js/main" { + import { + Amount, + Box, + EIP12UnsignedInput, + NonMandatoryRegisters, SignedTransaction, TokenAmount, + UnsignedTransaction + } from "@fleet-sdk/common"; + type SigmaCompilerNamedConstantsMap = { [key: string]: Value }; type HexString = string; type ByteArray = { u: Int8Array }; @@ -35,6 +43,95 @@ declare module "sigmastate-js/main" { static fromPointHex(value: HexString): SigmaProp; } + export declare class AvlTree { + digest: HexString; + insertAllowed: Boolean; + updateAllowed: Boolean; + removeAllowed: Boolean; + keyLength: number; + valueLengthOpt: number | undefined; + } + + export declare class PreHeader { + /** Block version, to be increased on every soft and hardfork. */ + version: number; + /** Hex of id of parent block */ + parentId: HexString; + /** Block timestamp (in milliseconds since beginning of Unix Epoch) */ + timestamp: bigint; + /** Current difficulty in a compressed view. + * NOTE: actually it is unsigned integer */ + nBits: bigint; + /** Block height */ + height: number; + /** Miner public key (hex of EC Point). Should be used to collect block rewards. */ + minerPk: GroupElement; + /** Hex of miner votes bytes for changing system parameters. */ + votes: HexString; + } + + export declare class Header { + /** Hex representation of ModifierId of this Header */ + id: HexString; + /** Block version, to be increased on every soft and hardfork. */ + version: number; + /** Hex representation of ModifierId of the parent block */ + parentId: HexString; + /** Hex hash of ADProofs for transactions in a block */ + ADProofsRoot: HexString; + /** AvlTree of a state after block application */ + stateRoot: AvlTree; + /** Hex of root hash (for a Merkle tree) of transactions in a block. */ + transactionsRoot: HexString; + /** Block timestamp (in milliseconds since beginning of Unix Epoch) */ + timestamp: bigint; + /** Current difficulty in a compressed view. + * NOTE: actually it is unsigned Int */ + nBits: bigint; + /** Block height */ + height: number; + /** Hex of root hash of extension section */ + extensionRoot: HexString; + + /** Miner public key (hex of EC Point). Should be used to collect block rewards. + * Part of Autolykos solution. + */ + minerPk: GroupElement; + + /** One-time public key (hex of EC Point). Prevents revealing of miners secret. */ + powOnetimePk: GroupElement; + + /** Hex of nonce bytes */ + powNonce: HexString; + + /** Distance between pseudo-random number, corresponding to nonce `powNonce` and a secret, + * corresponding to `minerPk`. The lower `powDistance` is, the harder it was to find this solution. */ + powDistance: bigint; + + /** Miner votes for changing system parameters. */ + votes: HexString; + } + + export declare class BlockchainParameters { + storageFeeFactor: number; + minValuePerByte: number; + maxBlockSize: number; + tokenAccessCost: number; + inputCost: number; + dataInputCost: number; + outputCost: number; + maxBlockCost: number; + softForkStartingHeight: number | undefined; + softForkVotesCollected: number | undefined; + blockVersion: number; + } + + export declare class BlockchainStateContext { + sigmaLastHeaders: Header[]; + previousStateDigest: HexString; + sigmaPreHeader: PreHeader; + } + export declare class Type { name: string; toString(): string; @@ -90,4 +187,118 @@ declare module "sigmastate-js/main" { static forMainnet(): SigmaCompiler; static forTestnet(): SigmaCompiler; } + + /** Represents results for transaction reduction by {@link SigmaProver}. */ + export declare class ReducedTransaction { + /** Serialized bytes of this transaction in hex format. */ + toHex(): HexString; + } + + export declare class ReducedTransactionObj { + /** Creates a {@link ReducedTransaction} from serialized bytes in hex format. */ + fromHex(hex: HexString): ReducedTransaction; + } + + /** Represents a prover for signing Ergo transactions and messages. + * + * Equivalent of [[org.ergoplatform.sdk.SigmaProver]] available from JS. + */ + export declare class SigmaProver { + /** Returns the Pay-to-Public-Key (P2PK) address associated with the prover's public key. + * The returned address corresponds to the master secret derived from the mnemonic + * phrase configured in the [[ProverBuilder]]. + */ + getP2PKAddress(): HexString; + + /** Returns the prover's secret key. */ + getSecretKey(): bigint; + + /** Returns an array of EIP-3 addresses associated with the prover's secret keys. */ + getEip3Addresses(): HexString[]; + + /** Reduces the transaction to the reduced form, which is ready to be signed. + * @param stateCtx blockchain state context + * @param unsignedTx unsigned transaction to be reduced (created by Fleet builders) + * @param boxesToSpend boxes to be spent by the transaction + * @param dataInputs data inputs to be used by the transaction + * @param tokensToBurn tokens to be burned by the transaction + * @param baseCost base cost of the transaction + * @return reduced transaction + */ + reduce( + stateCtx: BlockchainStateContext, + unsignedTx: UnsignedTransaction, + boxesToSpend: EIP12UnsignedInput[], + dataInputs: Box[], + tokensToBurn: TokenAmount[], + baseCost: number): ReducedTransaction; + + /** Signs the reduced transaction. + * @param reducedTx reduced transaction to be signed + * @return signed transaction containting all the required proofs (signatures) + */ + signReduced(reducedTx: ReducedTransaction): SignedTransaction; + } + + /** Equivalent of [[sdk.ProverBuilder]] available from JS. + * + * @param parameters Blockchain parameters re-adjustable via miners voting and + * voting-related data. All of them are included into extension + * section of a first block of a voting epoch. + * @param network Network prefix to use for addresses. + */ + export declare class ProverBuilder { + /** Configure this builder to use the given seed when building a new prover. + * + * @param mnemonicPhrase secret seed phrase to be used in prover for generating proofs. + * @param mnemonicPass password to protect secret seed phrase. + */ + withMnemonic(mnemonicPhrase: HexString, mnemonicPass: HexString): ProverBuilder; + /** Configure this builder to derive the new EIP-3 secret key with the given index. + * The derivation uses master key derived from the mnemonic configured using + * [[ErgoProverBuilder.withMnemonic]]. + * + * @param index last index in the EIP-3 derivation path. + */ + withEip3Secret(index: number): ProverBuilder; + + /** Configures this builder to use group elements (g, h, u, v) and secret x for a + * ProveDHTuple statement when building a new prover. + * + * ProveDHTuple is a statement consisting of 4 group elements (g, h, u, v) and + * requires the prover to prove knowledge of secret integer x such that. + * + * u = g^x + * and + * y = h^x + * + * @param g [[GroupElement]] instance defining g + * @param h [[GroupElement]] instance defining h + * @param u [[GroupElement]] instance defining u + * @param v [[GroupElement]] instance defining v + * @param x [[BigInteger]] instance defining x + * @see + * example + * @see + * implementation + */ + withDHTSecret(g: HexString, h: HexString, u: HexString, v: HexString, x: bigint): ProverBuilder; + + /** This allows adding additional secret for use in proveDlog, when the secret is not + * part of the wallet. + * + * Multiple secrets can be added by calling this method multiple times. + * + * Multiple secrets are necessary for statements that need multiple proveDlogs, such + * as proveDlog(a) && proveDlog(b), where a and b are two group elements. + */ + withDLogSecret(x: bigint): ProverBuilder; + + /** Builds a new prover using provided configuration. */ + build(): SigmaProver; + } + + export declare class ProverBuilderObj { + static create(parameters: BlockchainParameters, network: number): ProverBuilder; + } } From 17f00a47eb25dff18b37c8a7c146f8f33728b71b Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Tue, 5 Sep 2023 14:49:44 +0200 Subject: [PATCH 2/9] v5.0.11: bump sigma-js version v0.3.0 --- sigma-js/package-lock.json | 4 ++-- sigma-js/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sigma-js/package-lock.json b/sigma-js/package-lock.json index 153254dd3e..893a0ee141 100644 --- a/sigma-js/package-lock.json +++ b/sigma-js/package-lock.json @@ -1,12 +1,12 @@ { "name": "sigmastate-js", - "version": "0.2.2", + "version": "0.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "sigmastate-js", - "version": "0.2.2", + "version": "0.3.0", "license": "MIT", "dependencies": { "@fleet-sdk/common": "0.1.3", diff --git a/sigma-js/package.json b/sigma-js/package.json index 57d5b171cf..79f15e803d 100644 --- a/sigma-js/package.json +++ b/sigma-js/package.json @@ -1,6 +1,6 @@ { "name": "sigmastate-js", - "version": "0.2.2", + "version": "0.3.0", "description": "Sigma.js library", "files": [ "dist/", From 334149bfa9f55cb7e3d5339252671dda93decd89 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Mon, 11 Sep 2023 21:18:07 +0200 Subject: [PATCH 3/9] documented how propBytes can be compared with propositionBytes --- docs/LangSpec.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/LangSpec.md b/docs/LangSpec.md index 6aae2a9880..ddbb7bd680 100644 --- a/docs/LangSpec.md +++ b/docs/LangSpec.md @@ -480,6 +480,21 @@ trait SigmaProp { * 2. new ErgoTree created with with ErgoTree.DefaultHeader, EmptyConstant and SigmaPropConstant as the root * * Thus obtained ErgoTree is serialized using DefaultSerializer and compared with `box.propositionBytes`. + * Here, propBytes uses very specific ErgoTree with header == 0, and hence ErgoTree.version == 0. + * However, `box.propositionBytes`, contain bytes of ErgoTree from `box`, and version of that + * tree depends on how the `box` was created. + * A better way to compare `box.propositionBytes` and `prop.propBytes` is to use the following code: + * ``` + * val propBytes = prop.propBytes + * val treeBytes = box.propositionBytes + * if (treeBytes(0) == 0) { + * treeBytes == propBytes + * } else { + * // offset = 1 + + * val offset = if (propositionBytes.size > 127) 3 else 2 + * propBytes.slice(1, propBytes.size) == propositionBytes.slice(offset, propositionBytes.size) + * } + * ``` */ def propBytes: Coll[Byte] From a61c9ef8d888b2f17c569e45239586bdf269e709 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Tue, 12 Sep 2023 16:04:03 +0200 Subject: [PATCH 4/9] improved ScalaDoc for DeserializeContext --- .../scala/sigmastate/utxo/transformers.scala | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala b/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala index 8a434afc2b..a3bcdf0da1 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala @@ -532,13 +532,22 @@ object ExtractCreationInfo extends SimpleTransformerCompanion { trait Deserialize[V <: SType] extends NotReadyValue[V] -/** Extracts context variable as Coll[Byte], deserializes it to script and then executes this script in the current context. - * The original `Coll[Byte]` of the script is available as `getVar[Coll[Byte]](id)` +/** This ErgoTree operation work as macros (i.e. executed before ErgoTree reduction) and + * allows to inline arbitrary expression at the point where it is used in ErgoTree. + * + * This operation is executed before ErgoTree reduction as the following: + * 1) the context variable `id` is checked to have type Coll[Byte], if not, then this + * node remains in the ErgoTree which means the reduction will fail later. + * 2) the bytes collection is deserialized to `expr: Value[V]` using ValueSerializer.deserialize + * 3) `this` node is replaced with the deserialized `expr` + * + * This step are performed for each [[DeserializeContext]] node via single traverse of + * ErgoTree. The resulting ErgoTree is passed to reduction. + * + * NOTE, the original `Coll[Byte]` from context variables is available as `getVar[Coll[Byte]](id)` + * * @param id identifier of the context variable - * @tparam V result type of the deserialized script. - * @throws InterpreterException if the actual script type doesn't conform to T - * @return result of the script execution in the current context - * @since 2.0 + * @param tpe expected type of the deserialized script (i.e. expected type of `expr`). */ case class DeserializeContext[V <: SType](id: Byte, tpe: V) extends Deserialize[V] { override def companion = DeserializeContext From d98325ea0a5707ccfe896d552404b59b0b8e4f6f Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Mon, 25 Sep 2023 16:43:05 +0200 Subject: [PATCH 5/9] ergotree-version: abstract classes for BlockchainParameters and BlockchainStateContext --- .../scala/org/ergoplatform/sdk/js/Isos.scala | 4 +- .../org/ergoplatform/sdk/js/IsosSpec.scala | 4 +- .../sdk/BlockchainParameters.scala | 44 ++++++++++++------- .../context/BlockchainStateContext.scala | 25 ++++++----- 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala index a317e3ab29..56df9cd2c9 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala @@ -189,7 +189,7 @@ object Isos { val isoBlockchainParameters: Iso[BlockchainParameters, sdk.BlockchainParameters] = new Iso[BlockchainParameters, sdk.BlockchainParameters] { override def to(a: BlockchainParameters): sdk.BlockchainParameters = { - sdk.BlockchainParameters( + sdk.CBlockchainParameters( storageFeeFactor = a.storageFeeFactor, minValuePerByte = a.minValuePerByte, maxBlockSize = a.maxBlockSize, @@ -222,7 +222,7 @@ object Isos { implicit val isoBlockchainStateContext: Iso[BlockchainStateContext, context.BlockchainStateContext] = new Iso[BlockchainStateContext, context.BlockchainStateContext] { override def to(a: BlockchainStateContext): context.BlockchainStateContext = { - context.BlockchainStateContext( + context.CBlockchainStateContext( sigmaLastHeaders = isoArrayToColl(isoHeader).to(a.sigmaLastHeaders), previousStateDigest = isoStringToColl.to(a.previousStateDigest), sigmaPreHeader = isoPreHeader.to(a.sigmaPreHeader) diff --git a/sdk/js/src/test/scala/org/ergoplatform/sdk/js/IsosSpec.scala b/sdk/js/src/test/scala/org/ergoplatform/sdk/js/IsosSpec.scala index 47eedf2706..3e27513f02 100644 --- a/sdk/js/src/test/scala/org/ergoplatform/sdk/js/IsosSpec.scala +++ b/sdk/js/src/test/scala/org/ergoplatform/sdk/js/IsosSpec.scala @@ -2,7 +2,7 @@ package org.ergoplatform.sdk.js import org.ergoplatform.ErgoBox.{AdditionalRegisters, BoxId, TokenId} import org.ergoplatform._ -import org.ergoplatform.sdk.wallet.protocol.context.BlockchainStateContext +import org.ergoplatform.sdk.wallet.protocol.context.{BlockchainStateContext, CBlockchainStateContext} import org.ergoplatform.sdk.{ExtendedInputBox, Iso} import org.scalacheck.{Arbitrary, Gen} import org.scalatest.matchers.should.Matchers @@ -30,7 +30,7 @@ class IsosSpec extends AnyPropSpec with Matchers with ObjectGenerators with Sca stateRoot <- avlTreeGen headers <- headersGen(stateRoot) preHeader <- preHeaderGen(headers.headOption.map(_.id).getOrElse(modifierIdBytesGen.sample.get)) - } yield BlockchainStateContext( + } yield CBlockchainStateContext( sigmaLastHeaders = Colls.fromItems(headers:_*), previousStateDigest = stateRoot.digest, sigmaPreHeader = preHeader diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainParameters.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainParameters.scala index 4a1014b112..6f799ff8d8 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainParameters.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainParameters.scala @@ -1,21 +1,35 @@ package org.ergoplatform.sdk /** Blockchain parameters re-adjustable via miners voting and voting-related data. - * All these fields are included into extension section of a first block of a voting epoch. - * - * @param storageFeeFactor cost of storing 1 byte in UTXO for four years, in nanoErgs - * @param minValuePerByte cost of a transaction output, in computation unit - * @param maxBlockSize max block size, in bytes - * @param tokenAccessCost cost of a token contained in a transaction, in computation unit - * @param inputCost cost of a transaction input, in computation unit - * @param dataInputCost cost of a transaction data input, in computation unit - * @param outputCost cost of a transaction output, in computation unit - * @param maxBlockCost computation units limit per block - * @param softForkStartingHeight height when voting for a soft-fork had been started - * @param softForkVotesCollected votes for soft-fork collected in previous epochs - * @param blockVersion Protocol version activated on the network + * All these parameters are included into extension section of a first block of a voting epoch. */ -case class BlockchainParameters( +abstract class BlockchainParameters { + /** Cost of storing 1 byte in UTXO for four years, in nanoErgs. */ + def storageFeeFactor: Int + /** Cost of a transaction output, in computation unit. */ + def minValuePerByte: Int + /** Max block size, in bytes. */ + def maxBlockSize: Int + /** Cost of a token contained in a transaction, in computation unit. */ + def tokenAccessCost: Int + /** Cost of a transaction input, in computation unit. */ + def inputCost: Int + /** Cost of a transaction data input, in computation unit. */ + def dataInputCost: Int + /** Cost of a transaction output, in computation unit. */ + def outputCost: Int + /** Computation units limit per block. */ + def maxBlockCost: Int + /** Height when voting for a soft-fork had been started. */ + def softForkStartingHeight: Option[Int] + /** Votes for soft-fork collected in previous epochs. */ + def softForkVotesCollected: Option[Int] + /** Protocol version activated on the network. */ + def blockVersion: Byte +} + +/** Concete implementation of blockchain parameters. */ +case class CBlockchainParameters( storageFeeFactor: Int, minValuePerByte: Int, maxBlockSize: Int, @@ -27,7 +41,7 @@ case class BlockchainParameters( softForkStartingHeight: Option[Int], softForkVotesCollected: Option[Int], blockVersion: Byte -) +) extends BlockchainParameters /** Global parameters used by SDK */ object BlockchainParameters { diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala index 5c8d97df4f..e2fc88eaf9 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala @@ -2,14 +2,19 @@ package org.ergoplatform.sdk.wallet.protocol.context import special.collection.Coll -/** Blockchain context used in tx signing. - * - * @param sigmaLastHeaders fixed number (10 in Ergo) of last block headers - * @param previousStateDigest UTXO set digest from a last header (of sigmaLastHeaders) - * @param sigmaPreHeader returns pre-header (header without certain fields) of the current block - */ -case class BlockchainStateContext( - sigmaLastHeaders: Coll[special.sigma.Header], +/** Blockchain context used in tx signing. */ +abstract class BlockchainStateContext { + /** Fixed number (10 in Ergo) of last block headers. */ + def sigmaLastHeaders: Coll[sigma.Header] + /** UTXO set digest from a last header (of sigmaLastHeaders). */ + def previousStateDigest: Coll[Byte] + /** Returns pre-header (header without certain fields) of the current block. */ + def sigmaPreHeader: sigma.PreHeader +} + +/** Blockchain context used in tx signing. */ +case class CBlockchainStateContext( + sigmaLastHeaders: Coll[sigma.Header], previousStateDigest: Coll[Byte], - sigmaPreHeader: special.sigma.PreHeader -) + sigmaPreHeader: sigma.PreHeader +) extends BlockchainStateContext From dca61811bd8dc839b97178d9c862d65c210c3af2 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Tue, 26 Sep 2023 22:38:21 +0200 Subject: [PATCH 6/9] v5.0.11-fix1: abstract classes for BlockchainParameters and BlockchainStateContext --- .../wallet/protocol/context/BlockchainStateContext.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala index e2fc88eaf9..985a4acf8d 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala @@ -5,16 +5,16 @@ import special.collection.Coll /** Blockchain context used in tx signing. */ abstract class BlockchainStateContext { /** Fixed number (10 in Ergo) of last block headers. */ - def sigmaLastHeaders: Coll[sigma.Header] + def sigmaLastHeaders: Coll[special.sigma.Header] /** UTXO set digest from a last header (of sigmaLastHeaders). */ def previousStateDigest: Coll[Byte] /** Returns pre-header (header without certain fields) of the current block. */ - def sigmaPreHeader: sigma.PreHeader + def sigmaPreHeader: special.sigma.PreHeader } /** Blockchain context used in tx signing. */ case class CBlockchainStateContext( - sigmaLastHeaders: Coll[sigma.Header], + sigmaLastHeaders: Coll[special.sigma.Header], previousStateDigest: Coll[Byte], - sigmaPreHeader: sigma.PreHeader + sigmaPreHeader: special.sigma.PreHeader ) extends BlockchainStateContext From 770d297b53529f1cbd2a3a4074d4f3ddd0b74042 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Thu, 28 Sep 2023 11:55:37 +0200 Subject: [PATCH 7/9] v5.0.11-fix1: fix issue with tx decoders --- .../src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala index 52e1565ca3..0806e78098 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala @@ -379,8 +379,7 @@ trait JsonCodecs { implicit val ergoLikeTransactionDecoder: Decoder[ErgoLikeTransaction] = Decoder.instance({ implicit cursor => for { - t <- cursor.downField("type").as[String] - inputs <- {require(t == "ELT"); cursor.downField("inputs").as[IndexedSeq[Input]] } + inputs <- cursor.downField("inputs").as[IndexedSeq[Input]] dataInputs <- cursor.downField("dataInputs").as[IndexedSeq[DataInput]] outputs <- cursor.downField("outputs").as[IndexedSeq[ErgoBoxCandidate]] } yield new ErgoLikeTransaction(inputs, dataInputs, outputs) @@ -398,8 +397,7 @@ trait JsonCodecs { implicit val unsignedErgoLikeTransactionDecoder: Decoder[UnsignedErgoLikeTransaction] = Decoder.instance({ implicit cursor => for { - t <- cursor.downField("type").as[String] - inputs <- {require(t == "UELT"); cursor.downField("inputs").as[IndexedSeq[UnsignedInput]] } + inputs <- cursor.downField("inputs").as[IndexedSeq[UnsignedInput]] dataInputs <- cursor.downField("dataInputs").as[IndexedSeq[DataInput]] outputs <- cursor.downField("outputs").as[IndexedSeq[ErgoBoxCandidate]] } yield new UnsignedErgoLikeTransaction(inputs, dataInputs, outputs) From 7de88b03806c588d46487e0873ea9648cbbc0c65 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Thu, 28 Sep 2023 12:52:12 +0200 Subject: [PATCH 8/9] v5.0.11-fix1: rollback changes in decoders --- .../scala/org/ergoplatform/sdk/JsonCodecs.scala | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala index 0806e78098..d4a3c08ea6 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala @@ -369,7 +369,6 @@ trait JsonCodecs { implicit val ergoLikeTransactionEncoder: Encoder[ErgoLikeTransaction] = Encoder.instance({ tx => Json.obj( - "type" -> "ELT".asJson, // ErgoLikeTransaction "id" -> tx.id.asJson, "inputs" -> tx.inputs.asJson, "dataInputs" -> tx.dataInputs.asJson, @@ -387,7 +386,6 @@ trait JsonCodecs { implicit val unsignedErgoLikeTransactionEncoder: Encoder[UnsignedErgoLikeTransaction] = Encoder.instance({ tx => Json.obj( - "type" -> "UELT".asJson, // UnsignedErgoLikeTransaction "id" -> tx.id.asJson, "inputs" -> tx.inputs.asJson, "dataInputs" -> tx.dataInputs.asJson, @@ -409,15 +407,10 @@ trait JsonCodecs { case t => throw new SigmaException(s"Don't know how to encode transaction $t") }) - implicit val ergoLikeTransactionTemplateDecoder: Decoder[ErgoLikeTransactionTemplate[_ <: UnsignedInput]] = Decoder.instance({ implicit cursor => - for { - t <- cursor.downField("type").as[String] - tx <- t match { - case "ELT" => ergoLikeTransactionDecoder(cursor) - case "UELT" => unsignedErgoLikeTransactionDecoder(cursor) - } - } yield tx - }) + implicit val ergoLikeTransactionTemplateDecoder: Decoder[ErgoLikeTransactionTemplate[_ <: UnsignedInput]] = { + ergoLikeTransactionDecoder.asInstanceOf[Decoder[ErgoLikeTransactionTemplate[_ <: UnsignedInput]]] or + unsignedErgoLikeTransactionDecoder.asInstanceOf[Decoder[ErgoLikeTransactionTemplate[_ <: UnsignedInput]]] + } implicit val sigmaValidationSettingsEncoder: Encoder[SigmaValidationSettings] = Encoder.instance({ v => SigmaValidationSettingsSerializer.toBytes(v).asJson From 4c5386420fb0bf014a8b228825bd6aa04c189dc3 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Thu, 28 Sep 2023 13:54:04 +0200 Subject: [PATCH 9/9] v5.0.11-fix1: rollback changes in decoders (2) --- .../src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala index d4a3c08ea6..008f71bb68 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala @@ -372,7 +372,7 @@ trait JsonCodecs { "id" -> tx.id.asJson, "inputs" -> tx.inputs.asJson, "dataInputs" -> tx.dataInputs.asJson, - "outputs" -> tx.outputCandidates.asJson + "outputs" -> tx.outputs.asJson ) }) @@ -389,7 +389,7 @@ trait JsonCodecs { "id" -> tx.id.asJson, "inputs" -> tx.inputs.asJson, "dataInputs" -> tx.dataInputs.asJson, - "outputs" -> tx.outputCandidates.asJson + "outputs" -> tx.outputs.asJson ) })