@@ -203,6 +203,8 @@ func deriveEventsHash(spork *config.Spork, events []flowEvent) flow.Identifier {
203203 return deriveEventsHashV2 (events )
204204 case 4 , 5 , 6 , 7 :
205205 return deriveEventsHashV4 (events )
206+ case 8 :
207+ return deriveEventsHashV8 (events )
206208 }
207209 panic ("unreachable code" )
208210}
@@ -293,11 +295,42 @@ func deriveEventsHashV4(events []flowEvent) flow.Identifier {
293295 return root
294296}
295297
298+ func deriveEventsHashV8 (events []flowEvent ) flow.Identifier {
299+ tree , err := merkle .NewTree (flow .IdentifierLen )
300+ if err != nil {
301+ log .Fatalf ("Failed to instantiate merkle tree: %s" , err )
302+ }
303+ for _ , src := range events {
304+ dst := struct {
305+ Type string
306+ TxID []byte
307+ TransactionIndex uint32
308+ EventIndex uint32
309+ Payload []byte
310+ }{
311+ Type : string (src .Type ),
312+ TxID : src .TransactionID [:],
313+ TransactionIndex : src .TransactionIndex ,
314+ EventIndex : src .EventIndex ,
315+ Payload : src .Payload ,
316+ }
317+ fp := fingerprint .Fingerprint (dst )
318+ eventID := flow .MakeIDFromFingerPrint (fp )
319+ _ , err = tree .Put (eventID [:], fp )
320+ if err != nil {
321+ log .Fatalf ("Failed to put event into the merkle tree: %s" , err )
322+ }
323+ }
324+ var root flow.Identifier
325+ copy (root [:], tree .Hash ())
326+ return root
327+ }
328+
296329func deriveExecutionResult (spork * config.Spork , exec flowExecutionResult ) flow.Identifier {
297330 switch spork .Version {
298331 case 1 :
299332 return deriveExecutionResultV1 (exec )
300- case 2 , 3 , 4 , 5 , 6 , 7 :
333+ case 2 , 3 , 4 , 5 , 6 , 7 , 8 :
301334 return deriveExecutionResultV2 (exec )
302335 }
303336 panic ("unreachable code" )
@@ -335,6 +368,17 @@ func deriveExecutionResultV2(exec flowExecutionResult) flow.Identifier {
335368 return flow .MakeID (dst )
336369}
337370
371+ func deriveExecutionReceiptHash (spork * config.Spork , receipt flow.ExecutionReceiptStub ) flow.Identifier {
372+ switch spork .Version {
373+ case 1 , 2 , 3 , 4 , 5 , 6 , 7 :
374+ return receipt .UnsignedExecutionReceiptStub .ID ()
375+ case 8 :
376+ return receipt .ID ()
377+ default :
378+ panic ("unreachable code" )
379+ }
380+ }
381+
338382func toFlowIdentifier (v []byte ) flow.Identifier {
339383 id := flow.Identifier {}
340384 copy (id [:], v )
@@ -433,13 +477,15 @@ func verifyBlockHash(spork *config.Spork, hash []byte, height uint64, hdr *entit
433477 sealHash := flow .MerkleRoot (sealIDs ... )
434478 var receiptIDs []flow.Identifier
435479 for _ , src := range block .ExecutionReceiptMetaList {
436- receipt := flow.ExecutionReceiptMeta {
437- ExecutorID : toFlowIdentifier (src .ExecutorId ),
438- ResultID : toFlowIdentifier (src .ResultId ),
480+ receipt := flow.ExecutionReceiptStub {
481+ UnsignedExecutionReceiptStub : flow.UnsignedExecutionReceiptStub {
482+ ExecutorID : toFlowIdentifier (src .ExecutorId ),
483+ ResultID : toFlowIdentifier (src .ResultId ),
484+ Spocks : toSignatureSlice (src .Spocks ),
485+ },
439486 ExecutorSignature : src .ExecutorSignature ,
440- Spocks : toSignatureSlice (src .Spocks ),
441487 }
442- receiptIDs = append (receiptIDs , receipt . ID ( ))
488+ receiptIDs = append (receiptIDs , deriveExecutionReceiptHash ( spork , receipt ))
443489 }
444490 receiptHash := flow .MerkleRoot (receiptIDs ... )
445491
@@ -477,7 +523,7 @@ func derivePayloadHash(
477523 switch sporkVersion {
478524 case 1 , 2 , 3 , 4 , 5 , 6 :
479525 return derivePayloadHashV1 (collectionHash , sealHash , receiptHash , resultHash )
480- case 7 :
526+ case 7 , 8 :
481527 return derivePayloadHashV7 (collectionHash , sealHash , receiptHash , resultHash , protocolStateId )
482528 default :
483529 panic ("unreachable code" )
0 commit comments