I am a cyber security analyst who is new to ethereum and working on a project to study crypto security. It's a series of 22 vulnerable smart contracts that you're supposed to exploit. For anyone who is interested, here's the challenge:
https://ethernaut.zeppelin.solutions/
I'm trying to configure a truffle project for the challenge using this guide: https://www.notonlyowner.com/ethereum/solving-zeppelin-ethernaut-ctf-fallback/ and after I run the installation command:
npm i truffle@4 ganache-cli@6 openzeppelin-solidity@2.0.0
I'll try to deploy the contract and I get a bunch of errors. I started trying to fix them and knocked out a few, but I feel like there's gotta be a better solution. If an experienced blockchain dev would help me get this deployed I'd really appreciate it, been bashing my head against my desk at work all day. I've posted the source code and my errors below:
pragma solidity ^0.4.18;
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
contract Fallback is Ownable {
mapping(address => uint) public contributions;
function Fallback() public {
contributions[msg.sender] = 1000 * (1 ether);
}
function contribute() public payable {
require(msg.value < 0.001 ether);
contributions[msg.sender] += msg.value;
if(contributions[msg.sender] > contributions[owner]) {
owner = msg.sender;
}
}
function getContribution() public view returns (uint) {
return contributions[msg.sender];
}
function withdraw() public onlyOwner {
owner.transfer(this.balance);
}
function() payable public {
require(msg.value > 0 && contributions[msg.sender] > 0);
owner = msg.sender;
}
}
The errors:
Compiling ./contracts/Fallback.sol...
Compiling ./contracts/Migrations.sol...
Compiling openzeppelin-solidity/contracts/ownership/Ownable.sol...
/home/awile/smart_contracts/ethernaut/contracts/Fallback.sol:16:48: TypeError: Type function () view returns (address) is not implicitly convertible to expected type address.
if(contributions[msg.sender] > contributions[owner]) {
^---^
,/home/awile/smart_contracts/ethernaut/contracts/Fallback.sol:17:4: TypeError: Expression has to be an lvalue.
owner = msg.sender;
^---^
,/home/awile/smart_contracts/ethernaut/contracts/Fallback.sol:17:12: TypeError: Type address is not implicitly convertible to expected type function () view returns (address).
owner = msg.sender;
^--------^
,/home/awile/smart_contracts/ethernaut/contracts/Fallback.sol:31:3: TypeError: Expression has to be an lvalue.
owner = msg.sender;
^---^
,/home/awile/smart_contracts/ethernaut/contracts/Fallback.sol:31:11: TypeError: Type address is not implicitly convertible to expected type function () view returns (address).
owner = msg.sender;
^--------^
Compilation failed. See above.
Edit: fixed by downgrading openzeppelin-solidity to 1.11.0
npm uninstall openzeppelin-solidity
npm i openzeppelin-solidity@1.11.0