koinos / koinos-sdk-as

AssemblyScript (AS) Software Development Toolkit (SDK) for the Koinos Blockchain
https://roaminroe.github.io/koinos-as-sdk/
MIT License
6 stars 3 forks source link

System.checkAuthority using getContractMetadata #74

Closed joticajulian closed 2 months ago

joticajulian commented 7 months ago

Brief description

This PR takes advantage of the new system contract called "get_contract_metadata", which is used to determine if an account has a contract or not. This is useful to improve the security of the assets (see references).

Changes:

References

Checklist

Demonstration

I deployed 3 contracts in mainnet: smart wallet, assets contract, and third party contract. These contracts interact between them to demonstrate the advantages of the new system call. They are working as expected. You can follow the tests described in this post but using these addresses for mainnet:

mvandeberg commented 7 months ago

I have also requested @sgerbino's review on this PR to ensure correctness and usability before we release it to contract devs.

joticajulian commented 7 months ago

With the implicit calls to getArguments and getCaller in function signatures, do we want to add some internal caching so when those calls are made multiple times, we can short circuit and return the cached object?

Good suggestion. I just added a cache value for these 2 functions.

mvandeberg commented 6 months ago

Sorry for the delay in review. LGTM, I want @sgerbino to look at it as well before we merge.

joticajulian commented 3 months ago

I've been very busy in other topics. I'd appreciate if someone can work in the unit tests.