Skip to content

Commit 2ed985f

Browse files
committed
Merge branch 'master' into hc-simple-mapping-primitive
2 parents 644ab71 + ee42309 commit 2ed985f

File tree

472 files changed

+13438
-5354
lines changed

Some content is hidden

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

472 files changed

+13438
-5354
lines changed

.config/cargo_spellcheck.dic

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
100
1+
110
22

33
ABI
44
AST
@@ -37,8 +37,8 @@ defrag
3737
defragmentation
3838
deploy
3939
dereferencing
40-
deserializes
41-
dispatchable
40+
deserialize/S
41+
dispatchable/S
4242
encodable
4343
evaluable
4444
fuzzer
@@ -65,6 +65,7 @@ v3
6565
validator
6666
variadic
6767
versa
68+
versioned
6869
versioning
6970
Verbatim
7071
metadata
@@ -95,4 +96,9 @@ runtime/S
9596
struct/S
9697
vec/S
9798
vector/S
99+
implementer/S
100+
deduplicated
98101
wildcard/S
102+
natively
103+
payability
104+
unpayable

.gitlab-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ fmt:
289289
script:
290290
- cargo fmt --verbose --all -- --check
291291
# For the UI tests we need to disable the license check
292-
- cargo fmt --verbose --all -- --check --config=license_template_path="" crates/lang/macro/tests/ui/contract/{pass,fail}/*.rs
292+
- cargo fmt --verbose --all -- --check --config=license_template_path="" crates/lang/tests/ui/contract/{pass,fail}/*.rs
293+
- cargo fmt --verbose --all -- --check --config=license_template_path="" crates/lang/tests/ui/trait_def/{pass,fail}/*.rs
293294

294295

295296
#### stage: examples

.rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ trailing_comma = "Vertical"
4343
match_block_trailing_comma = false
4444
blank_lines_upper_bound = 1
4545
blank_lines_lower_bound = 0
46-
edition = "2018" # changed
46+
edition = "2021" # changed
4747
version = "One"
4848
merge_derives = true
4949
use_try_shorthand = true # changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
"crates/metadata",
45
"crates/allocator",

RELEASES.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,85 @@
1+
# Version 3.0-rc7 (UNRELEASED)
2+
3+
This is the 7th release candidate for ink! 3.0.
4+
5+
## Added
6+
7+
- The ink! codegen now heavily relies on static type information based on traits defined in `ink_lang`.
8+
- Some of those traits and their carried information can be used for static reflection of ink!
9+
smart contracts. Those types and traits reside in the new `ink_lang::reflect` module and is
10+
publicly usable by ink! smart contract authors.
11+
12+
## Changed
13+
14+
- ink! Contract via `#[ink::contract]`:
15+
- ink! smart contracts now always generated two contract types. Given `MyContract`:
16+
17+
- `MyContract` will still be the storage struct.
18+
However, it can now additionally be used as static dependency in other smart contracts.
19+
Static dependencies can be envisioned as being directly embedded into a smart contract.
20+
- `MyContractRef` is pretty much the same of what we had gotten with the old `ink-as-dependency`.
21+
It is a typed thin-wrapper around an `AccountId` that is mirroring the ink! smart contract's API
22+
and implemented traits.
23+
- ink! Trait Definitions via `#[ink::trait_definition]`:
24+
- ink! trait definitions no longer can define trait constructors.
25+
- ink! trait implementations now inherit `selector` and `payable` properties for trait messages.
26+
- Now explicitly setting `selector` or `payable` property for an implemented ink! trait method
27+
will only act as a guard that the set property is in fact the same as defined by the ink!
28+
trait definition.
29+
- Improve quite a few ink! specific compile errors:
30+
- For example when using ink! messages and constructors that have inputs or outputs that cannot
31+
be encoded or decoded using the SCALE codec.
32+
- Simplified selector computation for ink! trait methods.
33+
- Now selectors are encoded as `blake2b({namespace}::{trait_identifier}::{message_identifier})[0..4]`.
34+
If no `namespace` is set for the ink! trait definition then the formula is
35+
`blake2b({trait_identifier}::{message_identifier})[0..4]`.
36+
Where `trait_identifier` and `message_identifier` both refer to the identifiers of the ink! trait
37+
definition and ink! trait message respectively.
38+
39+
## Fixed
40+
41+
- Contracts that are compiled as root (the default) now properly revert the transaction if a message
42+
returned `Result::Err`.
43+
- This does not apply to ink! smart contracts that are used as dependencies. Therefore it is still possible to match against a result return type for a called dependency.
44+
145
# Version 3.0-rc6
246

347
This is the 6th release candidate for ink! 3.0.
448

49+
## Compatibility
50+
51+
### Please upgrade `cargo-contract`
52+
53+
You need to update to the latest `cargo-contract` in order to use this release:
54+
```
55+
cargo install cargo-contract --vers ^0.15 --force --locked
56+
```
57+
58+
If you build contracts from this release candidate with an older `cargo-contract`,
59+
the UI's won't display all contract-relevant fields.
60+
61+
### Please upgrade `scale-info` in your contract's dependencies
62+
63+
In this release candidate we upgraded `scale-info`. You have to use a compatible
64+
version in your contract's `Cargo.toml` as well; `cargo-contract` will throw
65+
an error otherwise.
66+
67+
The `Cargo.toml` should contain
68+
```
69+
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
70+
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive", "full"] }
71+
```
72+
73+
### New metadata format
74+
75+
There are breaking changes to the metadata format in this release.
76+
77+
- Removes top level `metadataVersion` field from the contract metadata (https://github.com/paritytech/cargo-contract/pull/342/files).
78+
- Introduces new top level versioned metadata [enum](https://github.com/paritytech/ink/blob/master/crates/metadata/src/lib.rs#L68).
79+
- Upgrades to `scale-info` version `1.0` (https://github.com/paritytech/ink/pull/845).
80+
- The previous supported version was `0.6`, so check release notes for all changes since then: https://github.com/paritytech/ink/pull/845
81+
- One of the main changes to be aware of is the change to 0 based type lookup ids: https://github.com/paritytech/scale-info/pull/90
82+
583
## Added
684
- Added an Ethereum-compatibility function to recover a public key from an ECDSA signature and message hash - [#914](https://github.com/paritytech/ink/pull/914) (thanks [@xgreenx](https://github.com/xgreenx)).
785
- Added new utility proc. macros to `ink_lang` crate - [#947](https://github.com/paritytech/ink/pull/947):

crates/allocator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "ink_allocator"
33
version = "3.0.0-rc6"
44
authors = ["Parity Technologies <[email protected]>", "Robin Freyler <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
license = "Apache-2.0"
88
readme = "README.md"

crates/engine/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "ink_engine"
33
version = "3.0.0-rc6"
44
authors = ["Parity Technologies <[email protected]>", "Michael Müller <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
license = "Apache-2.0"
88
readme = "README.md"
@@ -23,7 +23,7 @@ sha3 = { version = "0.9" }
2323
blake2 = { version = "0.9" }
2424

2525
# ECDSA for the off-chain environment.
26-
libsecp256k1 = { version = "0.3.5", default-features = false }
26+
libsecp256k1 = { version = "0.7.0" }
2727

2828
[features]
2929
default = ["std"]

crates/engine/src/ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl Engine {
428428
message_hash: &[u8; 32],
429429
output: &mut [u8; 33],
430430
) -> Result {
431-
use secp256k1::{
431+
use libsecp256k1::{
432432
recover,
433433
Message,
434434
RecoveryId,
@@ -443,7 +443,7 @@ impl Engine {
443443
signature[64]
444444
};
445445
let message = Message::parse(message_hash);
446-
let signature = Signature::parse_slice(&signature[0..64])
446+
let signature = Signature::parse_standard_slice(&signature[0..64])
447447
.unwrap_or_else(|error| panic!("Unable to parse the signature: {}", error));
448448

449449
let recovery_id = RecoveryId::parse(recovery_byte)

crates/engine/src/tests.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ use crate::ext::{
1616
Engine,
1717
Error,
1818
};
19+
use libsecp256k1::{
20+
Message,
21+
PublicKey,
22+
SecretKey,
23+
};
1924

2025
/// The public methods of the `contracts` pallet write their result into an
2126
/// `output` buffer instead of returning them. Since we aim to emulate this
@@ -192,3 +197,74 @@ fn must_panic_when_buffer_too_small() {
192197
// then
193198
unreachable!("`get_storage` must already have panicked");
194199
}
200+
201+
#[test]
202+
fn ecdsa_recovery_test_from_contracts_pallet() {
203+
// given
204+
let mut engine = Engine::new();
205+
#[rustfmt::skip]
206+
let signature: [u8; 65] = [
207+
161, 234, 203, 74, 147, 96, 51, 212, 5, 174, 231, 9, 142, 48, 137, 201,
208+
162, 118, 192, 67, 239, 16, 71, 216, 125, 86, 167, 139, 70, 7, 86, 241,
209+
33, 87, 154, 251, 81, 29, 160, 4, 176, 239, 88, 211, 244, 232, 232, 52,
210+
211, 234, 100, 115, 230, 47, 80, 44, 152, 166, 62, 50, 8, 13, 86, 175,
211+
28,
212+
];
213+
#[rustfmt::skip]
214+
let message_hash: [u8; 32] = [
215+
162, 28, 244, 179, 96, 76, 244, 178, 188, 83, 230, 248, 143, 106, 77, 117,
216+
239, 95, 244, 171, 65, 95, 62, 153, 174, 166, 182, 28, 130, 73, 196, 208
217+
];
218+
219+
// when
220+
let mut output = [0; 33];
221+
engine
222+
.ecdsa_recover(&signature, &message_hash, &mut output)
223+
.expect("must work");
224+
225+
// then
226+
#[rustfmt::skip]
227+
const EXPECTED_COMPRESSED_PUBLIC_KEY: [u8; 33] = [
228+
2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11,
229+
7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23,
230+
152,
231+
];
232+
assert_eq!(output, EXPECTED_COMPRESSED_PUBLIC_KEY);
233+
}
234+
235+
#[test]
236+
fn ecdsa_recovery_with_secp256k1_crate() {
237+
// given
238+
let mut engine = Engine::new();
239+
let seckey = [
240+
59, 148, 11, 85, 134, 130, 61, 253, 2, 174, 59, 70, 27, 180, 51, 107, 94, 203,
241+
174, 253, 102, 39, 170, 146, 46, 252, 4, 143, 236, 12, 136, 28,
242+
];
243+
let pubkey = PublicKey::parse_compressed(&[
244+
2, 29, 21, 35, 7, 198, 183, 43, 14, 208, 65, 139, 14, 112, 205, 128, 231, 245,
245+
41, 91, 141, 134, 245, 114, 45, 63, 82, 19, 251, 210, 57, 79, 54,
246+
])
247+
.expect("pubkey creation failed");
248+
249+
let mut msg_hash = [0; 32];
250+
crate::hashing::sha2_256(b"Some message", &mut msg_hash);
251+
252+
let msg = Message::parse(&msg_hash);
253+
let seckey = SecretKey::parse(&seckey).expect("secret key creation failed");
254+
let (signature, recovery_id) = libsecp256k1::sign(&msg, &seckey);
255+
256+
let mut signature = signature.serialize().to_vec();
257+
signature.push(recovery_id.serialize());
258+
let signature_with_recovery_id: [u8; 65] = signature
259+
.try_into()
260+
.expect("unable to create signature with recovery id");
261+
262+
// when
263+
let mut output = [0; 33];
264+
engine
265+
.ecdsa_recover(&signature_with_recovery_id, &msg.serialize(), &mut output)
266+
.expect("ecdsa recovery failed");
267+
268+
// then
269+
assert_eq!(output, pubkey.serialize_compressed());
270+
}

crates/env/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "ink_env"
33
version = "3.0.0-rc6"
44
authors = ["Parity Technologies <[email protected]>", "Robin Freyler <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
license = "Apache-2.0"
88
readme = "README.md"
@@ -15,7 +15,6 @@ categories = ["no-std", "embedded"]
1515
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
1616

1717
[dependencies]
18-
ink_engine = { version = "3.0.0-rc6", path = "../engine/", default-features = false, optional = true }
1918
ink_metadata = { version = "3.0.0-rc6", path = "../metadata/", default-features = false, features = ["derive"], optional = true }
2019
ink_allocator = { version = "3.0.0-rc6", path = "../allocator/", default-features = false }
2120
ink_primitives = { version = "3.0.0-rc6", path = "../primitives/", default-features = false }
@@ -30,13 +29,19 @@ arrayref = "0.3"
3029
static_assertions = "1.1"
3130
sp-arithmetic = { version = "3.0", default-features = false }
3231

32+
[target.'cfg(target_arch = "wasm32")'.dependencies]
33+
libsecp256k1 = { version = "0.7.0", default-features = false }
34+
35+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
36+
ink_engine = { version = "3.0.0-rc6", path = "../engine/", default-features = false, optional = true }
37+
3338
# Hashes for the off-chain environment.
3439
sha2 = { version = "0.9", optional = true }
3540
sha3 = { version = "0.9", optional = true }
3641
blake2 = { version = "0.9", optional = true }
3742

3843
# ECDSA for the off-chain environment.
39-
libsecp256k1 = { version = "0.3.5", default-features = false }
44+
libsecp256k1 = { version = "0.7.0" }
4045

4146
# Only used in the off-chain environment.
4247
#

0 commit comments

Comments
 (0)