Skip to content

autoload: ABIFunction result sometimes missing selector (marked as required by type) #164

Description

@GalloDaSballo

Impact

The type declaration for AbiFunction is as follows:

export type ABIFunction = {
    type: "function"; // TODO: constructor, receive, fallback
    selector: string;
    name?: string;
    outputs?: ABIOutput[];
    inputs?: ABIInput[];
    sig?: string;
    sigAlts?: string[];
    payable?: boolean;
    stateMutability?: StateMutability;
};

Which led me to believe that you'd always get the selector

However, it seems like when whatsabi can determine the "real" abi, it will not return the selector

POC

Address is 0xF576e1f09e2eb4992d5FFDF68bec4Ea489FA417d, basically one for which the tool is able to grab the ABI correctly

async function makeRepro() {
    const result = await whatsabi.autoload(address, { provider });

    console.log("result.abi", result.abi)
    const fns: ABIFunction[] = result.abi.filter(abi => abi.type === "function") as undefined as ABIFunction[]
    console.log("result.abi", fns[0].selector)
}

makeRepro()

Logs

/// omitted
  },
  {
    inputs: [ [Object], [Object] ],
    name: 'totalUltiAllocated',
    outputs: [ [Object] ],
    stateMutability: 'view',
    type: 'function'
  },
  ... 8 more items
]
result.abi undefined

Mitigation

I believe the tool should always return the selector or the declaration should be changed to have a conditional value

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsoonPlanned, targeting a near-future release

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions