Challenge 16
tx.origin Misuse
MediumRole-based access control
Challenge
Review how the admin role is granted and how createProposal is restricted.
Starter code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/AccessControl.sol";
contract Voting is AccessControl {
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
constructor(address admin) {
_grantRole(ADMIN_ROLE, admin);
}
function createProposal(string memory proposal) public onlyRole(ADMIN_ROLE) {
// Proposal creation logic
}
}Show hint
Check role setup and make sure each privileged operation has the intended role requirement.