Great video. You explained it very well. I have read about delegate call a few times, but this video really helped make the knowledge useful. Thanks :)
Thanks for this awesome video! This was something I was searching for :) But I have a doubt Wouldn’t this have any security issue? Since I can run any custom code and update the actual storage. Is there a way to allow only trusted upgraded contracts created by the owner?
Thanks for the great tutorial. I deployed your example using Javascript VM. It works. I deployed it using Ropsten testnet. It does not work. Can you please help me to run it on a testnet. Thank you
@@smartcontractprogrammer I ran the same code on Ropsten again and I am sure that the addresses are correct. It still does not work. Have you tried it yourself? I even modified your code as below. I give the input 2. When I run it on JavaScript VM the result is 8. When I run it on Ropsten the result is 4. Different results for the same code. Please try the code below yourself /*first file*/ pragma solidity ^0.7.6; abstract contract B { function setVars(uint _num) public payable returns(uint) {} } contract A { uint public num=1; uint x=1; function setVars(address _contract, uint _num) public payable { // A's storage is set, B is not modified.
num = B(_contract).setVars(_num); (bool success, bytes memory data) = _contract.delegatecall(abi.encodeWithSignature("setVars(uint256)", num)); } } /*second file*/ pragma solidity ^0.7.6; contract B { // NOTE: storage layout must be the same as contract A uint public num; address public sender; uint public value; uint x=1; function setVars(uint _num) public payable returns(uint) { num = 2*_num; sender = msg.sender; value = msg.value; return num; } } Thank you and I appreciate your kind help to me
Very Good and no one can do better than you ! Well, If I don't other contracts to call or delegatecall the functions of my contract, what should I do? Please advise, Thanks!
I'm wondering, when was delegatecall introduced into the EVM? Was it there from the beginning, or did they add it later when they figured out that they'd need a way to upgrade contracts?
Good explanation, what happens if you do a delegate call, the contract calls the second contract, but the first contract doesnt have that state variables defined, I assume the call would fail?
very interesting, programming was getting kind of dull for me over many decades (nothing new under the sun as it were) until i discovered crypto currency
Great video. You explained it very well. I have read about delegate call a few times, but this video really helped make the knowledge useful. Thanks :)
awesome , best channel for solidity I've seen 😍
😍👍 super video explaining the content!!! Classic diagram with animation made very easy to grasp !! Thank you!!
Great explanation. Easy to understand.
thanks for explaining all these very easily . that solidity document was driving me crazy
awesome explanation!
Great video. Helped me beat the level on ethernaut lol
excellent. that was an important puzzle piece for me.
This video was so helpful. Thanks!
Great video - I really appreciate you!
Best explanation ever!
You are the best as always!
Thanks for this awesome video! This was something I was searching for :)
But I have a doubt Wouldn’t this have any security issue? Since I can run any custom code and update the actual storage. Is there a way to allow only trusted upgraded contracts created by the owner?
Yes there are hacks done exploiting delegatecall. You will have to write authorization code for trusted upgrade
address admin_address;
// only run in deploy
constructor(){
admin_address = admin_address;
}
function something(){
require( msg.sender == admin_address, "Dont authorized");
delegatecall()
}
@@gabrielnastari8513
constructor() { admin_address = msg.sender ; }
@@smartcontractprogrammer right, lol! i wrote twice ! You correct admin_address =msg.sender !
@@smartcontractprogrammer Thanks , you are awesome man!
You are the best!
Thanks for the great tutorial. I deployed your example using Javascript VM. It works.
I deployed it using Ropsten testnet. It does not work.
Can you please help me to run it on a testnet.
Thank you
Deploy all relevant contracts on Ropsten. Make sure the addresses are correct
@@smartcontractprogrammer I ran the same code on Ropsten again and I am sure that the addresses are correct. It still does not work. Have you tried it yourself?
I even modified your code as below. I give the input 2. When I run it on JavaScript VM the result is 8. When I run it on Ropsten the result is 4. Different results for the same code. Please try the code below yourself
/*first file*/
pragma solidity ^0.7.6;
abstract contract B {
function setVars(uint _num) public payable returns(uint) {}
}
contract A {
uint public num=1;
uint x=1;
function setVars(address _contract, uint _num) public payable {
// A's storage is set, B is not modified.
num = B(_contract).setVars(_num);
(bool success, bytes memory data) = _contract.delegatecall(abi.encodeWithSignature("setVars(uint256)", num));
}
}
/*second file*/
pragma solidity ^0.7.6;
contract B {
// NOTE: storage layout must be the same as contract A
uint public num;
address public sender;
uint public value;
uint x=1;
function setVars(uint _num) public payable returns(uint) {
num = 2*_num;
sender = msg.sender;
value = msg.value;
return num;
}
}
Thank you and I appreciate your kind help to me
can you help me please :)
Very Good and no one can do better than you ! Well, If I don't other contracts to call or delegatecall the functions of my contract, what should I do? Please advise, Thanks!
I'm wondering, when was delegatecall introduced into the EVM? Was it there from the beginning, or did they add it later when they figured out that they'd need a way to upgrade contracts?
It was there from long time ago. I don't know when
So the first contract works like a proxy.
Exactly! Upgradable contracts use this to separate storage and code
Good explanation, what happens if you do a delegate call, the contract calls the second contract, but the first contract doesnt have that state variables defined, I assume the call would fail?
it might fail
it might be an entry to hack the contract
super helpful , thanks a lot
very cool
very interesting, programming was getting kind of dull for me over many decades (nothing new under the sun as it were) until i discovered crypto currency
You are the best!