Git Product home page Git Product logo

metatx-standard's Introduction

Generalized Meta Transaction

Repository containing a gas cost effective standard for meta transaction to be used by any contract to enable native meta transaction feature on any function. The approach support signed typed messages so that while signing the data on client side user see a human readable message instead of scary hex string.

You can see the LIVE DEMO Here(works on Kovan)

The standard is the result of initiative by metamask here https://medium.com/metamask/announcing-a-generalized-metatransaction-contest-abd4f321470b

Biconomy was selected as one of the finalist in the hackathon. Read here

How do i use this in my Smart Contracts?

  1. Inherit EIP712MetaTransaction contract
  2. Use msgSender() method where ever you were using msg.sender

How do i use this in my client code?

In order to execute meta transactions you just need to call executeMetaTransaction(address userAddress, bytes memory functionSignature, bytes32 sigR, bytes32 sigS, uint8 sigV) inherited from EIP712MetaTransaction.sol

userAddress => externally owned address of the user eg the user address in his metamask wallet

functionSignature => ABI encoding of function name with its parameter. Use web3 encodeABI method here

sigR => 32 bytes r part of the signature

sigS => 32 bytes s part of the signature

sigV => integer v part of the signature

r,s,v can be calculated using web3 getSignatureParameters utility method.

Since this standard supports EIP-712 so signature parameters should be generated using eth_signTypedData_v3 or eth_signTypedData_v4 JSON RPC method.

How to Run test cases

Setup
Rename .secret.example to .secret and add 12 word mnemonic string in the first line

NOTE: Make sure you have nodejs version > 12.0.0

  1. Hardcode the chainId() at line 28 in EIP712Base.sol to the specific network Id e.g 42 for Kovan etc.
  2. Similarly change the same networkId as above in EIP712MetaTransaction.test.js at line 146.
  3. Run npm install command to install all the dependencies
  4. Run ganache-cli in separate cmd/terminal to run ganache client
  5. At last, Run npm run test to run all the test cases.

How to get test coverage

  1. Hardcode the chainId() at line 28 in EIP712Base.sol to the specific network Id e.g 42 for Kovan etc.
  2. Similarly change the same networkId as above in EIP712MetaTransaction.test.js at line 146.
  3. Run npm install command to install all the dependencies
  4. Run ganache-cli in separate cmd/terminal to run ganache client
  5. At last, Run npm run coverage to get test coverage report

Check out example front-end code here and example solidity code here

This repository is basic implementation of Native Meta Transactions. This reposiory will be updated as per the EIP-1776 to implement native meta transactions with support of batching, transaction expiry etc

metatx-standard's People

Contributors

divyan73 avatar tarun1475 avatar tomarsachin2271 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

metatx-standard's Issues

Test on master is broken

The test is broken on master branch now even following the README. The minimum to fix this is altering domainType in the test file as below:

const domainType = [{
        name: "name",
        type: "string"
    },
    {
        name: "version",
        type: "string"
    },
-   {
-       name: "chainId",
-       type: "uint256"
-   },
    {
        name: "verifyingContract",
        type: "address"
    },
+   {
+       name: "salt",
+       type: "bytes32"
+   }
];

and domainData in the test file should be altered as below:

domainData = {
    name: "TestContract",
    version: "1",
    verifyingContract: testContract.address,
-   chainId: 99999
+   salt: "0x000000000000000000000000000000000000000000000000000000000000002A" // chainID: 42
};

But I suggest we add all fields (name, version, chainId, verifyingContract, salt) to it or at least don't use chain ID as salt.

  • string name the user readable name of signing domain, i.e. the name of the DApp or the protocol.
  • string version the current major version of the signing domain. Signatures from different versions are not compatible.
  • uint256 chainId the EIP-155 chain id. The user-agent should refuse signing if it does not match the currently active chain.
  • address verifyingContract the address of the contract that will verify the signature. The user-agent may do contract specific phishing prevention.
  • bytes32 salt an disambiguating salt for the protocol. This can be used as a domain separator of last resort.

Metamask error with BSC integration

MetaMask - RPC Error: Internal JSON-RPC error.
{code: -32603, message: "Internal JSON-RPC error.", data: {โ€ฆ}}
code: -32603
data: {code: -32000, message: "missing from address"}

Linter error: missing SPDX license identifier

I get the following linting error when adding the contracts to my project:

SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

Not supporting Big Numbers >1e10 for BSC

USDC in BSC has 18 decimals, so need support for values in the range 1e18 for meta transactions.

Getting the below error when trying to use big numbers, However it is working well with normal txns without Biconomy

Uncaught (in promise) Error: invalid hexlify value (operation="checkSafeInteger", fault="out-of-safe-range", value=1000000000000000000, code=NUMERIC_FAULT, version=bytes/5.0.10)

msg.value was not handled properly

The executeMetaTransaction function has the payable modifier, and users can pass in native tokens such as ETH when calling this function. But the incoming ETH is not handled properly inside executeMetaTransaction.

There is no msg.value passed in the function call here:
https://github.com/bcnmy/metatx-standard/blob/master/src/contracts/EIP712MetaTransaction.sol#L49

If the target function relies on msg.value for data recording, it may cause that the ETH passed in by tx.origin cannot be processed or the target function throws an exception. The native token will remain in the contract and may not be able to be withdrawn.

The test contract looks like this:

contract Pool is EIP712MetaTransaction("TestMetaTransaction", "1"){
    mapping (address=>uint256) public userInfo;
    function deposit(uint256 amount) public payable{
        require(msg.value==amount);
        userInfo[msgSender()] = userInfo[msgSender()] + msg.value; 
    }
    function withdraw(uint256 amount)public {
        payable(msgSender()).transfer(amount);
        userInfo[msgSender()] = userInfo[msgSender()] - amount;
    }
}

When the executeMetaTransaction function is used to stake for other addresses, ETH is sent to the Pool contract, but it cannot be recorded in the userInfo mapping. As a result, the transfer cannot be withdrawn.

It is suggested to change to:

(bool success, bytes memory returnData) = address(this).call{value:msg.value}(abi.encodePacked(functionSignature, userAddress));

BEOSIN is a leading global blockchain security company dedicated to the construction of blockchain security ecology.

If you need additional assistance, please contact us from:
twitter: https://twitter.com/Beosin_com
telegram: https://t.me/dawnxia

ERC20 Forwarder is not supported for this network

When I run branch erc20-forwarder-demo, errors are reported:

Current provider network id: 5

Please pass a provider connected to a wallet that can sign messages in Biconomy options

ERC20 Forwarder is not supported for this network

It doesn't seem to support Goerli.

Unable to compile contracts

metatx-standard/src$ git b
* erc20-forwarder-demo
  master



metatx-standard/src$ npx truffle compile

Compiling your contracts...
===========================
> Compiling ./contracts/TestForwarder.sol

CompileError: project:/contracts/TestForwarder.sol:5:1: ParserError: Source "@opengsn/gsn/contracts/BaseRelayRecipient.sol" not found: File outside of allowed directories.
import "@opengsn/gsn/contracts/BaseRelayRecipient.sol";
^-----------------------------------------------------^

Compilation failed. See above.
    at /home/aping/.nvm/versions/node/v18.12.1/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/run.js:95:1
    at Generator.next (<anonymous>)
    at fulfilled (/home/aping/.nvm/versions/node/v18.12.1/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/run.js:28:43)
Truffle v5.7.1 (core: 5.7.1)
Node v18.12.1

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.