What is the error? I need more information in order to help you.
I posted the error first, its above your question asking for the code. I think it could be some config issue⌠but again no idea.
Finally worked!! Not sure what it was⌠I copyed your code from github and specified the compiler on the truffle.config and it works. I can go on now, thanks!
Dear @filip and others !
I am struggling understand, why donât we just set the owner in the Storage contract?
This would solve issues like having to create the function initialized();
Since Proxy and Functional are inheriting from Storage, would not been better to set the owner only in Storage? We save a lot of work.
module.exports = async function (deployed,network,accounts){
// Deploy contracts;
const functional = await Functional.new();
const proxy = await Proxy.new(functional.address);
//Create proxy to fool truffle;
var proxyFunctional = await Functional.at(proxy.address);
//Set the number through the proxy;
await proxyFunctional.setNumber(10);
//Tested
var x = await proxyFunctional.getNumber();
console.log("First: " +x.toNumber());
//Create a new functional contract and update the address the proxy uses;
const functional2 = await Functional2.new();
proxy.upgradeAddress(functional2.address);
await proxyFunctional.setNumber(15);
x = await proxyFunctional.getNumber();
console.log("Second: " + x.toNumber());
await proxyFunctional.setNumber(20,{from: accounts[1]}); //This one fails since it's from accounts[1];
x = await proxyFunctional.getNumber();
console.log("Third: " + x.toNumber());
}
Or even, canât I just use my Ownable.sol and I set there the constructor owner = msg.sender and the modifier?
Got a question: Wouldnât it make more sense to set the update function in the proxy contract to onlyOwner? Because literally anyone can call that function and make it point to his own smart contract and destroy everything or empy out the balance with his functions Or have I missunderstood anything about the proxy contract functionality? @filip
Hi, @filip
I have a question. In https://github.com/filipmartinsson/Smart-Contract-Security/blob/master/Upgradeable-Advanced/contracts/DogsUpdated.sol#L14 isnât this exposed to reentrancy attacks? Shouldnât we have followed the âChecks Effects Interactionsâ paradigm and apply _initialized = true;
before setting the owner? We could possibly also assert()
in the end to make sure it was correctly set.
Is my assumption correct (possible vulnerability), or am I complicating things?
EDIT: Also, this way of setting the owner only works when weâre assuming the contract will be initialized right after it has been deployed (truffle script), correct? Because, if otherwise, there is no way of checking if any other person could call initialize()
and claim ownership of the contract, right?
Thanks!
OMG! If you get an error that says âexpected 1 argument for getNumberOfDogs but got zeroâ delete the /build
directory, recompile, and it will work again. Filip points out this workaround in âPart 10â! Thanks.
I wish this was pointed out earlier as it wouldâve saved me a lot of time in Part 7!
Also if you get a download error when doing truffle init
uninstall Truffle and reinstall the exact version listed in the lecture 5.0.14. I had a different version from a previous course that had issues⌠more
I have the same questionâŚ
@pmk , @illyushin, @dan-i
Yes we should set the owner in the constructor and add a require msg.sender == owner in the upgrade contract .
I ll open a pull request but do not hesitate to open one if you see this kind of issue.
Good catch
Hi @Daisy
Are you using a Chinese character ?
It seems that visual studio is not supporting it. Try to change your variables and functions name with the latin alphabet
I tried out to create an upgreadable smart contract and want to console log something like Filip did in his video (nrOfDogs). I have a get function that returns a uint and an address of a struct (return person.number, person.address). I want to console log this info, but how do I do this?
Also how do I google correctly to find a solution for a specific problem like this? I tried different things out in my code but nothing worked and I couldnât find anything online. Is there an API for what you can do in the migration files? lol
Hi @illyushin
Yes you can look at this documentation for migration
Can you share your migration file ? Because itâs supposed to work as in the video, i can that during your deployment that you have 2 values displayed , one is a bignumber and the other one is the address so i think it works for you too. Try to convert the Big number to string if you want it to be more readable
I have a question. I did everything like Filip in his video (I mean, Improving and Updating videoâŚ), but I could run the code without the error of reverting the transactionâŚ
Here is my code:
const Dogs = artifacts.require("Dogs");
const DogsUpdated = artifacts.require("DogsUpdated");
const Proxy = artifacts.require("Proxy");
module.exports = async function(deployer, network, accounts){
const dogs = await Dogs.new();
const proxy = await Proxy.new(dogs.address);
var proxyDog = await Dogs.at(proxy.address);
await proxyDog.setNumberOfDogs(10);
var nrOfDogs =await proxyDog.getNumberOfDogs();
console.log(nrOfDogs.toNumber());
const dogsUpdated = await DogsUpdated.new();
proxy.upgrade(dogsUpdated.address);
nrOfDogs =await proxyDog.getNumberOfDogs();
console.log(nrOfDogs.toNumber());
nrOfDogs= await proxyDog.setNumberOfDogs(30);
}
And here:
pragma solidity 0.5.16;
import "./Storage.sol";
contract DogsUpdated is Storage {
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
constructor() public {
owner = msg.sender;
}
function getNumberOfDogs() public view returns(uint256) {
return _uintStorage["Dogs"];
}
function setNumberOfDogs(uint256 toSet) public onlyOwner {
_uintStorage["Dogs"] = toSet;
}
}
It throws no error but I cannot print the result to the console, so that means there is an issue but it is not reverted. A little bit weird but OK.
@gabba @filip powershell is showing me nothing when i am using âtruffle developâ command âŚit is getting compiled correctly
Hi @KryptoDr
Did you solve this issue ? Can you send a screenshot of your console output ?
Thank you
@Gandharv_dalal did you do the eth 101 and 201 course ? Did you have any issues during those courses ?
Can you show me your version of node/npm/truffle ?