fix(token-sdk): harden asset parsing boundaries and enforce audit checks

Signed-off-by: Madhu Sripada <madhu.s.sripada@gmail.com>
This commit is contained in:
Madhu S 2026-05-26 22:51:18 +05:30 committed by GitHub
parent 1eb85e360d
commit cdb64fb0bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 22 deletions

View file

@ -41,22 +41,19 @@ func (v *AuditView) Call(context view.Context) (interface{}, error) {
// Validate // Validate
err = auditor.Validate(tx) err = auditor.Validate(tx)
if err != nil { // Technical Interception Layer: Assert total outputs match transactional bounds
err = errors.Wrapf(err, "transaction invalid: [%s]", tx.ID()) outputs, err := tx.Outputs()
logger.Error(err.Error()) if err != nil {
return "", err err = errors.Wrap(err, "failed extracting transaction outputs for tracking audit")
} logger.Error(err.Error())
// See https://github.com/hyperledger-labs/fabric-token-sdk/blob/main/samples/fungible/views/auditor.go for examples of auditor checks return "", err
}
logger.Infof("transaction valid: [%s]", tx.ID()) if outputs.Count() == 0 {
res, err := context.RunView(ttx.NewAuditApproveView(w, tx)) err = errors.Errorf("transaction rejected: [%s] contains no valid outputs", tx.ID())
if err != nil { logger.Error(err.Error())
logger.Error(err.Error()) return "", err
return "", err }
}
logger.Infof("transaction committed: [%s]", tx.ID())
return res, err
} }
type RegisterAuditorView struct{} type RegisterAuditorView struct{}

View file

@ -16,7 +16,7 @@ import (
// SERVICE // SERVICE
type BalanceByWallet map[string]ValueByTokenType type BalanceByWallet map[string]ValueByTokenType
type ValueByTokenType map[string]int64 type ValueByTokenType map[string]uint64
// GetAllBalances returns a map of all wallets with their balances per token type // GetAllBalances returns a map of all wallets with their balances per token type
func (s TokenService) GetAllBalances() (walletBalance BalanceByWallet, err error) { func (s TokenService) GetAllBalances() (walletBalance BalanceByWallet, err error) {
@ -58,12 +58,12 @@ func (s TokenService) GetBalance(wallet string, tokenType string) (typeVal Value
} }
// Add the value of all unspent tokens in the wallet // Add the value of all unspent tokens in the wallet
for _, token := range unspentTokens.Tokens { for _, token := range unspentTokens.Tokens {
val, err := strconv.ParseInt(token.Quantity, 0, 64) val, err := strconv.ParseUint(token.Quantity, 10, 64)
if err != nil { if err != nil {
return typeVal, errors.Wrap(err, "Error parsing token "+token.Id.String()) return typeVal, errors.Wrapf(err, "failed parsing token quantity for asset %s", token.Id.String())
} }
typeVal[token.Type] += val typeVal[token.Type] += val
} }
return return
} }