Skip to content

Commit

Permalink
correctly compute ToSign for ByronBlock
Browse files Browse the repository at this point in the history
Uses pre-encoded CBOR from an unreleased cborg revision.
This will be obsoleted by a better solution, in which the DSIGN classes
can use ByteStrings directly, rather than cborg Encodings.
  • Loading branch information
Alexander Vieth committed Jul 22, 2019
1 parent 49da3b5 commit 01ede38
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Expand Up @@ -109,7 +109,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/well-typed/cborg
tag: 80fbe0ee5e67a5622e2cb9eaa9d8594a2214322d
tag: 73840112f4eae0a16a863fe17d413e0808d84461
subdir: cborg

source-repository-package
Expand Down
Expand Up @@ -58,13 +58,19 @@ instance Given (VerKeyDSIGN CardanoDSIGN) => HasSignTag CC.Block.ToSign where
signTag = const $ SignBlock vk
where VerKeyCardanoDSIGN vk = given

instance Given (VerKeyDSIGN CardanoDSIGN) => HasSignTag (Annotated CC.Block.ToSign a) where
signTag = const $ signTag (Proxy :: Proxy CC.Block.ToSign)

-- See https://hackage.haskell.org/package/constraints-0.10.1/docs/Data-Constraint.html#t::-61--62-
--
-- This instance reflects the instance head/body relationship, and allows us to
-- reconstruct the `HasSignTag` constraint using the relevant `Given` constraint.
instance Given (VerKeyDSIGN CardanoDSIGN) :=> HasSignTag CC.Block.ToSign where
ins = Sub Dict

instance Given (VerKeyDSIGN CardanoDSIGN) :=> HasSignTag (Annotated CC.Block.ToSign a) where
ins = Sub Dict

data CardanoDSIGN

instance Given ProtocolMagicId => DSIGNAlgorithm CardanoDSIGN where
Expand Down
9 changes: 4 additions & 5 deletions ouroboros-consensus/src/Ouroboros/Consensus/Ledger/Byron.hs
Expand Up @@ -49,7 +49,7 @@ module Ouroboros.Consensus.Ledger.Byron
) where

import Codec.CBOR.Decoding (Decoder, decodeListLenOf)
import Codec.CBOR.Encoding (Encoding, encodeListLen)
import Codec.CBOR.Encoding (Encoding, encodeListLen, encodePreEncoded)
import qualified Codec.CBOR.Read as CBOR
import qualified Codec.CBOR.Write as CBOR
import Codec.Serialise (Serialise, decode, encode)
Expand Down Expand Up @@ -286,10 +286,9 @@ type instance BlockProtocol (ByronBlock cfg) =
ExtNodeConfig cfg (PBft PBftCardanoCrypto)

instance ByronGiven => SignedHeader (Header (ByronBlock cfg)) where
type Signed (Header (ByronBlock cfg)) = CC.Block.ToSign
encodeSigned = const toCBOR
headerSigned = unAnnotated
. CC.Block.recoverSignedBytes given
type Signed (Header (ByronBlock cfg)) = Annotated CC.Block.ToSign ByteString
encodeSigned = const (encodePreEncoded . annotation)
headerSigned = CC.Block.recoverSignedBytes given
. unByronHeader

instance (ByronGiven, Typeable cfg)
Expand Down
3 changes: 3 additions & 0 deletions stack.yaml
Expand Up @@ -12,6 +12,9 @@ packages:
- ./io-sim-classes

extra-deps:
- git: https://github.com/well-typed/cborg
- commit: 73840112f4eae0a16a863fe17d413e0808d84461

- git: https://github.com/input-output-hk/iohk-monitoring-framework
commit: bd31cd2f3922010ddb76bb869f29c4e63bb8001b
subdirs:
Expand Down

0 comments on commit 01ede38

Please sign in to comment.