Skip to content

autoload() never resolves on some Diamond proxies #192

Description

@yog4a

When calling whatsabi.autoload() the Promise never resolves for certain contracts (notably Diamond proxy patterns).
The function halts after the "loadDiamondFacets" phase and no result is returned nor error thrown.

--- Logs

For 0x3914bdb4130306f80f5d8ee099c180442d19680d
[whatsabi][onProgress] getCode { address: '0x3914bdb4130306f80f5d8ee099c180442d19680d' }
[whatsabi][onProgress] loadDiamondFacets { address: '0x3914bdb4130306f80f5d8ee099c180442d19680d' }

--> Then nothing happened until node process crash.

--- Details
The issue happens when followProxies: true and false
The issue happens with any viem provider (and with timeout set)
The issue happens only for this contract
Tested on Node.js v20.15.1, @shazow/whatsabi@0.11.2.

// Imports
// ===========================================================

import { whatsabi, proxies } from '@shazow/whatsabi';
import { createPublicClient, http, chains } from 'viem';

const provider = createPublicClient({
    chain: chains.mainnet,
    transport: http()
});
// Functions
// ===========================================================

export const resolveProxy = async (address: `0x${string}`, bytecode: `0x${string}`): Promise<ResolveProxyOutput> => {
    try {
        const cachedCodeProvider = whatsabi.providers.WithCachedCode(provider, {
            [address]: bytecode,
        });

        const result = await whatsabi.autoload(address, {
            provider: cachedCodeProvider,
            abiLoader: false, // Skip ABI loaders
            signatureLookup: false, // Skip looking up selector signatures
            followProxies: true, // Follow proxy
        });

        const selectors = result.abi.map((func: any) => func.selector);
        const proxies = result.proxies.map((proxy: any) => ({ name: proxy.name, address: proxy.resolvedAddress }));

        return { selectors, proxies };
        
    } catch (error) {
        const _selectors = whatsabi.selectorsFromBytecode(bytecode) as `0x${string}`[]; 
        return { selectors: _selectors, proxies: [] };
    }
}

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