-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal for web3-compatible wallets support #518
Comments
This proposal is an extension and rework of the #498 |
@near/wg-protocol , please nominate SMEs who can review this NEP |
Notice that this is not a NEP yet but a proposal for discussion. This format is beneficial for high-level discussion, and once it becomes a NEP, we can discuss low-level details of the implementation. |
I just wanted to say, that I've been integrating the Aurora SDK into a Near smart contract and the asset bridging is extremely complex and also the gas usage is so high, that it's very limiting. In theory it's a nice addition, but almost all DeFi apps would need some sort of token bridging, but all the cross contract calls consume so much gas, that you have very few gas remaining for the actual smart contract execution on Near. You can check out this example, that I co-authored and there's only 35TGas allocated for the Near smart contract call, because the remaining gas is consumed elsewhere: The bridged wNEAR for Aurora XCC that Alex is mentioning can be circumvented by a small code change in the Aurora SDK, but you would need to make sure, that users would have to pay for the wNEAR deposit somehow else (e.g. by depositing ETH instead, like it's done with Gas on Aurora). Overall the Aurora SDK is somewhat impractical for DeFi apps on Near (but much better for dapps, that don't need token bridging), but it's possible to use it and you can implement some tricky workarounds to have better way of token refunding. |
## Context Tracking issue: #10018. Design: near/NEPs#518 (comment). ### Goal We want the NEAR Protocol's ecosystem to be closer with Ethereum by integrating Web3 wallet support. To accomplish that, some changes on the protocol level are needed with an emphasis on user experience continuity. Following the design, the main change on the protocol level would be to have ETH-style addresses managed by a new `Wallet Contract` integrated into the protocol. For seamless onboarding of EVM users, the contract will be free of charge. ### Previous work This PR is built on top of a [preparatory PR](#10020). It reintroduces some changes from a [closed PR](#10056) that follows an old design. ## Summary On a transfer to an ETH-implicit address: 1. An account is created at this address. 2. The account does not have any access key added. Thus, it is not possible to make a transaction from this account directly. 3. The Wallet Contract (as a part of the protocol) is deployed to the account. For this PR, an empty smart contract is used as a placeholder. ### Changes - On a transfer to an ETH-implicit address, if an account does not exist yet at this address: - Create account at this address. - Deploy a `Wallet Contract` placeholder (empty contract now) to this account. - Update fee for a transfer to an ETH-implicit address to include account creation cost. `Wallet Contract` deployment is free of charge (user only pays for an increased storage). - Tests: - Test whether it is possible to create an ETH-implicit account by making a transfer to that address, and whether further funds can be sent to this account. - Test that no access key is added to an ETH-implicit account (the account is locked) and in consequence no transactions are possible from this account. - Guard the changes with `EthImplicitAccounts` protocol feature and `eth_implicit_accounts` runtime config flag. ## Next work - Discuss how the `Wallet Contract` should be integrated into the protocol for efficiency. - Use the `Wallet Contract` placeholder implementation that allows to transfer funds only.
@alexauroradev , please ping NEP moderator once the NEP is ready to be reviewed- |
I don't have a lot of context, so forgive me for that. Is this design inspired by EIP-4337? |
We had some related discussion in https://near.zulipchat.com/#narrow/stream/295306-pagoda.2Fcontract-runtime/topic/Eth-wallet.20support/near/403646004 . In particular, I think the idea of actually having some hash-containing placeholder for the smart contract code, would help us be forward-compatible with shared smart contracts. This idea would result in us having eg. |
I’m seeing that this is suggesting |
On Ethereum itself the addresses are derived from the public key for the account by taking the rightmost 20 bytes (160 bits) of the keccak256 hash (this is defined in Appendix F, eq 323 of the Ethereum Yellow Paper). We are applying this same rule when deriving an address from a Near account id. We could choose any rule for deriving a 20-byte address from a Near account id, but reusing the Ethereum rule for an Ethereum compatibility protocol is a sensible choice in my opinion (principle of least surprise for devs familiar with Ethereum). |
## Context NEP: near/NEPs#518 Tracking issue: #10018. ### Goal We want the NEAR Protocol's ecosystem to be closer with Ethereum by integrating Web3 wallet support. To accomplish that, some changes on the protocol level are needed with an emphasis on user experience continuity. Following the design, the main change on the protocol level would be to have ETH-style addresses managed by a new `Wallet Contract` integrated into the protocol. For seamless onboarding of EVM users, the contract will be free of charge. ### Previous work This PR is built on top of two PRs: * #10020: no-op PR, laying groundwork for further changes. * #10224: empty contract as a placeholder, literally deployed to new ETH accounts. ## Summary This PR adds `near-wallet-contract` crate (based on `runtime/near-test-contracts`) that exposes `Wallet Contract` WASM code to the runtime. It stops deploying a copy of the `Wallet Contract` to each newly created ETH-implicit account. Instead, it uses an in-memory cached contract code on `execute_function_call` action from such account. ### Changes - Add `wallet-contract` crate (separated from the workspace) with placeholder `Wallet Contract` implementation. - Add `near-wallet-contract` crate (part of the workspace) that generates (through `build.rs`) and exposes the `Wallet Contract` WASM code. - Do not literally deploy `Wallet Contract` when creating ETH-implicit account. Just store reference to the `Wallet Contract`. - Treat ETH-implicit accounts specially when retrieving contract code from an account (in such case returns in-memory cached `Wallet Contract` code). - Add tests calling `Wallet Contract` where a transfer from an ETH-implicit account is possible depending on the public key passed with `rlp_transaction` argument.
What's the current status of this NEP? It is ready to be reviewed by SMEs? |
This PR adds the eth wallet contract implementation which will be automatically deployed with eth implicit accounts. This is as per the design outlined in near/NEPs#518 . It is intentional that the wallet contract implementation is isolated as its own crate and not contained in the broader nearcore workspace. This allows it to be reviewed, tested and audited independently from the rest of the Near code. The crate includes integration tests written using `near-workspaces`. However, the nearcore integration test related to the wallet contract has also been updated to check that the contract is automatically deployed when creating an eth address and that it works as expected. This will not be the last PR in this project because I am only adding the logic for the implementation. It still remains to setup the reproducible build pipeline and update the tests which check the contract hashes. Additionally, there are still a few details which need to be finalized: (1) the Ethereum chain ID that will be associated with Near and (2) the Near account ID that will have the eth address registrar contract deployed. The eth address registrar contract stores a reverse lookup of Ethereum-like address to Near account IDs. It is necessary for the wallet contract to detect faulty relayers. However this (relatively large) PR can be reviewed and merged, and the points above will be addressed in much more manageable follow-up PRs.
Hello everyone, I'd like to understand the current status of this NEP? Can we nominate reviewers and discuss low-level details of the implementation? |
There is an implementation prepared under a nightly feature of nearcore and it is currently being audited. The proposal also has support from the infrastructure working group (they already have a tracking issue related to tasks associated with the proposal). I suggest we move forward with the review and voting stage for the protocol change parts of this proposal (which is just the wallet contract and eth-implicit accounts). |
Thank you @alexauroradev for submitting this NEP. As a moderator, I reviewed this NEP and it meets the proposed template guidelines. I am moving this NEP to the REVIEW stage and would like to ask the @near/wg-protocol working group members to assign 2 Technical Reviewers to complete a technical review. |
…#11606) The eth-implicit accounts feature had been assuming that all Ethereum address-like accounts would be [created implicitly](https://github.com/near/nearcore/blob/c020ee5bf48c0426b3913497550c2b639c7f7f73/runtime/runtime/src/actions.rs#L505) (via a `Transfer` action as opposed to the `CreateAccount` action) and therefore always have [the wallet contract "magic bytes" deployed](https://github.com/near/nearcore/blob/c020ee5bf48c0426b3913497550c2b639c7f7f73/runtime/runtime/src/actions.rs#L582). This invariant is maintained after account creation because the wallet contract [does not allow adding full-access keys](https://github.com/near/nearcore/blob/c020ee5bf48c0426b3913497550c2b639c7f7f73/runtime/near-wallet-contract/implementation/wallet-contract/src/lib.rs#L312) and therefore deploying different contract code is impossible. However, on Near today there are already 5552 accounts (attached list: [eth_addresses.txt](https://github.com/user-attachments/files/15892188/eth_addresses.txt)) that will be [classified as eth-implicit accounts](https://github.com/near/near-account-id-rs/blob/86b3003c28760c6d83e32fc81439da1ce83edd6e/src/validation.rs#L96). These accounts do have full access keys and therefore can have any arbitrary Wasm code deployed to them. Thus the supposed invariant of all eth-implicit accounts having the magic bytes deployed is in fact already broken. This PR removes the `assert` from the runtime which was checking this invariant. As a side note, the broader [web3 wallets project](near/NEPs#518) will blacklist these 5552 accounts in the relayer implementation since the relayer also operations on the assumption that the accounts it interacts with will have the protocol-level wallet contract deployed and this assumption cannot be guaranteed on "legacy" eth-implicit accounts.
I only see an issue here and not a PR for the NEP. Is there a link to the NEP? |
@akhi3030 I'll make a PR which contains this issue description. For now please treat the issue description as the NEP. |
@birchmd: thanks, I will start with the issue description. It will be great to have the PR eventually as that will make it easier to review and provide feedback. |
## **Description** Adds NEAR Icon for ChainId `397` and `398`. These chains are currently new networks being integrated onto EVM. They are currently in development, but it was requested from their team to preemptively add these icons, before production RPC endpoints are available. For context, here is their proposal: near/NEPs#518 https://chainlist.org/chain/397 https://chainlist.org/chain/398 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26459?quickstart=1) ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/MMASSETS-343 ## **Manual testing steps** Once production RPCs are available, these icons should appear when NEAR RPC gets added in custom networks. ## **Screenshots/Recordings** ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
Summary
This proposal introduces a significant enhancement to the NEAR Protocol, aiming to make its ecosystem closer with Ethereum by integrating Web3 wallet support. The primary goal is to resolve the incompatibility issues between Ethereum and NEAR standards, thus facilitating a seamless user experience for Ethereum users on the NEAR platform. Central to this initiative are several components: the Wallet Contract, Wallet Selector Extension, RPC-Translator, Transaction Relayer, and the Ethereum Translation Contract. Together, these elements enable Ethereum-compatible transactions within NEAR, ensuring that users familiar with Ethereum's environment face minimal friction in using NEAR dApps.
Key features include a protocol change that embeds the Wallet Contract for implicit Ethereum-style accounts as a fundamental feature of NEAR and simulating Ethereum standards for transaction compatibility on the level of this contract.
Proposal also acknowledges inherent limitations and risks, which, however, are manageable. The proposal outlines future opportunities for extending its capabilities to include more Ethereum standards and exploring further integrations. The project's scope is vast, requiring rigorous development, testing, and collaboration across various components and entities of the NEAR ecosystem.
In essence, this proposal strives to enhance NEAR's interoperability with Ethereum, significantly improving accessibility and user experience for a broader audience in the blockchain community.
The proposal has core and advanced topics. Pieces that are marked with [COMPLEX] may be omitted during the first read.
Problem Statement
Currently, the Ethereum ecosystem is a leading force in the smart contract blockchain space, boasting a large user base and extensive installations of Ethereum-compatible tooling and wallets. However, a significant challenge arises due to the incompatibility of these tools and wallets with NEAR Protocol. This incompatibility necessitates a complete onboarding process for users to interact with NEAR contracts and accounts, leading to confusion, decreased adoption, and the marginalization of NEAR Protocol.
Implementing Web3 wallet support in NEAR Protocol, with an emphasis on user experience continuity, would significantly benefit the entire NEAR Ecosystem.
Goals / Deliverables
The primary goal is to develop a solution enabling Web3 wallet users to seamlessly interact with NEAR Protocol while retaining their user experience with other EVM-compatible networks. This solution should be straightforward, requiring minimal changes to the NEAR protocol, avoiding potential reversals of protocol changes, and minimizing the need for extensive user education. Additionally, it should prioritize minimizing the risk of phishing attacks that trick users into signing indecipherable data. It's crucial that transactions signed by users are processed unambiguously at the NEAR blockchain level, eliminating the need for a trusted intermediary.
Prior work
Previous efforts have been made in this area. Notable examples include the nEth project and the Metamask Snap for NEAR. These projects enable Metamask compatibility with NEAR natively but fall short in supporting arbitrary Ethereum wallets. Moreover, neither project provides a user experience comparable to that of EVM-compatible chains.
With nEth, users must sign EIP-712 messages, which differs from executing standard transactions in Metamask. The Metamask Snap project effectively creates a distinct application within Metamask, separate from typical Metamask workflows. This application cannot interact with Metamask keys, nor can it display token balances or transaction histories, and it lacks integration with Ledger. Both projects also necessitate funding new accounts from external sources.
Aurora XCC offers another avenue for Ethereum wallet users to interact with Near native. However, this approach has drawbacks, such as the requirement for WNEAR (NEP-141 wrapped NEAR bridged into Aurora from Near native) for many applications. This necessity complicates users' understanding of transaction costs. Additionally, XCC introduces a gas overhead compared to direct Near usage, potentially hindering user interactions with some applications due to Near's 300 Tgas transaction limit.
Technical Description
Ethereum and NEAR exhibit several fundamental incompatibilities that impact areas such as transaction formats, signature algorithms, addressing schemes, public RPC APIs, and interaction workflows. This proposal seeks to effectively conceal and/or resolve these incompatibilities to facilitate standard wallet operations like balance inquiries, account top-ups, transfers of fungible tokens, and smart contract function calls on the NEAR blockchain.
Solution Overview
The proposed solution comprises five key components:
Wallet Contract (WC): An on-chain smart contract designed to receive, validate, and execute Ethereum-compatible transactions on the NEAR blockchain. It functions as a user account.
Wallet Selector Extension: A frontend module that connects NEAR-compatible wallets to dApps. This project aims to develop add-ons supporting Ethereum wallets, primarily to create Ethereum-compatible transactions from NEAR-compatible inputs.
RPC-Translator (RPCT): Given that Ethereum wallets access blockchain state via a specific Web3 API, the RPC-Translator is designed to provide Ethereum methods implementations using the NEAR RPC as a data source. This component, along with the Transaction Relayer, is publicly hosted and accessible to all users. While the RPC-Translator and Transaction Relayer are operated together, they are listed separately to highlight their distinct functions.
Transaction Relayer (TR): Ethereum wallets cannot generate NEAR-compatible transactions. Instead, Ethereum-compatible transactions produced by them are processed by the Transaction Relayer, which embeds it into a NEAR transaction and forwards it to the user’s Wallet Contract. Again, while operated in conjunction with the RPC-Translator, the Transaction Relayer is distinct in its role.
[COMPLEX] Ethereum Translation Contract (ETC): Addressing the incompatibility between NEAR's human-readable account names and Ethereum's cryptographic hash-based addresses, the ETC functions as an on-chain mapping system. This system records NEAR-compatible input values (like NEAR account names and smart contract function names) and maps them to their corresponding Ethereum-compatible cryptographic hashes. This feature is vital for preserving familiar user experiences, such as recognizing
ft_transfer
operations in NEP-141 as fungible token (ERC20) transfers, rather than generic contract calls, and ensuring that fungible token balances are displayed in Web3 wallets.Transaction Flow
The transaction flow between components is outlined as follows:
Below are detailed examples, with implementation specifics provided subsequently.
Example Transaction Flow: Incoming $NEAR Transfer
alice.near
account on NEAR.0xb794f5ea0ba39494ce839613fffba74279579268
.0xb794f5ea0ba39494ce839613fffba74279579268
.0xb794f5ea0ba39494ce839613fffba74279579268
is created, with a Wallet Contract deployed to it by the NEAR Protocol.eth_getBalance
RPC method via the RPC-Translator. Once Alice’s transaction is confirmed on-chain, the RPC-Translator reports the balance of the implicit account, which is then displayed to Bob by his wallet.This process aligns with the user experience expectations of both NEAR and Ethereum users.
Example Transaction Flow: Outgoing Function Call
0xb794f5ea0ba39494ce839613fffba74279579268
.defiex.near
.signAndSendTransaction
method, typical in NEAR wallet interactions.eth_sendRawTransaction
.0xb794f5ea0ba39494ce839613fffba74279579268
.This method meets the expectations of both NEAR developers and Ethereum users.
[COMPLEX] Example Transaction Flow: NEP-141 Transfer from Metamask
0xb794f5ea0ba39494ce839613fffba74279579268
.0xf977814e90da44bfa03b6295a0616a897441acec
.keccak-256
hash of the NEAR accountusdt.tether-token.near
.transfer
method call.usdt.tether-token.near
contract.ft_transfer
action, attaching1 yoctoNEAR
as per NEP-141.This transaction flow adheres to the expectations of Ethereum users.
Wallet Selector and Transaction Transformation
Ethereum transactions, RLP encoded, encapsulate the following information:
To
address of the transaction,From
address (derived from the signature),Gas price
,Gas limit
,Nonce
,value
),Chain ID
,Data field
,Signature
(yielding the public key andFrom
address).For function calls to a smart contract, the data field contains:
Function Selector
,Both
To
andFrom
addresses, encoded in hexadecimal and prefixed with “0x”, comprise 20 bytes. TheFrom
address is the right-most 20 bytes of the Keccak-256 hash of the binary public key of the transaction sender (an EOA, externally owned address). TheTo
address signifies either the recipient EOA or an on-chain contract address.The
Function Selector
is the first 4 bytes of the Keccak-256 hash of the full function signature intended for the contract specified by theTo
address. For instance, the ERC-20 standard functiontransfer(address _to, uint256 _value)
has the Function Selectorkeccak-256("transfer(address,uint256)")[0,4]
, equal to0xa9059cbb
.Proposed Ethereum Transaction Construction
chain ID
to a public constant (to be determined).gas price
, fetched by the Ethereum Wallet from the RPC Translator (sourced from NEAR RPC), reflects the NEAR gas price.1e-4
$NEAR per TGas translates to1e-9
$NEAR or1 gwei
for Ethereum wallets, a familiar unit for Ethereum users.gas limit
is determined by the dApp-developer or througheth_estimateGas
by the Ethereum Wallet, applying the aforementioned recalculation rules.nonce
andsignature
are managed by the Ethereum wallet, in line with Ethereum protocol.From
address adheres to Ethereum protocol too.Special Considerations for
To
andData Field
The
To
address anddata field
creation vary based on the dApp's input to the Wallet Selector:receiverID
matches^0x[a-f0-9]{40}$
(indicating another Ethereum account), it's treated as an EOA and used as-is. This case is restricted to $NEAR transfers (excluding smart contract calls) and is integral to the Ethereum standards simulation.receiverID
refers to a non-EOA account on NEAR. Herekekeccak-256(receiverID)[12,32]
is used as theTo
address.For the
data field
:FunctionCall(to: string, method: string, args: bytes, yoctoNear: uint32)
Transfer(to: string, yoctoNear: uint32)
Stake(public_key: bytes, yoctoNear: uint32)
AddKey(public_key: bytes, nonce: uint64, is_full_access: bool, allowance: uint256, receiver_id: string, method_names: string[])
yoctoNear
values are 32-bit, accommodating values under1e6
. The totalyoctoNEAR
attached to a NEAR Action is1e6 * <ethereum transaction value> + <yoctoNEAR in data field>
, enabling:yoctoNEAR
forft_transfer
andft_transfer_call
methods.transfer(to address, amount uint256)
calls map to NEAR actions in the Wallet Contract.Wallet Contract
The Wallet Contract is designed to process Ethereum transactions through the method
executeRLP(target: AccountId, rlp_transaction: Vec<u8>)
. The following steps outline its operation:Parse the Transaction: It starts by parsing the incoming Ethereum transaction.
Verify Target Address: It checks if the
target
equals the transaction'sTo
address, or ifkeccak256(target)[12,32]
matches theTo
address.Signature Verification and Extraction: The contract verifies the signature to extract the
Public key
andchainID
, ensuring the integrity of the transaction.From
Address Creation and Verification: It generates theFrom
address from the public key and confirms that it aligns with thecurrent_account_id
(the ID of the Wallet Contract).ChainID
Validation: The contract validates that thechainID
corresponds to the constant defined for NEAR.Nonce
Verification and Update: It ensures the transaction nonce matches the stored nonce and then increments the stored nonce by one.[COMPLEX]
Value
Calculation: The contract sets theValue
by multiplying the Ethereum transaction value by1e6
and adding theyoctoNear
value from the data field. It then confirms the attached deposit is either greater than or equal to this value or identifies it as a self-transaction (refer to TR and Gas Payment section for details).[COMPLEX] ETC Lookup and Execution for Ethereum Transfers:
To
Address equals thetarget
and thevalue
is more than zero (indicating an Ethereum transfer), the Wallet Contract consults the ETC ("Ethereum Translation Contract") for theTo
address.To
address, it implies the recipient is an Ethereum EOA. In this case, the transaction is an ordinary transfer and should be executed as such.To
address, indicating the recipient is a NEAR smart contract simulating an Ethereum standard (like NEP-141), the data field of the transaction is parsed against supported ERC standard calls to form the appropriate NEAR action.NEAR Native Account Transfer: If the data field is empty, it transfers the value to the target, typical for a $NEAR transfer to a NEAR-native account. Values below
1e6 yoctoNEAR
cannot be transferred.Function Selector and Parameter Verification: In cases where the data field is not empty, the contract verifies the function selector against matching NEAR actions.
Execution of NEAR Action: After parameter verification, the Wallet Contract executes the corresponding NEAR action by creating a promise.
These steps ensure that the Wallet Contract accurately processes and executes transactions, bridging the gap between Ethereum and NEAR protocols.
Transaction Relayer and Gas Payment
The Transaction Relayer (TR) serves as an HTTP-JSONRPC endpoint compatible with Ethereum, primarily implementing the
eth_sendRawTransaction
method. Its validation process involves:Upon receiving a transaction, the TR assesses the
To
Address:executeRLP
on theFrom
address account, settingtarget
to theTo
Address.To
Address is not on-chain, the TR consults the ETC (Ethereum Translation Contract) for the preimage of theTo
Address. If retrievable, it creates a FunctionCall toexecuteRLP
on theFrom
address account, directingtarget
to the ETC result.Approaches to Gas Payment
This project's challenge lies in appropriately assigning gas costs to the Ethereum-compatible account. Our proposed solutions are:
Simplified Gas Calculation: By default, all transactions use the maximum gas limit, or a limit specified by the dApp developer, to bypass the complexity of gas amount computation.
Gas Payment Scheme:
functionCall
key on its account, authorizing theexecuteRLP
method call with a public key from the Transaction Relayer. This setup, compatible with the Transaction Translation model, employs theAddKey
Action. Received transactions under this scheme are forwarded and paid for by the Transaction Relayer. Alternatively, the Wallet Contract could reimburse the Transaction Relayer via aTransfer
promise.functionCall
key is utilized for all subsequent transactions. Effectively, the Transaction Relayer operates on the account's behalf, with the account bearing all gas costs.functionCall
key in cases of non-parseable transactions, invalid signatures, or nonce replay (subject to specific time and value deltas). This limitation restricts a dishonest Transaction Relayer to a single invalid transaction's NEAR gas cost (typically not exceeding 0.03 $NEAR under normal conditions).[COMPLEX]: This approach avoids unnecessary cross-contract calls, maintaining NEAR protocol interactivity for Ethereum users.
Optional Free Transactions: Some relayers may offer a number of free transactions as an incentive for users to engage with NEAR. This can be achieved by the relayer's account directly calling the Wallet Contract's
executeRLP
function, instead of using the user’s account'sfunctionCall
access key. Some of these transactions may require attachment of $NEAR for covering storage staking or other requirements of NEAR protocol standards.RPC Translator
The RPC-Translator, functioning as an HTTP-JSONRPC endpoint compatible with Ethereum, implements a set of methods crucial for supporting Ethereum wallets. These include:
eth_chainId
: Returns a constant value.eth_gasPrice
: Fetches and recalculates respective data from NEAR RPC.eth_estimateGas
: Returns a constant30M
, aligned with the gas recalculation considerations previously mentioned.eth_blockNumber
: Provides the current NEAR block height.eth_getBalance
: Delivers the account's $NEAR balance, adjusted to Ethereum's decimal count (omitting the last 6 digits).eth_getTransactionCount
: Retrieves the nonce value from the account's Wallet Contract.eth_getTransactionByHash
andeth_getTransactionReceipt
: Present transaction details by indexing the NEAR chain, with values recalculated for Ethereum's decimal count.get_logs
: Offers log information from the NEAR chain, reformatted and recalculated for Ethereum compatibility.eth_call
: Conducts a view call against NEAR RPC, translating parameters as per the Ethereum standards simulation.These methods enable Ethereum wallets to create transactions and access transaction status. The proposal also accommodates direct $NEAR and ERC20 transfers from Ethereum wallets.
[COMPLEX] Ethereum Standards Simulation and Ethereum Translation Contract
To bridge the gap between NEAR's and Ethereum's differing addressing schemes, especially for interactions initiated directly from web3 wallets, the Ethereum Translation Contract (ETC) is pivotal. It maintains a simple mapping between Ethereum transaction hashes and corresponding NEAR account names:
key
:keccak256(<NEAR account>)[12,32]
value
:<NEAR account>
The ETC provides two core functions:
record(account_id: AccountId)
: Calculates the hash and records it in the map, requiring a deposit for storage staking. It is not applicable for Ethereum-style accounts.lookup(hash: [u8; 32]) -> Option<AccountId>
: A view function that returns the associated NEAR account for a given hash, if available.NEAR accounts intending to interact with Ethereum wallets must register with the ETC. This registration is permissionless, allowing third-party on-the-fly registrations if necessary.
It's important to note that ETC registration is not mandatory for most NEAR applications. For instance, applications like ref.finance, typically not called directly from Metamask, would route their contract calls through the frontend, thereby utilizing the Wallet Selector's transaction translation.
In the initial phase, the focus will be on $NEAR token transfers and ERC-20 transfers, and approval management in the Ethereum Standards Simulation. Future expansions may include additional standards in the Wallet Contract (refer to the testing and upgrades section). The ETC itself does not require upgrades to support these enhancements.
Implementation Notes
The proposed solution necessitates a protocol change for deploying the Wallet Contract on implicit Ethereum accounts. To facilitate this, we suggest integrating the Wallet Contract as a core feature of the NEAR protocol. This change would treat all Ethereum accounts as if they already have the Wallet Contract deployed.
Additionally, to enhance security and align with Ethereum's operational flows, we propose prohibiting the deployment of other contracts on Ethereum accounts. This can be achieved by restricting Ethereum users from adding full access keys to these accounts, thereby significantly reducing the attack surface.
Testing and Upgrades
Integrating the Wallet Contract as a protocol feature requires synchronized testing and upgrade processes between
nearcore
and the Wallet Contract. Fortunately, due to the absence of cross-dependencies, the Wallet Contract can be developed, maintained, and tested independently. Its latest stable version would then be incorporated into thenearcore
Testnet release, followed by integration into the Mainnet release.We recommend that any modifications to the Wallet Contract's functionality, such as adding support for new Ethereum standards over time, should be incorporated into the NEAR enhancement process. This approach ensures a structured and systematic update mechanism.
The development and testing of off-chain components, like the RPC-Translator, will precede those of on-chain components. This sequential approach allows for thorough testing and refinement of each component before integration into the larger system.
Limitations and Risks
[COMPLEX] Dependence on Ethereum Standards Simulation: The solution heavily depends on simulating Ethereum standards in the Wallet Contract and RPC-Translator. While standards like ERC20 are manageable, others may be too complex or impossible to emulate accurately.
[COMPLEX] Ambiguity in Transaction Conversion: The emulation of Ethereum standards may lead to confusion in indexing or displaying transactions due to the dual paths of NEP-141 transfer encoding – either through standard conversion via Wallet Selector or originating directly from the wallet. This does not introduce new attack vectors. Users in general should exercise caution and avoid transactions with unfamiliar contracts or frontends.
RPC-Translator Limitations: The RPC-Translator is tailored for wallet interactions and simple chain functions, but it's not equipped for advanced use cases requiring complete block data. Extending its capabilities could be challenging and resource-intensive.
[COMPLEX] Challenges with the Ethereum Translation Contract (ETC): The ETC, vital for integrating NEAR accounts with Ethereum wallets, adds complexity and can lead to user experience issues if registration is overlooked. Automating ETC population through indexing services could mitigate this risk. Future developments might explore on-chain contract lists and function signatures for introspection.
Power and Opacity of Wallet Contract: The Wallet Contract, pivotal for executing NEAR Actions, may be obscure to Ethereum Wallet users. This necessitates stringent checks and limitations on action parameters, as noted in the proposal to restrict full access key additions.
Lack of Batch Transaction Support: The proposal currently does not accommodate batch transactions available in Wallet Selector, primarily due to limited utility and the complexity it would introduce, along with associated security concerns.
[COMPLEX] Potential for inclusion NEAR account functionality in Wallet Contract: An expanded version of the Wallet Contract, which includes NEAR account functionality, could retain valuable NEAR user patterns. For example, alowing using BOS frontend
functionCall
keys for Ethereum accounts. This would facilitate simple actions without needing to sign each transaction in the Ethereum wallet. While promising, this approach requires careful management.Wallet Contract Upgrades: Positioning the Wallet Contract as a protocol feature could limit its upgradability and inadvertently enable smart contract deployments with unbilled storage allocation. Careful implementation can mitigate potential storage growth on NEAR.
Exclusion of Native Ethereum Contract Deployment on NEAR: The proposal does not address the deployment of Ethereum contracts natively on NEAR. Although this is possible via the Aurora network, interactions between NEAR-onboarded Ethereum users and Aurora contracts would necessitate additional steps, like asset bridging or using the Aurora XCC SDK.
Future Opportunities
Scope of the Project
The scope of this project is extensive, encompassing several critical components:
Core Technology:
Integration Testing: Given the solution's distributed nature, comprehensive integration testing is imperative.
Documentation Development: Detailed documentation is necessary, enabling third-party developers to understand and potentially replicate parts of the system, except for the Wallet Contract.
Node Operators Awareness and Public Infrastructure: Launching and maintaining the NEAR Web3 RPC as a public service, similar to the existing NEAR RPC, and informing third-party node operators about the update and maintenance protocols.
Integration with Key Platforms: For effective Ethereum user engagement, integration with the following is essential:
Bug Bounty Program: Establishing a program to address potential vulnerabilities, especially for on-chain components like the Wallet Contract and ETC.
Ongoing Development and Bug Fixes: The project's complexity necessitates a proactive approach to bug fixes and future enhancements.
The text was updated successfully, but these errors were encountered: