Skip to content

Commit d410f3c

Browse files
committed
refactor
1 parent 0a05b6c commit d410f3c

File tree

9 files changed

+621
-100
lines changed

9 files changed

+621
-100
lines changed

sc/universal_accumulator/core.go renamed to sc/universal_accumulator/cgo_bridge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func addHashedElementsWrapper(accumulator unsafe.Pointer, flatHashes []byte, cou
3737
// Use C.add_hashed_elements directly
3838
ret := C.add_hashed_elements((*C.t_state)(accumulator), (*C.uchar)(unsafe.Pointer(&flatHashes[0])), C.int(count))
3939
if ret != 0 {
40-
return errors.New("C.add_hashed_elements failed, possibly due to memory allocation error")
40+
return errors.New("add_hashed_elements failed, possibly due to memory allocation error")
4141
}
4242

4343
return nil
@@ -51,7 +51,7 @@ func batchDelHashedElementsWrapper(accumulator unsafe.Pointer, flatHashes []byte
5151
// Use the existing batch_del_hashed_elements C function
5252
ret := C.batch_del_hashed_elements((*C.t_state)(accumulator), (*C.uchar)(unsafe.Pointer(&flatHashes[0])), C.int(count))
5353
if ret != 0 {
54-
return errors.New("C.batch_del_hashed_elements failed, possibly due to memory allocation error")
54+
return errors.New("batch_del_hashed_elements failed, possibly due to memory allocation error")
5555
}
5656

5757
return nil

sc/universal_accumulator/api.go renamed to sc/universal_accumulator/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
)
99

1010
// UniversalAccumulator provides the main interface for the Universal Accumulator.
11-
// This follows the same patterns as other storage APIs in the repo.
1211
type UniversalAccumulator struct {
1312
engine *AccumulatorEngine
1413
mu sync.RWMutex
File renamed without changes.

sc/universal_accumulator/errors.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package universalaccumulator
2+
3+
import "errors"
4+
5+
// Core accumulator errors
6+
var (
7+
// ErrNotInitialized indicates the accumulator is not properly initialized
8+
ErrNotInitialized = errors.New("accumulator not initialized")
9+
10+
// ErrInvalidFactor indicates an invalid factor was provided
11+
ErrInvalidFactor = errors.New("invalid factor")
12+
13+
// ErrFactorSize indicates the factor size is incorrect
14+
ErrFactorSize = errors.New("empty factor")
15+
16+
// ErrAlreadyInitialized indicates the accumulator is already initialized
17+
ErrAlreadyInitialized = errors.New("accumulator already initialized")
18+
)
19+
20+
// Witness and proof errors
21+
var (
22+
// ErrWitnessGeneration indicates failure to generate a witness
23+
ErrWitnessGeneration = errors.New("failed to generate witness")
24+
25+
// ErrWitnessVerification indicates failure to verify a witness
26+
ErrWitnessVerification = errors.New("failed to verify witness")
27+
28+
// ErrInvalidWitness indicates the witness is invalid or corrupted
29+
ErrInvalidWitness = errors.New("invalid witness")
30+
31+
// ErrElementHashSize indicates incorrect element hash size
32+
ErrElementHashSize = errors.New("element hash must be 32 bytes")
33+
)
34+
35+
// State management errors
36+
var (
37+
// ErrStateCalculation indicates failure to calculate state
38+
ErrStateCalculation = errors.New("failed to calculate state")
39+
40+
// ErrStateRestore indicates failure to restore state from factor
41+
ErrStateRestore = errors.New("failed to restore state from factor")
42+
43+
// ErrSnapshotCreation indicates failure to create snapshot
44+
ErrSnapshotCreation = errors.New("failed to create snapshot")
45+
46+
// ErrSnapshotRestore indicates failure to restore from snapshot
47+
ErrSnapshotRestore = errors.New("failed to restore from snapshot")
48+
)
49+
50+
// Storage and persistence errors
51+
var (
52+
// ErrFactorNotFound indicates the factor for given height was not found
53+
ErrFactorNotFound = errors.New("factor not found")
54+
55+
// ErrRootNotFound indicates the root for given height was not found
56+
ErrRootNotFound = errors.New("root not found")
57+
58+
// ErrStorageValueNotFound indicates the storage value was not found
59+
ErrStorageValueNotFound = errors.New("storage value not found")
60+
61+
// ErrInvalidHeight indicates an invalid block height
62+
ErrInvalidHeight = errors.New("invalid block height")
63+
)
64+
65+
// Proof API errors
66+
var (
67+
// ErrInvalidAddress indicates an invalid address format
68+
ErrInvalidAddress = errors.New("invalid address")
69+
70+
// ErrInvalidStorageKey indicates an invalid storage key format
71+
ErrInvalidStorageKey = errors.New("invalid storage key")
72+
73+
// ErrProofGeneration indicates failure to generate proof
74+
ErrProofGeneration = errors.New("failed to generate proof")
75+
76+
// ErrProofVerification indicates failure to verify proof
77+
ErrProofVerification = errors.New("failed to verify proof")
78+
79+
// ErrRootMismatch indicates proof root doesn't match consensus root
80+
ErrRootMismatch = errors.New("proof root doesn't match consensus root")
81+
)
82+
83+
// CGO and C library errors
84+
var (
85+
// ErrCGOCall indicates a CGO function call failed
86+
ErrCGOCall = errors.New("CGO function call failed")
87+
88+
// ErrRelicInit indicates RELIC library initialization failed
89+
ErrRelicInit = errors.New("RELIC library initialization failed")
90+
91+
// ErrMemoryAllocation indicates memory allocation failed
92+
ErrMemoryAllocation = errors.New("memory allocation failed")
93+
)

sc/universal_accumulator/universal_accumulator_test.go renamed to sc/universal_accumulator/integration_test.go

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -624,103 +624,6 @@ func TestWitnessValidationAcrossUpdates(t *testing.T) {
624624
t.Logf("Witness validation across updates successful")
625625
}
626626

627-
// Benchmark tests for performance measurement
628-
629-
// BenchmarkAddEntries_1K benchmarks 1K entry addition.
630-
func BenchmarkAddEntries_1K(b *testing.B) {
631-
benchmarkAddEntries(b, 1000)
632-
}
633-
634-
// BenchmarkAddEntries_10K benchmarks 10K entry addition.
635-
func BenchmarkAddEntries_10K(b *testing.B) {
636-
benchmarkAddEntries(b, 10000)
637-
}
638-
639-
// BenchmarkAddEntries_100K benchmarks 100K entry addition.
640-
func BenchmarkAddEntries_100K(b *testing.B) {
641-
benchmarkAddEntries(b, 100000)
642-
}
643-
644-
// benchmarkAddEntries runs addition benchmark.
645-
func benchmarkAddEntries(b *testing.B, numEntries int) {
646-
acc, err := NewUniversalAccumulator(10)
647-
if err != nil {
648-
b.Fatalf("Failed to create accumulator: %v", err)
649-
}
650-
defer acc.Close()
651-
652-
entries := generateTestEntries(numEntries)
653-
654-
b.ResetTimer()
655-
for i := range b.N {
656-
_ = i // unused loop variable
657-
// Reset accumulator state for each iteration
658-
err = acc.Reset()
659-
if err != nil {
660-
b.Fatalf("Failed to reset accumulator: %v", err)
661-
}
662-
663-
err = acc.AddEntries(entries)
664-
if err != nil {
665-
b.Fatalf("Failed to add entries: %v", err)
666-
}
667-
}
668-
}
669-
670-
// BenchmarkRootCalculation benchmarks root computation.
671-
func BenchmarkRootCalculation(b *testing.B) {
672-
acc, err := NewUniversalAccumulator(10)
673-
if err != nil {
674-
b.Fatalf("Failed to create accumulator: %v", err)
675-
}
676-
defer acc.Close()
677-
678-
// Add test data
679-
entries := generateTestEntries(10000)
680-
err = acc.AddEntries(entries)
681-
if err != nil {
682-
b.Fatalf("Failed to add entries: %v", err)
683-
}
684-
685-
b.ResetTimer()
686-
for i := range b.N {
687-
_ = i // unused loop variable
688-
_, err = acc.CalculateRoot()
689-
if err != nil {
690-
b.Fatalf("Failed to calculate root: %v", err)
691-
}
692-
}
693-
}
694-
695-
// BenchmarkWitnessOperations benchmarks witness issuance and verification.
696-
func BenchmarkWitnessOperations(b *testing.B) {
697-
acc, err := NewUniversalAccumulator(10)
698-
if err != nil {
699-
b.Fatalf("Failed to create accumulator: %v", err)
700-
}
701-
defer acc.Close()
702-
703-
// Add test data
704-
entries := generateTestEntries(1000)
705-
err = acc.AddEntries(entries)
706-
if err != nil {
707-
b.Fatalf("Failed to add entries: %v", err)
708-
}
709-
710-
testKey := "key_500"
711-
testValue := "value_500" // Corresponding value
712-
713-
b.ResetTimer()
714-
for i := range b.N {
715-
_ = i // unused loop variable
716-
witness, err := acc.IssueWitness([]byte(testKey), []byte(testValue), true)
717-
if err != nil {
718-
b.Fatalf("Failed to issue witness: %v", err)
719-
}
720-
witness.Free()
721-
}
722-
}
723-
724627
// TestAccumulatorEngineErrorPaths tests error paths in AccumulatorEngine.
725628
func TestAccumulatorEngineErrorPaths(t *testing.T) {
726629
// Test uninitialized engine

0 commit comments

Comments
 (0)