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

Failing to compile contracts with @chainlink dependency #242

Open
ciaranightingale opened this issue Nov 27, 2024 · 3 comments
Open

Failing to compile contracts with @chainlink dependency #242

ciaranightingale opened this issue Nov 27, 2024 · 3 comments

Comments

@ciaranightingale
Copy link

ciaranightingale commented Nov 27, 2024

Contracts using the @chainlink dependency are failing to compile using the ZKsync plugin on Remix.

Steps to reproduce:

  1. Paste the following code into a Receiver.sol file:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {Client} from "@chainlink/[email protected]/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/[email protected]/src/v0.8/ccip/applications/CCIPReceiver.sol";

/**
 * THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
 * THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
 * DO NOT USE THIS CODE IN PRODUCTION.
 */

/// @title - A simple contract for receiving string data across chains.
contract Receiver is CCIPReceiver {
    // Event emitted when a message is received from another chain.
    event MessageReceived(
        bytes32 indexed messageId, // The unique ID of the message.
        uint64 indexed sourceChainSelector, // The chain selector of the source chain.
        address sender, // The address of the sender from the source chain.
        string text // The text that was received.
    );

    bytes32 private s_lastReceivedMessageId; // Store the last received messageId.
    string private s_lastReceivedText; // Store the last received text.

    /// @notice Constructor initializes the contract with the router address.
    /// @param router The address of the router contract.
    constructor(address router) CCIPReceiver(router) {}

    /// handle a received message
    function _ccipReceive(
        Client.Any2EVMMessage memory any2EvmMessage
    ) internal override {
        s_lastReceivedMessageId = any2EvmMessage.messageId; // fetch the messageId
        s_lastReceivedText = abi.decode(any2EvmMessage.data, (string)); // abi-decoding of the sent text

        emit MessageReceived(
            any2EvmMessage.messageId,
            any2EvmMessage.sourceChainSelector, // fetch the source chain identifier (aka selector)
            abi.decode(any2EvmMessage.sender, (address)), // abi-decoding of the sender address,
            abi.decode(any2EvmMessage.data, (string))
        );
    }

    /// @notice Fetches the details of the last received message.
    /// @return messageId The ID of the last received message.
    /// @return text The last received text.
    function getLastReceivedMessageDetails()
        external
        view
        returns (bytes32 messageId, string memory text)
    {
        return (s_lastReceivedMessageId, s_lastReceivedText);
    }
}
  1. Head to the ZKsync plugin tab and hit 'Compile Receiver.sol' or 'Compile project' (both fail for me).
    This produces the following error:
Failed to compile:
Error HH411: The library @chainlink/[email protected], imported from docs.chain.link/contracts/CCIP/Receiver.sol, is not installed. Try installing it using npm.
HardhatError: HH411: The library @chainlink/[email protected], imported from docs.chain.link/contracts/CCIP/Receiver.sol, is not installed. Try installing it using npm.
    at Resolver.resolveImport (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/resolver.ts:254:15)
    at async /opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/dependencyGraph.ts:188:28
    at async Promise.all (index 0)
    at async DependencyGraph._addDependenciesFrom (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/dependencyGraph.ts:186:5)
    at async Promise.all (index 0)
    at async Function.createFromResolvedFiles (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/dependencyGraph.ts:15:5)
    at async Environment._runTaskDefinition (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/core/runtime-environment.ts:359:14)
    at async Environment.run (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/core/runtime-environment.ts:192:14)
    at async SimpleTaskDefinition.action (/opt/app/api/hardhat_env/node_modules/hardhat/src/builtin-tasks/compile.ts:1389:58)
    at async Environment._runTaskDefinition (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/core/runtime-environment.ts:359:14)

    Caused by: HardhatError: HH401: Library @chainlink/[email protected] is not installed.
        at Resolver._resolveLibrarySourceName (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/resolver.ts:322:15)
        at Resolver.resolveSourceName (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/resolver.ts:103:33)
        at async Resolver.resolveImport (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/resolver.ts:194:24)
        at async /opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/dependencyGraph.ts:188:28
        at async Promise.all (index 0)
        at async DependencyGraph._addDependenciesFrom (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/dependencyGraph.ts:186:5)
        at async Promise.all (index 0)
        at async Function.createFromResolvedFiles (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/dependencyGraph.ts:15:5)
        at async Environment._runTaskDefinition (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/core/runtime-environment.ts:359:14)
        at async Environment.run (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/core/runtime-environment.ts:192:14)
    
        Caused by: Error: Cannot find module '@chainlink/[email protected]/package.json' from '/opt/app/api/hardhat_env/workspaces/b8b63a98-9fe3-4351-a9fe-6c1e727b508d'
            at Function.resolveSync [as sync] (/opt/app/api/hardhat_env/node_modules/resolve/lib/sync.js:89:15)
            at Resolver._resolveNodeModulesFileFromProjectRoot (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/resolver.ts:457:20)
            at Resolver._resolveLibrarySourceName (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/resolver.ts:311:30)
            at Resolver.resolveSourceName (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/resolver.ts:103:33)
            at async Resolver.resolveImport (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/resolver.ts:194:24)
            at async /opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/dependencyGraph.ts:188:28
            at async Promise.all (index 0)
            at async DependencyGraph._addDependenciesFrom (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/dependencyGraph.ts:186:5)
            at async Promise.all (index 0)
            at async Function.createFromResolvedFiles (/opt/app/api/hardhat_env/node_modules/hardhat/src/internal/solidity/dependencyGraph.ts:15:5)

Additional Information

This issue does not seem to be isolated as Updraft users are getting the same error. See this issue for more details.
Additionally, I attempted to make a simple ERC20 contract using OpenZeppelin and this compiled fine.

@popzxc
Copy link
Contributor

popzxc commented Nov 28, 2024

Hey @ciaranightingale

tl;dr is that currently plugin supports a limited set of dependencies (you can see them here). Given that plugin doesn't currently have a sandboxed environment, supporting any possible dependency is troublesome, as we cannot just allow to blindly install any npm package on the backend. However, what we can do short-term is to support a fixed set of popular libraries, if that works.

@ciaranightingale
Copy link
Author

Thanks for the prompt response @popzxc
I have updated my code to use @chainlink/contracts however I need to use release v1.3.0 (the most recent release as v1.0.0 does not have CCIP)
Does the plugin use the exact version specified in the package.json file you shared? By semantic versioning, I assumed minor versions were also compatible. However, this still seemed to cause an issue for me and the user who posted an issue on the Cyfrin GitHub

@popzxc
Copy link
Contributor

popzxc commented Nov 29, 2024

@ciaranightingale Well, the npm workspace is built inside the dockerfile so the versions on the backend are static (e.g. they are not updated during compilation). So, yes, the plugin does use the exact version from package.json.

What we can do is to at least bump the version of @chainlink/contracts. However, right now we're transitioning the plugin from Nethermind to Matter Labs (here's the corresponding issue), so the update can only happen after the migration.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants