Skip to content

Commit

Permalink
add storage_root to leaf data
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Jan 16, 2025
1 parent 147e486 commit 4020141
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 12 additions & 5 deletions rpc/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *StorageProofResult) String() string {
result.WriteString(" Leaves:\n")
for i, leaf := range s.ContractsProof.LeavesData {
if leaf != nil {
result.WriteString(fmt.Sprintf(" [%d] Nonce: %v, ClassHash: %v\n", i, leaf.Nonce, leaf.ClassHash))
result.WriteString(fmt.Sprintf(" [%d] Nonce: %v, ClassHash: %v Root: %v\n", i, leaf.Nonce, leaf.ClassHash, leaf.StorageRoot))
}

Check warning on line 104 in rpc/storage.go

View check run for this annotation

Codecov / codecov/patch

rpc/storage.go#L100-L104

Added lines #L100 - L104 were not covered by tests
}
}
Expand Down Expand Up @@ -221,6 +221,11 @@ func getContractProof(tr *trie.Trie, state core.StateReader, contracts []felt.Fe
return nil, err
}

Check warning on line 222 in rpc/storage.go

View check run for this annotation

Codecov / codecov/patch

rpc/storage.go#L221-L222

Added lines #L221 - L222 were not covered by tests

root, err := tr.Root()
if err != nil {
return nil, err
}

Check warning on line 227 in rpc/storage.go

View check run for this annotation

Codecov / codecov/patch

rpc/storage.go#L226-L227

Added lines #L226 - L227 were not covered by tests

nonce, err := state.ContractNonce(&contract)
if err != nil {
if errors.Is(err, db.ErrKeyNotFound) { // contract does not exist, skip getting leaf data
Expand All @@ -235,8 +240,9 @@ func getContractProof(tr *trie.Trie, state core.StateReader, contracts []felt.Fe
}

Check warning on line 240 in rpc/storage.go

View check run for this annotation

Codecov / codecov/patch

rpc/storage.go#L239-L240

Added lines #L239 - L240 were not covered by tests

contractLeavesData[i] = &LeafData{
Nonce: nonce,
ClassHash: classHash,
Nonce: nonce,
ClassHash: classHash,
StorageRoot: root,
}
}

Expand Down Expand Up @@ -342,8 +348,9 @@ type HashToNode struct {
}

type LeafData struct {
Nonce *felt.Felt `json:"nonce"`
ClassHash *felt.Felt `json:"class_hash"`
Nonce *felt.Felt `json:"nonce"`
ClassHash *felt.Felt `json:"class_hash"`
StorageRoot *felt.Felt `json:"storage_root"`
}

type ContractProof struct {
Expand Down
7 changes: 5 additions & 2 deletions rpc/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,12 @@ func TestStorageProof_VerifyPathfinderResponse(t *testing.T) {
{
Nonce: utils.HexToFelt(t, "0x0"),
ClassHash: utils.HexToFelt(t, "0x772164c9d6179a89e7f1167f099219f47d752304b16ed01f081b6e0b45c93c3"),
// TODO: get the storage root
},
{
Nonce: utils.HexToFelt(t, "0x0"),
ClassHash: utils.HexToFelt(t, "0x78401746828463e2c3f92ebb261fc82f7d4d4c8d9a80a356c44580dab124cb0"),
// TODO: get the storage root
},
},
Nodes: []*rpc.HashToNode{
Expand Down Expand Up @@ -652,8 +654,9 @@ func TestStorageProof_StorageRoots(t *testing.T) {
ContractsProof: &rpc.ContractProof{
LeavesData: []*rpc.LeafData{
{
Nonce: utils.HexToFelt(t, "0x0"),
ClassHash: utils.HexToFelt(t, "0x10455c752b86932ce552f2b0fe81a880746649b9aee7e0d842bf3f52378f9f8"),
Nonce: utils.HexToFelt(t, "0x0"),
ClassHash: utils.HexToFelt(t, "0x10455c752b86932ce552f2b0fe81a880746649b9aee7e0d842bf3f52378f9f8"),
StorageRoot: utils.HexToFelt(t, "0x3ceee867d50b5926bb88c0ec7e0b9c20ae6b537e74aac44b8fcf6bb6da138d9"),
},
},
Nodes: []*rpc.HashToNode{
Expand Down

0 comments on commit 4020141

Please sign in to comment.