Abstractions for mapping arbitrary Rust types to Solidity ABI compatible types#2441
Merged
davidsemakula merged 43 commits intomasterfrom Apr 1, 2025
Merged
Abstractions for mapping arbitrary Rust types to Solidity ABI compatible types#2441davidsemakula merged 43 commits intomasterfrom
davidsemakula merged 43 commits intomasterfrom
Conversation
3c83ded to 0424020 Compare davidsemakula commented Mar 29, 2025
b59f037 to bfbbe63 Compare cmichi reviewed Mar 31, 2025
crates/ink/tests/ui/contract/pass/message/message-selector-encoding-sol.rs Show resolved Hide resolved
cmichi reviewed Mar 31, 2025
cmichi reviewed Mar 31, 2025
…on/implementation
cmichi approved these changes Mar 31, 2025
1440c85 to 63f6b28 Compare This was referenced Apr 1, 2025
This was referenced May 29, 2025
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2429
Closes #2428
cargo-contractorpallet-revive?Description
SolEncodeandSolDecodetraits toink_primitivesas replacements foralloy_sol_types::SolValuein public interfaces (and analogs toscale::Encodeandscale::Decodebut for Solidity ABI encoding/decoding).SolEncodeandSolDecodeessentially describe how to map an arbitrary Rust/ink! type to a Solidity ABI type equivalent (i.e. a type that implementsSolTypeEncodeand/orSolTypeDecode) for Solidity ABI encoding/decodingSolTypeEncodeandSolTypeDecodesealed traits which describe a Rust/ink! equivalent of a Solidity ABI type, and implement logic for Solidity ABI encoding/decoding. These traits are implemented for all Rust primitive types that have an equivalent Solidity ABI type, as well asAddress/H160andU256ink! primitives. HoweverSolTypeEncodeis additionally implemented for references (and a few smart pointers) of types that implementSolTypeEncode(i.e.&T,&mut T,Box<T>andCow<T>forT: SolTypeEncode). The rustdoc for both traits includes a table showing the mapping of Rust/ink! primitives to equivalent Solidity ABI types. AllSolTypeEncodeandSolTypeDecodetypes also implementSolEncodeandSolDecodeSolBytes<T>type as a newtype wrapper that encodes/decodesu8sequences/collections as their equivalent Solidity bytes representations.Thas aSolBytesTypebound, andSolBytesTypeis a sealed trait that's only implemented foru8,[u8; N]where1 <= N <= 32andVec<u8>SolTypeEncode,SolTypeDecode,SolEncodeandSolDecodeimplementations matchalloy_sol_types::SolValueequivalentsalloy_sol_typesoutsideink_primitivesand instead uses the new Solidity compatibility abstractions above defined inink_primitivesSolEncodeandSolDecodeforAccountId,Hash,H160andH256types from ink! primitivesAddressinto a type alias forH160, and replacesH160withAddressin the public interfaces whereH160semantically represents an addressRelated/future work - to be done in a follow up PR(s)
Derivemacro for implementingSolEncodeandSolDecodefor arbitrary types Provide aDerivemacro for implementingSolEncodeandSolDecodefor arbitrary types #2462pallet-reviveequivalent (e.g.uint248) Provide Rust/ink! types for Solidity integer types that don't have a Rust/ink!/pallet-revive equivalent #2461SolEncodeandSolDecodeininkcrate rustdoc and ink-docs websiteinkcrate rustdoc Documentation for contract abi arg and provided Rust/ink! to Solidity type mappings #2463abiarg to#[ink::contract]docs for v6 ink-docs#379cargo-contractSolidity metadata generation to properly supportSolEncodeandSolDecodeimplementing arbitrary types Update Solidity metadata generation to properly supportSolEncodeandSolDecodeimplementing arbitrary types cargo-contract#1996See also
SolDecode,SolTypeDecodeand supportSolBytesfor boxed slices #2476Checklist before requesting a review
CHANGELOG.md