Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Missing head in abi encoded tuple for function #176

Closed
rockfridrich opened this issue Feb 7, 2019 · 2 comments
Closed

Missing head in abi encoded tuple for function #176

rockfridrich opened this issue Feb 7, 2019 · 2 comments

Comments

@rockfridrich
Copy link
Member

An offset of the data needed to be encoded into tuple is missing for contract call functions.

Example:
If a tuple is used as the first argument of function, then there should be 32 (0000000000000000000000000000000000000000000000000000000000000020) put between signature and encoded structure.

How to reproduce:
Call getOrderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes) function on the 0x exchange contract with the next set of parameters:

let network: Network = GethNetwork(url: "InfuraUrl")

let exchangeContract = EthAddress(
    hex: "0x4f833a24e1f95d70f028921e27040ca56e09ab0b"
)

let kittiesContract = EthAddress(
    hex: "0x06012c8cf97bead5deae237070f9587f8e7a266d"
)

let sender = EthAddress(
    hex: "0x0aD9Fb61a07BAC25625382B63693644497f1B204"
)

let receiver = EthAddress(
    hex: "0x4dB6d56Bbb49DD66abC7be5D671fDdF9a5255Cc5"
)

let zero = EthAddress(
    hex: "0x0000000000000000000000000000000000000000"
)

let makerAssetData = EncodedABIFunction(
    signature: SimpleString(
        string: "ERC721Token(address,uint256)"
    ),
    parameters: [
        ABIAddress(
            address: kittiesContract
        ),
        ABIUnsignedNumber(
            origin: EthNumber(value: 478404)
        )
    ]
)

let takerAssetData = EncodedABIFunction(
    signature: SimpleString(
        string: "ERC721Token(address,uint256)"
    ),
    parameters: [
        ABIAddress(
            address: kittiesContract
        ),
        ABIUnsignedNumber(
            origin: EthNumber(value: 392919)
        )
    ]
)

let orderInfo = EncodedABIFunction(
    signature: SimpleString(
        string: "getOrderInfo((" +
            "address," +
            "address," +
            "address," +
            "address," +
            "uint256," +
            "uint256," +
            "uint256," +
            "uint256," +
            "uint256," +
            "uint256," +
            "bytes," +
        "bytes))"
    ),
    parameters: [
        ABITuple(
            parameters: [
                // makerAddress
                ABIAddress(
                    address: sender
                ),
                // takerAddress
                ABIAddress(
                    address: receiver
                ),
                // feeRecipientAddress
                ABIAddress(
                    address: zero
                ),
                // senderAddress
                ABIAddress(
                    address: zero
                ),
                // makerAssetAmount
                ABIUnsignedNumber(
                    origin: EthNumber(value: 1)
                ),
                // takerAssetAmount
                ABIUnsignedNumber(
                    origin: EthNumber(value: 1)
                ),
                // makerFee
                ABIUnsignedNumber(
                    origin: EthNumber(value: 0)
                ),
                // takerFee
                ABIUnsignedNumber(
                    origin: EthNumber(value: 0)
                ),
                // expiration timestamp
                ABIUnsignedNumber(
                    origin: EthNumber(value: 1569523685)
                ),
                // salt
                ABIUnsignedNumber(
                    origin: EthNumber(value: Int(Date.init().timeIntervalSince1970 * 1000))
                ),
                // makerAssetData
                ABIVariableBytes(
                    origin: makerAssetData
                ),
                // takerAssetData
                ABIVariableBytes(
                    origin: takerAssetData
                )
            ]
        )
    ]
)

do {
    
    let call = try EthContractCall(
        network: network,
        contractAddress: exchangeContract,
        functionCall: orderInfo
        ).value()
    
} catch {
    print(error)
}

More information could be found here — https://medium.com/b2expand/abi-encoding-explanation-4f470927092d

@abdulowork
Copy link
Contributor

What is the expected value of orderInfo.value()?

@rockfridrich
Copy link
Member Author

0xc75e0a8100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000ad9fb61a07bac25625382b63693644497f1b2040000000000000000000000004db6d56bbb49dd66abc7be5d671fddf9a5255cc5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c5f8a23745a4c682985f13b4f6935e129e895a70737172437c4296d900c7b0a1b19354e0000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000600257179200000000000000000000000006012c8cf97bead5deae237070f9587f8e7a266d0000000000000000000000000000000000000000000000000000000000074cc40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600257179200000000000000000000000006012c8cf97bead5deae237070f9587f8e7a266d000000000000000000000000000000000000000000000000000000000005fed700000000000000000000000000000000000000000000000000000000

abdulowork added a commit to abdulowork/Web3Swift-1 that referenced this issue Feb 14, 2019
…dParameter to resolve incorrect tuple encoding
abdulowork added a commit to abdulowork/Web3Swift-1 that referenced this issue Feb 14, 2019
abdulowork added a commit to abdulowork/Web3Swift-1 that referenced this issue Feb 14, 2019
abdulowork added a commit that referenced this issue Feb 26, 2019
#176 - Fix dynamic tuple encoding
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants