Challenge 18
tx.origin Misuse
MediumStorage and memory
Challenge
Review activateUser. Does changing the local User value update the mapping entry?
Starter code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract StorageBug {
struct User {
uint256 balance;
bool isActive;
}
mapping(address => User) public users;
function activateUser() public {
User memory user = users[msg.sender];
user.isActive = true;
}
function deposit() public payable {
users[msg.sender].balance += msg.value;
}
}Show hint
A memory copy is separate from the mapping's stored struct. Update the storage entry itself.