Skip to content

Commit

Permalink
Add receipt and state diff commitment to BlockCommitments
Browse files Browse the repository at this point in the history
  • Loading branch information
IronGauntlets committed Jul 30, 2024
1 parent 0c279ac commit 808a669
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,31 @@ func TestStore(t *testing.T) {
})
}

func TestBlockCommitmetns(t *testing.T) {
chain := blockchain.New(pebble.NewMemTest(t), &utils.Mainnet)
client := feeder.NewTestClient(t, &utils.Mainnet)
gw := adaptfeeder.New(client)

b, err := gw.BlockByNumber(context.Background(), 0)
require.NoError(t, err)

su, err := gw.StateUpdate(context.Background(), 0)
require.NoError(t, err)

expectedCommitments := &core.BlockCommitments{
TransactionCommitment: new(felt.Felt).SetUint64(1),
EventCommitment: new(felt.Felt).SetUint64(2),
ReceiptCommitment: new(felt.Felt).SetUint64(3),
StateDiffCommitment: new(felt.Felt).SetUint64(4),
}

require.NoError(t, chain.Store(b, expectedCommitments, su, nil))

commitments, err := chain.BlockCommitmentsByNumber(0)
require.NoError(t, err)
require.Equal(t, expectedCommitments, commitments)
}

func TestTransactionAndReceipt(t *testing.T) {
chain := blockchain.New(pebble.NewMemTest(t), &utils.Mainnet)

Expand Down
3 changes: 3 additions & 0 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type BlockCommitments struct {
TransactionCommitment *felt.Felt
EventCommitment *felt.Felt
ReceiptCommitment *felt.Felt
StateDiffCommitment *felt.Felt
}

// VerifyBlockHash verifies the block hash. Due to bugs in Starknet alpha, not all blocks have
Expand Down Expand Up @@ -247,6 +248,8 @@ func Post0132Hash(b *Block, stateDiff *StateDiff) (*felt.Felt, *BlockCommitments
), &BlockCommitments{
TransactionCommitment: txCommitment,
EventCommitment: eCommitment,
ReceiptCommitment: rCommitment,
StateDiffCommitment: sdCommitment,
}, nil
}

Expand Down

0 comments on commit 808a669

Please sign in to comment.