Challenge 3: Cross-Contract Query with Polymer

Objective

Your mission, should you choose to accept it, involves the world of cross-chain communication. You are tasked with retrieving a secret message stored in a smart contract deployed on the Base blockchain. To achieve this, you will write a smart contract on Optimism that sends a query packet via Polymer to the target smart contract on Base. Upon receiving an acknowledgment, your contract should decode and log the secret message, showcasing the power of cross-chain interactions.

Background

Polymer provides a robust infrastructure for cross-chain communication, enabling smart contracts on different blockchains to interact seamlessly. This quest challenges you to leverage Polymer’s capabilities to execute a cross-contract query, a fundamental operation to retrieve information from another chain.

Task Details

Write a Smart Contract on Optimism: Create a smart contract on the Optimism network designed to send a cross-chain query to a contract on the Base blockchain. This query should request a secret message.

The contract on Optimism should use SIM Clients (non-proof) and Universal Channels to send packets.

Interact with the contract at address: 0x92b068E0b9DbCc59EeF8BD300Ff55f6BAdF1aF99 deployed on Base. The target smart contract on Base includes an onRecvUniversalPacket function. This function decodes the incoming packet and, upon recognizing a specific query (“crossChainQuery”), responds with a secret message alongside a counter value. Your contract on Optimism should properly format a packet to retrieve the secreteMessage and be prepared to handle this response. The onRecvUniversalPacket function on base is below:

   function onRecvUniversalPacket(bytes32 channelId, UniversalPacket calldata packet)
       external
       override
       onlyIbcMw
       returns (AckPacket memory ackPacket)
   {
        recvedPackets.push(UcPacketWithChannel(channelId, packet));
        uint64 _counter = getCounter();

        (address _caller, string memory _query) = abi.decode(packet.appData, (address, string));

        require(!addressMap[_caller], "Address already queried");
        if (_counter >= 500) {
            return AckPacket(true, abi.encode(LIMIT_MESSAGE));
        }

        if (keccak256(bytes(_query)) == keccak256(bytes("crossChainQuery"))) {
            increment();
            addressMap[_caller] = true;
            uint64 newCounter = getCounter();
            emit LogQuery(_caller, _query, newCounter);

            string memory counterString = Strings.toString(newCounter);

            string memory _ackData = string(abi.encodePacked(SECRET_MESSAGE, counterString));

            return AckPacket(true, abi.encode(_ackData));
        }
   }

  • Send and Receive Packets: Your contract on Optimism must use Polymer’s sendUniversalPacket method to correctly address the contract on Base. Ensure your packet’s data is correctly formatted to trigger the desired response from the Base contract’s onRecvUniversalPacket.
  • Log the Secret Message: In the onAcknowledgementUniversalPacket function of your Optimism contract, decode the acknowledgment packet received from Base to extract the secret message. Log this message using an event for transparency and easy verification.
  • Verify Your Contract: To enable the broader community to review and interact with your contract—and to see the logged messages in the explorer—verify your contract on the respective blockchain explorer. This step is crucial for full transparency and authenticity.

Submission Guidelines

  • Deploy your smart contract to the Optimism testnet and verify its source code on the Optimism explorer.
  • Ensure your contract on Optimism correctly interfaces with the specified contract on Base to retrieve and log the secret message.
  • Submit the address of your deployed contract, along with a link to the log message of the secret message on the Optimism explorer.
  • Screen shot of the IBC Explorers full packet life-cycle

Judging Criteria

Submissions will be evaluated based on the following:

  • Correct implementation of the cross-chain query and acknowledgment handling.
  • Successful retrieval and logging of the secret message.
  • Verification of the contract source code on the blockchain explorer in order to view the log
  • Your prowess in smart contract development and your understanding of Polymer’s cross-chain communication capabilities will be put to the test. Good luck!

Here is a starter template which can be used to complete challenge 3: GitHub - polymerdevs/testnet-challenge-3-template

14 Likes