Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 0.13.2 (hashes) #1964

Merged
merged 31 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3a78096
Update blockifier to 0.8.0-dev.0
kirugan Jun 19, 2024
a36430e
Update versioned_constants json files
kirugan Jun 21, 2024
b9e0386
Remove unused imports, added versioned constants for 0.13.1.1 to rust…
kirugan Jun 21, 2024
71f1cf8
Add concurrency_mode parameter to VM methods
kirugan Jun 21, 2024
b2fb322
Fix calls in tests, add StateMaps -> StateDiff conversion
kirugan Jun 23, 2024
e6c6b22
debugging issue
kirugan Jun 27, 2024
16bdc2a
Merge remote-tracking branch 'origin/main' into kirugan/blockifier-0.…
kirugan Jul 16, 2024
0cfd72a
Update blockifier, fix todos, update fgw response objects
kirugan Jul 16, 2024
96712c3
Draft impl of new block hashing scheme
kirugan Jul 17, 2024
ff3818f
Update blockifier to 0.8.0-rc.0
kirugan Jul 19, 2024
9190559
Merge remote-tracking branch 'origin/main' into kirugan/blockifier-0.…
kirugan Jul 19, 2024
34f07a8
Fix linter issues
kirugan Jul 19, 2024
a629a3b
Update cargo dependencies
kirugan Jul 19, 2024
521bbfd
Implement receipt Hash()
kirugan Jul 23, 2024
fb2aa5e
Fix receipt commitment
kirugan Jul 23, 2024
6e20a05
Merge remote-tracking branch 'origin/main' into kirugan/update-0.13.2…
kirugan Jul 29, 2024
9d5c4e9
Fix linter issues
kirugan Jul 29, 2024
0a4d0f9
Add new transaction commitment function
kirugan Jul 29, 2024
fbee124
Update hashing logic
kirugan Jul 29, 2024
7418da1
Refactor code
kirugan Jul 29, 2024
a8ad8ea
Fix StateDiff.Hash()
IronGauntlets Jul 30, 2024
233a578
Fix transaction commitment
IronGauntlets Jul 30, 2024
b1a9ca2
Fix review issues
IronGauntlets Jul 30, 2024
a380d7f
Refactor StateDiff's Hash() and Commitment()
IronGauntlets Jul 30, 2024
0c279ac
Remove nolint:exhaustruct
IronGauntlets Jul 30, 2024
278a97e
Add receipt and state diff commitment to BlockCommitments
IronGauntlets Jul 30, 2024
0138c37
Refactor trie, receipt, transaction and event commitment
IronGauntlets Jul 30, 2024
d6e8dbb
Small refactor
IronGauntlets Jul 30, 2024
89df932
Add 0.13.2 Block tests
IronGauntlets Jul 30, 2024
6937cc9
Refactor BlockHash calculation
IronGauntlets Jul 30, 2024
87506ca
Rename unit test
kirugan Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions adapters/p2p2core/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ func adaptExecutionResources(er *spec.Receipt_ExecutionResources) *core.Executio
Keccak: uint64(er.GetBuiltins().GetKeccak()),
Poseidon: uint64(er.GetBuiltins().GetPoseidon()),
SegmentArena: 0, // todo(kirill) recheck
// todo(kirill) set fields after spec update
AddMod: 0,
MulMod: 0,
RangeCheck96: 0,
},
DataAvailability: nil, // todo(kirill) recheck
MemoryHoles: uint64(er.MemoryHoles),
Steps: uint64(er.Steps), // todo SPEC 32 -> 64 bytes
TotalGasConsumed: nil, // todo(kirill) fill after spec update
}
}

Expand Down
12 changes: 12 additions & 0 deletions adapters/sn2core/sn2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ func AdaptTransactionReceipt(response *starknet.TransactionReceipt) *core.Transa
}
}

func adaptGasConsumed(response *starknet.GasConsumed) *core.GasConsumed {
if response == nil {
return nil
}

return &core.GasConsumed{
L1Gas: response.L1Gas,
L1DataGas: response.L1DataGas,
}
}

func AdaptEvent(response *starknet.Event) *core.Event {
if response == nil {
return nil
Expand All @@ -101,6 +112,7 @@ func AdaptExecutionResources(response *starknet.ExecutionResources) *core.Execut
MemoryHoles: response.MemoryHoles,
Steps: response.Steps,
DataAvailability: (*core.DataAvailability)(response.DataAvailability),
TotalGasConsumed: adaptGasConsumed(response.TotalGasConsumed),
}
}

Expand Down
4 changes: 4 additions & 0 deletions adapters/vm2core/vm2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ func AdaptExecutionResources(resources *vm.ExecutionResources) *core.ExecutionRe
Poseidon: resources.Poseidon,
SegmentArena: resources.SegmentArena,
Output: 0, // todo(kirill) recheck, add Output field to core?
AddMod: resources.AddMod,
MulMod: resources.MulMod,
RangeCheck96: resources.RangeCheck96,
},
MemoryHoles: resources.MemoryHoles,
Steps: resources.Steps,
DataAvailability: adaptDA(resources.DataAvailability),
TotalGasConsumed: nil, // todo: fill after 0.13.2
}
}

Expand Down
5 changes: 3 additions & 2 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Reader interface {

var (
ErrParentDoesNotMatchHead = errors.New("block's parent hash does not match head block hash")
supportedStarknetVersion = semver.MustParse("0.13.1")
supportedStarknetVersion = semver.MustParse("0.13.2")
)

func checkBlockVersion(protocolVersion string) error {
Expand Down Expand Up @@ -340,6 +340,7 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit
if err := verifyBlock(txn, block); err != nil {
return err
}

if err := core.NewState(txn).Update(block.Number, stateUpdate, newClasses); err != nil {
return err
}
Expand Down Expand Up @@ -636,7 +637,7 @@ func (b *Blockchain) SanityCheckNewHeight(block *core.Block, stateUpdate *core.S
return nil, err
}

return core.VerifyBlockHash(block, b.network)
return core.VerifyBlockHash(block, b.network, stateUpdate.StateDiff)
}

type txAndReceiptDBKey struct {
Expand Down
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 TestBlockCommitments(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
16 changes: 16 additions & 0 deletions clients/feeder/feeder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ func TestBlockHeaderV0131Unmarshal(t *testing.T) {
require.Equal(t, uint64(128), block.Receipts[0].ExecutionResources.DataAvailability.L1DataGas)
}

func TestBlockHeaderv0132Unmarshal(t *testing.T) {
client := feeder.NewTestClient(t, &utils.SepoliaIntegration)
block, err := client.Block(context.Background(), "35748")
require.NoError(t, err)

// Only focus on checking the new fields
require.Equal(t, utils.HexToFelt(t, "0x1ea2a9cfa3df5297d58c0a04d09d276bc68d40fe64701305bbe2ed8f417e869"), block.Hash)
require.Equal(t, utils.HexToFelt(t, "0x77140bef51bbb4d1932f17cc5081825ff18465a1df4440ca0429a4fa80f1dc5"), block.ParentHash)
require.Equal(t, utils.HexToFelt(t, "0x6f12628d21a8df7f158b631d801fc0dd20034b9e22eca255bddc0c1c1bc283f"), block.ReceiptCommitment)
require.Equal(t, utils.HexToFelt(t, "0x23587c54d590b57b8e25acbf1e1a422eb4cd104e95ee4a681021a6bb7456afa"), block.StateDiffCommitment)
require.Equal(t, uint64(6), block.StateDiffLength)
require.Equal(t, "0.13.2", block.Version)
require.Equal(t, uint64(117620), block.Receipts[0].ExecutionResources.TotalGasConsumed.L1Gas)
require.Equal(t, uint64(192), block.Receipts[0].ExecutionResources.TotalGasConsumed.L1DataGas)
}

func TestClassV0Unmarshal(t *testing.T) {
client := feeder.NewTestClient(t, &utils.Mainnet)

Expand Down
134 changes: 134 additions & 0 deletions clients/feeder/testdata/sepolia-integration/block/35748.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"block_hash": "0x1ea2a9cfa3df5297d58c0a04d09d276bc68d40fe64701305bbe2ed8f417e869",
"parent_block_hash": "0x77140bef51bbb4d1932f17cc5081825ff18465a1df4440ca0429a4fa80f1dc5",
"block_number": 35748,
"state_root": "0x38e01cbe2d5721780b2e1a478fd131f2ffcc099528dd2e1289f26b027127790",
"transaction_commitment": "0x54f43cf29b80cc83aef36f3195b73cb165ad12553eae147b4cce62adbf0b180",
"event_commitment": "0x12dfbe9dbbaba9c34b5a4c0ba622dcd8e2bb0264481c77f073008b59825a758",
"receipt_commitment": "0x6f12628d21a8df7f158b631d801fc0dd20034b9e22eca255bddc0c1c1bc283f",
"state_diff_commitment": "0x23587c54d590b57b8e25acbf1e1a422eb4cd104e95ee4a681021a6bb7456afa",
"state_diff_length": 6,
"status": "ACCEPTED_ON_L1",
"l1_da_mode": "BLOB",
"l1_gas_price": {
"price_in_wei": "0x7427e87c4",
"price_in_fri": "0x9346cee0949c"
},
"l1_data_gas_price": {
"price_in_wei": "0x3b095dc6",
"price_in_fri": "0x4ada914d823"
},
"transactions": [
{
"transaction_hash": "0x5ac644bbd6ae98d3be2d988439854e33f0961e24f349a63b43e16d172bfe747",
"version": "0x2",
"max_fee": "0x4f6ac5195e92e4",
"signature": [
"0x43ad3c7c77f7b7762db41ee9d33958813ee25efed77bc7199e08f4f40b1a59",
"0xfedb8715405faf28de29a07a3f3f06f078bac3fcb67ac7f5ae392e15a75921"
],
"nonce": "0xd",
"class_hash": "0x2fd9e122406490dc0f299f3070eaaa8df854d97ff81b47e91da32b8cd9d757a",
"compiled_class_hash": "0x55d1e0ee31f8f937fc75b37045129fbe0e01747baacb44b89d2d3d2c649117e",
"sender_address": "0x472aa8128e01eb0df145810c9511a92852d62a68ba8198ce5fa414e6337a365",
"type": "DECLARE"
},
{
"transaction_hash": "0x21bc0afe54123b946855e1bf9389d943313df5c5c396fbf0630234a44f6f592",
"version": "0x2",
"max_fee": "0xe6e9346a5ae75a",
"signature": [
"0x12a928f7042a66c5419fc5182da6879c357f013335d8b61d0ad774009afbb40",
"0x63479f4343dc2f068bff99fbbf0027250a672999fb5675cee1f2d1a64d33844"
],
"nonce": "0xe",
"class_hash": "0x19de7881922dbc95846b1bb9464dba34046c46470cfb5e18b4cb2892fd4111f",
"compiled_class_hash": "0x6506976af042088c9ea49e6cc9c9a12838ee6920bb989dce02f5c6467667367",
"sender_address": "0x472aa8128e01eb0df145810c9511a92852d62a68ba8198ce5fa414e6337a365",
"type": "DECLARE"
}
],
"timestamp": 1720426817,
"sequencer_address": "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
"transaction_receipts": [
{
"execution_status": "SUCCEEDED",
"transaction_index": 0,
"transaction_hash": "0x5ac644bbd6ae98d3be2d988439854e33f0961e24f349a63b43e16d172bfe747",
"l2_to_l1_messages": [],
"events": [
{
"from_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"keys": [
"0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"
],
"data": [
"0x472aa8128e01eb0df145810c9511a92852d62a68ba8198ce5fa414e6337a365",
"0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
"0xd07af45c84550",
"0x0"
]
}
],
"execution_resources": {
"n_steps": 3950,
"builtin_instance_counter": {
"pedersen_builtin": 16,
"range_check_builtin": 157,
"ecdsa_builtin": 1,
"poseidon_builtin": 4
},
"n_memory_holes": 0,
"data_availability": {
"l1_gas": 0,
"l1_data_gas": 192
},
"total_gas_consumed": {
"l1_gas": 117620,
"l1_data_gas": 192
}
},
"actual_fee": "0xd07af45c84550"
},
{
"execution_status": "SUCCEEDED",
"transaction_index": 1,
"transaction_hash": "0x21bc0afe54123b946855e1bf9389d943313df5c5c396fbf0630234a44f6f592",
"l2_to_l1_messages": [],
"events": [
{
"from_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"keys": [
"0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"
],
"data": [
"0x472aa8128e01eb0df145810c9511a92852d62a68ba8198ce5fa414e6337a365",
"0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
"0x471426f16c4330",
"0x0"
]
}
],
"execution_resources": {
"n_steps": 3950,
"builtin_instance_counter": {
"poseidon_builtin": 4,
"ecdsa_builtin": 1,
"range_check_builtin": 157,
"pedersen_builtin": 16
},
"n_memory_holes": 0,
"data_availability": {
"l1_gas": 0,
"l1_data_gas": 192
},
"total_gas_consumed": {
"l1_gas": 641644,
"l1_data_gas": 192
}
},
"actual_fee": "0x471426f16c4330"
}
],
"starknet_version": "0.13.2"
}
Loading
Loading