starcoinorg / sips

Starcoin Improvement Proposals
Apache License 2.0
10 stars 5 forks source link

Partial compatilibity with MetaMask #22

Open livid opened 2 years ago

livid commented 2 years ago

Make some essential features usable with MetaMask by adding a JSON RPC endpoint:

Since MetaMask is already on millions of users' Chrome, if users can access some Starcoin features from MetaMask, it would be an easier first step for users to try Starcoin.

Some more complicated features like interacting with an EVM contract would not be possible at the moment.

jolestar commented 2 years ago

Let me technically derive the feasibility of this solution:

We build an RPC proxy that translates requests to Ethereum RPC API into requests for Starcoin and the response of starcoin RPC into the response of Ethereum.

Translating the query API should not be too difficult. It is mainly an engineering task.

However, if we want to submit transactions, we encounter two difficulties:

  1. The transaction signed by MetaMask is an Ethereum transaction and cannot be converted to a Starcoin transaction. We can not change a transaction after it is signed.
  2. Starcoin's address is different from Ethereum's address and requires a mapping method.
jolestar commented 2 years ago

One solution maybe is:

The user sends the Ethereum transaction to the proxy node, which packages the Ethereum transaction into a payload of Starcoin transaction and submits it to a smart contract on the Starcoin chain through the proxy account, we call the smart contract EVMProxy.

The EVMProxy parses the Ethereum transaction and then verify and executes the transaction in the smart contract by simulating the user.

  1. The EVMProxy on starcoin can verify Ethereum transaction signature by 0x::Signature::ecrecover
  2. EVMProxy can use Signer Delegate to simulate the user.
  3. We take the first 16 bytes of the Ethereum address as the Starcoin address.
  4. The account delegated by EVMProxy, can not send transactions directly, so the proxy can provide a DApp to support withdrawing Token to another Starcoin address by signing a withdrawal transaction.
jolestar commented 2 years ago

Another approach might be to support Walletconnect, it supports multi chain, I record an issue: https://github.com/starcoinorg/starmask-extension/issues/54