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

memory --> calldata for read-only function params #5293

Closed
wants to merge 4 commits into from

Conversation

abhi3700
Copy link
Contributor

@abhi3700 abhi3700 commented Nov 5, 2024

Fixes #5291

Copy link

changeset-bot bot commented Nov 5, 2024

🦋 Changeset detected

Latest commit: abe27cb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@abhi3700 abhi3700 closed this Nov 6, 2024
@abhi3700 abhi3700 reopened this Nov 6, 2024
@abhi3700 abhi3700 closed this Nov 6, 2024
@abhi3700 abhi3700 deleted the issue-5291 branch November 6, 2024 07:43
@abhi3700 abhi3700 reopened this Nov 6, 2024
@abhi3700
Copy link
Contributor Author

abhi3700 commented Nov 6, 2024

The Github CI/CD tests are failing because of following error.

Using Node.js v22.11.0

Downloading compiler 0.8.24
TypeError: Member "recover" not found or not visible after argument-dependent lookup in type(library ECDSA).
  --> contracts/mocks/EIP712Verifier.sol:13:35:
   |
13 |         address recoveredSigner = ECDSA.recover(digest, signature);
   |                                   ^^^^^^^^^^^^^


Error HH600: Compilation failed

It doesn't make sense to me as in my VSCode, the method is valid. I am not sure what am I missing 🤔 .
image

@abhi3700 abhi3700 changed the title memory data loc changed to calldata wherever used as read-only memory --> calldata for read-only function params Nov 6, 2024
Copy link
Collaborator

@Amxx Amxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a good reason why we use memory instead of calldata here: We don't know how these function will be called or how they will be overidden.

For example, in contracts/utils/cryptography/MessageHashUtils.sol, what makes you think the message and data are in calldata? In most cases, this data will be produced onchain, using some variant of abi.encode.

Similarly for contracts/utils/cryptography/RSA.sol. The data buffer is likelly to live in memory. Similarly, the public key part (e and n) are likelly to be in some form of storage.

For these reason I would strongly oppose forcing the use of calldata when no alternative exist, and were there is any doubts about where the value may come from.

@Amxx Amxx closed this Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use calldata instead of memory
2 participants