Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article explores ERC6120, which proposes a Universal Token Router (UTR) that lets users transfer tokens and then make a call instead of approving tokens before making a call.
This article translates, summarizes, and expands on the following proposal.
As of January 17, 2024, ERC6120 was at the Review stage.
Other EIP articles are also available.
Overview
The basic pattern for Ethereum transactions is to transfer assets and then make a call (transfer-and-call).
However, ERC20 and other token standards were not designed around this pattern, making it difficult to apply a new standard to existing token contracts.
As a result, applications and router contracts have to use the approve-then-call (approve-then-call) pattern.
This approach requires additional approvals (approve or permit) for each contract, token, and account, degrading the user experience, consuming fees and network storage, and increasing security risks.
The risks are even greater when the approved contract is unaudited, unverified, or an upgradeable proxy.
The approve-then-call pattern is also error-prone, and many approval-related bugs and vulnerabilities have been discovered.
The Universal Token Router (UTR) was designed to address these issues. UTR separates token approvals from application logic, allowing any token to be used in contract calls in the same way as ETH without granting approvals to individual application contracts.
Tokens approved for UTR can only be used in transactions directly signed by their owner.
Token movements are explicit: the token type (ETH, ERC20, ERC721, or ERC1155), amountIn, amountOutMin, and recipient are clearly exposed.
See the following article for more on ERC20.
See the following article for more on ERC721.
See the following article for more on ERC1155.
The Universal Token Router contract is deployed at 0x8Bd6072372189A12A2889a56b6ec982fD02b0B87 on all EVM-compatible networks using the EIP1014 SingletonFactory contract, according to the proposal.
This allows new token contracts to designate UTR as a trusted address in advance, eliminating approval transactions during interactive use.
This significantly improves the user experience and strengthens security.
transfer-and-call and approve-then-call
Transfer-and-Call
Ethereum smart contracts are commonly used to manage digital assets such as ether (ETH) and tokens.
Transfer-and-Call refers to a process in which a smart contract sends a specified quantity of tokens to another address and then invokes a particular function of another smart contract.
The procedure typically works as follows.
1. The sending smart contract transfers (transfer) a specified quantity of tokens to another address.
2. The recipient address hosts a smart contract that performs an operation on the tokens it receives.
3. The recipient smart contract executes a particular function upon receiving the tokens.
Approve-then-Call
Approve-then-Call is a process in which the token owner (usually a smart contract) authorizes another smart contract to operate on the tokens and then invokes a particular function.
The procedure typically works as follows.
1. The token owner (smart contract) grants a specific address permission to operate on the tokens (approve).
2. The other smart contract receives permission to perform the specified token operation.
3. The authorized smart contract performs the specified token operation and can then invoke a particular function.
In short, Transfer-and-Call directly sends tokens before calling another smart contract, whereas Approve-then-Call obtains permission from the token owner, performs an operation, and then calls a function.
Both are ways of safely combining token operations with other smart contracts.
Motivation
UTR is designed to improve security when users approve tokens for contracts. Users rely on two key security properties.
- Tokens are used only with the user's authorization (via
msg.senderorecrecover). - No
delegatecallis used (for example, through an upgradeable proxy).
By maintaining these properties, UTR can be shared across interactive applications, eliminating most approval transactions for existing tokens and all approval transactions for new tokens.
Under earlier EIPs, users signing transactions with approved tokens had to fully trust the frontend to submit the correct transaction. This creates significant risk from phishing sites.
UTR function arguments act as a manifest when the user signs a transaction. With wallet support, users can inspect and review the expected token behavior. This makes phishing sites easier to detect and avoid.
Many application contracts are already compatible with UTR and can benefit in the following ways.
- Safely share user token approvals with other applications.
- Update peripheral contracts frequently.
- Reduce router contract development and security audit costs.
UTR also promotes security by outcome rather than security by process: it verifies outputs by directly querying changes in token balances, protecting user transactions even when interacting with incorrect or malicious contracts. For outcomes other than tokens, application helper contracts can provide additional result checks for UTR output verification.
Specification
The main interface of the UTR contract.
interface IUniversalTokenRouter {
function exec(
Output[] memory outputs,
Action[] memory actions
) payable;
}Output verification
struct Output {
address recipient;
uint eip; // token standard: 0 for ETH or EIP number
address token; // token contract address
uint id; // token id for ERC-721 and ERC-1155
uint amountOutMin;
}UTR defines an Output struct to verify changes in token balances.
This struct contains the following fields.
recipient- Recipient address.
eip- Token standard (
0for ETH; otherwise, the EIP number).
- Token standard (
token- Token contract address.
id- Token ID for ERC721 or ERC1155.
amountOutMin- Minimum output amount.
During execution of exec, the recipient's token balance is recorded for each output, and the initial and final balances are compared.
If the balance increase is less than amountOutMin, the transaction reverts with an INSUFFICIENT_OUTPUT_AMOUNT error.
The special ID ERC_721_BALANCE is reserved for ERC721 and can be used in an output action to verify the total number of NFTs owned by the recipient across all token IDs.
This ID is calculated as keccak256('UniversalTokenRouter.ERC_721_BALANCE').
ERC_721_BALANCE = keccak256('UniversalTokenRouter.ERC_721_BALANCE')Action
struct Action {
Input[] inputs;
address code; // contract code address
bytes data; // contract input data
}The Action struct defines token inputs and contract calls.
This struct contains the following fields.
inputs- Array of input tokens.
code- Address of the contract code.
data- Input data for the contract.
To be called by UTR, an action code contract must implement the ERC165 interface with ID 0x61206120.
This interface check prevents UTR from directly calling token allowance-spending functions, such as transferFrom.
New token contracts must therefore not implement this interface ID.
The abstract contract NotToken implements ERC165 and declares support for specific interface IDs through supportsInterface.
The function returns true for ID 0x61206120 or another supported interface ID.
See the following article for more on ERC165.
[ERC165] Checking Whether a Contract Supports a Specific Interface
For example, the Application contract inherits NotToken and can be used as a UTR-compatible contract.
abstract contract NotToken is ERC165 {
// IERC165-supportsInterface
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return
interfaceId == 0x61206120 ||
super.supportsInterface(interfaceId);
}
}
contract Application is NotToken {
// this contract can be used with the UTR
}Input
struct Input {
uint mode;
address recipient;
uint eip; // token standard: 0 for ETH or EIP number
address token; // token contract address
uint id; // token id for ERC-721 and ERC-1155
uint amountIn;
}The Input struct defines input tokens to be prepared or transferred before the action contract executes.
The Input struct contains the following fields.
mode- Processing mode.
recipient- Recipient address.
eip- Token standard (
0for ETH; otherwise, the EIP number).
- Token standard (
token- Token contract address.
id- Token ID for ERC721 or ERC1155.
amountIn- Input amount.
mode takes one of the following values.
PAYMENT = 0- Creates a pending payment for transferring tokens from
msg.senderto the recipient. - The payment can be executed by calling UTR's
payfrom anywhere within the same transaction.
- Creates a pending payment for transferring tokens from
TRANSFER = 1- Directly transfers tokens from
msg.senderto the recipient.
- Directly transfers tokens from
CALL_VALUE = 2- Records the amount of ETH to pass to the action.
Each input in the inputs argument is processed in order.
For simplicity, duplicate PAYMENT or CALL_VALUE inputs are valid, but only the last amountIn value is used.
Payment Input
The following explains the PAYMENT input mode in the Universal Token Router (UTR).
This mode is especially recommended for application contracts that use the transfer-in-callback pattern, such as flash loan contracts, Uniswap/v3-core, and Derivable.
For each input using PAYMENT mode, UTR's pay can be called from anywhere within the same transaction to transfer tokens from msg.sender to the recipient.
However, the amount transferred is limited to amountIn.
The UTR execution flow is as follows.
- UTR makes payments in
PAYMENTmode available for spending through UTR'spay. - The action code calls the application contract.
- The application contract calls UTR's
pay. - UTR clears all pending payments.
- The transaction ends.
UTR
|
| PAYMENT
| (payments pended for UTR.pay)
|
| Application Contracts
action.code.call ---------------------> |
|
UTR.pay <----------------------- (call) |
|
| <-------------------------- (return) |
|
| (clear all pending payments)
|
ENDToken allowances (allowance) and PAYMENT differ fundamentally.
- Allowance (
allowance)- Allows a particular address to transfer tokens to anyone at any time.
PAYMENT- Allows anyone to transfer tokens to a particular recipient, but only within the transaction.
Spend payment
interface IUniversalTokenRouter {
function pay(bytes memory payment, uint amount);
}The IUniversalTokenRouter interface includes a function called pay.
To call this function, encode the payment parameter as follows.
payment = abi.encode(
payer, // address
recipient, // address
eip, // uint256
token, // address
id // uint256
);The payment bytes may also be used by adapter UTR contracts to pass context or a payload for custom payment logic.
Discard payment
Sometimes it is useful to discard a payment instead of transferring tokens.
For example, an application contract might want to burn its own tokens held by payment.payer.
The following function can verify a payment for the caller's address and discard part of it.
interface IUniversalTokenRouter {
function discard(bytes memory payment, uint amount);
}Payment lifetime
Payments are recorded in UTR storage and are intended for use through the external input.action call within that transaction only.
All payment storage is cleared before UTR's exec finishes.
Native token transfer
UTR should have a receive() function for cases where users need to transfer ETH as part of execution logic.
The msg.value transferred to the router can be used by multiple inputs across different actions.
The caller is fully responsible for movements of ETH within the router, but exec should refund any ETH remaining before the function returns.
Usage examples
Uniswap V2 Router
Legacy function
The swapExactTokensForTokens function of UniswapV2Router01 is defined as follows.
UniswapV2Router01.swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
)Improved version
UniswapV2Helper01.swapExactTokensForTokens is a modified version of the function above with its token transfer logic removed.
The user signs the following transaction to execute a swap instead of calling the legacy function.
UniversalTokenRouter.exec([{
recipient: to,
eip: 20,
token: path[path.length-1],
id: 0,
amountOutMin,
}], [{
inputs: [{
mode: TRANSFER,
recipient: UniswapV2Library.pairFor(factory, path[0], path[1]),
eip: 20,
token: path[0],
id: 0,
amountIn: amountIn,
}],
code: UniswapV2Helper01.address,
data: encodeFunctionData("swapExactTokensForTokens", [
amountIn,
amountOutMin,
path,
to,
deadline,
]),
}])This transaction uses UTR to transfer tokens, while UniswapV2Helper01 executes the actual swap logic.
This allows token swaps to be carried out more efficiently and securely than the traditional approach.
Uniswap V3 Router
Legacy router contract
contract SwapRouter {
// this function is called by pool to pay the input tokens
function pay(
address token,
address payer,
address recipient,
uint256 value
) internal {
...
// pull payment
TransferHelper.safeTransferFrom(token, payer, recipient, value);
}
}The SwapRouter contract includes a pay function that the pool calls to pay for input tokens.
Inside this function, TransferHelper.safeTransferFrom handles the token payment.
Helper contract using UTR
contract SwapHelper {
// this function is called by pool to pay the input tokens
function pay(
address token,
address payer,
address recipient,
uint256 value
) internal {
...
// pull payment
bytes memory payment = abi.encode(payer, recipient, 20, token, 0);
UTR.pay(payment, value);
}
}The SwapHelper contract also has a pay function, but uses UTR's pay function to handle token payments.
This function encodes the token payment information with abi.encode and passes it to UTR.
Executing a transaction with UTR
The following is the transaction the user signs to execute exactInput in PAYMENT mode.
UniversalTokenRouter.exec([{
eip: 20,
token: tokenOut,
id: 0,
amountOutMin: 1,
recipient: to,
}], [{
inputs: [{
mode: PAYMENT,
eip: 20,
token: tokenIn,
id: 0,
amountIn: amountIn,
recipient: pool.address,
}],
code: SwapHelper.address,
data: encodeFunctionData("exactInput", [...]),
}])This transaction uses UTR to handle the token payment, while the SwapHelper contract executes the actual swap logic.
This allows token swaps to be carried out more efficiently and securely than the traditional approach.
Allowance Adapter
Allowance Adapter contract
contract AllowanceAdapter is ReentrancyGuard {
struct Input {
address token;
uint amountIn;
}
function approveAndCall(
Input[] memory inputs,
address spender,
bytes memory data,
address leftOverRecipient
) external payable nonReentrant {
for (uint i = 0; i < inputs.length; ++i) {
Input memory input = inputs[i];
IERC20(input.token).approve(spender, input.amountIn);
}
(bool success, bytes memory result) = spender.call{value: msg.value}(data);
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
for (uint i = 0; i < inputs.length; ++i) {
Input memory input = inputs[i];
// clear all allowance
IERC20(input.token).approve(spender, 0);
uint leftOver = IERC20(input.token).balanceOf(address(this));
if (leftOver > 0) {
TransferHelper.safeTransfer(input.token, leftOverRecipient, leftOver);
}
}
}
}The AllowanceAdapter contract is a reentrancy-aware ERC20 adapter for applications and router contracts that use allowances (allowance).
It includes an approveAndCall function with the following structure.
- Accepts multiple tokens and their amounts as input.
- Approves (
approve) the specified spender (spender) for each token. - Sends the data and ETH (
msg.value) to the spender contract. - Reverts with the error if the transaction fails.
- Finally, clears all allowances and transfers remaining tokens to the specified recipient (
leftOverRecipient).
Constructing a transaction with UTR
const { data: routerData } = await uniswapRouter.populateTransaction.swapExactTokensForTokens(
amountIn,
amountOutMin,
path,
to,
deadline,
)
const { data: adapterData } = await adapter.populateTransaction.approveAndCall(
[{
token: path[0],
amountIn,
}],
uniswapRouter.address,
routerData,
leftOverRecipient,
)
await utr.exec([], [{
inputs: [{
mode: TRANSFER,
recipient: adapter.address,
eip: 20,
token: path[0],
id: 0,
amountIn,
}],
code: adapter.address,
data: adapterData,
}])The following transaction is constructed to interact with Uniswap V2 Router using UTR.
- Retrieve transaction data for
swapExactTokensForTokensfromuniswapRouter. - Retrieve transaction data for
approveAndCallfromAllowanceAdapter. - Call UTR's
execfunction to execute the transaction using the data above.
This process enables secure and efficient transactions with Uniswap V2 Router through UTR without directly approving tokens for the application.
Additional explanation
This section describes the Universal Token Router's policy on support for Permit-style signatures.
The Universal Token Router aims to eliminate all interactive approval (approve) signatures for new tokens and most such signatures for older tokens.
For this reason, Permit-style signatures are not supported.
Permit-style signatures, used by tokens such as ERC20, allow users to approve tokens by signing a message.
However, UTR aims to make token transactions more efficient and secure by eliminating this interactive approval process.
For that reason, UTR does not support Permit-style signatures.
Compatibility
Tokens
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
/**
* @dev Implementation of the {ERC20} token standard that support a trusted ERC6120 contract as an unlimited spender.
*/
contract ERC20WithUTR is ERC20 {
address immutable UTR;
/**
* @dev Sets the values for {name}, {symbol} and ERC6120's {utr} address.
*
* All three of these values are immutable: they can only be set once during
* construction.
*
* @param utr can be zero to disable trusted ERC6120 support.
*/
constructor(string memory name, string memory symbol, address utr) ERC20(name, symbol) {
UTR = utr;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
if (spender == UTR && spender != address(0)) {
return type(uint256).max;
}
return super.allowance(owner, spender);
}
/**
* Does not check or update the allowance if `spender` is the UTR.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual override {
if (spender == UTR && spender != address(0)) {
return;
}
super._spendAllowance(owner, spender, amount);
}
}Existing token contracts (ERC20, ERC721, ERC1155)
These contracts require a one-time approval for UTR from each account. This grants UTR the authorization it needs to move tokens.
New token contracts
New token contracts can preconfigure UTR as a trusted spender (spender).
This eliminates the need for approval transactions during interactive use.
ERC20WithUTR is an implementation of the ERC20 token standard that supports UTR as an unlimited spender.
The contract has the following characteristics.
UTRis immutable (immutable) and is set once in the constructor.- The
allowancefunction returns an unlimited allowance whenspenderis UTR. - The
_spendAllowancefunction neither checks nor updates the allowance ifspenderis UTR.
This approach allows new token contracts to move tokens efficiently and securely using UTR. It simplifies the token approval process and improves the user experience.
Applications
Application contracts incompatible with UTR
The only application contracts incompatible with UTR are those that use msg.sender as the recipient in internal storage and lack a mechanism for transferring ownership.
This is because the recipient may differ from msg.sender when using UTR.
Application contracts compatible with UTR
All application contracts that accept a recipient (or to) argument are already compatible with UTR.
When adapters are needed for token transfers
Application contracts that transfer ERC20, ERC721, or ERC1155 tokens to msg.sender need an additional adapter to introduce a recipient argument to their functionality.
Example adapter contract
The WethAdapter contract is a sample adapter for WETH tokens.
Its deposit function calls IWETH(WETH).deposit() and then uses TransferHelper.safeTransfer to transfer the tokens to the specified recipient.
// sample adapter contract for WETH
contract WethAdapter {
function deposit(address recipient) external payable {
IWETH(WETH).deposit(){value: msg.value};
TransferHelper.safeTransfer(WETH, recipient, msg.value);
}
}Additional helper and adapter contracts
Additional helpers or adapter contracts may be necessary. These contracts hold neither tokens nor allowances, may be updated frequently, and have little or no effect on the security of the core application contract.
Implementation
/// @title The implemetation of the EIP-6120.
/// @author Derivable Labs
contract UniversalTokenRouter is ERC165, IUniversalTokenRouter {
uint256 constant PAYMENT = 0;
uint256 constant TRANSFER = 1;
uint256 constant CALL_VALUE = 2;
uint256 constant EIP_ETH = 0;
uint256 constant ERC_721_BALANCE = uint256(keccak256('UniversalTokenRouter.ERC_721_BALANCE'));
/// @dev transient pending payments
mapping(bytes32 => uint256) t_payments;
/// @dev accepting ETH for user execution (e.g. WETH.withdraw)
receive() external payable {}
/// The main entry point of the router
/// @param outputs token behaviour for output verification
/// @param actions router actions and inputs for execution
function exec(
Output[] memory outputs,
Action[] memory actions
) external payable virtual override {
unchecked {
// track the expected balances before any action is executed
for (uint256 i = 0; i < outputs.length; ++i) {
Output memory output = outputs[i];
uint256 balance = _balanceOf(output);
uint256 expected = output.amountOutMin + balance;
require(expected >= balance, 'UTR: OUTPUT_BALANCE_OVERFLOW');
output.amountOutMin = expected;
}
address sender = msg.sender;
for (uint256 i = 0; i < actions.length; ++i) {
Action memory action = actions[i];
uint256 value;
for (uint256 j = 0; j < action.inputs.length; ++j) {
Input memory input = action.inputs[j];
uint256 mode = input.mode;
if (mode == CALL_VALUE) {
// eip and id are ignored
value = input.amountIn;
} else {
if (mode == PAYMENT) {
bytes32 key = keccak256(abi.encode(sender, input.recipient, input.eip, input.token, input.id));
t_payments[key] = input.amountIn;
} else if (mode == TRANSFER) {
_transferToken(sender, input.recipient, input.eip, input.token, input.id, input.amountIn);
} else {
revert('UTR: INVALID_MODE');
}
}
}
if (action.code != address(0) || action.data.length > 0 || value > 0) {
require(
ERC165Checker.supportsInterface(action.code, 0x61206120),
"UTR: NOT_CALLABLE"
);
(bool success, bytes memory result) = action.code.call{value: value}(action.data);
if (!success) {
assembly {
revert(add(result,32),mload(result))
}
}
}
// clear all transient storages
for (uint256 j = 0; j < action.inputs.length; ++j) {
Input memory input = action.inputs[j];
if (input.mode == PAYMENT) {
// transient storages
bytes32 key = keccak256(abi.encodePacked(
sender, input.recipient, input.eip, input.token, input.id
));
delete t_payments[key];
}
}
}
// refund any left-over ETH
uint256 leftOver = address(this).balance;
if (leftOver > 0) {
TransferHelper.safeTransferETH(sender, leftOver);
}
// verify balance changes
for (uint256 i = 0; i < outputs.length; ++i) {
Output memory output = outputs[i];
uint256 balance = _balanceOf(output);
// NOTE: output.amountOutMin is reused as `expected`
require(balance >= output.amountOutMin, 'UTR: INSUFFICIENT_OUTPUT_AMOUNT');
}
} }
/// Spend the pending payment. Intended to be called from the input.action.
/// @param payment encoded payment data
/// @param amount token amount to pay with payment
function pay(bytes memory payment, uint256 amount) external virtual override {
discard(payment, amount);
(
address sender,
address recipient,
uint256 eip,
address token,
uint256 id
) = abi.decode(payment, (address, address, uint256, address, uint256));
_transferToken(sender, recipient, eip, token, id, amount);
}
/// Discard a part of a pending payment. Can be called from the input.action
/// to verify the payment without transfering any token.
/// @param payment encoded payment data
/// @param amount token amount to pay with payment
function discard(bytes memory payment, uint256 amount) public virtual override {
bytes32 key = keccak256(payment);
require(t_payments[key] >= amount, 'UTR: INSUFFICIENT_PAYMENT');
unchecked {
t_payments[key] -= amount;
}
}
// IERC165-supportsInterface
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return
interfaceId == type(IUniversalTokenRouter).interfaceId ||
super.supportsInterface(interfaceId);
}
function _transferToken(
address sender,
address recipient,
uint256 eip,
address token,
uint256 id,
uint256 amount
) internal virtual {
if (eip == 20) {
TransferHelper.safeTransferFrom(token, sender, recipient, amount);
} else if (eip == 1155) {
IERC1155(token).safeTransferFrom(sender, recipient, id, amount, "");
} else if (eip == 721) {
IERC721(token).safeTransferFrom(sender, recipient, id);
} else {
revert("UTR: INVALID_EIP");
}
}
function _balanceOf(
Output memory output
) internal view virtual returns (uint256 balance) {
uint256 eip = output.eip;
if (eip == 20) {
return IERC20(output.token).balanceOf(output.recipient);
}
if (eip == 1155) {
return IERC1155(output.token).balanceOf(output.recipient, output.id);
}
if (eip == 721) {
if (output.id == ERC_721_BALANCE) {
return IERC721(output.token).balanceOf(output.recipient);
}
try IERC721(output.token).ownerOf(output.id) returns (address currentOwner) {
return currentOwner == output.recipient ? 1 : 0;
} catch {
return 0;
}
}
if (eip == EIP_ETH) {
return output.recipient.balance;
}
revert("UTR: INVALID_EIP");
}
}Security
ERC-165 Tokens
Token contracts must never support the ERC165 interface with ID 0x61206120.
This ID is reserved for non-token contracts called through UTR.
Any token that has been approved for UTR and implements interface ID 0x61206120 can be used by anyone without restriction.
In other words, if a token contract supports this particular interface ID, there is a risk that its tokens can be moved without restriction through UTR. This can cause serious security problems, so token contracts should not support the interface ID. Avoid supporting this ID to ensure compatibility with UTR.
Reentrancy
Transferring tokens to the UTR contract
Tokens transferred to the UTR contract are permanently lost.
Once tokens have been transferred to UTR, there is no way to transfer them out.
Applications that need to hold tokens temporarily should use their own helper contract with a reentrancy guard (reentrancy guard) to ensure safe execution.
Transferring ETH to the UTR contract
ETH must be transferred to the UTR contract before it is used in an action call (using CALL_VALUE mode).
This ETH may be drained from UTR through reentrant calls in the action code or malicious token functions.
However, this cannot happen if the user transfers no more ETH than the transaction will use.
Example
// transfer 100 in, but spend only 60,
// so at most 40 wei can be exploited in this transaction
UniversalTokenRouter.exec([
...
], [{
inputs: [{
mode: CALL_VALUE,
eip: 20,
token: 0,
id: 0,
amountIn: 60, // spend 60
recipient: AddressZero,
}],
...
}], {
value: 100, // transfer 100 in
})In this example, 100 wei is transferred to the UTR contract, of which only 60 wei is used by the action call.
This demonstrates that up to 40 wei may be drained.
Avoid this risk by transferring no more ETH than the transaction needs.
Discarding payments
Verifying the result of pay
The result of the UTR contract's pay function can be verified by querying the balance after the call.
This allows the function to be called safely even when the UTR contract is not trusted.
Precautions when using discard
Since there is no way to verify the execution of discard, it should be used only with a trusted UTR contract.
The discard function discards a particular payment, but external observers cannot verify whether the function executed correctly.
It must therefore be used carefully and only in trusted circumstances.
References
Derivable (@derivable-labs), Zergity (@Zergity), Ngo Quang Anh (@anhnq82), BerlinP (@BerlinP), Khanh Pham (@blackskin18), Hal Blackburn (@h4l), "ERC-6120: Universal Token Router [DRAFT]," Ethereum Improvement Proposals, no. 6120, December 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6120.
Conclusion
This article covered ERC6120, which proposes a Universal Token Router (UTR) that allows users to transfer tokens and then make a call rather than approve tokens before making a call. I hope this explanation was useful.
If you have questions, feel free to contact me via a direct message on Twitter.
I also share information on other platforms. Feel free to explore them.


