Skip to content

Commit 35b5fcc

Browse files
authored
Merge branch 'paritytech:master' into feature/ink-ecdsa-recovery
2 parents a1e6fcb + 6e7941a commit 35b5fcc

File tree

169 files changed

+1373
-322
lines changed

Some content is hidden

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

169 files changed

+1373
-322
lines changed

.config/cargo_spellcheck.dic

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
ABI
44
AST
55
BLAKE2
6+
BLAKE2b
67
DApp
78
ECDSA
89
ERC

.gitlab-ci.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ codecov:
220220
variables:
221221
# For codecov it's sufficient to run the fuzz tests only once.
222222
QUICKCHECK_TESTS: 1
223+
INK_COVERAGE_REPORTING: "true"
223224
CARGO_INCREMENTAL: 0
224225
# Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
225226
RUSTFLAGS: "-Zprofile -Zmir-opt-level=0 -Ccodegen-units=1
226-
-Copt-level=0 -Coverflow-checks=off"
227+
-Clink-dead-code -Copt-level=0 -Coverflow-checks=off"
227228
# The `cargo-taurpalin` coverage reporting tool seems to have better code instrumentation and thus
228229
# produces better results for Rust codebases in general. However, unlike `grcov` it requires
229230
# running docker with `--security-opt seccomp=unconfined` which is why we use `grcov` instead.
@@ -236,6 +237,7 @@ codecov:
236237
- cargo clean
237238
# make sure there's no stale coverage artifacts
238239
- find . -name "*.profraw" -type f -delete
240+
- find . -name "*.gcda" -type f -delete
239241
script:
240242
# RUSTFLAGS are the cause target cache can't be used here
241243
- cargo build --verbose --all-features --workspace
@@ -287,7 +289,7 @@ fmt:
287289
script:
288290
- cargo fmt --verbose --all -- --check
289291
# For the UI tests we need to disable the license check
290-
- cargo fmt --verbose --all -- --check --config=license_template_path="" crates/lang/macro/tests/ui/{pass,fail}/*.rs
292+
- cargo fmt --verbose --all -- --check --config=license_template_path="" crates/lang/macro/tests/ui/contract/{pass,fail}/*.rs
291293

292294

293295
#### stage: examples

crates/engine/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ categories = ["no-std", "embedded"]
1515
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
1616

1717
[dependencies]
18-
scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
18+
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive", "full"] }
1919
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
2020

2121
sha2 = { version = "0.9" }

crates/engine/src/ext.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,12 @@ impl Engine {
464464
///
465465
/// Panics if the slice is too large and does not fit.
466466
fn set_output(output: &mut &mut [u8], slice: &[u8]) {
467-
if slice.len() > output.len() {
468-
panic!(
469-
"the output buffer is too small! the decoded storage is of size {} bytes, \
470-
but the output buffer has only room for {}.",
471-
slice.len(),
472-
output.len()
473-
);
474-
}
467+
assert!(
468+
slice.len() <= output.len(),
469+
"the output buffer is too small! the decoded storage is of size {} bytes, \
470+
but the output buffer has only room for {}.",
471+
slice.len(),
472+
output.len(),
473+
);
475474
output[..slice.len()].copy_from_slice(slice);
476475
}

crates/env/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ink_allocator = { version = "3.0.0-rc5", path = "../allocator/", default-feature
2121
ink_primitives = { version = "3.0.0-rc5", path = "../primitives/", default-features = false }
2222
ink_prelude = { version = "3.0.0-rc5", path = "../prelude/", default-features = false }
2323

24-
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
24+
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive", "full"] }
2525
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
2626
num-traits = { version = "0.2", default-features = false, features = ["i128"] }
2727
cfg-if = "1.0"

crates/env/src/engine/off_chain/db/exec_context.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ where
148148
///
149149
/// If there has already been set a caller.
150150
pub fn caller(mut self, caller: T::AccountId) -> Self {
151-
if self.caller.is_some() {
152-
panic!("already has a caller");
153-
}
151+
assert!(self.caller.is_none(), "already has a caller");
154152
self.caller = Some(caller);
155153
self
156154
}
@@ -161,9 +159,7 @@ where
161159
///
162160
/// If there has already been set a callee.
163161
pub fn callee(mut self, callee: T::AccountId) -> Self {
164-
if self.callee.is_some() {
165-
panic!("already has a callee");
166-
}
162+
assert!(self.callee.is_none(), "already has a callee");
167163
self.callee = Some(callee);
168164
self
169165
}
@@ -174,9 +170,7 @@ where
174170
///
175171
/// If there has already been set provided gas.
176172
pub fn gas(mut self, gas: u64) -> Self {
177-
if self.gas.is_some() {
178-
panic!("already has provided gas");
179-
}
173+
assert!(self.gas.is_none(), "already has provided gas");
180174
self.gas = Some(gas);
181175
self
182176
}
@@ -187,9 +181,10 @@ where
187181
///
188182
/// If there has already been set transferred value (endowment).
189183
pub fn transferred_value(mut self, transferred_value: T::Balance) -> Self {
190-
if self.transferred_value.is_some() {
191-
panic!("already has set transferred value (endowment)");
192-
}
184+
assert!(
185+
self.transferred_value.is_none(),
186+
"already has set transferred value (endowment)"
187+
);
193188
self.transferred_value = Some(transferred_value);
194189
self
195190
}
@@ -200,9 +195,7 @@ where
200195
///
201196
/// If there has already been set call data.
202197
pub fn call_data(mut self, call_data: CallData) -> Self {
203-
if self.call_data.is_some() {
204-
panic!("already has set call data");
205-
}
198+
assert!(self.call_data.is_none(), "already has set call data");
206199
self.call_data = Some(call_data);
207200
self
208201
}

crates/env/src/engine/off_chain/impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl EnvBackend for EnvInstance {
157157
{
158158
self.exec_context()
159159
.map(|exec_ctx| &exec_ctx.call_data)
160-
.map(|call_data| scale::Encode::encode(call_data))
160+
.map(scale::Encode::encode)
161161
.map_err(Into::into)
162162
.and_then(|encoded| {
163163
<T as scale::Decode>::decode(&mut &encoded[..])
@@ -247,12 +247,12 @@ impl EnvBackend for EnvInstance {
247247
D: FnOnce(&[u8]) -> ::core::result::Result<T, E>,
248248
{
249249
let encoded_input = input.encode();
250-
let (status_code, mut output) = self
250+
let (status_code, output) = self
251251
.chain_extension_handler
252252
.eval(func_id, &encoded_input)
253253
.expect("encountered unexpected missing chain extension method");
254254
status_to_result(status_code)?;
255-
let decoded = decode_to_result(&mut output)?;
255+
let decoded = decode_to_result(output)?;
256256
Ok(decoded)
257257
}
258258
}

crates/lang/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ink_prelude = { version = "3.0.0-rc5", path = "../prelude", default-features = f
2323
ink_eth_compatibility = { version = "3.0.0-rc5", path = "../eth_compatibility", default-features = false }
2424
ink_lang_macro = { version = "3.0.0-rc5", path = "macro", default-features = false }
2525

26-
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
26+
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive", "full"] }
2727
derive_more = { version = "0.99", default-features = false, features = ["from"] }
2828
static_assertions = "1.1"
2929

crates/lang/codegen/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ itertools = "0.10"
2727
either = { version = "1.5", default-features = false }
2828
blake2 = "0.9"
2929
heck = "0.3.1"
30-
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
30+
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive", "full"] }
3131
impl-serde = "0.3.1"
3232

3333
[features]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2018-2021 Parity Technologies (UK) Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use crate::GenerateCode;
16+
use derive_more::From;
17+
use ir::HexLiteral;
18+
use proc_macro2::TokenStream as TokenStream2;
19+
use quote::quote_spanned;
20+
21+
/// Generates code for the `selector_id!` macro.
22+
#[derive(From)]
23+
pub struct Blake2x256<'a> {
24+
/// The `blake2x256!` macro input.
25+
macro_input: &'a ir::Blake2x256Macro,
26+
}
27+
28+
impl GenerateCode for Blake2x256<'_> {
29+
/// Generates `selector_id!` macro code.
30+
fn generate_code(&self) -> TokenStream2 {
31+
let span = self.macro_input.input().span();
32+
let hash_bytes = self
33+
.macro_input
34+
.hash()
35+
.map(|byte| byte.hex_padded_suffixed());
36+
quote_spanned!(span=> [ #( #hash_bytes ),* ] )
37+
}
38+
}

crates/lang/codegen/src/generator/contract.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ pub struct Contract<'a> {
2727
/// The contract to generate code for.
2828
contract: &'a ir::Contract,
2929
}
30-
31-
impl AsRef<ir::Contract> for Contract<'_> {
32-
fn as_ref(&self) -> &ir::Contract {
33-
self.contract
34-
}
35-
}
30+
impl_as_ref_for_generator!(Contract);
3631

3732
impl GenerateCode for Contract<'_> {
3833
/// Generates ink! contract code.

crates/lang/codegen/src/generator/cross_calling.rs

+40-8
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,25 @@ impl CrossCalling<'_> {
243243
ir::Receiver::Ref => None,
244244
ir::Receiver::RefMut => Some(quote! { mut }),
245245
};
246+
let error_ident = match option_env!("INK_COVERAGE_REPORTING") {
247+
Some("true") => {
248+
quote! {
249+
// The code coverage reporting CI stage links dead code,
250+
// hence we have to provide an `unreachable!` here. If
251+
// the invalid implementation above is linked this results
252+
// in a linker error.
253+
::core::unreachable!("this is an invalid ink! message call which should never be possible.");
254+
}
255+
}
256+
_ => {
257+
quote! {
258+
extern {
259+
fn #linker_error_ident() -> !;
260+
}
261+
unsafe { #linker_error_ident() }
262+
}
263+
}
264+
};
246265
quote_spanned!(span=>
247266
type #output_ident = #output_ty;
248267

@@ -253,10 +272,7 @@ impl CrossCalling<'_> {
253272
& #mut_tok self,
254273
#( #input_bindings : #input_types ),*
255274
) -> Self::#output_ident {
256-
extern {
257-
fn #linker_error_ident() -> !;
258-
}
259-
unsafe { #linker_error_ident() }
275+
#error_ident
260276
}
261277
)
262278
}
@@ -377,6 +393,25 @@ impl CrossCalling<'_> {
377393
.inputs()
378394
.map(|pat_type| &*pat_type.ty)
379395
.collect::<Vec<_>>();
396+
let error_ident = match option_env!("INK_COVERAGE_REPORTING") {
397+
Some("true") => {
398+
quote! {
399+
// The code coverage reporting CI stage links dead code,
400+
// hence we have to provide an `unreachable!` here. If
401+
// the invalid implementation above is linked this results
402+
// in a linker error.
403+
::core::unreachable!("this is an invalid ink! message call which should never be possible.");
404+
}
405+
}
406+
_ => {
407+
quote! {
408+
extern {
409+
fn #linker_error_ident() -> !;
410+
}
411+
unsafe { #linker_error_ident() }
412+
}
413+
}
414+
};
380415
quote_spanned!(span =>
381416
type #output_ident = ::ink_lang::NeverReturns;
382417

@@ -386,10 +421,7 @@ impl CrossCalling<'_> {
386421
fn #ident(
387422
#( #input_bindings : #input_types ),*
388423
) -> Self::#output_ident {
389-
extern {
390-
fn #linker_error_ident() -> !;
391-
}
392-
unsafe { #linker_error_ident() }
424+
#error_ident
393425
}
394426
)
395427
}

0 commit comments

Comments
 (0)