You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/language/contracts.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,8 +71,8 @@ Function parameters are passed in the reversed order of their declaration. This
71
71
72
72
In CashScript the types for the function arguments are **not** enforced automatically at the contract level. This can be especially relevant for types like `bool`, `bytesX` and other semantic bytes types. Instead this type information is only used by the SDK to check whether these arguments match the expected type during transaction building.
73
73
74
-
:::caution
75
-
The typings for the function arguments are only semantic, this means the length of bounded bytes types like `bytes20`are **not** contract enforced automatically. Instead add an explicit length check `require(item.length == 20)`.
74
+
:::info
75
+
The typings for function arguments are enforced by default for boolean values and bounded bytes types such as `bytes20`and `bytes32`.
If you want to keep the old behaviour (without added opcodes), you can use the `unsafe_bool()` casting function instead.
54
54
55
+
#### Function parameter type enforcement
56
+
57
+
Function parameter types are now strictly enforced by default. Previously, no length checks were performed on bounded bytes types like `bytes20` and `bytes32` and no value checks were performed on boolean values. That meant that you could pass arguments to functions that were not of the correct type, which could lead to runtime vulnerabilities.
58
+
59
+
We made this the new compiler default because it is more secure and more explicit. If you want to opt out of this behaviour, you can set the `enforceFunctionParameterTypes` option to `false` in the compiler options when compiling programatically, or use the `--skip-enforce-function-parameter-types` flag when using the CLI.
60
+
61
+
Now, the compiler adds extra opcodes to the script to enforce the correct types. If you pass a byte string of an incorrect length to a function that expects e.g. a `bytes20`, the transaction will fail. If you pass in a numeric non-boolean value to a function that expects a `bool`, it will be converted to a boolean value using the `OP_0NOTEQUAL` opcode. If you pass in a non-numeric value to a function that expects a `bool`, the transaction will fail.
62
+
63
+
We added no extra checks for `int` values, because any numeric operations on a non-numeric value will automatically fail the entire transaction.
64
+
65
+
### CashScript SDK
66
+
67
+
The `addressType` option on the `Contract` constructor has been renamed to `contractType`.
If you are using a custom network provider, you will need to update the code for the custom provider to implement the new `getUtxosForLockingBytecode()` method to be compatible with the new `NetworkProvider` interface.
80
+
81
+
```ts
82
+
/**
83
+
* Retrieve all UTXOs (confirmed and unconfirmed) for a given locking bytecode.
84
+
* @paramlockingBytecode The locking bytecode for which we wish to retrieve UTXOs.
85
+
* @returns List of UTXOs spendable by the provided locking bytecode.
Copy file name to clipboardExpand all lines: website/docs/sdk/instantiation.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ If compilation is done using the `cashc` CLI with the <span style={{ display: 'i
29
29
30
30
The `NetworkProvider` option is used to manage network operations for the CashScript contract. By default, a mainnet `ElectrumNetworkProvider` is used, but the network providers can be configured. See the docs on [NetworkProvider](/docs/sdk/network-provider).
31
31
32
-
The `contractType` option is used to choose between a `p2sh20`, `p2sh32` or `p2s` contract type for the CashScript contract. By default `p2sh32` is used because it has increased cryptographic security — but it is not yet supported by all wallets.
32
+
The `contractType` option is used to choose between a `p2sh20`, `p2sh32` or `p2s` contract type for the CashScript contract. By default `p2sh32` is used because it has increased cryptographic security over `p2sh20`— but it is not yet supported by all wallets. `p2s` is a new contract type where the contract code is not hidden behind a hash. This has some benefits for public visibility of the contract code.
33
33
34
34
:::caution
35
35
p2sh32 was introduced because p2sh20 is cryptographically insecure for a large subset of smart contracts. For contracts holding large sums of BCH this provides an incentive to find a hash collision and hack the contract.
0 commit comments