Skip to content

Commit 7f2e305

Browse files
authored
refactor: Babbage block header VRF result decoding (#833)
1 parent 2a4efda commit 7f2e305

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

ledger/babbage/babbage.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ func (b *BabbageBlock) Utxorpc() *utxorpc.Block {
140140
return block
141141
}
142142

143+
type BabbageBlockHeaderVrfResult struct {
144+
cbor.StructAsArray
145+
Output []byte
146+
Proof []byte
147+
}
148+
143149
type BabbageBlockHeader struct {
144150
cbor.StructAsArray
145151
cbor.DecodeStoreCbor
@@ -151,7 +157,7 @@ type BabbageBlockHeader struct {
151157
PrevHash common.Blake2b256
152158
IssuerVkey common.IssuerVkey
153159
VrfKey []byte
154-
VrfResult interface{}
160+
VrfResult BabbageBlockHeaderVrfResult
155161
BlockBodySize uint64
156162
BlockBodyHash common.Blake2b256
157163
OpCert struct {

ledger/verify_block.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,16 @@ func VerifyBlock(block BlockHexCbor) (error, bool, string, uint64, uint64) {
7575
), false, "", 0, 0
7676
}
7777
vrfBytes := header.Body.VrfKey[:]
78-
vrfResult := header.Body.VrfResult.([]interface{})
79-
vrfProofBytes := vrfResult[1].([]byte)
80-
vrfOutputBytes := vrfResult[0].([]byte)
78+
vrfResult := header.Body.VrfResult
8179
seed := MkInputVrf(int64(header.Body.Slot), epochNonceByte)
82-
output, errVrf := VrfVerifyAndHash(vrfBytes, vrfProofBytes, seed)
80+
output, errVrf := VrfVerifyAndHash(vrfBytes, vrfResult.Proof, seed)
8381
if errVrf != nil {
8482
return fmt.Errorf(
8583
"VerifyBlock: vrf invalid, %v",
8684
errVrf.Error(),
8785
), false, "", 0, 0
8886
}
89-
isVrfValid := bytes.Equal(output, vrfOutputBytes)
87+
isVrfValid := bytes.Equal(output, vrfResult.Output)
9088

9189
// check if block data valid
9290
blockBodyHash := header.Body.BlockBodyHash

0 commit comments

Comments
 (0)