Skip to content

Commit

Permalink
Merge pull request #945 from wavesplatform/cherry-pick-one-proof-limit
Browse files Browse the repository at this point in the history
Cherry pick one proof limit
  • Loading branch information
alexeykiselev authored Mar 28, 2018
2 parents 067b5cd + a49cd60 commit f76d9f3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/scala/scorex/transaction/smart/Verifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
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, recipient, amt, ts, fee, Array.emptyByteArray).explicitGet()
} yield (genesis, setScript, transfer)

forAll(s) {
case ((genesis, script, transfer)) =>
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"))
}
}

}

0 comments on commit f76d9f3

Please sign in to comment.