Rockside
Search…
Forwarder
I you want to pay the gas for your user you can use a forwarder contract.
A user signs a message representing its transaction intent. The message is then sent to Rockside. There it gets wrapped in a new transaction to be sent and executed on chain by the Forwarder contract.
Relay overview

User signs its message and sends it to Rockside

The parameters to be included on the signed message are:
    signer: address of the account who signed the message. The user who want to interact with the destination contract.
    to: if the destination contract has to interact with another account (contract or EOA), this field can be used (for example to transfer tokens).
    data: bytes to be executed.
    nonce: nonce value used by the signer. It's a 2 dimensional nonce represented as a 256 bit integer split in two.
At Rockside we follow EIP-712 to structure the relay message.
When the message is created and signed, it's sent to Rockside with a chosen speed of inclusion in the blockchain.

Rockside validates the transaction and sends it to the Forwarder

    1.
    Accept the transaction: Rockside use EthGasStation as a reference for the gas prices. Depending on your given gas price limit, your requested speed and the current market gas prices, we decide whether or not to relay your transaction. We also verify that the Forwarder has enough ether to refund Rockside for the gas used by the transaction.
    2.
    Choose the appropriate EOA: Rockside manages different pools of EOA to send transactions. A pool of EOA for each available speed. This way, we guarantee that a "fast" transaction will not be slowed down by a transaction with a "safelow" speed. It's like on the highway, each transaction has its own queue depending on its speed.
    3.
    The message is included within a transaction: Using the corresponding EOA a transaction containing the signed message of the user is sent to the user's Forwarder. The gas price used by Rockside is in accordance with the speed requested.
The source code of Forwarder contract is available on Github.

The Forwarder validates the message and calls the destination contract

    1.
    Message signature validation: The Forwarder verifies that the signature corresponds to the signer and the parameters of the transaction.
    2.
    Check and update nonce: To avoid replay attacks, the forwarder verifies that the nonce was not already used. Once done, the current nonce is incremented.
    3.
    Call the destination contract: When all verifications are done, the destination contract is called with the parameters of the transactions.
    4.
    Refund Rockside relayer: An amount of ether corresponding to the gas consumed and the gas price used (limited by the gas price limit) is sent from the Forwarder to the Rockside Relayer.

The transaction is executed

The destination contract is called with "data+signer". To be compatible with Rockside's forwarder, the destination contract must use a special function instead of the usual msg.sender
1
function _msgSender() internal view returns (address ret) {
2
address sender = msg.sender;
3
if (msg.data.length >= 24 && msg.sender == authorizedForwarder) {
4
assembly {
5
sender := shr(96,calldataload(sub(calldatasize(),20)))
6
}
7
}
8
return sender;
9
}
Copied!
This function is used for your contract to know if it was called by a meta transaction or a normal transaction.
You can see an example of implementation in our SmartWallet contract.

Replay Protection

The Forwarder contract implements a two dimensional nonce from EIP 2585 .
We think it's the less restrictive approach. It allows ordered but also concurrent meta-transactions. It provides different channels for nonce management. If you don't need concurrency, just use one channel. If you need concurrent transactions, use different channels. An extra gas fee will be charged the first time you use a channel.
In this implementation, the nonce is an uint256 that is split in two 128 bit values. The higher bits represent the channel ID while the lower bits represent the nonce in the channel. The nonce to be sent is equal to the current nonce of a channel. For every use the current nonce get increased by one.
1
mapping(address => mapping(uint128 => uint128)) public nonces;
2
3
function checkAndUpdateNonce(address signer, uint256 nonce) internal returns (bool) {
4
uint128 channelId = uint128(nonce % 2**128);
5
uint128 channelNonce = uint128(nonce / 2**128);
6
7
uint128 currentNonce = nonces[signer][channelId];
8
if (channelNonce == currentNonce) {
9
nonces[signer][channelId]++;
10
return true;
11
}
12
return false;
13
}
Copied!

Get an API KEY

To access the forwarder API you need an API Key. It's available by registering on Rockside Dashboard.
post
https://api.rockside.io
/ethereum/:network/forwarders
Deploy a Forwarder contract
get
https://api.rockside.io
/ethereum/:network/forwarders
List Forwarders
post
https://api.rockside.io
/ethereum/:network/forwarders/:forwarder_address/relayParams
Get relay parameters
post
https://api.rockside.io
/ethereum/:network/forwarders/:forwarder_address/
Relay a transaction
get
https://api.rockside.io
/ethereum/:network/transactions/:id
Get transaction infos
Last modified 10mo ago