Skip to content
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

Add RSKIP432 #432

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions IPs/RSKIP432.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
rskip: 432
title: RbtcSwap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a little bit more descriptive name? Something like "Add new RBTCSwap contract"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the name RbtcSwap mechanism? This feature is not a new contract, but an implementation of a mechanisim that uses an existing contact

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's a hardcoded bytecode contract that you invoke how ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if it got confusing, what I meant is that this RSKIP is not only to add the contract but also the mechanism that allows the claim to be paid after its execution.

description:
status: Draft
purpose: Usa
author: (@rmoreliovlabs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "RM" and add you to the README file as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you included RM in the README but we also use initials here

layer: Core
complexity: 2
created: 2024-05
---
# RbtcSwap


|RSKIP | 432 |
| :------------ |:-------------|
|**Title** |RbtcSwap|
|**Created** |MAY-2024 |
|**Author** |@rmoreliovlabs |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before

|**Purpose** |Usa |
|**Layer** |Core |
|**Complexity** |2 |
|**Status** |Draft |

# **Abstract**

This RSKIP proposes a mechanism for users to issue normal transactions that pay their own gas but do it at the end of transaction execution, instead of at the beginning.

## Motivation

Often, users receive stablecoins and wish to transact on the Rootstock network but face a challenge: they lack RBTC, needed for transaction fees. Although they may be willing to exchange some stablecoins for RBTC on a DEX, this solution is also hindered because the exchange transaction itself requires payment in RBTC.

This can be solved using RIF Relay, which allows a third party to pay for the transaction. However, this solution requires the use of a special smart-contract wallet that accepts encapsulated commands, so it’s not compatible with any EOA-based wallet.

Another use case is when users receive a signed message or certain message which entitles them to withdraw some RBTC from a certain contract. This is the case of the Boltz Exchange. However, they cannot collect it without issuing a new transaction, and they cannot issue a transaction without RBTC.

Both of these functionalities are considered part of the Account Abstraction meta-proposals, but we aim to address a narrower use case. This RSKIP only solves how to bootstrap a wallet without RBTC. It doesn't solve how to use a different signature scheme for safekeeping the wallet, nor how to use a multi-signature scheme, nor how to do social recovery, nor how to set withdrawal limits, nor any functionality that restricts how the user spends their funds.

## Specification

We could create our own contract, be it native or using Solidity, or we could deploy one that already exists like for
example the Boltz EtherSwap contract.

Regardless of the choice the contract to use should have the following methods:

Lock: This method should create a claim record by generating a hash using the arguments it recieves and some information from the transaction. The arguments should at least include the claimer address, a preimage hash, the amount to lock and a timelock (a numeric value that indicates the amount of time the funds will be locked, represented in block height). The claim record hash would be generated by using the afore mentioned argument and the depositor address which would be the msg.sender and the amount to be locked sent in the msg.value. The claim record would be stored as a mapping from the claim hash to a boolean.

Claim: This method transfer the funds locked in a claim record after verifying that said actually exist. I would do this by generating a hash that must match the has generated by the Lock method for that record. To generate this hash the method should receive at least these arguments: the preimage hash provided by the depositer, the amount locked in the record, the refund address which is the despositor's and the timelock of the record, the claimer address could be obtained from msg.sender. If a matching hash is found among the claim records stored in the contract, the corresponding amount would be transferer to the claimer account and the claim record would be deleted. On the contrary if not record that matches the hash is found then the method reverts.

Refund: This method would transfer the funds back to the depositor if a record matching the hash generated by it is found and if the timelock has exipired. The arguments for this method should at least include the preimage hash, the amount locked in the record, the claimer address and the timelock, the despositer address could be obtained from msg.sender. If a record with a matching hash is found and the corresponding timelock has expired then the funds are transfered to the despositer account. In case no record is found or the timelock hasn't expired yet then the method reverts.

Before adding the claim transaction to the mempool the mechanism should check if the funds it tries to claim do indeed exist. To do so it would generate a hash using data from the transaction and use it to look for a claim record with a matching hash. If a record is found it would then verify that the amount locked is enough to pay for the transaction, in case it is then the transaction would be included in the mempool but if any of these conditions are not fulfilled then the transaction would be discarded.

The next check would happen during the claim transaction execution, here the mechanism would check again if the funds corresponding the the claim transaction still exists, this validation would cover cases when the claimer manages to get the locked funds by other means (like the ones described in the last section). If the claim record still exists the transaction would be executed but the payment logic would be delayed until after the execution when the funds would have been transfered to the claimer.

## Rationale

The mechanism would only trigger if a claimer tries to send a transaction that calls the Claim method from the contract and doesn't have enough balance in their account to pay for said transaction. This means that regular/funded transactions would not be affected by the changes introduced for this feature.

## Backwards Compatibility

This feature would not be backwards compatible, it would need a hardfork and activation block height defined for each network.

# **Copyright**

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).



2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ You can find an easily browseable version of this information [here](https://ips
| 415 |[Fix pegnatories address derivation from public keys](IPs/RSKIP415.md)| 30-JAN-24 | MI | Usa | Core | 1 | Adopted |
| 417 |[Avoid transactions to be reverted when Bridge method calls from smart contracts return an empty response](IPs/RSKIP417.md)| 28-FEB-24 | MI | Usa | Core | 1 | Adopted |
| 419 |[Powpeg Spendability Validation Protocol](IPs/RSKIP419.md)| 31-AUG-23 | JD, JZ | Sec | Core | 2 | Draft |
| 432 |[RbtcSwap](IPs/RSKIP432.md)| 24-MAY-24 | RM | Usa | Core | 2 | Draft |

(*) Under evaluation to be implemented in the next reference client release

Expand Down Expand Up @@ -265,6 +266,7 @@ You can find an easily browseable version of this information [here](https://ips
| SM | Shreemoy Mishra | [email protected] |
| SMS | Sebastian Matias Sicardi | |
| VK | Volodymyr Kravets | [email protected] |
| RM | Reynold Morel | [email protected] |

## Build locally

Expand Down