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

feat: bytes to base64 encoding in VM #6785

Merged
merged 6 commits into from
Jan 14, 2024

Conversation

0xAndoroid
Copy link
Contributor

@0xAndoroid 0xAndoroid commented Jan 13, 2024

Motivation

Closes #6744

Solution

  • Add function signatures
  • Add cheatcode implementation
  • Add tests


/// Encodes a `string` value to base64 string
#[cheatcode(group = Base64)]
function toBase64(string calldata data) external pure returns (string memory);
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we don't need functions for both bytes and string because bytes alone suffices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is bytes alone preferable? My understanding is the primary use case here will be for encoding/decoding tokenURIs which are strings, so if anything it seems string only would be preferable to avoid unnecessary casting? However looking at existing Base64 libs (OZ and solady) they also use bytes input, so maybe I'm missing something

Copy link
Member

@DaniPopes DaniPopes Jan 17, 2024

Choose a reason for hiding this comment

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

Thought strings coerce to bytes but that's only for literals. It's not that big of a deal if we can support both.

#6830

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

I believe this can be just abi_encoded.

crates/cheatcodes/src/base64.rs Outdated Show resolved Hide resolved
crates/cheatcodes/src/base64.rs Outdated Show resolved Hide resolved
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM! FYI I've edited the description to use GitHub keywords when referencing issues.

@DaniPopes DaniPopes merged commit bb35926 into foundry-rs:master Jan 14, 2024
20 checks passed
@0xAndoroid
Copy link
Contributor Author

Thanks for your help!

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.

Add bytes to Base64 encoding in VM
3 participants