Skip to content

Commit

Permalink
Use digest instead of array
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Sep 27, 2024
1 parent fbfd89d commit be4f41c
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions core/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,42 +70,42 @@ func (c *Cairo0Class) Hash() (*felt.Felt, error) {
return nil, err

Check warning on line 70 in core/class.go

View check run for this annotation

Codecov / codecov/patch

core/class.go#L70

Added line #L70 was not covered by tests
}

externalEntryPointElements := make([]*felt.Felt, 0, len(definition.EntryPoints.External)*2)
l1HandlerEntryPointElements := make([]*felt.Felt, 0, len(definition.EntryPoints.L1Handler)*2)
constructorEntryPointElements := make([]*felt.Felt, 0, len(definition.EntryPoints.Constructor)*2)
builtInsHashElements := make([]*felt.Felt, 0, len(program.Builtins))
dataHashElements := make([]*felt.Felt, 0, len(program.Data))

// Use goroutines to parallelize hash computations
var wg sync.WaitGroup
var externalEntryPointHash, l1HandlerEntryPointHash, constructorEntryPointHash, builtInsHash, dataHash *felt.Felt
var hintedClassHash *felt.Felt
var hintedClassHashErr error

externalEntryPointDigest := crypto.PedersenDigest{}
l1HandlerEntryPointDigest := crypto.PedersenDigest{}
constructorEntryPointDigest := crypto.PedersenDigest{}
builtInsDigest := crypto.PedersenDigest{}
dataDigest := crypto.PedersenDigest{}

wg.Add(6) //nolint:mnd

go func() {
defer wg.Done()
for _, ep := range definition.EntryPoints.External {
externalEntryPointElements = append(externalEntryPointElements, ep.Selector, ep.Offset)
externalEntryPointDigest.Update(ep.Selector, ep.Offset)
}
externalEntryPointHash = crypto.PedersenArray(externalEntryPointElements...)
externalEntryPointHash = externalEntryPointDigest.Finish()
}()

go func() {
defer wg.Done()
for _, ep := range definition.EntryPoints.L1Handler {
l1HandlerEntryPointElements = append(l1HandlerEntryPointElements, ep.Selector, ep.Offset)
l1HandlerEntryPointDigest.Update(ep.Selector, ep.Offset)
}
l1HandlerEntryPointHash = crypto.PedersenArray(l1HandlerEntryPointElements...)
l1HandlerEntryPointHash = l1HandlerEntryPointDigest.Finish()
}()

go func() {
defer wg.Done()
for _, ep := range definition.EntryPoints.Constructor {
constructorEntryPointElements = append(constructorEntryPointElements, ep.Selector, ep.Offset)
constructorEntryPointDigest.Update(ep.Selector, ep.Offset)
}
constructorEntryPointHash = crypto.PedersenArray(constructorEntryPointElements...)
constructorEntryPointHash = constructorEntryPointDigest.Finish()
}()

go func() {
Expand All @@ -116,9 +116,9 @@ func (c *Cairo0Class) Hash() (*felt.Felt, error) {
if err != nil {
return

Check warning on line 117 in core/class.go

View check run for this annotation

Codecov / codecov/patch

core/class.go#L117

Added line #L117 was not covered by tests
}
builtInsHashElements = append(builtInsHashElements, builtInFelt)
builtInsDigest.Update(builtInFelt)
}
builtInsHash = crypto.PedersenArray(builtInsHashElements...)
builtInsHash = builtInsDigest.Finish()
}()

go func() {
Expand All @@ -133,9 +133,9 @@ func (c *Cairo0Class) Hash() (*felt.Felt, error) {
if err != nil {
return

Check warning on line 134 in core/class.go

View check run for this annotation

Codecov / codecov/patch

core/class.go#L134

Added line #L134 was not covered by tests
}
dataHashElements = append(dataHashElements, dataFelt)
dataDigest.Update(dataFelt)
}
dataHash = crypto.PedersenArray(dataHashElements...)
dataHash = dataDigest.Finish()
}()

wg.Wait()
Expand Down

0 comments on commit be4f41c

Please sign in to comment.