Skip to content

Commit 6fb6936

Browse files
authored
fix: VC range clause fix (#2961)
* fix: P-717 use > instead of >= in amount VC first assertion clause * fix: only use > 0 in clause when amount = 0 for amount assertion * fix: use > instead of >= in solidity amount VC first assertion clause, only use > 0 in clause when amount = 0 for solidity amount assertion * fix: update the schema url of solidity contract: TokenHoldingAmount * fix: wrong op in first clause of bnb domain amount vc --------- Co-authored-by: higherordertech <higherordertech>
1 parent 8af6dba commit 6fb6936

File tree

10 files changed

+73
-51
lines changed

10 files changed

+73
-51
lines changed

tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,8 @@ mod tests {
447447
create_network_address_assertion_logics(Web3TokenType::Nfp),
448448
Box::new(AssertionLogic::Item {
449449
src: "$holding_amount".into(),
450-
op: Op::GreaterEq,
450+
op: Op::GreaterThan,
451451
dst: "0".into()
452-
}),
453-
Box::new(AssertionLogic::Item {
454-
src: "$holding_amount".into(),
455-
op: Op::LessThan,
456-
dst: "1".into()
457452
})
458453
]
459454
}
@@ -483,7 +478,7 @@ mod tests {
483478
create_network_address_assertion_logics(Web3TokenType::Nfp),
484479
Box::new(AssertionLogic::Item {
485480
src: "$holding_amount".into(),
486-
op: Op::GreaterEq,
481+
op: Op::GreaterThan,
487482
dst: "0".into()
488483
}),
489484
Box::new(AssertionLogic::Item {

tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
4545
string
4646
memory description = "The amount of a particular token you are holding";
4747
string memory assertion_type = "Token Holding Amount";
48-
schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/25-token-holding-amount/1-1-3.json";
48+
schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/25-token-holding-amount/1-1-4.json";
4949

5050
string memory tokenLowercaseName = abi.decode(params, (string));
5151

@@ -68,6 +68,7 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
6868
string[] memory assertions = assembleAssertions(
6969
min,
7070
max,
71+
balance,
7172
tokenLowercaseName
7273
);
7374

@@ -134,12 +135,13 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
134135
function assembleAssertions(
135136
uint256 min,
136137
int256 max,
138+
uint256 balance,
137139
string memory tokenName
138140
) private pure returns (string[] memory) {
139141
string memory variable = "$holding_amount";
140142
AssertionLogic.CompositeCondition memory cc = AssertionLogic
141143
.CompositeCondition(
142-
new AssertionLogic.Condition[](max > 0 ? 3 : 2),
144+
new AssertionLogic.Condition[](max > 0 && balance > 0 ? 3 : 2),
143145
true
144146
);
145147
AssertionLogic.andOp(
@@ -153,10 +155,12 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
153155
cc,
154156
1,
155157
variable,
156-
AssertionLogic.Op.GreaterEq,
158+
min == 0
159+
? AssertionLogic.Op.GreaterThan
160+
: AssertionLogic.Op.GreaterEq,
157161
StringShift.toShiftedString(min, Constants.decimals_factor)
158162
);
159-
if (max > 0) {
163+
if (max > 0 && balance > 0) {
160164
AssertionLogic.andOp(
161165
cc,
162166
2,

tee-worker/litentry/core/assertion-build/src/dynamic/tests/token-holding-amount.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('TokenHoldingAmount', () => {
2929
await expectAssertionResult(contract, val, {
3030
tokenType: 'Token Holding Amount',
3131
tokenDesc: 'The amount of a particular token you are holding',
32-
schemaUrl: assembleSchemaUrl('25-token-holding-amount/1-1-3.json'),
32+
schemaUrl: assembleSchemaUrl('25-token-holding-amount/1-1-4.json'),
3333
assertions: [assertion],
3434
result,
3535
})
@@ -54,14 +54,9 @@ describe('TokenHoldingAmount', () => {
5454
},
5555
{
5656
src: '$holding_amount',
57-
op: Op.GTE,
57+
op: Op.GT,
5858
dst: '0',
5959
},
60-
{
61-
src: '$holding_amount',
62-
op: Op.LT,
63-
dst: '1',
64-
},
6560
],
6661
},
6762
false
@@ -118,7 +113,7 @@ describe('TokenHoldingAmount', () => {
118113
},
119114
{
120115
src: '$holding_amount',
121-
op: Op.GTE,
116+
op: Op.GT,
122117
dst: '0',
123118
},
124119
{

tee-worker/litentry/core/assertion-build/src/nodereal/amount_holding/evm_amount_holding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ mod tests {
226226
create_ton_network_assertion_logic(),
227227
Box::new(AssertionLogic::Item {
228228
src: "$holding_amount".into(),
229-
op: Op::GreaterEq,
229+
op: Op::GreaterThan,
230230
dst: "0".into()
231231
}),
232232
Box::new(AssertionLogic::Item {

tee-worker/litentry/core/credentials-v2/src/token_holding_amount/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,18 @@ fn update_assertion(token_type: Web3TokenType, balance: f64, credential: &mut Cr
8686
Some(index) => {
8787
let min = format!("{}", token_holding_amount_range[index]);
8888
let max = format!("{}", token_holding_amount_range[index + 1]);
89-
let min_item =
90-
AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::GreaterEq, &min);
91-
let max_item =
92-
AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max);
89+
let min_item = AssertionLogic::new_item(
90+
ASSERTION_KEYS.holding_amount,
91+
if index == 0 { Op::GreaterThan } else { Op::GreaterEq },
92+
&min,
93+
);
9394

9495
assertion = assertion.add_item(min_item);
95-
assertion = assertion.add_item(max_item);
96+
if balance > 0_f64 {
97+
let max_item =
98+
AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max);
99+
assertion = assertion.add_item(max_item);
100+
}
96101

97102
credential.credential_subject.values.push(index != 0 || balance > 0_f64);
98103
},

tee-worker/litentry/core/credentials/src/brc20/amount_holder.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,18 @@ fn update_assertion(token: &BRC20Token, balance: f64, credential: &mut Credentia
150150
Some(index) => {
151151
let min = format!("{}", range[index]);
152152
let max = format!("{}", range[index + 1]);
153-
let min_item =
154-
AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::GreaterEq, &min);
155-
let max_item =
156-
AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max);
153+
let min_item = AssertionLogic::new_item(
154+
ASSERTION_KEYS.holding_amount,
155+
if index == 0 { Op::GreaterThan } else { Op::GreaterEq },
156+
&min,
157+
);
157158

158159
assertion = assertion.add_item(min_item);
159-
assertion = assertion.add_item(max_item);
160+
if balance > 0_f64 {
161+
let max_item =
162+
AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max);
163+
assertion = assertion.add_item(max_item);
164+
}
160165

161166
credential.credential_subject.values.push(index != 0 || balance > 0_f64);
162167
},

tee-worker/litentry/core/credentials/src/credential_schema.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ pub fn get_schema_url(assertion: &Assertion) -> Option<String> {
5252

5353
Assertion::Achainable(params) => match params {
5454
AchainableParams::AmountHolding(_) =>
55-
Some(format!("{BASE_URL}/17-token-holding-amount/1-1-0.json")),
55+
Some(format!("{BASE_URL}/17-token-holding-amount/1-1-2.json")),
5656

5757
AchainableParams::AmountToken(_) =>
58-
Some(format!("{BASE_URL}/17-token-holding-amount/1-1-0.json")),
58+
Some(format!("{BASE_URL}/17-token-holding-amount/1-1-2.json")),
5959

6060
AchainableParams::Amount(_) => Some(format!("{BASE_URL}/11-token-holder/1-1-0.json")),
6161

@@ -86,24 +86,24 @@ pub fn get_schema_url(assertion: &Assertion) -> Option<String> {
8686
Some(format!("{BASE_URL}/14-generic-discord-role/1-1-0.json")),
8787

8888
Assertion::BnbDomainHolding =>
89-
Some(format!("{BASE_URL}/15-bnb-domain-holding-amount/1-1-0.json")),
89+
Some(format!("{BASE_URL}/15-bnb-domain-holding-amount/1-1-1.json")),
9090

9191
Assertion::BnbDigitDomainClub(_) =>
92-
Some(format!("{BASE_URL}/16-bnb-3d-4d-club-domain-holding-amount/1-1-0.json")),
92+
Some(format!("{BASE_URL}/16-bnb-3d-4d-club-domain-holding-amount/1-1-1.json")),
9393

9494
Assertion::VIP3MembershipCard(_) =>
9595
Some(format!("{BASE_URL}/19-vip3-card-holder/1-1-0.json")),
9696

9797
Assertion::WeirdoGhostGangHolder =>
9898
Some(format!("{BASE_URL}/18-weirdoghostgang-holder/1-1-0.json")),
9999

100-
Assertion::LITStaking => Some(format!("{BASE_URL}/17-token-holding-amount/1-1-0.json")),
100+
Assertion::LITStaking => Some(format!("{BASE_URL}/17-token-holding-amount/1-1-2.json")),
101101

102102
Assertion::EVMAmountHolding(_) =>
103-
Some(format!("{BASE_URL}/21-evm-holding-amount/1-1-0.json")),
103+
Some(format!("{BASE_URL}/21-evm-holding-amount/1-1-2.json")),
104104

105105
Assertion::BRC20AmountHolder =>
106-
Some(format!("{BASE_URL}/20-token-holding-amount-list/1-1-0.json")),
106+
Some(format!("{BASE_URL}/20-token-holding-amount-list/1-1-1.json")),
107107

108108
Assertion::CryptoSummary => Some(format!("{BASE_URL}/23-crypto-summary/1-1-0.json")),
109109

@@ -112,7 +112,7 @@ pub fn get_schema_url(assertion: &Assertion) -> Option<String> {
112112
Assertion::NftHolder(_) => Some(format!("{BASE_URL}/26-nft-holder/1-1-2.json")),
113113

114114
Assertion::TokenHoldingAmount(_) =>
115-
Some(format!("{BASE_URL}/25-token-holding-amount/1-1-3.json")),
115+
Some(format!("{BASE_URL}/25-token-holding-amount/1-1-4.json")),
116116

117117
Assertion::Dynamic(..) => None,
118118
}

tee-worker/litentry/core/credentials/src/litentry_profile/token_balance.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ fn update_assertion(token: ETokenAddress, balance: f64, credential: &mut Credent
8181
Some(index) => {
8282
let min = format!("{}", range[index]);
8383
let max = format!("{}", range[index + 1]);
84-
let min_item = AssertionLogic::new_item(content, Op::GreaterEq, &min);
85-
let max_item = AssertionLogic::new_item(content, Op::LessThan, &max);
84+
let min_item = AssertionLogic::new_item(
85+
content,
86+
if index == 0 { Op::GreaterThan } else { Op::GreaterEq },
87+
&min,
88+
);
8689

8790
assertion = assertion.add_item(min_item);
88-
assertion = assertion.add_item(max_item);
91+
if balance > 0_f64 {
92+
let max_item = AssertionLogic::new_item(content, Op::LessThan, &max);
93+
assertion = assertion.add_item(max_item);
94+
}
8995

9096
credential.credential_subject.values.push(index != 0 || balance > 0_f64);
9197
},

tee-worker/litentry/core/credentials/src/nodereal/amount_holding/evm_amount_holding.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,18 @@ fn update_assertion(token_type: EVMTokenType, balance: f64, credential: &mut Cre
113113
Some(index) => {
114114
let min = format!("{}", &EVM_HOLDING_AMOUNT_RANGE[index]);
115115
let max = format!("{}", &EVM_HOLDING_AMOUNT_RANGE[index + 1]);
116-
let min_item =
117-
AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::GreaterEq, &min);
118-
let max_item =
119-
AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max);
116+
let min_item = AssertionLogic::new_item(
117+
ASSERTION_KEYS.holding_amount,
118+
if index == 0 { Op::GreaterThan } else { Op::GreaterEq },
119+
&min,
120+
);
120121

121122
assertion = assertion.add_item(min_item);
122-
assertion = assertion.add_item(max_item);
123+
if balance > 0_f64 {
124+
let max_item =
125+
AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max);
126+
assertion = assertion.add_item(max_item);
127+
}
123128

124129
credential.credential_subject.values.push(index != 0 || balance > 0_f64);
125130
},

tee-worker/litentry/core/credentials/src/nodereal/bnb_domain/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@ pub trait RangeCredentialDetail {
4141
Some(index) => {
4242
let min = range[index - 1];
4343
let max = range[index];
44-
let min_item =
45-
AssertionLogic::new_item(breakdown, Op::GreaterEq, &format!("{}", min));
46-
let max_item =
47-
AssertionLogic::new_item(breakdown, Op::LessThan, &format!("{}", max));
44+
let min_item = AssertionLogic::new_item(
45+
breakdown,
46+
if index == 1 { Op::GreaterThan } else { Op::GreaterEq },
47+
&format!("{}", min),
48+
);
4849

49-
vec![min_item, max_item]
50+
if amount > 0 {
51+
let max_item =
52+
AssertionLogic::new_item(breakdown, Op::LessThan, &format!("{}", max));
53+
vec![min_item, max_item]
54+
} else {
55+
vec![min_item]
56+
}
5057
},
5158
None => {
5259
// >= last value

0 commit comments

Comments
 (0)