unpackdev / solgo

Solidity parser in Go, designed to transform Solidity code into a structured format for enhanced analysis, particularly beneficial for developers using Go to analyze Solidity smart contracts.
https://unpack.dev
Apache License 2.0
1 stars 0 forks source link

[Bug] Improperly encoded uint8 (enum) @ decoding constructor #196

Open 0x19 opened 5 months ago

0x19 commented 5 months ago

There's an edge case with advanced use of constructor arguments.

Etherscan addr: https://etherscan.io/address/0x8e7e518b0481ADFaF969ED1f2B25bf553B79a677#code

Constructor ABI:

[{"inputs":[{"internalType":"address","name":"cvpToken_","type":"address"},{"internalType":"address","name":"reservoir_","type":"address"},{"internalType":"uint256","name":"anchorPeriod_","type":"uint256"},{"internalType":"struct UniswapConfig.TokenConfig","name":"TokenConfig","type":"tuple","components":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"underlying","type":"address"},{"internalType":"bytes32","name":"symbolHash","type":"bytes32"},{"internalType":"uint256","name":"baseUnit","type":"uint256"},{"internalType":"enum UniswapConfig.PriceSource","name":"priceSource","type":"uint8"},{"internalType":"uint256","name":"fixedPrice","type":"uint256"},{"internalType":"address","name":"uniswapMarket","type":"address"},{"internalType":"bool","name":"isUniswapReversed","type":"bool"}]}],"outputs":[],"name":"","type":"constructor","stateMutability":"nonpayable"}]

Basically it results back with error failed to unpack values: abi: improperly encoded uint8 value

0x19 commented 5 months ago

Potential root causes:

I've checked and constructor bytecode passed for unpacking is correct. That's not issue.

0x19 commented 1 month ago

Our constructor

[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"cvpToken_\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"reservoir_\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"anchorPeriod_\",\"type\":\"uint256\"},{\"internalType\":\"struct UniswapConfig.TokenConfig\",\"name\":\"TokenConfig\",\"type\":\"tuple\",\"components\":[{\"internalType\":\"address\",\"name\":\"cToken\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"underlying\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"symbolHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"baseUnit\",\"type\":\"uint256\"},{\"internalType\":\"enum UniswapConfig.PriceSource\",\"name\":\"priceSource\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"fixedPrice\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"uniswapMarket\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"isUniswapReversed\",\"type\":\"bool\"}]}],\"outputs\":[],\"name\":\"\",\"type\":\"constructor\",\"stateMutability\":\"nonpayable\"}]

Etherscan constructor

[
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "cvpToken_",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "reservoir_",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "anchorPeriod_",
        "type": "uint256"
      },
      {
        "components": [
          {
            "internalType": "address",
            "name": "cToken",
            "type": "address"
          },
          {
            "internalType": "address",
            "name": "underlying",
            "type": "address"
          },
          {
            "internalType": "bytes32",
            "name": "symbolHash",
            "type": "bytes32"
          },
          {
            "internalType": "uint256",
            "name": "baseUnit",
            "type": "uint256"
          },
          {
            "internalType": "enum UniswapConfig.PriceSource",
            "name": "priceSource",
            "type": "uint8"
          },
          {
            "internalType": "uint256",
            "name": "fixedPrice",
            "type": "uint256"
          },
          {
            "internalType": "address",
            "name": "uniswapMarket",
            "type": "address"
          },
          {
            "internalType": "bool",
            "name": "isUniswapReversed",
            "type": "bool"
          }
        ],
        "internalType": "struct UniswapConfig.TokenConfig[]",
        "name": "configs",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "constructor"
  }]
0x19 commented 1 month ago

Ah well... It's tuple[] not a tuple...