Skip to content

Commit 8bf234e

Browse files
committed
Update release and migration notes + small docs changes
1 parent 8f1522d commit 8bf234e

4 files changed

Lines changed: 47 additions & 5 deletions

File tree

website/docs/language/contracts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ Function parameters are passed in the reversed order of their declaration. This
7171

7272
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.
7373

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`.
7676
:::
7777

7878
## Statements

website/docs/releases/migration-notes.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,41 @@ require(bool(5) == true); // => true || compiles to 0x05 OP_0NOTEQUAL 0x01 OP_NU
5252

5353
If you want to keep the old behaviour (without added opcodes), you can use the `unsafe_bool()` casting function instead.
5454

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`.
68+
69+
```ts
70+
// Before: addressType option
71+
const contract = new Contract(artifact, constructorArgs, { addressType: 'p2sh32' });
72+
73+
// After: contractType option
74+
const contract = new Contract(artifact, constructorArgs, { contractType: 'p2sh32' });
75+
```
76+
77+
### Network Provider
78+
79+
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+
* @param lockingBytecode The locking bytecode for which we wish to retrieve UTXOs.
85+
* @returns List of UTXOs spendable by the provided locking bytecode.
86+
*/
87+
getUtxosForLockingBytecode(lockingBytecode: Uint8Array | string): Promise<Utxo[]>;
88+
```
89+
5590
## v0.11 to v0.12
5691

5792
There are several breaking changes to the SDK in this release.

website/docs/releases/release-notes.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@
22
title: Release Notes
33
---
44

5-
## v0.13.0-next.3
5+
## v0.13.0-next.4
66

77
This release contains several breaking changes, please refer to the [migration notes](/docs/releases/migration-notes) for more information.
88

99
#### cashc compiler
1010
- :sparkles: Add support for `do {} while ()` loops.
1111
- :sparkles: Add support for bitwise and arithmetic shift operators (`<<`, `>>`) and bitwise inversion (`~`).
1212
- :sparkles: Add `unsafe_bool()` and `unsafe_int()` casting for semantic-only casts.
13+
- :hammer_and_wrench: **BREAKING**: Function parameter types are now strictly enforced (bounded bytes and boolean values).
14+
- :hammer_and_wrench: Add compiler option to `cashc` (programmatic and CLI compilation) to allow for opting out of function parameter type enforcement.
1315
- :bug: **BREAKING**: Fix issue where `bool()` casting did not change the value of the argument.
1416
- :boom: **BREAKING**: Rename `bytes4(int)` and `bytes(int, 4)` to `toPaddedBytes(int, 4)`.
1517
- :boom: **BREAKING**: Rename `bytes4(bytes)` to `unsafe_bytes4(bytes)`.
16-
- :racehorse: Add optimisations for negated number comparisons.
18+
- :racehorse: Add optimisations for negated number comparisons and boolean comparisons.
1719

1820
#### CashScript SDK
1921

2022
- :sparkles: Add support for `do {} while ()` loops in debug tooling.
23+
- :sparkles: Add support for `p2s` contract type.
24+
- :sparkles: Add `lockingBytecode` property to `Contract` class.
25+
- :sparkles: Add `getUtxosForLockingBytecode()` method to `ElectrumNetworkProvider` class and `MockNetworkProvider` interface.
26+
- :hammer_and_wrench: **BREAKING**: Rename `addressType` option on `Contract` constructor to `contractType`.
27+
- :hammer_and_wrench: **BREAKING**: Remove undocumented `redeemScript` property from `Contract` class.
2128
- :hammer_and_wrench: Update default VM target to `BCH_2026_05`.
2229
- :hammer_and_wrench: Improve package size by tidying up dependencies.
2330

website/docs/sdk/instantiation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If compilation is done using the `cashc` CLI with the <span style={{ display: 'i
2929

3030
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).
3131

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.
3333

3434
:::caution
3535
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

Comments
 (0)