Skip to content

Commit 717b498

Browse files
Improve Solidity ABI support in codegen, ink_env and ink_e2e (#2517)
* codegen: Solidity ABI support for trait definitions * codegen: Refactor CallBuilder generation * codegen: Refactor dispatchable message info * codegen: Solidity ABI support for trait message guards * tests: Add `trait-flipper` to Solidity ABI integration tests * tests: Add `trait-dyn-cross-contract-calls` to Solidity ABI integration tests * e2e: Solidity ABI support for call result decoding * codegen: Disable ink! metadata generator for Solidity ABI only contracts * ci: Update `examples-test` job * codegen: Refactor Solidity selector utilities * ci: Silence unexpected `ink_abi` `cfg` warnings for `clippy-examples` and `examples-docs` jobs * ir: Remove unused ABI enum * docs: Encoding types * env: Add `build_call_abi` * codegen: ABI specific contract refs, call builders and message builders * e2e: call builder utilities * Update changelog * style: Refactor ABI types * tests: Update ui test output * codegen: input and output guards for Solidity ABI * docs: Update `contract_ref!` and `message_builder!` docs and examples * ci: Update `clippy-examples` and `examples-contract-build-riscv` * env: Use the "default" for `build_call` utility * docs: "default" ABI for calls * codegen: Ensure Solidity selector and selector ids are always computed at compile time * docs: `build_call_abi` rustdoc formatting * primitives: Standard trait derives for ABI type * chore: Remove unnecessary lint suppression * primitives: Solidity ABI encode/decode for function params * env: Fix `SolEncode` implementation for `ArgumentList` * codegen: Use `SolParamsDecode` trait for parameter decoding
1 parent aea5c92 commit 717b498

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2155
-1143
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ jobs:
172172
fail-fast: false
173173
matrix:
174174
type: [STD, RISCV]
175+
env:
176+
# TODO: (@davidsemakula) Update all manifests for integration-tests and remove this
177+
# i.e. update with equivalent of setting `--check-cfg cfg(ink_abi,values("ink","sol","all"))`
178+
ALLOWED_LINTS: -A unexpected_cfgs
175179
steps:
176180
- name: Checkout
177181
uses: actions/checkout@v4
@@ -191,7 +195,7 @@ jobs:
191195
with:
192196
command: |
193197
scripts/for_all_contracts_exec.sh --path integration-tests -- cargo clippy --all-targets \
194-
--manifest-path {} -- -D warnings -A $CLIPPY_ALLOWED
198+
--manifest-path {} -- -D warnings -A $CLIPPY_ALLOWED $ALLOWED_LINTS
195199
196200
- name: Run Clippy for RISC-V Examples
197201
uses: ./.github/run-container-command
@@ -200,7 +204,7 @@ jobs:
200204
command: |
201205
scripts/for_all_contracts_exec.sh --path integration-tests -- cargo clippy --no-default-features \
202206
--target ${CLIPPY_TARGET} \
203-
--manifest-path {} -- -D warnings -A $CLIPPY_ALLOWED
207+
--manifest-path {} -- -D warnings -A $CLIPPY_ALLOWED $ALLOWED_LINTS
204208
205209
check:
206210
runs-on: ubuntu-latest
@@ -560,6 +564,7 @@ jobs:
560564
--ignore internal/mapping --ignore public/debugging-strategies --ignore public/wildcard-selector \
561565
--ignore solidity-abi/sol-cross-contract --ignore solidity-abi/sol-encoding \
562566
--ignore solidity-abi/solidity-calls-flipper --ignore solidity-abi/events \
567+
--ignore solidity-abi/trait-flipper --ignore solidity-abi/trait-dyn-cross-contract-calls \
563568
--partition ${{ matrix.partition }}/4 -- \
564569
cargo contract test --all-features --manifest-path {}
565570
@@ -741,19 +746,36 @@ jobs:
741746
- name: Build Contract Examples for RISC-V
742747
uses: ./.github/run-container-command
743748
env:
744-
RUSTC_BOOTSTRAP: 1
745749
MANIFEST_PATH: ""
746750
CONTRACT_SIZE_FILE: "measurements-${{ env.MEASUREMENTS_ID }}/contract_size_"
747751
CARGO_INCREMENTAL: 0
748752
with:
749753
command: |
750754
mkdir -p measurements-${{ env.MEASUREMENTS_ID }}/
751-
scripts/for_all_contracts_exec2.sh --path integration-tests -- \
755+
scripts/for_all_contracts_exec2.sh --path integration-tests \
756+
--ignore solidity-abi/sol-cross-contract --ignore solidity-abi/sol-encoding \
757+
--ignore solidity-abi/solidity-calls-flipper --ignore solidity-abi/events \
758+
--ignore solidity-abi/trait-flipper --ignore solidity-abi/trait-dyn-cross-contract-calls -- \
752759
scripts/build_and_determine_contract_size.sh {}
753760
754761
#bash -c "scripts/build_and_determine_contract_size.sh {} >> ${CONTRACT_SIZE_FILE} && \
755762
#sed -ie 's/^integration-tests\/\(public\/\|internal\/\)\?//' ${CONTRACT_SIZE_FILE}"
756763

764+
# NOTE: Sharing build artifacts (i.e. via a shared cargo target directory) with other contracts
765+
# that don't have the same ABI set makes the builds fail.
766+
- name: Build Contract Examples for RISC-V (Solidity ABI)
767+
uses: ./.github/run-container-command
768+
env:
769+
MANIFEST_PATH: ""
770+
CONTRACT_SIZE_FILE: "measurements-${{ env.MEASUREMENTS_ID }}/contract_size_"
771+
CARGO_INCREMENTAL: 0
772+
CARGO_TARGET_DIR: ${{ env.CARGO_TARGET_DIR }}/sol-abi
773+
with:
774+
command: |
775+
mkdir -p measurements-${{ env.MEASUREMENTS_ID }}/
776+
scripts/for_all_contracts_exec2.sh --path integration-tests/solidity-abi -- \
777+
scripts/build_and_determine_contract_size.sh {}
778+
757779
- uses: actions/upload-artifact@v4
758780
with:
759781
path: ./measurements-${{ env.MEASUREMENTS_ID }}/*
@@ -805,7 +827,8 @@ jobs:
805827
- name: Create Examples Docs
806828
uses: ./.github/run-container-command
807829
env:
808-
RUSTDOCFLAGS: -Dwarnings
830+
# TODO: (@davidsemakula) Update all manifests for integration-tests and remove `--check-cfg` flag
831+
RUSTDOCFLAGS: -Dwarnings --check-cfg cfg(ink_abi,values("ink","sol","all"))
809832
with:
810833
command: |
811834
# `--document-private-items` needs to be in here because currently our contract macro

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- Support ABI `cfg` flag in codegen - [#2501](https://github.com/use-ink/ink/pull/2501)
1111
- Generate Solidity ABI compatibility metadata - [#2510](https://github.com/use-ink/ink/pull/2510)
12+
- Improve Solidity ABI support in `codegen`, `ink_env` and `ink_e2e` - [#2517](https://github.com/use-ink/ink/pull/2517)
1213

1314
### Changed
1415
- Use marker trait for finding ink! storage `struct` during code analysis - [2499](https://github.com/use-ink/ink/pull/2499)

crates/e2e/src/backend.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use ink_env::{
16+
DefaultEnvironment,
17+
Environment,
18+
};
19+
use ink_primitives::{
20+
abi::{
21+
AbiDecodeWith,
22+
AbiEncodeWith,
23+
Ink,
24+
},
25+
DepositLimit,
26+
};
27+
use jsonrpsee::core::async_trait;
28+
use pallet_revive::evm::CallTrace;
29+
use sp_weights::Weight;
30+
use subxt::dynamic::Value;
31+
1532
use super::{
1633
InstantiateDryRunResult,
1734
Keypair,
@@ -30,22 +47,6 @@ use crate::{
3047
CallDryRunResult,
3148
UploadResult,
3249
};
33-
use ink_env::{
34-
DefaultEnvironment,
35-
Environment,
36-
};
37-
use ink_primitives::{
38-
reflect::{
39-
AbiDecodeWith,
40-
AbiEncodeWith,
41-
ScaleEncoding,
42-
},
43-
DepositLimit,
44-
};
45-
use jsonrpsee::core::async_trait;
46-
use pallet_revive::evm::CallTrace;
47-
use sp_weights::Weight;
48-
use subxt::dynamic::Value;
4950

5051
/// Full E2E testing backend: combines general chain API and contract-specific operations.
5152
#[async_trait]
@@ -134,7 +135,7 @@ pub trait ContractsBackend<E: Environment> {
134135
fn instantiate<
135136
'a,
136137
Contract: Clone,
137-
Args: Send + Clone + AbiEncodeWith<ScaleEncoding> + Sync,
138+
Args: Send + Clone + AbiEncodeWith<Ink> + Sync,
138139
R,
139140
>(
140141
&'a mut self,
@@ -271,7 +272,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
271272
message: &CallBuilderFinal<E, Args, RetType, Abi>,
272273
value: E::Balance,
273274
storage_deposit_limit: DepositLimit<E::Balance>,
274-
) -> Result<CallDryRunResult<E, RetType>, Self::Error>
275+
) -> Result<CallDryRunResult<E, RetType, Abi>, Self::Error>
275276
where
276277
CallBuilderFinal<E, Args, RetType, Abi>: Clone;
277278

@@ -311,7 +312,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
311312
/// instance is reused!
312313
async fn bare_instantiate<
313314
Contract: Clone,
314-
Args: Send + Sync + AbiEncodeWith<ScaleEncoding> + Clone,
315+
Args: Send + Sync + AbiEncodeWith<Ink> + Clone,
315316
R,
316317
>(
317318
&mut self,
@@ -326,7 +327,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
326327
/// Dry run contract instantiation.
327328
async fn bare_instantiate_dry_run<
328329
Contract: Clone,
329-
Args: Send + Sync + AbiEncodeWith<ScaleEncoding> + Clone,
330+
Args: Send + Sync + AbiEncodeWith<Ink> + Clone,
330331
R,
331332
>(
332333
&mut self,

crates/e2e/src/backend_calls.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::marker::PhantomData;
16+
17+
use ink_env::Environment;
18+
use ink_primitives::{
19+
abi::{
20+
AbiDecodeWith,
21+
AbiEncodeWith,
22+
Ink,
23+
},
24+
DepositLimit,
25+
};
26+
use sp_weights::Weight;
27+
1528
use super::{
1629
balance_to_deposit_limit,
1730
InstantiateDryRunResult,
@@ -28,25 +41,13 @@ use crate::{
2841
UploadResult,
2942
H256,
3043
};
31-
use ink_env::Environment;
32-
use ink_primitives::{
33-
reflect::{
34-
AbiDecodeWith,
35-
AbiEncodeWith,
36-
ScaleEncoding,
37-
},
38-
DepositLimit,
39-
};
40-
use sp_weights::Weight;
41-
use std::marker::PhantomData;
4244

4345
/// Allows to build an end-to-end call using a builder pattern.
4446
pub struct CallBuilder<'a, E, Args, RetType, B, Abi>
4547
where
4648
E: Environment,
4749
Args: AbiEncodeWith<Abi> + Clone,
4850
RetType: Send + AbiDecodeWith<Abi>,
49-
5051
B: BuilderClient<E>,
5152
Abi: Clone,
5253
{
@@ -141,7 +142,7 @@ where
141142
/// to add a margin to the gas limit.
142143
pub async fn submit(
143144
&mut self,
144-
) -> Result<CallResult<E, RetType, B::EventLog>, B::Error>
145+
) -> Result<CallResult<E, RetType, B::EventLog, Abi>, B::Error>
145146
where
146147
CallBuilderFinal<E, Args, RetType, Abi>: Clone,
147148
{
@@ -184,7 +185,7 @@ where
184185
}
185186

186187
/// Dry run the call.
187-
pub async fn dry_run(&mut self) -> Result<CallDryRunResult<E, RetType>, B::Error>
188+
pub async fn dry_run(&mut self) -> Result<CallDryRunResult<E, RetType, Abi>, B::Error>
188189
where
189190
CallBuilderFinal<E, Args, RetType, Abi>: Clone,
190191
{
@@ -203,7 +204,7 @@ where
203204
pub struct InstantiateBuilder<'a, E, Contract, Args, R, B>
204205
where
205206
E: Environment,
206-
Args: AbiEncodeWith<ScaleEncoding> + Clone,
207+
Args: AbiEncodeWith<Ink> + Clone,
207208
Contract: Clone,
208209

209210
B: ContractsBackend<E>,
@@ -221,7 +222,7 @@ where
221222
impl<'a, E, Contract, Args, R, B> InstantiateBuilder<'a, E, Contract, Args, R, B>
222223
where
223224
E: Environment,
224-
Args: AbiEncodeWith<ScaleEncoding> + Clone + Send + Sync,
225+
Args: AbiEncodeWith<Ink> + Clone + Send + Sync,
225226
Contract: Clone,
226227
B: BuilderClient<E>,
227228
{

crates/e2e/src/builders.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::H256;
1615
use ink_env::{
1716
call::{
1817
utils::{
@@ -25,23 +24,25 @@ use ink_env::{
2524
},
2625
Environment,
2726
};
28-
use ink_primitives::reflect::{
27+
use ink_primitives::abi::{
2928
AbiEncodeWith,
30-
ScaleEncoding,
29+
Ink,
3130
};
3231

32+
use crate::H256;
33+
3334
/// The type returned from `ContractRef` constructors, partially initialized with the
3435
/// execution input arguments.
3536
pub type CreateBuilderPartial<E, ContractRef, Args, R> = CreateBuilder<
3637
E,
3738
ContractRef,
3839
Set<LimitParamsV2>,
39-
Set<ExecutionInput<Args, ScaleEncoding>>,
40+
Set<ExecutionInput<Args, Ink>>,
4041
Set<ReturnType<R>>,
4142
>;
4243

4344
/// Get the encoded constructor arguments from the partially initialized `CreateBuilder`
44-
pub fn constructor_exec_input<E, ContractRef, Args: AbiEncodeWith<ScaleEncoding>, R>(
45+
pub fn constructor_exec_input<E, ContractRef, Args: AbiEncodeWith<Ink>, R>(
4546
builder: CreateBuilderPartial<E, ContractRef, Args, R>,
4647
) -> Vec<u8>
4748
where

0 commit comments

Comments
 (0)