Skip to content

Commit

Permalink
Add receipt commitment calculation in post07Hash function (#2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan authored Sep 24, 2024
1 parent aa241f1 commit 72535cc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,20 @@ func post07Hash(b *Block, overrideSeqAddr *felt.Felt) (*felt.Felt, *BlockCommitm
}

wg := conc.NewWaitGroup()
var txCommitment, eCommitment *felt.Felt
var tErr, eErr error
var txCommitment, eCommitment, rCommitment *felt.Felt
var tErr, eErr, rErr error

wg.Go(func() {
txCommitment, tErr = transactionCommitmentPedersen(b.Transactions, b.Header.ProtocolVersion)
})
wg.Go(func() {
eCommitment, eErr = eventCommitmentPedersen(b.Receipts)
})
wg.Go(func() {
// even though rCommitment is not required for pre 0.13.2 hash
// we need to calculate it for BlockCommitments that will be stored in db
rCommitment, rErr = receiptCommitment(b.Receipts)
})
wg.Wait()

if tErr != nil {
Expand All @@ -258,6 +263,9 @@ func post07Hash(b *Block, overrideSeqAddr *felt.Felt) (*felt.Felt, *BlockCommitm
if eErr != nil {
return nil, nil, eErr
}
if rErr != nil {
return nil, nil, rErr
}

// Unlike the pre07Hash computation, we exclude the chain
// id and replace the zero felt with the actual values for:
Expand All @@ -277,7 +285,7 @@ func post07Hash(b *Block, overrideSeqAddr *felt.Felt) (*felt.Felt, *BlockCommitm
&felt.Zero, // reserved: protocol version
&felt.Zero, // reserved: extra data
b.ParentHash, // parent block hash
), &BlockCommitments{TransactionCommitment: txCommitment, EventCommitment: eCommitment}, nil
), &BlockCommitments{TransactionCommitment: txCommitment, EventCommitment: eCommitment, ReceiptCommitment: rCommitment}, nil
}

func MarshalBlockNumber(blockNumber uint64) []byte {
Expand Down

0 comments on commit 72535cc

Please sign in to comment.