PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 25, 2022

[FIXED] How does uniswap upgrade its smart contract given that smart contract are immutable once deployed?

 September 25, 2022     blockchain, ethereum, smartcontracts, uniswap     No comments   

Issue

In my understanding, smart contracts on Ethereum are immutable once they are pushed onto chain. Then how does uniswap keeps upgrading itself from v1 to v2 to v3? How can they modify their smart contract code? "They" here apparently refer to Uniswap Labs. Additionally, since it is decentralized and nothing is special about Uniswap Labs, can anyone else modify the Uniswap contract as well?


Solution

Each version of Uniswap is a different set of contracts, deployed on different addresses. So there is no upgrading of existing contracts. See the links for the list of addresses:

  • v1: https://docs.uniswap.org/protocol/V1/guides/connect-to-uniswap#factory-address
  • v2: https://docs.uniswap.org/protocol/V2/reference/smart-contracts/factory
  • v3: https://docs.uniswap.org/protocol/reference/deployments

Besides this approach of deploying each version to a new address, there's also the proxy pattern. Similarly to networking proxies, you can redirect the request to a target contract, and possibly modify it along the way. If the target address is stored in a variable, you can change the value without changing the actual contract bytecode.

pragma solidity ^0.8;

contract Proxy {
    address target;

    function setTarget(address _target) external {
        // you can change the value of `target` variable in storage
        // without chanding the `Proxy` contract bytecode
        target = _target;
    }

    fallback(bytes calldata) external returns (bytes memory) {
        (bool success, bytes memory returnedData) = target.delegatecall(msg.data);
        require(success);
        return returnedData;
    }
}

You can read more about the upgradable proxy pattern here: https://docs.openzeppelin.com/upgrades-plugins/1.x/proxies

Note that my code above is simplified to showcase just the basic proxy functionality. It is vulnerable to storage collision mentioned in the article, as well as to Delegatecall to Untrusted Callee.



Answered By - Petr Hejda
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing