ERC-7638 Smart Account Batch Call Encoding (Batch Calls Encoding in SCA)

Draft · Accounts & wallets · created 2024-02-26

An encoding scheme that lets a smart contract account (SCA) bundle multiple calls into a single byte string and send them at once. It compresses onchain data to save gas and can also be used for atomic execution.

Why it is needed

When a user interacts with a contract, multiple operations often follow one another, such as approve followed by transferFrom. With an ordinary externally owned account (EOA) wallet, the user must confirm each operation separately, and if approve succeeds but transferFrom fails, the approval remains in place and creates a security risk. To be safe, atomicity is needed so that if one operation fails, the entire bundle of operations fails. In addition, the struct array format commonly used to bundle multiple calls encodes each item's type information along with it, which makes the data larger and increases gas costs. This standard defines a simple encoding that concatenates only three fixed values per call, compressing the data and saving gas while allowing use in both atomic and non-atomic execution.

In depth

Call Encoding Structure

A single Call is constructed by concatenating to, value, data length, and data in order. to is the address of the contract being called, 20 bytes corresponding to Solidity's address type. value is the amount of ETH (in wei) sent to the contract, 32 bytes corresponding to the uint type. data length is the byte length of data, also 32 bytes of uint type. data is the encoded functionData sent to the contract, whose length is determined by data length. Concatenating multiple Calls built this way produces the Batch Calls byte string.

Why a byte string is used instead of a struct array

The conventional approach is to group the three values to, value, and data into a struct and pass them as a struct array. But using a struct also encodes each value's type information, which increases the size. Since the types of these three values are fixed, this extra encoding can be omitted. Also, reading bytes calldata as slices in Solidity is gas efficient. Taking these points into account, Batch Calls Encoding compresses onchain data and saves gas.

Ensuring atomicity

In sequential operations like approve followed by transferFrom, if only approve succeeds and transferFrom fails, it becomes a security risk. The safe approach is to make the entire bundle of operations fail if one operation fails. An EOA wallet requires user confirmation for each operation, but an SCA wallet can achieve atomicity by completing all operations within a single call with one confirmation. This encoding can be used for both atomic and non-atomic execution.

Relationship Between Gas Sponsorship and EIP-4337

If a user signs a bundle that includes a call sending 10 USDT to the bundler as a fee, the bundler submits it, pays the ETH gas, and receives the fee, which constitutes gas sponsorship. EIP-4337 also implements gas sponsorship, but the two approaches are not mutually exclusive and can be implemented together within a single SCA. Based on measurements, the source states that BCE is simpler and more gas efficient than other methods.

Behavior of the reference implementation

This proposal defines only the encoding and leaves the specific implementation and naming to each project. In the example SmartWallet contract, the atomSignCall function can only be called by the bundler and rejects execution once the deadline has passed. The message hash is constructed by appending block.chainid, the wallet address, and a valid value to the call data, and the usedMsgHashes mapping prevents the same hash from being reused. After verifying that the signature belongs to the owner, the byte string is sliced from the front in chunks of 20, 32, and 32 bytes to read to, value, and the length, and each call is executed; if any one fails, the entire batch is reverted. If the user regrets a signature, they can invalidate the existing signature by changing the valid value through makeAtomSignInvalid.

Backward compatibility

This ERC does not change the consensus layer, so it has no backward compatibility issues for Ethereum as a whole. It also does not change other ERC standards, so it has no backward compatibility issues for Ethereum applications either.

Proposal status

This proposal is still in Draft status. Since the content may change going forward, it is advisable to check the latest source before implementing it.

Original ERC · ← ERCs