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

replacing-arrays-hash-code #934

Open
wants to merge 2 commits into
base: v5.0.13-RC
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 9 additions & 8 deletions core/shared/src/main/scala/sigma/util/CollectionUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import scala.collection.{Seq, mutable, GenIterable}
import scala.collection.mutable.{HashMap, ArrayBuffer}
import scala.reflect.ClassTag
import scala.collection.compat._
import scorex.utils.Ints

object CollectionUtil {

Expand Down Expand Up @@ -58,14 +59,14 @@ object CollectionUtil {
*/
def deepHashCode[T](arr: Array[T]): Int = arr match {
case arr: Array[AnyRef] => java.util.Arrays.deepHashCode(arr)
case arr: Array[Byte] => java.util.Arrays.hashCode(arr)
case arr: Array[Short] => java.util.Arrays.hashCode(arr)
case arr: Array[Int] => java.util.Arrays.hashCode(arr)
case arr: Array[Long] => java.util.Arrays.hashCode(arr)
case arr: Array[Char] => java.util.Arrays.hashCode(arr)
case arr: Array[Float] => java.util.Arrays.hashCode(arr)
case arr: Array[Double] => java.util.Arrays.hashCode(arr)
case arr: Array[Boolean] => java.util.Arrays.hashCode(arr)
case arr: Array[Byte] => Ints.fromByteArray(arr)
case arr: Array[Short] => Ints.fromByteArray(arr)
case arr: Array[Int] => Ints.fromByteArray(arr)
case arr: Array[Long] => Ints.fromByteArray(arr)
case arr: Array[Char] => Ints.fromByteArray(arr)
case arr: Array[Float] => Ints.fromByteArray(arr)
case arr: Array[Double] => Ints.fromByteArray(arr)
case arr: Array[Boolean] => Ints.fromByteArray(arr)
}

/** Group the given sequence of pairs by first values as keys.
Expand Down
3 changes: 2 additions & 1 deletion core/shared/src/main/scala/sigma/validation/RuleStatus.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package sigma.validation
import scorex.utils.Ints

/** Base trait for rule status information. */
sealed trait RuleStatus {
Expand Down Expand Up @@ -43,7 +44,7 @@ case class ReplacedRule(newRuleId: Short) extends RuleStatus {
case class ChangedRule(newValue: Array[Byte]) extends RuleStatus {
val statusCode: Byte = RuleStatus.ChangedRuleCode

override def hashCode(): Int = java.util.Arrays.hashCode(newValue)
override def hashCode(): Int = Ints.fromByteArray(newValue)

override def canEqual(that: Any): Boolean = that.isInstanceOf[ChangedRule]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sigma.interpreter

import scorex.util.encode.Base16
import sigma.serialization.{SigmaByteReader, SigmaByteWriter, SigmaSerializer}
import scorex.utils.Ints

/**
* Proof of correctness of tx spending
Expand All @@ -10,7 +11,7 @@ import sigma.serialization.{SigmaByteReader, SigmaByteWriter, SigmaSerializer}
* @param extension - user-defined variables to be put into context
*/
class ProverResult(val proof: Array[Byte], val extension: ContextExtension) {
override def hashCode(): Int = java.util.Arrays.hashCode(proof) * 31 + extension.hashCode()
override def hashCode(): Int = Ints.fromByteArray(proof) * 31 + extension.hashCode()

override def equals(obj: scala.Any): Boolean =
(this eq obj.asInstanceOf[AnyRef]) || (obj match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
package sigmastate.crypto

import debox.cfor
import scorex.utils.Ints

import java.util

Expand Down Expand Up @@ -113,7 +114,7 @@ class GF2_192 extends AnyRef {
}
}

override def hashCode = java.util.Arrays.hashCode(word)
override def hashCode = Ints.fromByteArray(word)

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import java.util
import java.util.concurrent.locks.Lock
import scala.reflect.ClassTag
import scala.util.{Either, Failure, Right, Success, Try}
import scorex.utils.Ints

object Helpers {

Expand Down Expand Up @@ -64,7 +65,7 @@ object Helpers {
*/
@inline final def safeIdHashCode(id: Array[Byte]): Int =
if (id != null && id.length >= 4) Ints.fromBytes(id(0), id(1), id(2), id(3))
else java.util.Arrays.hashCode(id)
else Ints.fromByteArray(id)

implicit class TryOps[+A](val source: Try[A]) extends AnyVal {
def fold[B](onError: Throwable => B, onSuccess: A => B) = source match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ErgoId(val _idBytes: Array[Byte]) {

override def hashCode =
if (_idBytes != null && _idBytes.length >= 4) Ints.fromByteArray(_idBytes)
else java.util.Arrays.hashCode(_idBytes)
else Ints.fromByteArray(_idBytes)

override def equals(obj: Any): Boolean = {
if (obj == null) return false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.ergoplatform.sdk

import debox.cfor
import scorex.utils.Ints


import java.util

Expand Down Expand Up @@ -73,7 +75,7 @@ final class SecretString private[sdk](val _data: Array[Char]) {

override def hashCode(): Int = {
checkErased()
java.util.Arrays.hashCode(_data)
Ints.fromByteArray(_data)
}

/** this is adapted version of java.lang.String */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sigma.data.ProveDlog
import sigmastate.crypto.DLogProtocol.DLogProverInput
import sigma.serialization.{SigmaByteReader, SigmaByteWriter, SigmaSerializer}
import scala.annotation.tailrec
import scorex.utils.Ints

/**
* Public key, its chain code and path in key tree.
Expand Down Expand Up @@ -32,8 +33,8 @@ final class ExtendedPublicKey(/*private[secrets] */val keyBytes: Array[Byte],
})

override def hashCode(): Int = {
var h = java.util.Arrays.hashCode(keyBytes)
h = 31 * h + java.util.Arrays.hashCode(chainCode)
var h = Ints.fromByteArray(keyBytes)
h = 31 * h + Ints.fromByteArray(chainCode)
h = 31 * h + path.hashCode()
h
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sigma.data.ProveDlog
import java.math.BigInteger
import sigmastate.crypto.DLogProtocol.DLogProverInput
import sigma.serialization.{SigmaByteReader, SigmaByteWriter, SigmaSerializer}
import scorex.utils.Ints

/**
* Secret, its chain code and path in key tree.
Expand Down Expand Up @@ -40,8 +41,8 @@ final class ExtendedSecretKey(/*private[secrets]*/ val keyBytes: Array[Byte],
})

override def hashCode(): Int = {
var h = java.util.Arrays.hashCode(keyBytes)
h = 31 * h + java.util.Arrays.hashCode(chainCode)
var h = Ints.fromByteArray(keyBytes)
h = 31 * h + Ints.fromByteArray(chainCode)
h = 31 * h + path.hashCode()
h
}
Expand Down