Git Product home page Git Product logo

Comments (5)

platocrat avatar platocrat commented on July 28, 2024 1

Contracts can interact with this "cross domain messenger" with the same interface as is given by the l2geth precompile but the mock simplifies relaying the message (and doesn't actually do any "cross domain" calls as everything is happening in the jsvm)

Sorry, I was being a numpty and didn't realize I was overlooking the cross-domain messaging 😅.

l2geth doesn't give revert messages, will only show gas estimations for l2 contracts with solidity-gas-reporter (even if you have l1 contracts you interact with in your tests) and is incompatible with solidity-coverage.

ethereum-optimism/optimism/issues/474 should fix the issue with revert reasons not being returned when using l2geth.

from community-hub.

platocrat avatar platocrat commented on July 28, 2024 1

Per this comment on ethereum-optimism/optimism/issues/474, the fix for revert reasons issue will not be pushed to production until 05/03/21

from community-hub.

platocrat avatar platocrat commented on July 28, 2024 1

Stale

from community-hub.

transmissions11 avatar transmissions11 commented on July 28, 2024

could you expand on what exactly to mock and give an example?

Basically any Optimism precompiles that you use when running your tests on l2geth (OVM_ETH, cross domain messengers, etc, etc) need to be manually deployed in the jsvm (where as on L2 geth they are assigned addresses at geth startup and useable without setup in tests).

However some of those contracts are pretty complex to setup manually on L1 and require external relayers, etc so for some I would recommend writing a custom "mock" version.

Here's my extremely insecure (but simple) implementation of a mock "cross domain messenger":

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.7.6;

contract MockCrossDomainMessenger {
   struct xDomainMessage {
       address _target;
       bytes _message;
       uint32 _gasLimit;
       address sender;
   }

   xDomainMessage currentMessage;

   function xDomainMessageSender() external view returns (address) {
       return currentMessage.sender;
   }

   function sendMessage(
       address _target,
       bytes memory _message,
       uint32 _gasLimit
   ) external {
       uint256 startingGas = gasleft();
       uint256 gasToConsume = _gasLimit / 32;

       currentMessage = xDomainMessage(_target, _message, _gasLimit, msg.sender);

       // Mimic enqueue gas burn (https://github.com/ethereum-optimism/optimism/blob/master/packages/contracts/contracts/optimistic-ethereum/OVM/chain/OVM_CanonicalTransactionChain.sol)
       uint256 i;
       while (startingGas - gasleft() < gasToConsume) {
           i++;
       }
   }

   function relayCurrentMessage() external {
       (bool success, bytes memory result) = currentMessage._target.call(currentMessage._message);

       require(success, _getRevertMsg(result));
       delete currentMessage;
   }

   function _getRevertMsg(bytes memory _returnData) private pure returns (string memory) {
       // If the _res length is less than 68, then the transaction failed silently (without a revert message)
       if (_returnData.length < 68) return "Transaction reverted silently";

       assembly {
           // Slice the sighash.
           _returnData := add(_returnData, 0x04)
       }
       return abi.decode(_returnData, (string)); // All that remains is the revert string
   }
}

Contracts can interact with this "cross domain messenger" with the same interface as is given by the l2geth precompile but the mock simplifies relaying the message (and doesn't actually do any "cross domain" calls as everything is happening in the jsvm)

from community-hub.

transmissions11 avatar transmissions11 commented on July 28, 2024

It can also be more explicit that debugging first with the jsvm and local l2geth is far easier than against Kovan or in a CI.

Mainly was emphasizing that debugging with jsvm specifically is much easier than l2geth. l2geth doesn't give revert messages, will only show gas estimations for l2 contracts with solidity-gas-reporter (even if you have l1 contracts you interact with in your tests) and is incompatible with solidity-coverage. You also can't use hardhat's console.sol with l2geth of course.

from community-hub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.