CORDA-2515 - Fix bug in verifier for has to signature constraints (auto-migration). (#4680) (#4689)

This commit is contained in:
josecoll 2019-01-31 09:59:52 +00:00 committed by Katelyn Baker
parent 1324676348
commit 91589849bb

View File

@ -342,27 +342,22 @@ class Verifier(val ltx: LedgerTransaction, val transactionClassLoader: ClassLoad
checkMinimumPlatformVersion(ltx.networkParameters!!.minimumPlatformVersion, 4, "Signature constraints") checkMinimumPlatformVersion(ltx.networkParameters!!.minimumPlatformVersion, 4, "Signature constraints")
} }
val constraintAttachment = if (state.contract in hashToSignatureConstrainedContracts) { val constraintAttachment =
// hash to to signature constraint migration logic: if (state.contract in hashToSignatureConstrainedContracts && state.constraint is HashAttachmentConstraint) {
// pass the unsigned attachment when verifying the constraint of the input state, and the signed attachment when verifying val unsignedAttachment = contractAttachmentsByContract[state.contract].unsigned
// the constraint of the output state. ?: throw TransactionVerificationException.MissingAttachmentRejection(ltx.id, state.contract)
val unsignedAttachment = contractAttachmentsByContract[state.contract].unsigned AttachmentWithContext(unsignedAttachment, state.contract, ltx.networkParameters!!)
?: throw TransactionVerificationException.MissingAttachmentRejection(ltx.id, state.contract) } else if (state.contract in hashToSignatureConstrainedContracts && state.constraint is SignatureAttachmentConstraint) {
val signedAttachment = contractAttachmentsByContract[state.contract].signed val signedAttachment = contractAttachmentsByContract[state.contract].signed
?: throw TransactionVerificationException.MissingAttachmentRejection(ltx.id, state.contract) ?: throw TransactionVerificationException.MissingAttachmentRejection(ltx.id, state.contract)
when { AttachmentWithContext(signedAttachment, state.contract, ltx.networkParameters!!)
// use unsigned attachment if hash-constrained input state }
state.data in ltx.inputStates -> AttachmentWithContext(unsignedAttachment, state.contract, ltx.networkParameters!!) else {
// use signed attachment if signature-constrained output state // standard processing logic
state.data in ltx.outputStates -> AttachmentWithContext(signedAttachment, state.contract, ltx.networkParameters!!) val contractAttachment = contractAttachmentsByContract[state.contract]?.firstOrNull()
else -> throw IllegalStateException("${state.contract} must use either signed or unsigned attachment in hash to signature constraints migration") ?: throw TransactionVerificationException.MissingAttachmentRejection(ltx.id, state.contract)
AttachmentWithContext(contractAttachment, state.contract, ltx.networkParameters!!)
} }
} else {
// standard processing logic
val contractAttachment = contractAttachmentsByContract[state.contract]?.firstOrNull()
?: throw TransactionVerificationException.MissingAttachmentRejection(ltx.id, state.contract)
AttachmentWithContext(contractAttachment, state.contract, ltx.networkParameters!!)
}
if (!state.constraint.isSatisfiedBy(constraintAttachment)) { if (!state.constraint.isSatisfiedBy(constraintAttachment)) {
throw TransactionVerificationException.ContractConstraintRejection(ltx.id, state.contract) throw TransactionVerificationException.ContractConstraintRejection(ltx.id, state.contract)