Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-dynamic, fixed-length array encoding is broken #14

Open
coinop-logan opened this issue Mar 6, 2019 · 2 comments
Open

Non-dynamic, fixed-length array encoding is broken #14

coinop-logan opened this issue Mar 6, 2019 · 2 comments

Comments

@coinop-logan
Copy link

If a contract has a function that takes an argument like uint[6], the binding generated for that function just takes a single uint argument for the entire array and encodes it where the array would go.

Currently I can get around this by just adding in all the arguments I need in the Elm binding, and encoding them all sequentially.

Here's some example code...

Solidity function:

function openToastytrade(address payable _initiator, bool initiatorIsBuyer, uint[6] calldata uintArgs, string calldata _totalPrice, string calldata _fiatTransferMethods, string calldata _commPubkey)
external
returns (Toastytrade) {
    ....
}

ABI entry for that function:

   {
        "constant": false,
        "inputs": [
            {
                "name": "_initiator",
                "type": "address"
            },
            {
                "name": "initiatorIsBuyer",
                "type": "bool"
            },
            {
                "name": "uintArgs",
                "type": "uint256[6]"
            },
            {
                "name": "_totalPrice",
                "type": "string"
            },
            {
                "name": "_fiatTransferMethods",
                "type": "string"
            },
            {
                "name": "_commPubkey",
                "type": "string"
            }
        ],
        "name": "openToastytrade",
        "outputs": [
            {
                "name": "",
                "type": "address"
            }
        ],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    }

Generated Elm binding:

openToastytrade : Address -> Address -> Bool -> BigInt -> String -> String -> String -> Call Address
openToastytrade contractAddress initiator initiatorIsBuyer uintArgs totalPrice fiatTransferMethods commPubkey =
    { to = Just contractAddress
    , from = Nothing
    , gas = Nothing
    , gasPrice = Nothing
    , value = Nothing
    , data = Just <| AbiEncode.functionCall "openToastytrade(address,bool,uint256[6],string,string,string)" [ AbiEncode.address initiator, AbiEncode.bool initiatorIsBuyer, AbiEncode.uint uintArgs, string-UNSUPPORTED-plz-open-github-issue totalPrice, string-UNSUPPORTED-plz-open-github-issue fiatTransferMethods, string-UNSUPPORTED-plz-open-github-issue commPubkey ]
    , nonce = Nothing
    , decoder = toElmDecoder AbiDecode.address
    }

Obviously that won't take all the info I need to pass, so I then change that to:

openToastytrade : Address -> Address -> Bool -> BigInt -> BigInt -> BigInt -> BigInt -> BigInt -> BigInt -> String -> String -> String -> Call Address
openToastytrade contractAddress initiator initiatorIsBuyer uintArg1 uintArg2 uintArg3 uintArg4 uintArg5 uintArg6 totalPrice fiatTransferMethods commPubkey =
    { to = Just contractAddress
    , from = Nothing
    , gas = Nothing
    , gasPrice = Nothing
    , value = Nothing
    , data = Just <| AbiEncode.functionCall "openToastytrade(address,bool,uint256[6],string,string,string)" 
        [ AbiEncode.address initiator, AbiEncode.bool initiatorIsBuyer, AbiEncode.uint uintArg1, AbiEncode.uint uintArg2, AbiEncode.uint uintArg3, AbiEncode.uint uintArg4, AbiEncode.uint uintArg5, AbiEncode.uint uintArg6, string-UNSUPPORTED-plz-open-github-issue totalPrice, string-UNSUPPORTED-plz-open-github-issue fiatTransferMethods, string-UNSUPPORTED-plz-open-github-issue commPubkey ]
    , nonce = Nothing
    , decoder = toElmDecoder AbiDecode.address
    }

which seems to work without issue--not too surprising, because a fixed-length array of static values is just encoded sequentially: https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#argument-encoding

@coinop-logan
Copy link
Author

coinop-logan commented Mar 6, 2019

By the way, I tried using AbiEncode.list (List.map AbiEncode.uint listOfUintArgs), and that failed to encode correctly. Not sure if that's a bug or I just don't understand what AbiEncode.list is supposed to be used for.

@cmditch
Copy link
Owner

cmditch commented Mar 29, 2020

@coinop-logan Was this related to the tillMod64 bug?

cmditch/elm-ethereum@ad35d0d#diff-1be9f4f724b980b8a832cdc09b856da1R704

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants