Skip to content

Commit e2592fa

Browse files
EvanYan1024AkramBitar
authored andcommitted
fix(token): keep request-carried audit info when the local lookup is empty
Request.AuditRecord overwrote the owner audit info of every input with the result of a local wallet service lookup. The wallet service only knows the identities registered on this node and returns nil for the others, so an auditor that never registered the owner lost the audit info the request metadata already carried. x509 owners never surfaced this: their enrollment ID is resolved from the metadata audit info earlier, in extractTransferInputs, and kept in a separate field. Owners whose audit info cannot be recomputed from the identity itself, such as boolpolicy identities with idemix members, have no such fallback and fail the audit with an empty audit info. Keep the local result when it is non-empty and fall back to what the request carries otherwise. Signed-off-by: Evan <evanyan@sign.global>
1 parent c132ccb commit e2592fa

2 files changed

Lines changed: 92 additions & 1 deletion

File tree

token/request.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,12 @@ func (r *Request) AuditRecord(ctx context.Context) (*AuditRecord, error) {
14701470
if err != nil {
14711471
return nil, errors.Wrapf(err, "failed getting audit info for owner [%s]", toks[i].Owner)
14721472
}
1473-
in.OwnerAuditInfo = ownerAuditInfo
1473+
// The wallet service only knows the identities registered on this node
1474+
// and returns nil for the others, so keep the audit info the request
1475+
// metadata already carries when the local lookup finds nothing.
1476+
if len(ownerAuditInfo) != 0 {
1477+
in.OwnerAuditInfo = ownerAuditInfo
1478+
}
14741479
}
14751480

14761481
return &AuditRecord{

token/request_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,3 +1105,89 @@ func TestRequest_PublicParamsHash(t *testing.T) {
11051105
hash := r.PublicParamsHash()
11061106
assert.Equal(t, expectedHash, hash)
11071107
}
1108+
1109+
// TestRequest_AuditRecord_OwnerAuditInfo checks how AuditRecord fills the audit
1110+
// info of an input: the local wallet service wins when it knows the owner, and
1111+
// the audit info carried by the request metadata survives when it does not.
1112+
func TestRequest_AuditRecord_OwnerAuditInfo(t *testing.T) {
1113+
ctx := t.Context()
1114+
owner := Identity("owner1")
1115+
metadataAuditInfo := []byte("audit-info-from-metadata")
1116+
1117+
newRequest := func(localAuditInfo []byte) *Request {
1118+
// A transfer with one input and no output: AuditRecord only reads back
1119+
// the inputs, and no output keeps the action deobfuscation out of play.
1120+
transferAction := &driver2.TransferAction{}
1121+
transferAction.NumInputsReturns(1)
1122+
transferAction.NumOutputsReturns(0)
1123+
1124+
transferService := &driver2.TransferService{}
1125+
transferService.DeserializeTransferActionReturns(transferAction, nil)
1126+
1127+
walletService := &driver2.WalletService{}
1128+
walletService.GetAuditInfoReturns(localAuditInfo, nil)
1129+
1130+
pp := &driver2.PublicParameters{}
1131+
pp.PrecisionReturns(64)
1132+
ppm := &driver2.PublicParamsManager{}
1133+
ppm.PublicParametersReturns(pp)
1134+
1135+
tms := &driver2.TokenManagerService{}
1136+
tms.TransferServiceReturns(transferService)
1137+
tms.WalletServiceReturns(walletService)
1138+
tms.PublicParamsManagerReturns(ppm)
1139+
1140+
qe := &driver2.QueryEngine{}
1141+
qe.ListAuditTokensReturns([]*token.Token{{Owner: owner, Type: "USD", Quantity: "0x64"}}, nil)
1142+
vault := &driver2.Vault{}
1143+
vault.QueryEngineReturns(qe)
1144+
1145+
logger := logging.MustGetLogger()
1146+
1147+
return &Request{
1148+
Anchor: "test-anchor",
1149+
Actions: &driver.TokenRequest{
1150+
Actions: []*driver.TypedAction{
1151+
{Type: request.ActionType_ACTION_TYPE_TRANSFER, Raw: []byte("transfer1")},
1152+
},
1153+
},
1154+
Metadata: &driver.TokenRequestMetadata{
1155+
Actions: []*driver.ActionMetadataEntry{
1156+
{
1157+
ActionID: 0,
1158+
TransferMetadata: &driver.TransferMetadata{
1159+
Inputs: []*driver.TransferInputMetadata{
1160+
{
1161+
TokenID: &token.ID{TxId: "tx1", Index: 0},
1162+
Senders: []*driver.AuditableIdentity{
1163+
{Identity: owner, AuditInfo: metadataAuditInfo},
1164+
},
1165+
},
1166+
},
1167+
},
1168+
},
1169+
},
1170+
},
1171+
TokenService: &ManagementService{
1172+
tms: tms,
1173+
logger: logger,
1174+
vault: &Vault{v: vault, logger: logger},
1175+
},
1176+
}
1177+
}
1178+
1179+
t.Run("local wallet service knows the owner", func(t *testing.T) {
1180+
localAuditInfo := []byte("audit-info-from-wallet-service")
1181+
record, err := newRequest(localAuditInfo).AuditRecord(ctx)
1182+
require.NoError(t, err)
1183+
require.Equal(t, 1, record.Inputs.Count())
1184+
assert.Equal(t, localAuditInfo, record.Inputs.At(0).OwnerAuditInfo)
1185+
})
1186+
1187+
t.Run("local wallet service does not know the owner", func(t *testing.T) {
1188+
record, err := newRequest(nil).AuditRecord(ctx)
1189+
require.NoError(t, err)
1190+
require.Equal(t, 1, record.Inputs.Count())
1191+
assert.Equal(t, metadataAuditInfo, record.Inputs.At(0).OwnerAuditInfo)
1192+
})
1193+
}

0 commit comments

Comments
 (0)