Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
b8dc4d61
Commit
b8dc4d61
authored
1 year ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
fix(
#125
): review: invalid pubkeys (len 33)
parent
ff48760d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
node/src/chain_spec/gen_genesis_data.rs
+44
-16
44 additions, 16 deletions
node/src/chain_spec/gen_genesis_data.rs
with
44 additions
and
16 deletions
node/src/chain_spec/gen_genesis_data.rs
+
44
−
16
View file @
b8dc4d61
...
@@ -36,6 +36,7 @@ use sp_runtime::Perbill;
...
@@ -36,6 +36,7 @@ use sp_runtime::Perbill;
use
std
::
collections
::{
BTreeMap
,
HashMap
};
use
std
::
collections
::{
BTreeMap
,
HashMap
};
use
std
::
fmt
::{
Debug
,
Display
,
Formatter
};
use
std
::
fmt
::{
Debug
,
Display
,
Formatter
};
use
std
::
fs
;
use
std
::
fs
;
use
std
::
ops
::{
Add
,
Sub
};
static
G1_DUNITER_V1_EXISTENTIAL_DEPOSIT
:
u64
=
100
;
static
G1_DUNITER_V1_EXISTENTIAL_DEPOSIT
:
u64
=
100
;
static
G1_DUNITER_V1_DECIMALS
:
usize
=
2
;
static
G1_DUNITER_V1_DECIMALS
:
usize
=
2
;
...
@@ -241,7 +242,8 @@ where
...
@@ -241,7 +242,8 @@ where
std
::
env
::
var
(
"DUNITER_GENESIS_CONFIG"
)
.unwrap_or_else
(|
_
|
json_file_path
.to_owned
()),
std
::
env
::
var
(
"DUNITER_GENESIS_CONFIG"
)
.unwrap_or_else
(|
_
|
json_file_path
.to_owned
()),
)
?
;
)
?
;
let
treasury_funder
=
v1_pubkey_to_account_id
(
treasury_funder
);
let
treasury_funder
=
v1_pubkey_to_account_id
(
treasury_funder
)
.expect
(
"treasury founder must have a valid public key"
);
let
common_parameters
=
get_common_parameters
(
&
parameters
);
let
common_parameters
=
get_common_parameters
(
&
parameters
);
...
@@ -296,7 +298,8 @@ where
...
@@ -296,7 +298,8 @@ where
name
,
name
,
IdentityV2
{
IdentityV2
{
index
:
i
.index
,
index
:
i
.index
,
owner_key
:
v1_pubkey_to_account_id
(
i
.owner_key
),
owner_key
:
v1_pubkey_to_account_id
(
i
.owner_key
)
.expect
(
"a G1 identity necessarily has a valid pubkey"
),
old_owner_key
:
None
,
old_owner_key
:
None
,
membership_expire_on
:
timestamp_to_relative_blocs
(
membership_expire_on
:
timestamp_to_relative_blocs
(
i
.membership_expire_on
,
i
.membership_expire_on
,
...
@@ -390,6 +393,7 @@ where
...
@@ -390,6 +393,7 @@ where
// smith certifications
// smith certifications
let
mut
smith_certs_by_receiver
=
BTreeMap
::
new
();
let
mut
smith_certs_by_receiver
=
BTreeMap
::
new
();
let
mut
initial_monetary_mass
=
0
;
let
mut
initial_monetary_mass
=
0
;
let
mut
invalid_wallets
=
0
;
//let mut total_dust = 0;
//let mut total_dust = 0;
// FORCED AUTHORITY //
// FORCED AUTHORITY //
...
@@ -463,7 +467,7 @@ where
...
@@ -463,7 +467,7 @@ where
monetary_mass
+=
balance
;
monetary_mass
+=
balance
;
// json prevents duplicate wallets
// json prevents duplicate wallets
let
owner_key
=
v1_pubkey_to_account_id
(
pubkey
.clone
())
;
if
let
Ok
(
owner_key
)
=
v1_pubkey_to_account_id
(
pubkey
.clone
())
{
accounts
.insert
(
accounts
.insert
(
owner_key
.clone
(),
owner_key
.clone
(),
GenesisAccountData
{
GenesisAccountData
{
...
@@ -472,6 +476,10 @@ where
...
@@ -472,6 +476,10 @@ where
is_identity
:
false
,
is_identity
:
false
,
},
},
);
);
}
else
{
log
::
warn!
(
"wallet {pubkey} has wrong format"
);
invalid_wallets
=
invalid_wallets
.add
(
1
);
}
}
}
// Technical Comittee //
// Technical Comittee //
...
@@ -949,7 +957,7 @@ where
...
@@ -949,7 +957,7 @@ where
);
);
assert_eq!
(
assert_eq!
(
accounts
.len
(),
accounts
.len
(),
identity_index
.len
()
+
genesis_data
.wallets
.len
()
identity_index
.len
()
+
genesis_data
.wallets
.len
()
.sub
(
invalid_wallets
)
);
);
// no inactive tech comm
// no inactive tech comm
for
tech_com_member
in
&
technical_committee
{
for
tech_com_member
in
&
technical_committee
{
...
@@ -1014,12 +1022,18 @@ where
...
@@ -1014,12 +1022,18 @@ where
transactions_history
:
genesis_data
.transactions_history
.map
(|
history
|
{
transactions_history
:
genesis_data
.transactions_history
.map
(|
history
|
{
history
history
.iter
()
.iter
()
// Avoid wrong pubkeys in tx history
.filter
(|(
pubkey
,
_
)|
v1_pubkey_to_account_id
((
*
pubkey
)
.clone
())
.is_ok
())
.map
(|(
pubkey
,
txs
)|
{
.map
(|(
pubkey
,
txs
)|
{
(
(
v1_pubkey_to_account_id
(
pubkey
.clone
()),
v1_pubkey_to_account_id
(
pubkey
.clone
())
.expect
(
"already checked account"
),
txs
.iter
()
txs
.iter
()
// Avoid wrong pubkeys in tx history
.filter
(|
tx
|
v1_pubkey_to_account_id
(
tx
.issuer
.clone
())
.is_ok
())
.map
(|
tx
|
TransactionV2
{
.map
(|
tx
|
TransactionV2
{
issuer
:
v1_pubkey_to_account_id
(
tx
.issuer
.clone
()),
issuer
:
v1_pubkey_to_account_id
(
tx
.issuer
.clone
())
.expect
(
"already checked tx.issuer"
),
amount
:
tx
.amount
.clone
(),
amount
:
tx
.amount
.clone
(),
written_time
:
tx
.written_time
,
written_time
:
tx
.written_time
,
comment
:
tx
.comment
.clone
(),
comment
:
tx
.comment
.clone
(),
...
@@ -1303,17 +1317,20 @@ fn get_authority_keys_from_seed(s: &str) -> AuthorityKeys {
...
@@ -1303,17 +1317,20 @@ fn get_authority_keys_from_seed(s: &str) -> AuthorityKeys {
/// Converts a Duniter v1 public key (Ed25519) to an Account Id.
/// Converts a Duniter v1 public key (Ed25519) to an Account Id.
/// No need to convert to address.
/// No need to convert to address.
fn
v1_pubkey_to_account_id
(
pubkey
:
PubkeyV1
)
->
AccountId
{
fn
v1_pubkey_to_account_id
(
pubkey
:
PubkeyV1
)
->
Result
<
AccountId
,
String
>
{
let
bytes
=
bs58
::
decode
(
pubkey
.0
)
let
bytes
=
bs58
::
decode
(
pubkey
.0
)
.into_vec
()
.into_vec
()
.expect
(
"Duniter v1 pubkey should be decodable"
);
.expect
(
"Duniter v1 pubkey should be decodable"
);
if
bytes
.len
()
>
32
{
return
Err
(
"Pubkey is too long"
.to_string
());
}
let
prepend
=
vec!
[
0u8
;
32
-
&
bytes
.len
()];
let
prepend
=
vec!
[
0u8
;
32
-
&
bytes
.len
()];
let
bytes
:
[
u8
;
32
]
=
[
prepend
.as_slice
(),
bytes
.as_slice
()]
let
bytes
:
[
u8
;
32
]
=
[
prepend
.as_slice
(),
bytes
.as_slice
()]
.concat
()
.concat
()
.as_slice
()
.as_slice
()
.try_into
()
.try_into
()
.expect
(
"incorrect pubkey length"
);
.expect
(
"incorrect pubkey length"
);
AccountPublic
::
from
(
ed25519
::
Public
::
from_raw
(
bytes
))
.into_account
()
Ok
(
AccountPublic
::
from
(
ed25519
::
Public
::
from_raw
(
bytes
))
.into_account
()
)
}
}
fn
timestamp_to_relative_blocs
(
timestamp
:
TimestampV1
,
start
:
u64
)
->
u32
{
fn
timestamp_to_relative_blocs
(
timestamp
:
TimestampV1
,
start
:
u64
)
->
u32
{
...
@@ -1348,8 +1365,19 @@ mod tests {
...
@@ -1348,8 +1365,19 @@ mod tests {
v1_pubkey_to_account_id
(
PubkeyV1
{
v1_pubkey_to_account_id
(
PubkeyV1
{
0
:
"2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ"
.to_string
()
0
:
"2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ"
.to_string
()
})
})
.unwrap
()
.to_ss58check_with_version
(
Ss58AddressFormat
::
custom
(
42
)),
.to_ss58check_with_version
(
Ss58AddressFormat
::
custom
(
42
)),
"5CfdJjEgh3jDkg3bzmZ1ED1xVhXAARtNmZJWbcXh53rU8z5a"
.to_owned
()
"5CfdJjEgh3jDkg3bzmZ1ED1xVhXAARtNmZJWbcXh53rU8z5a"
.to_owned
()
);
);
}
}
#[test]
fn
test_pubkey_with_33_bytes
()
{
assert_eq!
(
v1_pubkey_to_account_id
(
PubkeyV1
{
0
:
"d2meevcahfts2gqmvmrw5hzi25jddikk4nc4u1fkwrau"
.to_string
()
}),
Err
(
"Pubkey is too long"
.to_owned
())
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment