Skip to content

Commit

Permalink
Disable CreateAlias with multiple proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Nazarov committed Mar 18, 2022
1 parent 2f4f525 commit e0124dc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ case class FunctionalitySettings(
estimationOverflowFixHeight: Int = 0,
estimatorSumOverflowFixHeight: Int = 0,
forbidSyncDAppNegativePaymentHeight: Int = 0,
forbidNegativeMatcherFee: Int = 0
forbidNegativeMatcherFee: Int = 0,
allowMultipleProofsInCreateAliasUntil: Int = Int.MaxValue
) {
val allowLeasedBalanceTransferUntilHeight: Int = blockVersion3AfterHeight
val allowTemporaryNegativeUntil = lastTimeBasedForkParameter
Expand Down Expand Up @@ -128,7 +129,8 @@ object FunctionalitySettings {
estimationOverflowFixHeight = 2858710,
estimatorSumOverflowFixHeight = 2897510,
forbidSyncDAppNegativePaymentHeight = 2959447,
forbidNegativeMatcherFee = 2991300
forbidNegativeMatcherFee = 2991300,
allowMultipleProofsInCreateAliasUntil = 3029980
)

val TESTNET = apply(
Expand All @@ -144,7 +146,8 @@ object FunctionalitySettings {
estimationOverflowFixHeight = 1793770,
estimatorSumOverflowFixHeight = 1832520,
forbidSyncDAppNegativePaymentHeight = 1894600,
forbidNegativeMatcherFee = 1926200
forbidNegativeMatcherFee = 1926200,
allowMultipleProofsInCreateAliasUntil = 1964900
)

val STAGENET = apply(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ object CreateAliasTransactionDiff {
def apply(blockchain: Blockchain)(tx: CreateAliasTransaction): Either[ValidationError, Diff] =
if (blockchain.isFeatureActivated(BlockchainFeatures.DataTransaction, blockchain.height) && !blockchain.canCreateAlias(tx.alias))
Left(GenericError("Alias already claimed"))
else if (blockchain.height > blockchain.settings.functionalitySettings.allowMultipleProofsInCreateAliasUntil && tx.proofs.size > 1)
Left(GenericError("Invalid proofs size"))
else
Right(
Diff(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.wavesplatform.transaction

import com.google.common.primitives.Longs
import com.wavesplatform.account.{Alias, KeyPair, PublicKey}
import com.wavesplatform.block.Block
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils.EitherExt2
import com.wavesplatform.test.PropSpec
import com.wavesplatform.db.WithDomain
import com.wavesplatform.history.Domain._
import com.wavesplatform.lang.directives.values.V5
import com.wavesplatform.lang.v1.compiler.TestCompiler
import com.wavesplatform.test._
import com.wavesplatform.transaction.smart.SetScriptTransaction
import play.api.libs.json.Json

class CreateAliasTransactionSpecification extends PropSpec {
import scala.util.Random

class CreateAliasTransactionSpecification extends PropSpec with WithDomain {

property("CreateAliasTransaction serialization roundtrip") {
forAll(createAliasGen) { tx: CreateAliasTransaction =>
Expand Down Expand Up @@ -92,4 +101,46 @@ class CreateAliasTransactionSpecification extends PropSpec {
js shouldEqual tx.json()
}

property("Multiple proofs") {
withDomain(DomainPresets.RideV5.copy(
blockchainSettings = DomainPresets.RideV5.blockchainSettings.copy(
functionalitySettings = DomainPresets.RideV5.blockchainSettings.functionalitySettings.copy(
allowMultipleProofsInCreateAliasUntil = 2
)
)
)) { d =>
val sender = KeyPair(Longs.toByteArray(Random.nextLong()))
d.appendBlock(
GenesisTransaction.create(sender.toAddress, 100.waves, System.currentTimeMillis()).explicitGet(),
SetScriptTransaction.selfSigned(2.toByte, sender, Some(TestCompiler(V5).compileExpression(
"""{-# STDLIB_VERSION 5 #-}
|{-# CONTENT_TYPE EXPRESSION #-}
|{-# SCRIPT_TYPE ACCOUNT #-}
|
|true
|""".stripMargin)), 0.01.waves, System.currentTimeMillis()).explicitGet()
)

val kp1 = KeyPair(Longs.toByteArray(Random.nextLong()))
val kp2 = KeyPair(Longs.toByteArray(Random.nextLong()))

val cat = CreateAliasTransaction(3.toByte, sender.publicKey, "abc12345", 0.001.waves, System.currentTimeMillis(), Proofs.empty, 'T'.toByte)
val signedCreateAlias = cat.copy(
proofs = cat.signWith(kp1.privateKey).proofs.proofs ++ cat.signWith(kp2.privateKey).proofs.proofs
)
d.appendBlock(
signedCreateAlias
)

d.appendBlock()

val cat2 = CreateAliasTransaction(3.toByte, sender.publicKey, "xyz12345", 0.001.waves, System.currentTimeMillis(), Proofs.empty, 'T'.toByte)
val signedCreateAlias2 = cat2.copy(
proofs = cat.signWith(kp1.privateKey).proofs.proofs ++ cat.signWith(kp2.privateKey).proofs.proofs
)

d.blockchainUpdater
.processBlock(d.createBlock(Block.PlainBlockVersion, Seq(signedCreateAlias2))) should produce("Invalid proofs size")
}
}
}

0 comments on commit e0124dc

Please sign in to comment.