Skip to content
Permalink
Browse files

[#530] Add and utilize validateHeaderMatchesBody function

  • Loading branch information...
intricate committed Jun 12, 2019
1 parent 4e73619 commit e6d51919d621ba5fe5c65501f7201e21db22e1a7
Showing with 27 additions and 11 deletions.
  1. +27 −11 cardano-ledger/src/Cardano/Chain/Block/Validation.hs
@@ -47,6 +47,7 @@ import Streaming (Of(..), Stream, hoist)
import qualified Streaming.Prelude as S

import Cardano.Binary (Annotated(..), serialize')
import Cardano.Chain.Block.Body (ABody (..))
import Cardano.Chain.Block.Block
( ABlock(..)
, ABlockOrBoundary(..)
@@ -57,18 +58,18 @@ import Cardano.Chain.Block.Block
, blockHeader
, blockIssuer
, blockLength
, blockProof
, blockProtocolMagicId
, blockProtocolVersion
, blockSlot
, blockTxPayload
, blockUpdatePayload
)
import Cardano.Chain.Block.Header
( AHeader
( AHeader (..)
, BlockSignature
, HeaderHash
, headerLength
, headerProof
, headerSlot
, wrapBoundaryBytes
)
@@ -327,26 +328,41 @@ updateChainBoundary cvs bvd = do
}


validateBlockProofs
validateHeaderMatchesBody
:: MonadError ProofValidationError m
=> ABlock ByteString
=> AHeader ByteString
-> ABody ByteString
-> m ()
validateBlockProofs b = do
validateHeaderMatchesBody hdr body = do
let hdrProof = headerProof hdr

-- Validate the delegation payload signature
proofDelegation (blockProof b)
== hashDecoded (blockDlgPayload b)
proofDelegation hdrProof
== hashDecoded (bodyDlgPayload body)
`orThrowError` DelegationProofValidationError

-- Validate the transaction payload proof
proofUTxO (blockProof b)
== recoverTxProof (blockTxPayload b)
proofUTxO hdrProof
== recoverTxProof (bodyTxPayload body)
`orThrowError` UTxOProofValidationError

-- Validate the update payload proof
proofUpdate (blockProof b)
== hashDecoded (blockUpdatePayload b)
proofUpdate hdrProof
== hashDecoded (bodyUpdatePayload body)
`orThrowError` UpdateProofValidationError

validateBlockProofs
:: MonadError ProofValidationError m
=> ABlock ByteString
-> m ()
validateBlockProofs b =
validateHeaderMatchesBody blockHeader blockBody
where
ABlock
{ blockHeader
, blockBody
} = b


data BodyEnvironment = BodyEnvironment
{ protocolMagic :: !(AProtocolMagic ByteString)

0 comments on commit e6d5191

Please sign in to comment.
You can’t perform that action at this time.