From 124db5159f64e86cf7215789356a6ca47faa6426 Mon Sep 17 00:00:00 2001 From: Ilya Smagin Date: Tue, 20 Mar 2018 16:58:15 +0300 Subject: [PATCH 1/3] NODE-618: Transactions from non-scripted accounts must have exactly 1 proof --- .../scala/scorex/transaction/smart/Verifier.scala | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/scala/scorex/transaction/smart/Verifier.scala b/src/main/scala/scorex/transaction/smart/Verifier.scala index efaefbc90ec..5ffdf88ee8a 100644 --- a/src/main/scala/scorex/transaction/smart/Verifier.scala +++ b/src/main/scala/scorex/transaction/smart/Verifier.scala @@ -27,9 +27,12 @@ object Verifier { } def verifyAsEllipticCurveSignature[T <: ProvenTransaction](pt: T): Either[ValidationError, T] = - Either.cond( - crypto.verify(pt.proofs.proofs(0).arr, pt.bodyBytes(), pt.sender.publicKey), - pt, - GenericError(s"Script doesn't exist and proof doesn't validate as signature for $pt") - ) + pt.proofs.proofs match { + case p :: Nil => + Either.cond(crypto.verify(p.arr, pt.bodyBytes(), pt.sender.publicKey), + pt, + GenericError(s"Script doesn't exist and proof doesn't validate as signature for $pt")) + case _ => Left(GenericError("Transactions from non-scripted accounts must have exactly 1 proof")) + } + } From 0577ed6c829d9557319ce3c46be61d712862eefc Mon Sep 17 00:00:00 2001 From: Ilya Smagin Date: Tue, 20 Mar 2018 17:14:34 +0300 Subject: [PATCH 2/3] NODE-618: Transactions from non-scripted accounts must have exactly 1 proof --- .../state2/diffs/ScriptsValidationTest.scala | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/scala/com/wavesplatform/state2/diffs/ScriptsValidationTest.scala b/src/test/scala/com/wavesplatform/state2/diffs/ScriptsValidationTest.scala index d1c974e6b1d..ef09cbb729a 100644 --- a/src/test/scala/com/wavesplatform/state2/diffs/ScriptsValidationTest.scala +++ b/src/test/scala/com/wavesplatform/state2/diffs/ScriptsValidationTest.scala @@ -163,4 +163,26 @@ class ScriptsValidationTest extends PropSpec with PropertyChecks with Matchers w } } + property("exactly 1 proof required for non-scripted accounts") { + + val s = for { + master <- accountGen + recepient <- accountGen + amt <- positiveLongGen + fee <- smallFeeGen + ts <- positiveIntGen + genesis = GenesisTransaction.create(master, ENOUGH_AMT, ts).explicitGet() + setScript <- selfSignedSetScriptTransactionGenP(master, Script(Typed.TRUE)) + transfer = ScriptTransferTransaction.selfSigned(1, None, master, recepient, amt, ts, fee, Array.emptyByteArray).explicitGet() + } yield (genesis, setScript, transfer) + + forAll(s) { + case ((genesis, script, transfer)) => + val transferWithExtraProof = transfer.copy(proofs = transfer.proofs.copy(proofs = Seq(transfer.proofs.proofs.head, ByteStr(Array(1: Byte))))) + assertDiffAndState(db, Seq(TestBlock.create(Seq(genesis, script))), TestBlock.create(Seq(transfer)), fs) { case _ => () } + assertDiffEi(db, Seq(TestBlock.create(Seq(genesis, script))), TestBlock.create(Seq(transferWithExtraProof)), fs)(totalDiffEi => + totalDiffEi should produce("must have exactly 1 proof")) + } + } + } From a49cd601e3f61aeacb7c4514d1262b9c7ca54cfc Mon Sep 17 00:00:00 2001 From: Alexey Kiselev Date: Wed, 28 Mar 2018 16:44:54 +0300 Subject: [PATCH 3/3] Test fixed --- .../state2/diffs/ScriptsValidationTest.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/scala/com/wavesplatform/state2/diffs/ScriptsValidationTest.scala b/src/test/scala/com/wavesplatform/state2/diffs/ScriptsValidationTest.scala index ef09cbb729a..6e76bd7bed9 100644 --- a/src/test/scala/com/wavesplatform/state2/diffs/ScriptsValidationTest.scala +++ b/src/test/scala/com/wavesplatform/state2/diffs/ScriptsValidationTest.scala @@ -167,20 +167,20 @@ class ScriptsValidationTest extends PropSpec with PropertyChecks with Matchers w val s = for { master <- accountGen - recepient <- accountGen + recipient <- accountGen amt <- positiveLongGen fee <- smallFeeGen ts <- positiveIntGen genesis = GenesisTransaction.create(master, ENOUGH_AMT, ts).explicitGet() setScript <- selfSignedSetScriptTransactionGenP(master, Script(Typed.TRUE)) - transfer = ScriptTransferTransaction.selfSigned(1, None, master, recepient, amt, ts, fee, Array.emptyByteArray).explicitGet() + transfer = ScriptTransferTransaction.selfSigned(1, None, master, recipient, amt, ts, fee, Array.emptyByteArray).explicitGet() } yield (genesis, setScript, transfer) forAll(s) { case ((genesis, script, transfer)) => - val transferWithExtraProof = transfer.copy(proofs = transfer.proofs.copy(proofs = Seq(transfer.proofs.proofs.head, ByteStr(Array(1: Byte))))) - assertDiffAndState(db, Seq(TestBlock.create(Seq(genesis, script))), TestBlock.create(Seq(transfer)), fs) { case _ => () } - assertDiffEi(db, Seq(TestBlock.create(Seq(genesis, script))), TestBlock.create(Seq(transferWithExtraProof)), fs)(totalDiffEi => + val transferWithExtraProof = transfer.copy(proofs = Proofs(Seq(ByteStr.empty, ByteStr(Array(1: Byte))))) + assertDiffAndState(db, Seq(TestBlock.create(Seq(genesis, script))), TestBlock.create(Seq(transferWithExtraProof)), fs) { case _ => () } + assertDiffEi(db, Seq(TestBlock.create(Seq(genesis))), TestBlock.create(Seq(transferWithExtraProof)), fs)(totalDiffEi => totalDiffEi should produce("must have exactly 1 proof")) } }