Peera.

Допис

Діліться своїми знаннями.

0x515e...c7d4.Peera.
ДляAll Things Web3Oct 15, 2022
Питання та відповіді експертів

Are there any sid3-effects of using mappings in structs?

I have a question for any solidity expert out there. Is there any downside/security risk to storing mappings inside structs? I'm aware that deleting the struct won't delete the mapping as it's stored as a keccak256 of the mapping name and key rather than inside the struct itself.

I also aware that with ethers the mapping won't be returned as the evm doesnt store the mapping in the struct so it doesnt know where to find it except a separate getter function is created for it

  • blockchain
  • solidity
  • smart contract
  • learning
2
1
Поділитися
Коментарі
.

Відповіді

1
Sergey Ilin.
Oct 16 2022, 18:41

In addition to your points:

1 - A struct containing mapping can't be stored in a memory variable and will cause Type struct XXX is only valid in storage because it contains a (nested) mapping.;

2 - All keys in a mapping are always initialized with value 0x0. For that reason, 0x0 in the logic should be reserved for uninitialized values. Otherwise, there is no way to differentiate a value that was set to 0x0 and uninitialized value;

3 - There is now way to list all set key values in a mapping nor their count. If there is a need for that, then they need to be stored separately. OpenZepplin provides few class for extending the mapping, for example EnumerableMap.

0
Коментарі
.

Ви знаєте відповідь?

Будь ласка, увійдіть та поділіться нею.

Web3 (also known as Web 3.0) is an idea for a new iteration of the World Wide Web which incorporates concepts such as decentralization, blockchain technologies, and token-based economics.

142Пости198Відповіді
Sui.X.Peera.

Зароби свою частку з 1000 Sui

Заробляй бали репутації та отримуй винагороди за допомогу в розвитку спільноти Sui.

Кампанія винагородЧервень
Ми використовуємо файли cookie, щоб гарантувати вам найкращий досвід на нашому сайті.
Детальніше