Skip to content

Commit

Permalink
remove non-PR related code, improved DataSerializerSpecification
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Jun 4, 2024
1 parent 66003f4 commit 7795e5d
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 410 deletions.
9 changes: 7 additions & 2 deletions core/shared/src/main/scala/sigma/SigmaDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,17 @@ trait Header {
/** Miner votes for changing system parameters. */
def votes: Coll[Byte] //3 bytes

/** Bytes which are coming from future versions of the protocol, so
* their meaning is not known to current version of Sigma, but they
* are stored to get the same id as future version users.
*/
def unparsedBytes: Coll[Byte]

/**
* @return bytes without proof of work, needed for working to get the proof on
*/
def serializeWithoutPoW: Coll[Byte]

def checkPow: Boolean

}

/** Runtime representation of Context ErgoTree type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,6 @@ object ReflectionData {
},
mkMethod(clazz, "powDistance", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[Header].powDistance
},
mkMethod(clazz, "checkPow", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[Header].checkPow
}
)
)
Expand Down
84 changes: 0 additions & 84 deletions core/shared/src/main/scala/sigma/util/NBitsUtils.scala

This file was deleted.

30 changes: 15 additions & 15 deletions data/shared/src/main/scala/org/ergoplatform/ErgoHeader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scorex.crypto.authds.ADDigest
import scorex.crypto.hash.{Blake2b256, Digest32}
import scorex.util.ModifierId
import sigma.Colls
import sigma.crypto.{CryptoConstants, CryptoFacade, EcPointType}
import sigma.crypto.{CryptoConstants, EcPointType}
import sigma.serialization.{GroupElementSerializer, SigmaByteReader, SigmaByteWriter, SigmaSerializer}


Expand Down Expand Up @@ -91,22 +91,22 @@ object AutolykosSolution {
* @param _bytes - serialized bytes of the header when not `null`
*/
case class ErgoHeader(override val version: ErgoHeader.Version,
override val parentId: ModifierId,
override val ADProofsRoot: Digest32,
override val stateRoot: ADDigest, //33 bytes! extra byte with tree height here!
override val transactionsRoot: Digest32,
override val timestamp: ErgoHeader.Timestamp,
override val nBits: Long, //actually it is unsigned int
override val height: Int,
override val extensionRoot: Digest32,
powSolution: AutolykosSolution,
override val votes: Array[Byte], //3 bytes
override val unparsedBytes: Array[Byte],
_bytes: Array[Byte]) extends
override val parentId: ModifierId,
override val ADProofsRoot: Digest32,
override val stateRoot: ADDigest, //33 bytes! extra byte with tree height here!
override val transactionsRoot: Digest32,
override val timestamp: ErgoHeader.Timestamp,
override val nBits: Long, //actually it is unsigned int
override val height: Int,
override val extensionRoot: Digest32,
powSolution: AutolykosSolution,
override val votes: Array[Byte], //3 bytes
override val unparsedBytes: Array[Byte],
_bytes: Array[Byte]) extends
HeaderWithoutPow(version, parentId, ADProofsRoot, stateRoot, transactionsRoot, timestamp,
nBits, height, extensionRoot, votes, unparsedBytes) {
nBits, height, extensionRoot, votes, unparsedBytes) {

lazy val bytes = if(_bytes != null) {
lazy val bytes = if (_bytes != null) {
_bytes
} else {
ErgoHeader.sigmaSerializer.toBytes(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import scorex.util.{ModifierId, bytesToId, idToBytes}
import sigma.serialization.{SigmaByteReader, SigmaByteWriter, SigmaSerializer}
import scorex.util.Extensions._

//todo: unify with Ergo node codebase

/**
* Header without proof-of-work puzzle solution, see Header class description for details.
*/
Expand Down
30 changes: 5 additions & 25 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import sigma.ast.syntax.{SValue, ValueOps}
import sigma.data.OverloadHack.Overloaded1
import sigma.data.{DataValueComparer, KeyValueColl, Nullable, RType, SigmaConstants}
import sigma.eval.{CostDetails, ErgoTreeEvaluator, TracedCost}
import sigma.pow.Autolykos2PowValidation
import sigma.reflection.RClass
import sigma.serialization.CoreByteWriter.ArgInfo
import sigma.utils.SparseArrayContainer
Expand Down Expand Up @@ -1457,30 +1456,11 @@ case object SHeaderMethods extends MonoTypeMethods {
lazy val powDistanceMethod = propertyCall("powDistance", SBigInt, 14, FixedCost(JitCost(10)))
lazy val votesMethod = propertyCall("votes", SByteArray, 15, FixedCost(JitCost(10)))

lazy val checkPowMethod = SMethod(
this, "checkPow", SFunc(Array(SHeader), SBoolean), 16, GroupGenerator.costKind) // todo: cost
.withIRInfo(MethodCallIrBuilder)
.withInfo(Xor, "Check PoW of this header") // todo: desc

def checkPow_eval(mc: MethodCall, G: SigmaDslBuilder, header: Header)
(implicit E: ErgoTreeEvaluator): Boolean = {
E.checkPow_eval(mc, header)
}

protected override def getMethods() = {
if (VersionContext.current.isV6SoftForkActivated) {
// 6.0 : checkPow method added
super.getMethods() ++ Seq(
idMethod, versionMethod, parentIdMethod, ADProofsRootMethod, stateRootMethod, transactionsRootMethod,
timestampMethod, nBitsMethod, heightMethod, extensionRootMethod, minerPkMethod, powOnetimePkMethod,
powNonceMethod, powDistanceMethod, votesMethod, checkPowMethod)
} else {
super.getMethods() ++ Seq(
idMethod, versionMethod, parentIdMethod, ADProofsRootMethod, stateRootMethod, transactionsRootMethod,
timestampMethod, nBitsMethod, heightMethod, extensionRootMethod, minerPkMethod, powOnetimePkMethod,
powNonceMethod, powDistanceMethod, votesMethod)
}
}
protected override def getMethods() = super.getMethods() ++ Seq(
idMethod, versionMethod, parentIdMethod, ADProofsRootMethod, stateRootMethod, transactionsRootMethod,
timestampMethod, nBitsMethod, heightMethod, extensionRootMethod, minerPkMethod, powOnetimePkMethod,
powNonceMethod, powDistanceMethod, votesMethod
)
}

/** Type descriptor of `PreHeader` type of ErgoTree. */
Expand Down
20 changes: 5 additions & 15 deletions data/shared/src/main/scala/sigma/data/CHeader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.ergoplatform.{AutolykosSolution, ErgoHeader, HeaderWithoutPow, Header
import scorex.crypto.authds.ADDigest
import scorex.crypto.hash.Digest32
import scorex.util.{bytesToId, idToBytes}
import sigma.pow.Autolykos2PowValidation
import sigma.{AvlTree, BigInt, Coll, Colls, GroupElement, Header}

/** A default implementation of [[Header]] interface.
Expand Down Expand Up @@ -73,26 +72,19 @@ class CHeader(val ergoHeader: ErgoHeader) extends Header with WrapperOf[ErgoHead
Colls.fromArray(HeaderWithoutPowSerializer.toBytes(headerWithoutPow))
}

override def checkPow: Boolean = {
if (version == 1) {
throw new Exception("Autolykos v1 is not supported") //todo: more specific exception?
} else {
Autolykos2PowValidation.checkPoWForVersion2(this)
}
}

override def hashCode(): Int = id.hashCode()

override def equals(other: Any): Boolean = other match {
case ch: CHeader => ch.id == this.id
case _ => false
}

def copy(): CHeader = new CHeader(ergoHeader.copy()) // used in tests only
}

object CHeader {

def apply( id: Coll[Byte], // todo: ignored, remove
version: Byte,
def apply( version: Byte,
parentId: Coll[Byte],
ADProofsRoot: Coll[Byte],
stateRoot: AvlTree,
Expand All @@ -106,8 +98,7 @@ object CHeader {
powNonce: Coll[Byte],
powDistance: BigInt,
votes: Coll[Byte],
unparsedBytes: Coll[Byte]
): CHeader = {
unparsedBytes: Coll[Byte]): CHeader = {

val solution = AutolykosSolution(
minerPk.asInstanceOf[CGroupElement].wrappedValue,
Expand All @@ -128,5 +119,4 @@ object CHeader {
/** Size of nonce array from Autolykos POW solution in Header.powNonce array. */
val NonceSize: Int = SigmaConstants.AutolykosPowSolutionNonceArraySize.value


}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sigma.eval

import sigma.{AvlTree, Coll, Context, Header}
import sigma.{AvlTree, Coll, Context}
import sigma.ast.{Constant, FixedCost, MethodCall, OperationCostInfo, OperationDesc, PerItemCost, SType, TypeBasedCost}
import sigma.data.KeyValueColl

Expand Down Expand Up @@ -138,9 +138,6 @@ abstract class ErgoTreeEvaluator {
def remove_eval(
mc: MethodCall, tree: AvlTree,
operations: Coll[Coll[Byte]], proof: Coll[Byte]): Option[AvlTree]

def checkPow_eval(mc: MethodCall, header: Header): Boolean

}

object ErgoTreeEvaluator {
Expand Down
Loading

0 comments on commit 7795e5d

Please sign in to comment.