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

Private view functions cannot be called after 1.11.0 #358

Open
SamuelQZQ opened this issue Apr 9, 2024 · 5 comments
Open

Private view functions cannot be called after 1.11.0 #358

SamuelQZQ opened this issue Apr 9, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@SamuelQZQ
Copy link

SamuelQZQ commented Apr 9, 2024

🐛 Bug Description

Before ts-sdk 1.11.0, a private view function is callable through the sdk. However, after #334, calling private view function will result in Could not find view function ABI error. It's because a private view function won't be listed in ABI, and #334 add a ABI verification when calling view function.

For example, 0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::lending::preview_account_liquidity_given_withdraw is a private view function, which cannot be found in ABI: https://explorer.aptoslabs.com/account/0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba/modules/code/lending?network=mainnet

According to the Aptos document:

If you want to tag a mutable function as #[view], consider making it private so that it cannot be maliciously called during runtime.

Private view functions are considered a feature. It's suggested that either these functions be included in the ABI or the SDK not raise exceptions for functions absent from the ABI.

How to reproduce

client.view({
  payload: {
    function:
      "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::lending::preview_account_liquidity_given_withdraw",
    functionArguments: [
      "0x41ac08fb7ac6d7b6d29199e7232a5770dfa9318308d703e9a10672f6e3ab66aa",
      "0x127ea5b4c450be695e488da1c3bc013e2e93d8cf00270ef90385189844bc9755",
      "9000000",
    ],
    typeArguments: [],
  },
});
@SamuelQZQ SamuelQZQ added the bug Something isn't working label Apr 9, 2024
@gregnazario
Copy link
Contributor

Will take a look into it when I get back. Looks like the ABI doesn't include private view functions.

You can override remote ABI for now using a hard coded one like this, which will provide type safety and better performance

https://github.com/aptos-labs/aptos-ts-sdk/blob/main/examples%2Ftypescript-esm%2Ftransaction_with_predefined_abi.ts#L141-L150

@SamuelQZQ
Copy link
Author

@gregnazario The example you provided is for entry functions. Is there a way to provide ABI for view function?

@0xmaayan
Copy link
Collaborator

0xmaayan commented Apr 9, 2024

@gregnazario The example you provided is for entry functions. Is there a way to provide ABI for view function?

Yes. Take a look at the view function api. The payload argument is of type InputViewFunctionData which accepts an optional abi property. So could do something like that

const response = await aptos.view({
 payload: {
        function: "0x1::account::get_sequence_number",
        functionArguments: ["0x1"], 
        abi:myABI
  }
})

@SamuelQZQ
Copy link
Author

@0xmaayan I found that to use this, we need to construct an ABI object of the function. How to construct the ABI with an plain ABI json?

@gregnazario
Copy link
Contributor

We could optionally instead provide the ability to use a view function without an ABI, but you will have to encode the arguments as BCS, and get it right (with no hints).

Maybe need to make a ABI generator minimally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Ready
Development

No branches or pull requests

3 participants