Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ download-fabric:
.PHONY: unit-tests
# run standard unit tests
unit-tests:
@go test -coverprofile=profile.cov $(shell go list ./... | grep -v '/integration/' | grep -v 'regression' | grep -v 'mock' | grep -v 'protos-go')
@go test -coverprofile=profile.cov $(shell go list ./... | grep -v '/integration/' | grep -v 'regression' | grep -v 'mock' | grep -v 'protos-go' | grep -v 'testutils')
cd integration/nwo/; go test -cover ./...
cd token/services/storage/db/kvs/hashicorp/; go test -cover ./...

Expand Down
3 changes: 2 additions & 1 deletion integration/token/fungible/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/views"
token4 "github.com/hyperledger-labs/fabric-token-sdk/token"
dlognoghv1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/validator"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/storage/ttxdb"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
Expand Down Expand Up @@ -902,7 +903,7 @@ func TestPublicParamsUpdate(network *integration.Infrastructure, newAuditorID st
if updateWithAppend {
IssueCash(network, "", "USD", 110, alice, newAuditor, true, issuer)
} else {
IssueCash(network, "", "USD", 110, alice, newAuditor, true, issuer, "is not in issuers")
IssueCash(network, "", "USD", 110, alice, newAuditor, true, issuer, validator.ErrIssuerNotAuthorized.Error())
}
if newAuditorID != "auditor" {
if updateWithAppend {
Expand Down
20 changes: 5 additions & 15 deletions token/core/fabtoken/v1/validator/validator_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ SPDX-License-Identifier: Apache-2.0
package validator

import (
"bytes"
"context"
"slices"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/actions"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/validator"
"github.com/hyperledger-labs/fabric-token-sdk/token/token"
)

Expand All @@ -38,20 +39,9 @@ func IssueValidate(c context.Context, ctx *Context) error {
}
}

issuers := ctx.PP.IssuerIDs
if len(issuers) != 0 {
// check that issuer of this issue action is authorized
found := false
for _, issuer := range issuers {
if bytes.Equal(action.Issuer, issuer) {
found = true

break
}
}
if !found {
return errors.Errorf("issuer [%s] is not in issuers", action.Issuer.String())
}
// Check the issuer is among those known
if issuers := ctx.PP.Issuers(); len(issuers) != 0 && !slices.ContainsFunc(issuers, action.Issuer.Equal) {
return validator.ErrIssuerNotAuthorized
}

// deserialize verifier for the issuer
Expand Down
19 changes: 18 additions & 1 deletion token/core/zkatdlog/nogh/v1/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,27 @@ func GetTokensWithWitness(values []uint64, tokenType token.Type, pp []*math.G1,
if err != nil {
return nil, nil, errors.Wrap(err, "cannot get tokens with witness")
}
bfs := make([]*math.Zr, len(values))
for i := range values {
bfs[i] = c.NewRandomZr(rand)
}

return GetTokensWithWitnessAndBF(values, bfs, tokenType, pp, c)
}

// GetTokensWithWitnessAndBF returns token commitments and metadata for the passed values, blinding factors, and type.
// This is useful for recomputing commitments during validation or testing.
func GetTokensWithWitnessAndBF(values []uint64, bfs []*math.Zr, tokenType token.Type, pp []*math.G1, c *math.Curve) ([]*math.G1, []*Metadata, error) {
if c == nil {
return nil, nil, errors.New("cannot get tokens with witness: please initialize curve")
}
if len(values) != len(bfs) {
return nil, nil, errors.New("cannot get tokens with witness: values and bfs must have the same length")
}
tw := make([]*Metadata, len(values))
for i, v := range values {
tw[i] = &Metadata{
BlindingFactor: c.NewRandomZr(rand),
BlindingFactor: bfs[i],
Value: c.NewZrFromUint64(v),
Type: tokenType,
}
Expand Down
32 changes: 32 additions & 0 deletions token/core/zkatdlog/nogh/v1/validator/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package validator

import "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"

var (
// ErrInvalidInputs is returned when the number of token inputs is invalid
ErrInvalidInputs = errors.New("invalid number of token inputs, expected at least 1")
// ErrMissingIssuer is returned when an issuer is missing on a redeem action
ErrMissingIssuer = errors.New("On Redeem action, must have at least one issuer")
// ErrFabTokenNotFound is returned when the fabtoken token is not found in the witness
ErrFabTokenNotFound = errors.New("fabtoken token not found in witness")
// ErrCommitmentMismatch is returned when the recomputed commitment does not match
ErrCommitmentMismatch = errors.New("recomputed commitment does not match")
// ErrOwnersMismatch is returned when the owners do not correspond
ErrOwnersMismatch = errors.New("owners do not correspond")
// ErrInvalidHTLCAction is returned when an HTLC action is invalid
ErrInvalidHTLCAction = errors.New("invalid transfer action: an htlc script only transfers the ownership of a token")
// ErrHTLCOutputNotFound is returned when the HTLC output is not found
ErrHTLCOutputNotFound = errors.New("invalid transfer action: an htlc script only transfers the ownership of a token, output not found")
// ErrIssueVerificationFailed is returned when issue verification fails
ErrIssueVerificationFailed = errors.New("failed to verify issue")
// ErrIssuerNotAuthorized is returned when the issuer is not authorized
ErrIssuerNotAuthorized = errors.New("issuer is not authorized")
// ErrInvalidZKP is returned when the zk proof is not valid
ErrInvalidZKP = errors.New("invalid zero-knowledge proof")
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"path/filepath"

"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/benchmark"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/validator/testing"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/validator/testutils"
sbenchmark "github.com/hyperledger-labs/fabric-token-sdk/token/services/benchmark"
)

Expand Down Expand Up @@ -54,7 +54,7 @@ func main() {
i,
configuration.Bits, configuration.CurveID, testCase.BenchmarkCase.NumInputs, testCase.BenchmarkCase.NumOutputs,
)
env, err := testing.NewEnv(&sbenchmark.Case{
env, err := testutils.NewEnv(&sbenchmark.Case{
Bits: configuration.Bits,
CurveID: configuration.CurveID,
NumInputs: testCase.BenchmarkCase.NumInputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package testing
package testutils

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package testing
package testutils

import (
"encoding/base64"
Expand Down
Loading
Loading