Skip to content

Commit 6f083f5

Browse files
committed
ETCM-166: Move crypto to separate project
1 parent c380e5e commit 6f083f5

32 files changed

+94
-50
lines changed

.buildkite/pipeline.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ in
7575
];
7676
};
7777

78+
test-crypto = commonAttrs // {
79+
dependsOn = [ compile ];
80+
label = "Crypto tests";
81+
command = ''
82+
nix-shell --run '$SBT coverage crypto/test'
83+
'';
84+
artifactPaths = [
85+
"crypto/target/test-reports/**/*"
86+
"crypto/target/scala-2.12/scoverage-report/**/*"
87+
"crypto/target/scala-2.12/coverage-report/**/*"
88+
];
89+
};
90+
7891
test-rlp = commonAttrs // {
7992
dependsOn = [ compile ];
8093
label = "RLP tests";

build.sbt

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
4242
(scalastyleConfig in Test) := file("scalastyle-test-config.xml")
4343
)
4444

45-
lazy val bytes = {
46-
// Adding an "it" config because in `Dependencies.scala` some are declared with `% "it,test"`
47-
// which would fail if the project didn't have configuration to add to.
48-
val Integration = config("it") extend Test
45+
// Adding an "it" config because in `Dependencies.scala` some are declared with `% "it,test"`
46+
// which would fail if the project didn't have configuration to add to.
47+
val Integration = config("it") extend Test
4948

49+
lazy val bytes = {
5050
val bytes = project
5151
.in(file("bytes"))
5252
.configs(Integration)
@@ -60,9 +60,23 @@ lazy val bytes = {
6060
bytes
6161
}
6262

63-
lazy val rlp = {
64-
val Integration = config("it") extend Test
63+
lazy val crypto = {
64+
val crypto = project
65+
.in(file("crypto"))
66+
.configs(Integration)
67+
.dependsOn(bytes)
68+
.settings(commonSettings("mantis-crypto"))
69+
.settings(
70+
libraryDependencies ++=
71+
Dependencies.akkaUtil ++
72+
Dependencies.crypto ++
73+
Dependencies.testing
74+
)
75+
76+
crypto
77+
}
6578

79+
lazy val rlp = {
6680
val rlp = project
6781
.in(file("rlp"))
6882
.configs(Integration)
@@ -79,9 +93,6 @@ lazy val rlp = {
7993
}
8094

8195
lazy val node = {
82-
83-
val Integration = config("it") extend Test
84-
8596
val Benchmark = config("benchmark") extend Test
8697

8798
val Evm = config("evm") extend Test
@@ -135,7 +146,7 @@ lazy val node = {
135146
.in(file("."))
136147
.configs(Integration, Benchmark, Evm, Ets, Snappy, Rpc)
137148
.enablePlugins(BuildInfoPlugin)
138-
.dependsOn(bytes, rlp)
149+
.dependsOn(bytes, crypto, rlp)
139150
.settings(
140151
buildInfoKeys := Seq[BuildInfoKey](name, version, git.gitHeadCommit),
141152
buildInfoPackage := "io.iohk.ethereum.utils"
@@ -196,6 +207,8 @@ addCommandAlias(
196207
"compile-all",
197208
""";bytes/compile
198209
|;bytes/test:compile
210+
|;crypto/compile
211+
|;crypto/test:compile
199212
|;rlp/compile
200213
|;rlp/test:compile
201214
|;compile
@@ -216,6 +229,9 @@ addCommandAlias(
216229
|;bytes/scalafmtAll
217230
|;bytes/scalastyle
218231
|;bytes/test:scalastyle
232+
|;crypto/scalafmtAll
233+
|;crypto/scalastyle
234+
|;crypto/test:scalastyle
219235
|;rlp/scalafmtAll
220236
|;rlp/scalastyle
221237
|;rlp/test:scalastyle
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.iohk.ethereum.utils
2+
3+
import akka.util.ByteString
4+
5+
object ByteStringUtils {
6+
def hash2string(hash: ByteString): String =
7+
Hex.toHexString(hash.toArray[Byte])
8+
9+
// unsafe
10+
def string2hash(hash: String): ByteString =
11+
ByteString(Hex.decode(hash))
12+
}

rlp/src/main/scala/io/iohk/ethereum/rlp/Hex.scala renamed to bytes/src/main/scala/io/iohk/ethereum/utils/Hex.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package io.iohk.ethereum.rlp
1+
package io.iohk.ethereum.utils
22

3-
protected[rlp] object Hex {
3+
object Hex {
44
def toHexString(bytes: Array[Byte]): String =
55
bytes.map("%02x".format(_)).mkString
66

src/main/scala/io/iohk/ethereum/crypto/ECDSASignature.scala renamed to crypto/src/main/scala/io/iohk/ethereum/crypto/ECDSASignature.scala

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -179,25 +179,3 @@ case class ECDSASignature(r: BigInt, s: BigInt, v: Byte) {
179179
bigInt2Bytes(r) ++ bigInt2Bytes(s) :+ v
180180
}
181181
}
182-
183-
object ECDSASignatureImplicits {
184-
185-
import io.iohk.ethereum.rlp.RLPImplicitConversions._
186-
import io.iohk.ethereum.rlp.RLPImplicits._
187-
import io.iohk.ethereum.rlp._
188-
189-
implicit val ecdsaSignatureDec: RLPDecoder[ECDSASignature] = new RLPDecoder[ECDSASignature] {
190-
override def decode(rlp: RLPEncodeable): ECDSASignature = rlp match {
191-
case RLPList(r, s, v) => ECDSASignature(r: ByteString, s: ByteString, v)
192-
case _ => throw new RuntimeException("Cannot decode ECDSASignature")
193-
}
194-
}
195-
196-
implicit class ECDSASignatureEnc(ecdsaSignature: ECDSASignature) extends RLPSerializable {
197-
override def toRLPEncodable: RLPEncodeable = {
198-
RLPList(ecdsaSignature.r, ecdsaSignature.s, ecdsaSignature.v)
199-
}
200-
}
201-
202-
implicit val ECDSASignatureOrdering: Ordering[ECDSASignature] = Ordering.by(sig => (sig.r, sig.s, sig.v))
203-
}

src/test/scala/io/iohk/ethereum/crypto/ECDSASignatureSpec.scala renamed to crypto/src/test/scala/io/iohk/ethereum/crypto/ECDSASignatureSpec.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.iohk.ethereum.crypto
22

33
import akka.util.ByteString
4-
import io.iohk.ethereum.security.SecureRandomBuilder
54
import io.iohk.ethereum.utils.ByteStringUtils
65
import org.scalacheck.Arbitrary
76
import org.scalacheck.Arbitrary.arbitrary

src/test/scala/io/iohk/ethereum/crypto/ECIESCoderSpec.scala renamed to crypto/src/test/scala/io/iohk/ethereum/crypto/ECIESCoderSpec.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package io.iohk.ethereum.crypto
22

33
import java.math.BigInteger
44

5-
import io.iohk.ethereum.security.SecureRandomBuilder
65
import org.bouncycastle.crypto.generators.ECKeyPairGenerator
76
import org.bouncycastle.crypto.params.ECKeyGenerationParameters
87
import org.bouncycastle.util.encoders.Hex
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.iohk.ethereum.crypto
2+
3+
import java.security.SecureRandom
4+
5+
private[crypto] trait SecureRandomBuilder {
6+
lazy val secureRandom: SecureRandom = new SecureRandom()
7+
}

src/test/scala/io/iohk/ethereum/crypto/zksnarks/FpFieldSpec.scala renamed to crypto/src/test/scala/io/iohk/ethereum/crypto/zksnarks/FpFieldSpec.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ package io.iohk.ethereum.crypto.zksnarks
22

33
import io.iohk.ethereum.crypto.zksnark._
44
import io.iohk.ethereum.crypto.zksnark.FiniteField.Ops._
5-
import io.iohk.ethereum.vm.Generators._
65
import org.scalacheck.Gen
6+
import org.scalacheck.Arbitrary.arbitrary
77
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
88
import org.scalatest.funsuite.AnyFunSuite
9+
import java.math.BigInteger
910

1011
abstract class FieldSpec[T: FiniteField] extends AnyFunSuite with ScalaCheckPropertyChecks {
12+
val bigIntGen: Gen[BigInteger] = for {
13+
bytes <- Gen.listOfN(32, arbitrary[Byte])
14+
} yield new BigInteger(1, bytes.toArray)
15+
1116
def fpGenerator: Gen[Fp] = bigIntGen.map(Fp(_)).retryUntil(fp => fp.isValid())
1217

1318
def fp2Generator: Gen[Fp2] = for {

rlp/src/main/scala/io/iohk/ethereum/rlp/package.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.iohk.ethereum
33
import akka.util.ByteString
44
import scala.reflect.ClassTag
55
import scala.util.control.NonFatal
6+
import io.iohk.ethereum.utils.Hex
67

78
package object rlp {
89

rlp/src/test/scala/io/iohk/ethereum/rlp/RLPSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.iohk.ethereum.rlp
33
import akka.util.ByteString
44
import io.iohk.ethereum.rlp.RLPImplicitConversions._
55
import io.iohk.ethereum.rlp.RLPImplicits._
6+
import io.iohk.ethereum.utils.Hex
67
import org.scalacheck.{Arbitrary, Gen}
78
import org.scalatestplus.scalacheck.{ScalaCheckDrivenPropertyChecks, ScalaCheckPropertyChecks}
89
import scala.language.implicitConversions

src/benchmark/scala/io/iohk/ethereum/rlp/RLPSpeedSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.iohk.ethereum.domain.Block._
66
import io.iohk.ethereum.domain._
77
import io.iohk.ethereum.network.p2p.messages.CommonMessages.SignedTransactions._
88
import io.iohk.ethereum.utils.Logger
9+
import io.iohk.ethereum.utils.Hex
910
import org.scalacheck.Gen
1011
import org.scalatest.funsuite.AnyFunSuite
1112
import org.scalatestplus.scalacheck.{ScalaCheckDrivenPropertyChecks, ScalaCheckPropertyChecks}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.iohk.ethereum.crypto
2+
3+
import akka.util.ByteString
4+
5+
object ECDSASignatureImplicits {
6+
7+
import io.iohk.ethereum.rlp.RLPImplicitConversions._
8+
import io.iohk.ethereum.rlp.RLPImplicits._
9+
import io.iohk.ethereum.rlp._
10+
11+
implicit val ecdsaSignatureDec: RLPDecoder[ECDSASignature] = new RLPDecoder[ECDSASignature] {
12+
override def decode(rlp: RLPEncodeable): ECDSASignature = rlp match {
13+
case RLPList(r, s, v) => ECDSASignature(r: ByteString, s: ByteString, v)
14+
case _ => throw new RuntimeException("Cannot decode ECDSASignature")
15+
}
16+
}
17+
18+
implicit class ECDSASignatureEnc(ecdsaSignature: ECDSASignature) extends RLPSerializable {
19+
override def toRLPEncodable: RLPEncodeable = {
20+
RLPList(ecdsaSignature.r, ecdsaSignature.s, ecdsaSignature.v)
21+
}
22+
}
23+
24+
implicit val ECDSASignatureOrdering: Ordering[ECDSASignature] = Ordering.by(sig => (sig.r, sig.s, sig.v))
25+
}

src/main/scala/io/iohk/ethereum/utils/ByteStringUtils.scala

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/scala/io/iohk/ethereum/utils/Config.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import io.iohk.ethereum.domain.Address
1010
import io.iohk.ethereum.network.PeerManagerActor.{FastSyncHostConfiguration, PeerConfiguration}
1111
import io.iohk.ethereum.network.rlpx.RLPxConnectionHandler.RLPxConfiguration
1212
import io.iohk.ethereum.utils.VmConfig.VmMode
13-
import org.bouncycastle.util.encoders.Hex
1413
import ConfigUtils._
1514

1615
import scala.collection.JavaConverters._

0 commit comments

Comments
 (0)