Skip to content

Commit 7febab5

Browse files
committed
cleanup
Signed-off-by: Angelo De Caro <[email protected]>
1 parent 802b60c commit 7febab5

File tree

24 files changed

+1694
-1026
lines changed

24 files changed

+1694
-1026
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ tokengen:
139139
traceinspector:
140140
@go install ./token/services/benchmark/cmd/traceinspector
141141

142+
.PHONY: memcheck
143+
memcheck:
144+
@go install ./token/services/benchmark/cmd/memcheck
145+
142146
.PHONY: idemixgen
143147
txgen:
144148
@go install github.com/IBM/idemix/tools/idemixgen

cmd/tokengen/cobra/pp/common/common_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package common
88

99
import (
10+
"bytes"
1011
"os"
1112
"path/filepath"
1213
"testing"
@@ -45,11 +46,11 @@ func TestLoadExtras(t *testing.T) {
4546
t.Errorf("expected 2 entries, got %d", len(result))
4647
}
4748

48-
if string(result["foo"]) != string(file1Content) {
49+
if !bytes.Equal(result["foo"], file1Content) {
4950
t.Errorf("expected %q for foo, got %q", string(file1Content), string(result["foo"]))
5051
}
5152

52-
if string(result["bar"]) != string(file2Content) {
53+
if !bytes.Equal(result["bar"], file2Content) {
5354
t.Errorf("expected %q for bar, got %q", string(file2Content), string(result["bar"]))
5455
}
5556
})
@@ -144,7 +145,7 @@ func TestLoadExtras(t *testing.T) {
144145
t.Fatalf("expected no error, got: %v", err)
145146
}
146147

147-
if string(result["mykey"]) != string(fileContent) {
148+
if !bytes.Equal(result["mykey"], fileContent) {
148149
t.Errorf("expected %q, got %q", string(fileContent), string(result["mykey"]))
149150
}
150151
})

cmd/tokengen/cobra/pp/fabtokenv1/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type GeneratorArgs struct {
9595

9696
// Gen generates the public parameters for the FabToken driver
9797
func Gen(args *GeneratorArgs) ([]byte, error) {
98-
// PublicParamsBy
98+
// Setup
9999
ver := setupv1.ProtocolV1
100100
if Version != 0 {
101101
ver = driver.TokenDriverVersion(Version)

cmd/tokengen/cobra/pp/zkatdlognoghv1/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func Gen(args *GeneratorArgs) ([]byte, error) {
123123
return nil, errors.Wrap(err, "failed to load issuer public key")
124124
}
125125

126-
// PublicParamsBy
126+
// Setup
127127
// TODO: update the curve here
128128
curveID := math3.BN254
129129
if args.Aries {

docs/benchmark/dlognogh/dlognogh.md

Lines changed: 62 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ This allows the analyst to understand if shared data structures are actual bottl
120120
It uses a custom-made runner whose documentation can be found [here](../../../token/services/benchmark/runner.md).
121121

122122
```shell
123-
go test ./token/core/zkatdlog/nogh/v1/transfer -test.run=TestParallelBenchmarkSender -test.v -test.benchmem -test.timeout 0 -bits="32" -curves="BN254" -num_inputs="2" -num_outputs="2" -workers="1,10" -duration="10s" | tee bench.txt
123+
go test ./token/core/zkatdlog/nogh/v1/transfer -test.run=TestParallelBenchmarkSender -test.v -test.timeout 0 -bits="32" -curves="BN254" -num_inputs="2" -num_outputs="2" -workers="NumCPU" -duration="10s" -setup_samples=128 | tee bench.txt
124124
```
125125

126126
The test supports the following flags:
@@ -137,120 +137,82 @@ The test supports the following flags:
137137
a comma-separate list of number of outputs (1,2,3,...)
138138
-workers string
139139
a comma-separate list of workers (1,2,3,...,NumCPU), where NumCPU is converted to the number of available CPUs
140+
-profile bool
141+
write pprof profiles to file
142+
-setup_samples uint
143+
number of setup samples, 0 disables it
140144
```
141145

142146
### Results
143147

144-
```go
148+
```shell
145149
=== RUN TestParallelBenchmarkSender
146-
=== RUN TestParallelBenchmarkSender/Setup(bits_32,_curve_BN254,_#i_2,_#o_2)_with_1_workers
147-
Metric Value Description
148-
------ ----- -----------
149-
Workers 1
150-
Total Ops 168 (Low Sample Size)
151-
Duration 10.023390959s (Good Duration)
152-
Real Throughput 16.76/s Observed Ops/sec (Wall Clock)
153-
Pure Throughput 17.77/s Theoretical Max (Low Overhead)
154-
155-
Latency Distribution:
156-
Min 55.180375ms
157-
P50 (Median) 55.945812ms
158-
Average 56.290356ms
159-
P95 58.108814ms
160-
P99 58.758087ms
161-
Max 59.089958ms (Stable Tail)
162-
163-
Stability Metrics:
164-
Std Dev 898.087µs
165-
IQR 1.383083ms Interquartile Range
166-
Jitter 590.076µs Avg delta per worker
167-
CV 1.60% Excellent Stability (<5%)
168-
169-
Memory 1301420 B/op Allocated bytes per operation
170-
Allocs 18817 allocs/op Allocations per operation
171-
172-
Latency Heatmap (Dynamic Range):
173-
Range Freq Distribution Graph
174-
55.180375ms-55.369563ms 17 █████████████████████████ (10.1%)
175-
55.369563ms-55.5594ms 18 ██████████████████████████ (10.7%)
176-
55.5594ms-55.749887ms 27 ████████████████████████████████████████ (16.1%)
177-
55.749887ms-55.941028ms 20 █████████████████████████████ (11.9%)
178-
55.941028ms-56.132824ms 13 ███████████████████ (7.7%)
179-
56.132824ms-56.325277ms 9 █████████████ (5.4%)
180-
56.325277ms-56.51839ms 4 █████ (2.4%)
181-
56.51839ms-56.712165ms 6 ████████ (3.6%)
182-
56.712165ms-56.906605ms 9 █████████████ (5.4%)
183-
56.906605ms-57.101711ms 13 ███████████████████ (7.7%)
184-
57.101711ms-57.297486ms 10 ██████████████ (6.0%)
185-
57.297486ms-57.493933ms 3 ████ (1.8%)
186-
57.493933ms-57.691053ms 3 ████ (1.8%)
187-
57.691053ms-57.888849ms 4 █████ (2.4%)
188-
57.888849ms-58.087323ms 3 ████ (1.8%)
189-
58.087323ms-58.286478ms 2 ██ (1.2%)
190-
58.286478ms-58.486315ms 2 ██ (1.2%)
191-
58.486315ms-58.686837ms 2 ██ (1.2%)
192-
58.686837ms-58.888047ms 2 ██ (1.2%)
193-
58.888047ms-59.089958ms 1 █ (0.6%)
194-
195-
--- Analysis & Recommendations ---
196-
[WARN] Low sample size (168). Results may not be statistically significant. Run for longer.
197-
[INFO] High Allocations (18817/op). This will trigger frequent GC cycles and increase Max Latency.
198-
----------------------------------
199150
=== RUN TestParallelBenchmarkSender/Setup(bits_32,_curve_BN254,_#i_2,_#o_2)_with_10_workers
200-
Metric Value Description
201-
------ ----- -----------
202-
Workers 10
203-
Total Ops 1232 (Low Sample Size)
204-
Duration 10.070877291s (Good Duration)
205-
Real Throughput 122.33/s Observed Ops/sec (Wall Clock)
206-
Pure Throughput 130.12/s Theoretical Max (Low Overhead)
151+
Metric Value Description
152+
------ ----- -----------
153+
Workers 10
154+
Total Ops 1230 (Low Sample Size)
155+
Duration 10.068s (Good Duration)
156+
Real Throughput 122.17/s Observed Ops/sec (Wall Clock)
157+
Pure Throughput 123.04/s Theoretical Max (Low Overhead)
207158

208159
Latency Distribution:
209-
Min 61.2545ms
210-
P50 (Median) 75.461375ms
211-
Average 76.852256ms
212-
P95 93.50851ms
213-
P99 106.198982ms
214-
Max 144.872375ms (Stable Tail)
160+
Min 59.895916ms
161+
P50 (Median) 77.717333ms
162+
Average 81.27214ms
163+
P95 112.28194ms
164+
P99 137.126207ms
165+
P99.9 189.117473ms
166+
Max 215.981417ms (Stable Tail)
215167

216168
Stability Metrics:
217-
Std Dev 9.28799ms
218-
IQR 10.909229ms Interquartile Range
219-
Jitter 9.755984ms Avg delta per worker
220-
CV 12.09% Moderate Variance (10-20%)
221-
222-
Memory 1282384 B/op Allocated bytes per operation
223-
Allocs 18668 allocs/op Allocations per operation
169+
Std Dev 16.96192ms
170+
IQR 19.050834ms Interquartile Range
171+
Jitter 15.937043ms Avg delta per worker
172+
CV 20.87% Unstable (>20%) - Result is Noisy
173+
174+
System Health & Reliability:
175+
Error Rate 0.0000% (100% Success) (0 errors)
176+
Memory 1159374 B/op Allocated bytes per operation
177+
Allocs 17213 allocs/op Allocations per operation
178+
Alloc Rate 133.20 MB/s Memory pressure on system
179+
GC Overhead 1.27% (High GC Pressure)
180+
GC Pause 127.435871ms Total Stop-The-World time
181+
GC Cycles 264 Full garbage collection cycles
224182

225183
Latency Heatmap (Dynamic Range):
226184
Range Freq Distribution Graph
227-
61.2545ms-63.948502ms 36 ███████ (2.9%)
228-
63.948502ms-66.760987ms 86 █████████████████ (7.0%)
229-
66.760987ms-69.697167ms 152 ███████████████████████████████ (12.3%)
230-
69.697167ms-72.762481ms 181 █████████████████████████████████████ (14.7%)
231-
72.762481ms-75.962609ms 195 ████████████████████████████████████████ (15.8%)
232-
75.962609ms-79.303481ms 179 ████████████████████████████████████ (14.5%)
233-
79.303481ms-82.791286ms 152 ███████████████████████████████ (12.3%)
234-
82.791286ms-86.432486ms 94 ███████████████████ (7.6%)
235-
86.432486ms-90.233828ms 59 ████████████ (4.8%)
236-
90.233828ms-94.202355ms 40 ████████ (3.2%)
237-
94.202355ms-98.345419ms 29 █████ (2.4%)
238-
98.345419ms-102.670697ms 9 █ (0.7%)
239-
102.670697ms-107.186203ms 8 █ (0.6%)
240-
107.186203ms-111.900303ms 4 (0.3%)
241-
111.900303ms-116.821732ms 2 (0.2%)
242-
116.821732ms-121.959608ms 3 (0.2%)
243-
121.959608ms-127.32345ms 1 (0.1%)
244-
127.32345ms-132.923196ms 1 (0.1%)
245-
138.769222ms-144.872375ms 1 (0.1%)
185+
59.895916ms-63.862831ms 98 ██████████████████████ (8.0%)
186+
63.862831ms-68.092476ms 163 ████████████████████████████████████ (13.3%)
187+
68.092476ms-72.602251ms 170 ██████████████████████████████████████ (13.8%)
188+
72.602251ms-77.410709ms 172 █████████████████████████████████████ (14.0%)
189+
77.410709ms-82.537631ms 177 ████████████████████████████████████████ (14.4%)
190+
82.537631ms-88.004111ms 128 ████████████████████████████ (10.4%)
191+
88.004111ms-93.832637ms 119 ██████████████████████████ (9.7%)
192+
93.832637ms-100.047186ms 73 ████████████████ (5.9%)
193+
100.047186ms-106.673326ms 40 █████████ (3.3%)
194+
106.673326ms-113.738317ms 32 ███████ (2.6%)
195+
113.738317ms-121.271222ms 20 ████ (1.6%)
196+
121.271222ms-129.303034ms 14 ███ (1.1%)
197+
129.303034ms-137.866793ms 12 ██ (1.0%)
198+
137.866793ms-146.997731ms 3 (0.2%)
199+
146.997731ms-156.733413ms 4 (0.3%)
200+
167.11389ms-178.181868ms 2 (0.2%)
201+
178.181868ms-189.98288ms 1 (0.1%)
202+
189.98288ms-202.565475ms 1 (0.1%)
203+
202.565475ms-215.981417ms 1 (0.1%)
246204

247205
--- Analysis & Recommendations ---
248-
[WARN] Low sample size (1232). Results may not be statistically significant. Run for longer.
249-
[INFO] High Allocations (18668/op). This will trigger frequent GC cycles and increase Max Latency.
206+
[WARN] Low sample size (1230). Results may not be statistically significant. Run for longer.
207+
[FAIL] High Variance (CV 20.87%). System noise is affecting results. Isolate the machine or increase duration.
208+
[INFO] High Allocations (17213/op). This will trigger frequent GC cycles and increase Max Latency.
250209
----------------------------------
251-
--- PASS: TestParallelBenchmarkSender (20.83s)
252-
--- PASS: TestParallelBenchmarkSender/Setup(bits_32,_curve_BN254,_#i_2,_#o_2)_with_1_workers (10.39s)
253-
--- PASS: TestParallelBenchmarkSender/Setup(bits_32,_curve_BN254,_#i_2,_#o_2)_with_10_workers (10.44s)
210+
211+
--- Throughput Timeline ---
212+
Timeline: [▇▇▇█▇▇▇▇▆▇] (Max: 131 ops/s)
213+
214+
--- PASS: TestParallelBenchmarkSender (13.97s)
215+
--- PASS: TestParallelBenchmarkSender/Setup(bits_32,_curve_BN254,_#i_2,_#o_2)_with_10_workers (13.96s)
254216
PASS
255-
ok github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/transfer 21.409s
217+
ok github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/transfer 14.566s
256218
```

integration/nwo/token/fabric/fabric.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (p *NetworkHandler) GenerateArtifacts(tms *topology2.TMS) {
7171
cmGenerator := p.CryptoMaterialGenerators[tms.Driver]
7272
gomega.Expect(cmGenerator).NotTo(gomega.BeNil(), "Crypto material generator for driver %s not found", tms.Driver)
7373

74-
// - PublicParamsBy
74+
// - Setup
7575
root, err := cmGenerator.Setup(tms)
7676
gomega.Expect(err).NotTo(gomega.HaveOccurred())
7777

token/core/zkatdlog/nogh/v1/benchmark/setup.go

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,33 @@ package benchmark
88

99
import (
1010
"context"
11+
"crypto/ecdsa"
12+
"crypto/elliptic"
13+
"crypto/rand"
1114
"fmt"
1215
"os"
1316
"path/filepath"
1417

1518
"github.com/IBM/idemix/bccsp/types"
1619
math "github.com/IBM/mathlib"
1720
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
21+
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/msp/x509"
1822
math2 "github.com/hyperledger-labs/fabric-token-sdk/token/core/common/crypto/math"
1923
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
2024
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
2125
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity"
2226
idemix2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/idemix"
2327
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/idemix/crypto"
2428
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/storage/kvs"
29+
ix509 "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/x509"
30+
crypto2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/x509/crypto"
2531
)
2632

2733
type SetupConfiguration struct {
2834
PP *setup.PublicParams
2935
OwnerIdentity *OwnerIdentity
36+
AuditorSigner *Signer
37+
IssuerSigner *Signer
3038
}
3139

3240
type SetupConfigurations struct {
@@ -66,14 +74,35 @@ func NewSetupConfigurations(idemixTestdataPath string, bits []uint64, curveIDs [
6674
return nil, errors.Errorf("curveID [%d] not found", curveID)
6775
}
6876

77+
auditorSigner, err := PrepareECDSASigner()
78+
if err != nil {
79+
return nil, err
80+
}
81+
issuerSigner, err := NewECDSASigner()
82+
if err != nil {
83+
return nil, err
84+
}
85+
6986
for _, bit := range bits {
7087
pp, err := setup.Setup(bit, ipk, curveID)
7188
if err != nil {
7289
return nil, err
7390
}
91+
issuerID, err := issuerSigner.Serialize()
92+
if err != nil {
93+
return nil, err
94+
}
95+
pp.AddIssuer(issuerID)
96+
auditorID, err := auditorSigner.Serialize()
97+
if err != nil {
98+
return nil, err
99+
}
100+
pp.AddAuditor(auditorID)
74101
configurations[key(bit, curveID)] = &SetupConfiguration{
75102
PP: pp,
76103
OwnerIdentity: oID,
104+
AuditorSigner: auditorSigner,
105+
IssuerSigner: issuerSigner,
77106
}
78107
}
79108
}
@@ -90,12 +119,12 @@ func (c *SetupConfigurations) GetPublicParams(bits uint64, curveID math.CurveID)
90119
return configuration.PP, nil
91120
}
92121

93-
func (c *SetupConfigurations) GetOwnerIdentity(bits uint64, curveID math.CurveID) (*OwnerIdentity, error) {
122+
func (c *SetupConfigurations) GetSetupConfiguration(bits uint64, curveID math.CurveID) (*SetupConfiguration, error) {
94123
configuration, ok := c.Configurations[key(bits, curveID)]
95124
if !ok {
96125
return nil, fmt.Errorf("configuration not found")
97126
}
98-
return configuration.OwnerIdentity, nil
127+
return configuration, nil
99128
}
100129

101130
func key(bits uint64, curveID math.CurveID) string {
@@ -162,3 +191,43 @@ func loadOwnerIdentity(ctx context.Context, dir string, curveID math.CurveID) (*
162191
Signer: signer,
163192
}, nil
164193
}
194+
195+
func PrepareECDSASigner() (*Signer, error) {
196+
signer, err := NewECDSASigner()
197+
if err != nil {
198+
return nil, err
199+
}
200+
return signer, nil
201+
}
202+
203+
type Signer struct {
204+
SK *ecdsa.PrivateKey
205+
Signer driver.Signer
206+
}
207+
208+
func NewECDSASigner() (*Signer, error) {
209+
// Create ephemeral key and store it in the context
210+
sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
211+
if err != nil {
212+
return nil, err
213+
}
214+
return &Signer{SK: sk, Signer: crypto2.NewEcdsaSigner(sk)}, nil
215+
}
216+
217+
func (d *Signer) Sign(message []byte) ([]byte, error) {
218+
return d.Signer.Sign(message)
219+
}
220+
221+
func (d *Signer) Serialize() ([]byte, error) {
222+
pkRaw, err := x509.PemEncodeKey(&d.SK.PublicKey)
223+
if err != nil {
224+
return nil, errors.Wrap(err, "failed marshalling public key")
225+
}
226+
227+
wrap, err := identity.WrapWithType(ix509.IdentityType, pkRaw)
228+
if err != nil {
229+
return nil, errors.Wrap(err, "failed wrapping identity")
230+
}
231+
232+
return wrap, nil
233+
}

0 commit comments

Comments
 (0)