LIT-Protocol / Issues-and-Reports

For bug reports, feature requests, and implementation questions related to Lit Protocol and use of the Lit SDK.
0 stars 0 forks source link

Issue using custom contract access control condition #66

Open serdave-eth opened 1 week ago

serdave-eth commented 1 week ago

Is there an existing issue for this?

SDK version

6.4.0

Lit Network

datil-dev

Description of the bug/issue

I am trying to encrypt and decrypt a string using a custom contract call per this guide:

https://developer.litprotocol.com/sdk/access-control/evm/custom-contract-calls

I am currently using a standard ERC1155 contract just to check that I have the syntax correct for doing custom contract calls. When I encrypt my string using this access control condition:

[ { contractAddress: '0x098bBc82b56995dd84a1A4A868A7EbbDaB7ec0C3', standardContractType: 'ERC1155', chain: chain, method: 'balanceOf', parameters: [":userAddress", "1"], returnValueTest: { comparator: ">", value: "0", }, }, ]

I have zero issues encrypting and decrypting. However when I try encrypting the string with this access control condition: [ { contractAddress: "0x098bBc82b56995dd84a1A4A868A7EbbDaB7ec0C3", functionName: "balanceOf", functionParams: [":userAddress", "1"], functionAbi: { type: "function", stateMutability: "view", outputs: [ { type: "uint256", name: "", internalType: "uint256", }, ], name: "balanceOf", inputs: [ { type: "address", name: "account", internalType: "address", }, { type: "uint256", name: "id", internalType: "uint256", }, ], }, chain, returnValueTest: { key: "", comparator: ">", value: "0", }, }, ]

I get this error: An error occurred during encryption: errConstructorFunc { message: FAILED schema validation for parameter named accessControlConditions in Lit-JS-SDK function validateAccessControlConditionsSchema(). Value: {"contractAddress":"0x098bBc82b56995dd84a1A4A868A7EbbDaB7ec0C3","conditionType":"evmContract","functionName":"balanceOf","functionParams":[":userAddress","1"],"functionAbi":{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[{"type":"address","name":"account","internalType":"address"},{"type":"uint256","name":"id","internalType":"uint256"}]},"chain":"base","returnValueTest":{"key":"","comparator":">","value":"0"}}. Errors: [{"instancePath":"","schemaPath":"#/required","keyword":"required","params":{"missingProperty":"standardContractType"},"message":"must have required property 'standardContractType'"}], errorCode: 'InvalidParamType', errorKind: 'Validation', status: undefined, details: undefined, requestId: undefined }

It appears to be expecting me to write my access control condition like a basic EVM condition. I also tried using this access control condition: [ { contractAddress: '0x098bBc82b56995dd84a1A4A868A7EbbDaB7ec0C3', standardContractType: '', chain: chain, method: 'balanceOf', parameters: [":userAddress", "1"], returnValueTest: { comparator: ">", value: "0", }, }, ]

Which is the same as the first access control condition except I removed ERC1155 from the standard contract type, and I am able to encrypt the string but I am unable to decrypt it. I am able to decrypt the string without errors using the first access control condition.

I also tried adding a conditionType per this document: https://developer.litprotocol.com/sdk/access-control/condition-types/unified-access-control-conditions to my second condition but still got the same error.

My goal is to encrypt/decrypt using an ERC1155 token but using a custom EVM contract call to the "balanceOf" function instead of the standard calls because after I get this working, I'm going to replace the ERC1155 with a custom smart contract for managing keys.

Severity of the bug

Blocking me from finishing my project.

Steps To Reproduce

  1. Clone this code: https://github.com/serdave-eth/encrypt-cli
  2. Run "npm start"
  3. Press "e" to encrypt or "d" to encrypt
  4. Follow the prompts to put in wallet addresses and private keys for encryption settings.

The access control condition working is called "accessControlConditions_test" in encryptUtils.ts. The access control that is not working is called "evmContractConditions" in encryptUtils.ts.

When you encrypt a string, it'll save the ciphertext, hash of the data and access control conditions as files titled ciphertext, dataToEncryptHash and accessControlCondition, respectively. You need to provide the path to each file in the steps to decrypt.

Link to code

https://github.com/serdave-eth/encrypt-cli

Anything else?

No response

zach-is-my-name commented 1 week ago

have you explored this repo?
It contains vetted, runnable examples.

https://github.com/LIT-Protocol/developer-guides-code

More to the point, check out the structure here https://github.com/spacesailor24/erc20-allowance-acc-bug/blob/20721c823796da9bc24b6402fd7465092c184545/src/litAction.ts#L6-L28