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

Miscellaneous changes #2346

Merged
merged 4 commits into from
Dec 24, 2024
Merged
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
4 changes: 2 additions & 2 deletions clients/feeder/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func NopBackoff(d time.Duration) time.Duration {
}

// NewTestClient returns a client and a function to close a test server.
func NewTestClient(t *testing.T, network *utils.Network) *Client {
func NewTestClient(t testing.TB, network *utils.Network) *Client {
srv := newTestServer(t, network)
t.Cleanup(srv.Close)
ua := "Juno/v0.0.1-test Starknet Implementation"
Expand All @@ -117,7 +117,7 @@ func NewTestClient(t *testing.T, network *utils.Network) *Client {
return c
}

func newTestServer(t *testing.T, network *utils.Network) *httptest.Server {
func newTestServer(t testing.TB, network *utils.Network) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
queryMap, err := url.ParseQuery(r.URL.RawQuery)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions core/crypto/pedersen_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func PedersenArray(elems ...*felt.Felt) *felt.Felt {
// [Pedersen hash]: https://docs.starknet.io/architecture-and-concepts/cryptography/hash-functions/#pedersen_hash
func Pedersen(a, b *felt.Felt) *felt.Felt {
hash := pedersenhash.Pedersen(a.Impl(), b.Impl())
return felt.NewFelt(&hash)
f := felt.New(hash)
return &f
}

var _ Digest = (*PedersenDigest)(nil)
Expand All @@ -39,5 +40,6 @@ func (d *PedersenDigest) Update(elems ...*felt.Felt) Digest {

func (d *PedersenDigest) Finish() *felt.Felt {
d.digest = pedersenhash.Pedersen(&d.digest, new(fp.Element).SetUint64(d.count))
return felt.NewFelt(&d.digest)
f := felt.New(d.digest)
return &f
}
2 changes: 1 addition & 1 deletion core/crypto/poseidon_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func setRoundKeys() {
}
}

var _ Digest = (*PedersenDigest)(nil)
var _ Digest = (*PoseidonDigest)(nil)

type PoseidonDigest struct {
state [3]felt.Felt
Expand Down
6 changes: 3 additions & 3 deletions core/felt/felt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type Felt struct {
val fp.Element
}

func NewFelt(element *fp.Element) *Felt {
return &Felt{
val: *element,
func New(element fp.Element) Felt {
return Felt{
val: element,
}
}

Expand Down
12 changes: 12 additions & 0 deletions core/state_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ func TestStateDiffHash(t *testing.T) {
}
}

func BenchmarkStateDiffHash(b *testing.B) {
client := feeder.NewTestClient(b, &utils.SepoliaIntegration)
gw := adaptfeeder.New(client)
su, err := gw.StateUpdate(context.Background(), 38748)
require.NoError(b, err)

b.ResetTimer()
for n := 0; n < b.N; n++ {
su.StateDiff.Hash()
}
}

func TestStateDiffLength(t *testing.T) {
client := feeder.NewTestClient(t, &utils.Sepolia)
gw := adaptfeeder.New(client)
Expand Down
Loading