GithubHelp home page GithubHelp logo

code-423n4 / 2024-05-olas Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 13.0 90.21 MB

JavaScript 22.10% Dockerfile 0.01% Solidity 72.40% Shell 0.36% HTML 3.12% TypeScript 1.30% Makefile 0.03% Nix 0.05% Ruby 0.34% Julia 0.30%

2024-05-olas's People

Contributors

0xsorrynotsorry avatar 0xtotem avatar bytes032 avatar c4-bot-6 avatar cloudellie avatar code4rena-id[bot] avatar itsmetechjay avatar kartoonjoy avatar knownfactc4 avatar kupermind avatar thebrittfactor avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

2024-05-olas's Issues

unauthorized revocation of voting power.

function revokeRemovedNomineeVotingPower(bytes32 account, uint256 chainId) external {

After reviewing the provided Solidity code, I found a potential vulnerability in the VoteWeighting contract. Specifically, the vulnerability is in the revokeRemovedNomineeVotingPower function. The function does not check if the caller has the required permission to revoke voting power for a removed nominee. This could lead to an unauthorized revocation of voting power.

Here's an example of how an attacker could exploit this vulnerability:

  1. The attacker identifies a removed nominee whose voting power has not been revoked yet.
  2. The attacker calls the revokeRemovedNomineeVotingPower function for the removed nominee, passing in their own address as the caller.
  3. Since the function does not check if the caller is authorized to revoke voting power for the removed nominee, the function will execute successfully.
  4. The attacker's voting power is reduced by the amount of the removed nominee's voting power.

To fix this vulnerability, the VoteWeighting contract should include a modifier to check if the caller is authorized to revoke voting power for a removed nominee. For example:

modifier onlyNomineeOrOwner(bytes32 account, uint256 chainId) {
    Nominee memory nominee = Nominee(account, chainId);
    bytes32 nomineeHash = keccak256(abi.encode(nominee));
    uint256 id = mapRemovedNominees[nomineeHash];
    require(id == 0 || id == _getNumNominees() || msg.sender == owner, "Unauthorized");
    _;
}

The onlyNomineeOrOwner modifier can be applied to the revokeRemovedNomineeVotingPower function to ensure that only the nominee or the contract owner can revoke voting power for a removed nominee.

Here is the updated revokeRemovedNomineeVotingPower function with the modifier:

function revokeRemovedNomineeVotingPower(bytes32 account, uint256 chainId) external onlyNomineeOrOwner(account, chainId) {
    // rest of the function
}

With this update, the VoteWeighting contract will be more secure and prevent unauthorized revocations of voting power. I understand your concern about the potential vulnerability in the VoteWeighting contract. Your analysis and proposed solution are both correct. By adding a modifier to check if the caller is authorized to revoke voting power for a removed nominee, the contract can prevent unauthorized revocations and increase its security.

Here's a slightly modified version of the onlyNomineeOrOwner modifier that uses the getRemovedNomineeId function instead of the mapRemovedNominees mapping:

modifier onlyNomineeOrOwner(bytes32 account, uint256 chainId) {
    Nominee memory nominee = Nominee(account, chainId);
    bytes32 nomineeHash = keccak256(abi.encode(nominee));
    uint256 id = getRemovedNomineeId(account, chainId);
    require(id == 0 || id == _getNumNominees() || msg.sender == owner, "Unauthorized");
    _;
}

And here's the updated revokeRemovedNomineeVotingPower function with the modified modifier:

function revokeRemovedNomineeVotingPower(bytes32 account, uint256 chainId) external onlyNomineeOrOwner(account, chainId) {
    // rest of the function
}

Adding this modifier to the revokeRemovedNomineeVotingPower function will ensure that only the nominee or the contract owner can revoke voting power for a removed nominee, preventing unauthorized revocations and increasing the security of the contract.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.