Skip to content

Commit

Permalink
refactor: Babbage block header VRF result decoding (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney authored Jan 17, 2025
1 parent 2a4efda commit 7f2e305
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 7 additions & 1 deletion ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions ledger/verify_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7f2e305

Please sign in to comment.