Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue of handling decimals. #2886

Merged
merged 7 commits into from
Jul 15, 2024
Merged

Conversation

0xverin
Copy link
Contributor

@0xverin 0xverin commented Jul 11, 2024

Context

In Solidity, if division by a number results in a decimal, precision will be lost.
For example:
10001/1000=10(not 10.001), 1/1000=0(not 0.001).
Therefore, the previous method of range*1000 / 1000 is inaccurate and may lead to bugs:
If range*1000 is less than 1000, we will only get 0 (ranges for BTC and ETH may always equal to 0).

Solution:
Avoid mathematical operations and directly use string padding.

resolves p-877

Labels

Please apply following PR-related labels when appropriate:

  • C0-breaking: if your change could break the existing client, e.g. API change, critical logic change
  • C1-noteworthy: if your change is non-breaking, but is still worth noticing for the client, e.g. reference code improvement

How (Optional)

Testing Evidences

Please attach any relevant evidences if applicable

./bin/litentry-cli trusted -d link-identity did:litentry:substrate:0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e did:litentry:evm:0x52ee324F2bCD0c5363d713eb9f62D1eE47266ac1 ethereum
./bin/litentry-cli trusted -d request-vc did:litentry:substrate:0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e -a "dynamic 0000000000000000000000000000000000000002 0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000
00000000000000000000000000000000000036574680000000000000000000000000000000000000000000000000000000000 true"
{
    "@context": [
        "https://www.w3.org/2018/credentials/v1",
        "https://w3id.org/security/suites/ed25519-2020/v1"
    ],
    "id": "0xd981bf2c95277001a15df530c29c496a66207bed7244ab5e1e019e9128853381",
    "type": [
        "VerifiableCredential"
    ],
    "credentialSubject": {
        "id": "did:litentry:substrate:0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e",
        "description": "The amount of a particular token you are holding",
        "type": "Token Holding Amount",
        "assertionText": "",
        "assertions": [
            {
                "and": [
                    {
                        "src": "$token",
                        "op": "==",
                        "dst": "eth"
                    },
                    {
                        "src": "$holding_amount",
                        "op": ">=",
                        "dst": "0.6"
                    },
                    {
                        "src": "$holding_amount",
                        "op": "<",
                        "dst": "1.2"
                    }
                ]
            }
        ],
        "values": [
            true
        ],
        "endpoint": "http://localhost:9933/"
    },
    "issuer": {
        "id": "did:litentry:substrate:0xdf45100d260ed1e7e0d53c400858773d1263e814289f8f250499b6fa2a5d01c9",
        "name": "Litentry TEE Worker",
        "mrenclave": "DPtRXAxntVPL49TyARdwfJgHYHe23QtZC1bxV18wnLnd",
        "runtimeVersion": {
            "parachain": 9181,
            "sidechain": 108
        }
    },
    "issuanceDate": "2024-07-11T03:14:16.635804239+00:00",
    "parachainBlockNumber": 313,
    "sidechainBlockNumber": 618,
    "proof": {
        "created": "2024-07-11T03:14:16.636670817+00:00",
        "type": "Ed25519Signature2020",
        "proofPurpose": "assertionMethod",
        "proofValue": "47843437bcf5e3d839da934fe10651f2ee31dc574085d13c7a8c246884ecec55e2690dba2f625063ce11f933ad327dba64ca3c46827fec8ee6e39f7e161ce001",
        "verificationMethod": "0x6813b486dc599656b6112fd002351d3aea23162a697e6826e92d75ac834aad38"
    },
    "credentialSchema": {
        "id": "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/25-token-holding-amount/1-1-0.json",
        "type": "JsonSchemaValidator2018"
    }
}
image

@0xverin 0xverin requested review from kziemianek, a team and higherordertech July 11, 2024 03:28
@0xverin 0xverin force-pushed the fix-assembleAssertions-issue branch from 5e35292 to 06b8d65 Compare July 11, 2024 03:34
Copy link

linear bot commented Jul 11, 2024

@0xverin 0xverin force-pushed the fix-assembleAssertions-issue branch from 9502740 to 618b859 Compare July 12, 2024 07:10
@0xverin 0xverin requested a review from higherordertech July 12, 2024 07:11
@0xverin 0xverin force-pushed the fix-assembleAssertions-issue branch from 310090e to eab3ade Compare July 15, 2024 02:15
@0xverin 0xverin merged commit 2c80fdd into dev Jul 15, 2024
32 checks passed
@0xverin 0xverin deleted the fix-assembleAssertions-issue branch July 15, 2024 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants