Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider whether to allow typed bytesX function arguments #277

Open
mr-zwets opened this issue Feb 17, 2025 · 2 comments
Open

Consider whether to allow typed bytesX function arguments #277

mr-zwets opened this issue Feb 17, 2025 · 2 comments
Labels
breaking breaking change cashc-compiler Relates to the cashc compiler

Comments

@mr-zwets
Copy link
Member

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 mr-zwets added breaking breaking change cashc-compiler Relates to the cashc compiler labels Feb 17, 2025
@mr-zwets
Copy link
Member Author

I looked into the implementation details a bit to disallow the byte and byteX semantic types in function arguments, we have 2 broad strategies

  1. either we update visitFunctionDefinition in EnsureFinalRequireTraversal.ts to disallow these semantic bytes types
  2. or we could change the language definition types for functions in CashScript.g4

with reusable functions in mind i prefer 1 over 2 I think.

Then to get the type inference on the require check we'd need new logic in visitRequireStatement

@mr-zwets
Copy link
Member Author

a good argument for doing hidden checks on the unlocking arguments is that this works well with more complex types in the future like fixed size arrays. Solidity also does hidden checks that the provided types for unlocking arguments are correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking breaking change cashc-compiler Relates to the cashc compiler
Projects
None yet
Development

No branches or pull requests

1 participant