mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 07:41:08 +00:00
Add notes about safe uses of twox (#6082)
* Add notes about safe uses of twox * Update frame/grandpa/src/lib.rs Co-authored-by: Nikolay Volf <nikvolf@gmail.com> * Update frame/elections/src/lib.rs * Apply suggestions from code review Co-authored-by: Gavin Wood <gavin@parity.io> Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
@@ -257,6 +257,8 @@ decl_storage! {
|
||||
/// The next asset identifier up for grabs.
|
||||
NextAssetId get(fn next_asset_id): T::AssetId;
|
||||
/// The total unit supply of an asset.
|
||||
///
|
||||
/// TWOX-NOTE: `AssetId` is trusted, so this is safe.
|
||||
TotalSupply: map hasher(twox_64_concat) T::AssetId => T::Balance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +152,8 @@ decl_storage! {
|
||||
/// We reset all segments and return to `0` at the beginning of every
|
||||
/// epoch.
|
||||
SegmentIndex build(|_| 0): u32;
|
||||
|
||||
/// TWOX-NOTE: `SegmentIndex` is an increasing integer, so this is okay.
|
||||
UnderConstruction: map hasher(twox_64_concat) u32 => Vec<schnorrkel::Randomness>;
|
||||
|
||||
/// Temporary value (cleared at block finalization) which is `Some`
|
||||
|
||||
@@ -836,6 +836,8 @@ decl_storage! {
|
||||
/// The subtrie counter.
|
||||
pub AccountCounter: u64 = 0;
|
||||
/// The code associated with a given account.
|
||||
///
|
||||
/// TWOX-NOTE: SAFE since `AccountId` is a secure hash.
|
||||
pub ContractInfoOf: map hasher(twox_64_concat) T::AccountId => Option<ContractInfo<T>>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,6 +344,8 @@ decl_storage! {
|
||||
/// The public proposals. Unsorted. The second item is the proposal's hash.
|
||||
pub PublicProps get(fn public_props): Vec<(PropIndex, T::Hash, T::AccountId)>;
|
||||
/// Those who have locked a deposit.
|
||||
///
|
||||
/// TWOX-NOTE: Safe, as increasing integer keys are safe.
|
||||
pub DepositOf get(fn deposit_of):
|
||||
map hasher(twox_64_concat) PropIndex => Option<(Vec<T::AccountId>, BalanceOf<T>)>;
|
||||
|
||||
@@ -362,22 +364,30 @@ decl_storage! {
|
||||
pub LowestUnbaked get(fn lowest_unbaked) build(|_| 0 as ReferendumIndex): ReferendumIndex;
|
||||
|
||||
/// Information concerning any given referendum.
|
||||
///
|
||||
/// TWOX-NOTE: SAFE as indexes are not under an attacker’s control.
|
||||
pub ReferendumInfoOf get(fn referendum_info):
|
||||
map hasher(twox_64_concat) ReferendumIndex
|
||||
=> Option<ReferendumInfo<T::BlockNumber, T::Hash, BalanceOf<T>>>;
|
||||
|
||||
/// All votes for a particular voter. We store the balance for the number of votes that we
|
||||
/// have recorded. The second item is the total amount of delegations, that will be added.
|
||||
///
|
||||
/// TWOX-NOTE: SAFE as `AccountId`s are crypto hashes anyway.
|
||||
pub VotingOf: map hasher(twox_64_concat) T::AccountId => Voting<BalanceOf<T>, T::AccountId, T::BlockNumber>;
|
||||
|
||||
/// Who is able to vote for whom. Value is the fund-holding account, key is the
|
||||
/// vote-transaction-sending account.
|
||||
///
|
||||
/// TWOX-NOTE: OK ― `AccountId` is a secure hash.
|
||||
// TODO: Refactor proxy into its own pallet.
|
||||
// https://github.com/paritytech/substrate/issues/5322
|
||||
pub Proxy get(fn proxy): map hasher(twox_64_concat) T::AccountId => Option<ProxyState<T::AccountId>>;
|
||||
|
||||
/// Accounts for which there are locks in action which may be removed at some point in the
|
||||
/// future. The value is the block number at which the lock expires and may be removed.
|
||||
///
|
||||
/// TWOX-NOTE: OK ― `AccountId` is a secure hash.
|
||||
pub Locks get(fn locks): map hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;
|
||||
|
||||
/// True if the last referendum tabled was submitted externally. False if it was a public
|
||||
|
||||
@@ -197,6 +197,8 @@ decl_storage! {
|
||||
pub ElectionRounds get(fn election_rounds): u32 = Zero::zero();
|
||||
|
||||
/// Votes and locked stake of a particular voter.
|
||||
///
|
||||
/// TWOX-NOTE: SAFE as `AccountId` is a crypto hash
|
||||
pub Voting get(fn voting): map hasher(twox_64_concat) T::AccountId => (BalanceOf<T>, Vec<T::AccountId>);
|
||||
|
||||
/// The present candidate list. Sorted based on account-id. A current member or runner-up
|
||||
|
||||
@@ -237,16 +237,25 @@ decl_storage! {
|
||||
// bit-wise manner. In order to get a human-readable representation (`Vec<bool>`), use
|
||||
// [`all_approvals_of`]. Furthermore, each vector of scalars is chunked with the cap of
|
||||
// `APPROVAL_SET_SIZE`.
|
||||
///
|
||||
/// TWOX-NOTE: SAFE as `AccountId` is a crypto hash and `SetIndex` is not
|
||||
/// attacker-controlled.
|
||||
pub ApprovalsOf get(fn approvals_of):
|
||||
map hasher(twox_64_concat) (T::AccountId, SetIndex) => Vec<ApprovalFlag>;
|
||||
/// The vote index and list slot that the candidate `who` was registered or `None` if they
|
||||
/// are not currently registered.
|
||||
///
|
||||
/// TWOX-NOTE: SAFE as `AccountId` is a crypto hash.
|
||||
pub RegisterInfoOf get(fn candidate_reg_info):
|
||||
map hasher(twox_64_concat) T::AccountId => Option<(VoteIndex, u32)>;
|
||||
/// Basic information about a voter.
|
||||
///
|
||||
/// TWOX-NOTE: SAFE as `AccountId` is a crypto hash.
|
||||
pub VoterInfoOf get(fn voter_info):
|
||||
map hasher(twox_64_concat) T::AccountId => Option<VoterInfo<BalanceOf<T>>>;
|
||||
/// The present voter list (chunked and capped at [`VOTER_SET_SIZE`]).
|
||||
///
|
||||
/// TWOX-NOTE: OKAY ― `SetIndex` is not user-controlled data.
|
||||
pub Voters get(fn voters): map hasher(twox_64_concat) SetIndex => Vec<Option<T::AccountId>>;
|
||||
/// the next free set to store a voter in. This will keep growing.
|
||||
pub NextVoterSet get(fn next_nonfull_voter_set): SetIndex = 0;
|
||||
|
||||
@@ -442,16 +442,22 @@ pub struct BalanceLock<Balance> {
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as GenericAsset {
|
||||
/// Total issuance of a given asset.
|
||||
///
|
||||
/// TWOX-NOTE: `AssetId` is trusted.
|
||||
pub TotalIssuance get(fn total_issuance) build(|config: &GenesisConfig<T>| {
|
||||
let issuance = config.initial_balance * (config.endowed_accounts.len() as u32).into();
|
||||
config.assets.iter().map(|id| (id.clone(), issuance)).collect::<Vec<_>>()
|
||||
}): map hasher(twox_64_concat) T::AssetId => T::Balance;
|
||||
|
||||
/// The free balance of a given asset under an account.
|
||||
///
|
||||
/// TWOX-NOTE: `AssetId` is trusted.
|
||||
pub FreeBalance:
|
||||
double_map hasher(twox_64_concat) T::AssetId, hasher(blake2_128_concat) T::AccountId => T::Balance;
|
||||
|
||||
/// The reserved balance of a given asset under an account.
|
||||
///
|
||||
/// TWOX-NOTE: `AssetId` is trusted.
|
||||
pub ReservedBalance:
|
||||
double_map hasher(twox_64_concat) T::AssetId, hasher(blake2_128_concat) T::AccountId => T::Balance;
|
||||
|
||||
@@ -459,6 +465,8 @@ decl_storage! {
|
||||
pub NextAssetId get(fn next_asset_id) config(): T::AssetId;
|
||||
|
||||
/// Permission options for a given asset.
|
||||
///
|
||||
/// TWOX-NOTE: `AssetId` is trusted.
|
||||
pub Permissions get(fn get_permission):
|
||||
map hasher(twox_64_concat) T::AssetId => PermissionVersions<T::AccountId>;
|
||||
|
||||
|
||||
@@ -212,6 +212,8 @@ decl_storage! {
|
||||
|
||||
/// A mapping from grandpa set ID to the index of the *most recent* session for which its
|
||||
/// members were responsible.
|
||||
///
|
||||
/// TWOX-NOTE: `SetId` is not under user control.
|
||||
SetIdSession get(fn session_for_set): map hasher(twox_64_concat) SetId => Option<SessionIndex>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
|
||||
@@ -389,6 +389,8 @@ pub struct RegistrarInfo<
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as Identity {
|
||||
/// Information that is pertinent to identify the entity behind an account.
|
||||
///
|
||||
/// TWOX-NOTE: OK ― `AccountId` is a secure hash.
|
||||
pub IdentityOf get(fn identity):
|
||||
map hasher(twox_64_concat) T::AccountId => Option<Registration<BalanceOf<T>>>;
|
||||
|
||||
@@ -400,6 +402,8 @@ decl_storage! {
|
||||
/// Alternative "sub" identities of this account.
|
||||
///
|
||||
/// The first item is the deposit, the second is a vector of the accounts.
|
||||
///
|
||||
/// TWOX-NOTE: OK ― `AccountId` is a secure hash.
|
||||
pub SubsOf get(fn subs_of):
|
||||
map hasher(twox_64_concat) T::AccountId => (BalanceOf<T>, Vec<T::AccountId>);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user