Trick or Treat

First Flight #27
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Invalid

H-[01] Using wrong syntax while setting "owner". make contracts unusable

Summary

while setting up openzeppelin "Ownable" it has to be initialized besides constructor but 
rather done while declaring the contract which leads to owner address set to address variables default value and 
making the contract unusable

https://github.com/Cyfrin/2024-10-trick-or-treat/blob/9cb3955058cad9dd28a24eb5162a96d759bfa842/src/TrickOrTreat.sol#L9 

'''
pragma solidity ^0.8.24;


import "forge-std/Test.sol";
import {setOwner} from "../src/setOwner.sol";

contract SpookySwapTest is Test {
 setOwner public setowner;
 address public owner = address(0x123);
 address public nonOwner = address(0x456);

function setUp() public {
    // Deploy contract and set the deployer to `owner`
    vm.prank(owner);
    setowner = new setOwner(42);//setting a random number not related to poc
}

function testOwnerIsSetCorrectly() public {
    // Check if the contract owner is set to `owner` address on deployment
    assertEq(setowner.owner(), owner, "Owner is not set correctly");
}

'''

Impact

owner variable set to zero address making it unusable or DOS

Recommendations

constructor variables should be set inside constructor of inheriting contract

Updates

Appeal created

bube Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.