From 7f2e3059d573b4e0ee3e617d2f427b898b843293 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Thu, 16 Jan 2025 20:31:34 -0600 Subject: [PATCH] refactor: Babbage block header VRF result decoding (#833) --- ledger/babbage/babbage.go | 8 +++++++- ledger/verify_block.go | 8 +++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ledger/babbage/babbage.go b/ledger/babbage/babbage.go index d85480e2..bc27e6c3 100644 --- a/ledger/babbage/babbage.go +++ b/ledger/babbage/babbage.go @@ -140,6 +140,12 @@ func (b *BabbageBlock) Utxorpc() *utxorpc.Block { return block } +type BabbageBlockHeaderVrfResult struct { + cbor.StructAsArray + Output []byte + Proof []byte +} + type BabbageBlockHeader struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -151,7 +157,7 @@ type BabbageBlockHeader struct { PrevHash common.Blake2b256 IssuerVkey common.IssuerVkey VrfKey []byte - VrfResult interface{} + VrfResult BabbageBlockHeaderVrfResult BlockBodySize uint64 BlockBodyHash common.Blake2b256 OpCert struct { diff --git a/ledger/verify_block.go b/ledger/verify_block.go index 680b1fcf..f9009725 100644 --- a/ledger/verify_block.go +++ b/ledger/verify_block.go @@ -75,18 +75,16 @@ func VerifyBlock(block BlockHexCbor) (error, bool, string, uint64, uint64) { ), false, "", 0, 0 } vrfBytes := header.Body.VrfKey[:] - vrfResult := header.Body.VrfResult.([]interface{}) - vrfProofBytes := vrfResult[1].([]byte) - vrfOutputBytes := vrfResult[0].([]byte) + vrfResult := header.Body.VrfResult seed := MkInputVrf(int64(header.Body.Slot), epochNonceByte) - output, errVrf := VrfVerifyAndHash(vrfBytes, vrfProofBytes, seed) + output, errVrf := VrfVerifyAndHash(vrfBytes, vrfResult.Proof, seed) if errVrf != nil { return fmt.Errorf( "VerifyBlock: vrf invalid, %v", errVrf.Error(), ), false, "", 0, 0 } - isVrfValid := bytes.Equal(output, vrfOutputBytes) + isVrfValid := bytes.Equal(output, vrfResult.Output) // check if block data valid blockBodyHash := header.Body.BlockBodyHash