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

Implement starknet_getStorageProof RPC #2383

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions core/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
ContractNonce(addr *felt.Felt) (*felt.Felt, error)
ContractStorage(addr, key *felt.Felt) (*felt.Felt, error)
Class(classHash *felt.Felt) (*DeclaredClass, error)

ClassTrie() (*trie.Trie, error)
ContractTrie() (*trie.Trie, error)
ContractStorageTrie(addr *felt.Felt) (*trie.Trie, error)
}

type State struct {
Expand Down Expand Up @@ -124,6 +128,21 @@
return crypto.PoseidonArray(stateVersion, storageRoot, classesRoot), nil
}

func (s *State) ClassTrie() (*trie.Trie, error) {
// We don't need to call the closer function here because we are only reading the trie
tr, _, err := s.classesTrie()
return tr, err
}

func (s *State) ContractTrie() (*trie.Trie, error) {
tr, _, err := s.storage()
return tr, err
}

func (s *State) ContractStorageTrie(addr *felt.Felt) (*trie.Trie, error) {
return storage(addr, s.txn)

Check warning on line 143 in core/state.go

View check run for this annotation

Codecov / codecov/patch

core/state.go#L142-L143

Added lines #L142 - L143 were not covered by tests
}

// storage returns a [core.Trie] that represents the Starknet global state in the given Txn context.
func (s *State) storage() (*trie.Trie, func() error, error) {
return s.globalTrie(db.StateTrie, trie.NewTriePedersen)
Expand Down
15 changes: 15 additions & 0 deletions core/state_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"errors"

"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/core/trie"
"github.com/NethermindEth/juno/db"
)

var ErrHistoricalTrieNotSupported = errors.New("cannot support historical trie")

type stateSnapshot struct {
blockNumber uint64
state StateHistoryReader
Expand Down Expand Up @@ -87,3 +90,15 @@
}
return declaredClass, nil
}

func (s *stateSnapshot) ClassTrie() (*trie.Trie, error) {
return nil, ErrHistoricalTrieNotSupported

Check warning on line 95 in core/state_snapshot.go

View check run for this annotation

Codecov / codecov/patch

core/state_snapshot.go#L94-L95

Added lines #L94 - L95 were not covered by tests
}

func (s *stateSnapshot) ContractTrie() (*trie.Trie, error) {
return nil, ErrHistoricalTrieNotSupported

Check warning on line 99 in core/state_snapshot.go

View check run for this annotation

Codecov / codecov/patch

core/state_snapshot.go#L98-L99

Added lines #L98 - L99 were not covered by tests
}

func (s *stateSnapshot) ContractStorageTrie(addr *felt.Felt) (*trie.Trie, error) {
return nil, ErrHistoricalTrieNotSupported

Check warning on line 103 in core/state_snapshot.go

View check run for this annotation

Codecov / codecov/patch

core/state_snapshot.go#L102-L103

Added lines #L102 - L103 were not covered by tests
}
4 changes: 4 additions & 0 deletions core/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ func (t *Trie) Dump() {
t.dump(0, nil)
}

func (t *Trie) HashFn() crypto.HashFn {
return t.hash
}

// Try to print a [Trie] in a somewhat human-readable form
/*
Todo: create more meaningful representation of trie. In the current format string, storage is being
Expand Down
46 changes: 46 additions & 0 deletions mocks/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 0 additions & 62 deletions rpc/contract.go

This file was deleted.

174 changes: 0 additions & 174 deletions rpc/contract_test.go

This file was deleted.

Loading
Loading