Code Monkey home page Code Monkey logo

Comments (4)

arthcp avatar arthcp commented on July 1, 2024

@mudgen Meta transactions are executed by calling the executeMetaTransaction function of NativeMetaTransaction contract.

This function calls self contract with calldata and userAddress as can be seen here: https://github.com/maticnetwork/pos-portal/blob/master/contracts/common/NativeMetaTransaction.sol#L59-L61

Due to how it is being called, we expect the user address to be at add(array, index).

Thanks for pointing out that masking is not needed here. I think you are correct about that. I will run some tests to verify it and raise a PR.

from pos-portal.

mudgen avatar mudgen commented on July 1, 2024

@arthcp I see, cool.

Instead of copying calldata to memory and dropping to assembly you can use calldata slices. For example:

sender = abi.decode(msg.data[msg.data.length-32:], (address));

Array slices info here: https://solidity.readthedocs.io/en/v0.7.1/types.html#array-slices

from pos-portal.

mudgen avatar mudgen commented on July 1, 2024

Nevermind, you won't be able to decode it that way because it is encoded with abi.encodePacked. But if you encoded it with abi.encode instead then you could.

from pos-portal.

mudgen avatar mudgen commented on July 1, 2024

Since the address is encoded with abi.encodePacked, you could do it like this:

pragma solidity 0.6.6;

abstract contract ContextMixin {
    function msgSender()
        internal
        view
        returns (address payable sender)
    {
        if (msg.sender == address(this)) {
            uint256 index = msg.data.length - 20;
            assembly {
                // Load the 32 bytes word from calldata with the address on the lower 20 bytes.
                sender := calldataload(index)
            }
        } else {
            sender = msg.sender;
        }
        return sender;
    }
}

Saves some gas from having to copy calldata to memory.

from pos-portal.

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.