diff --git a/README.md b/README.md index c2c0310..351dbfd 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Kadena, namely, Chainweb, our proof-of-work blockchain, and the smart contract l | 12 | [KIP-0012: Kadena Single-Key Accounts](https://github.com/kda-community/KIPs/blob/master/kip-0012/kip-0012.md) | | | 15 | [KIP-0015: quicksign signing api v1](https://github.com/kda-community/KIPs/blob/master/kip-0015.md) | | | 17 | [KIP-0017: walletconnect-v2-sign implementation spec](https://github.com/kda-community/KIPs/blob/master/kip-0017.md) | | +| 24 | [KIP-0024: Pact pure Native](https://github.com/kda-community/KIPs/blob/master/kip-0024.md) | | | 26 | [KIP-0026: Key Derivation and Mnemonic encoding methods](https://github.com/kda-community/KIPs/blob/master/kip-0026.md) | | | 31 | [KIP-0031: Fungible token Metadata](https://github.com/kda-community/KIPs/pull/63) | | | 37 | [KIP-0037: Wallet RPC API kadena_getAccount_v1](https://github.com/kda-community/KIPs/pull/71) | | diff --git a/kip-0024.md b/kip-0024.md new file mode 100644 index 0000000..8b511d9 --- /dev/null +++ b/kip-0024.md @@ -0,0 +1,73 @@ +--- +KIP: "0024" +Title: Pact Pure primitive +Author: CryptoPascal +Status: Draft +Type: Standard +Category: Pact +Created: 2023-11-10 +--- + +## Abstract + +The Proposal is to add a new built-in in Pact: + +- `pure` to encapsulate and validate that a function call is "Read Only" pure. + + +## Motivation + +The introduction of module references introduced a lot of new possible security flaws. + +This has been stated in the official documentation. [1] + +Module writers need extreme care when handling modrefs, especially when modrefs are user supplied. + +Module writers should consider all the risks and infinite possibilities of re-entrancy, and cheating modules. + +While it is still possible to mitigate these issues by carefully managing capabilities scopes, having a `pure` native helps to add a new layer of defense against an attacker. + +If a module developer assumes that a function call should not have any side effects (*eg:* `fungible-v2::get-balance`), he can enclose it in `(pure )`, +and will be assured that the callee is not trying to cheat or modify a state somewhere. + + +## Specification + +#### Signature +``` +action -> +``` +#### Behaviour +``` +IF action FAIL => FAIL and propagate the error +IF action performs a non "ReadOnly pure" operation => FAIL +IF action returns a value => RETURN the same value +``` + +The behaviour is similar to the existing `(try )` function [2] , but without trying to catch errors. + +#### Example +*with the coin contract* + +```pact + +(pure (coin.get-balance "existing-account")) + > 3.0 + +(pure (coin.get-balance "unknown-account")) + > fails -> Error: with-read: row not found + +(pure (coin.create-account "new-account" ks)) + > fails -> Failure: Illegal database access attempt (writeRow) + +``` + +## Backwards Compatibility + +Introducing a new native doesn't cause backward compatibility issues. + + +## References +* [1] Pact PR [#1256] (https://github.com/kadena-io/pact/pull/1256) +* [2] Pact PR [#605] (https://github.com/kadena-io/pact/pull/605) +