cashscript icon indicating copy to clipboard operation
cashscript copied to clipboard

Consider whether to allow typed `bytesX` function arguments

Open mr-zwets opened this issue 8 months ago • 2 comments

Created a standalone issue for typed bytesX function arguments

previously part of #178 (previously titled 'Consider changes to bytes types)

Mathieu and I were talking about this and we think it could make sense to disallow bytesX as function parameters, since these types are not runtime enforced. We could alternatively also add an option to enforce these types by injecting require(x.length === y) statements. This is something we should consider in more detail later.

For bytesX types in function parameters:

  1. We disallow bytesX as function argument.
  2. If a user adds e.g. a require(x.length == 20) check, then the compiler will infer that x's type is bytes20 for the rest of the contract.
  3. (Optionally) apply the same for if statements.
  4. If people want to forgo these checks, they can always manually cast to bytesX(x). We should add a warning to the docs about the security implications of doing that.

this issue also came up when thinking about how to integrate structs (#27)

mr-zwets avatar Feb 17 '25 08:02 mr-zwets