Deposit and withdraw funds to and from keystore accounts
DEPOSIT
transaction on the keystore. DEPOSIT
transaction are L1-initiated transactions. A transaction must be submitted to the rollup bridge on L1 using the initiateL1Transaction
function. The bridge performs validation to ensure sufficient funds are deposited.
txType
is the transaction type. For DEPOSIT
transactions, it is KeystoreTxType.DEPOSIT
.data
is the transaction data, serialized differently depending on the transaction type. For DEPOSIT
transactions, it represents the keystore address.WITHDRAW
transaction on the keystore. A WITHDRAW
transaction is serialized in the following format:
bool isL1Initiated
: Whether the transaction is L1-initiated.bytes l1InitiatedNonce
: Represents the uint256
L1-initiated nonce for the transaction if the transaction is L1-initiated and the empty bytestring bytes(0x)
otherwise.uint256 nonce
: The nonce for the transaction.bytes feePerGas
: Represents the uint256
fee per gas for the transaction if the transaction is not L1-initiated and the empty bytestring bytes(0x)
otherwise.address to
: The L1 Ethereum address to withdraw to.uint256 amt
: The amount of ETH in wei to withdraw.KeystoreAccount userAcct
: The user account paying for the transaction.bytes userProof
: The user’s ZK authentication proof for the transaction.keystore_sendRawTransaction
RPC endpoint.
Once a withdrawal transaction is finalized on L1, it is possible to withdraw funds from the keystore bridge contract to the requested L1 Ethereum address, which is determined by the to
field of the withdrawal transaction. This process is called finalizing a withdrawal.
To finalize a withdrawal, call the finalizeWithdrawal
method on the keystore bridge contract, which is defined as:
tx
. Assume tx
was included in block k
, and k
was committed in batch c
. Also assume c
is finalized on L1.
To finalize tx
(to withdraw funds from bridge contract) user needs to call finalizeWithdrawal
method on the contract with following arguments:
batchIndex
such batchIndex >= c
, such that there is a batch h
where h.batchIndex = batchIndex
.preimage
must be a OutputRootPreImage
where:
preimage.stateRoot = h.lastBlock.stateRoot
preimage.withdrawalsRoot = h.lastBlock.withdrawalsRoot
preimage.lastValidBlockhash = h.lastBlock.blockhash
keystoreAddress = t.userAcct.keystoreAddress
withdrawAmount = t.amt
nonce = t.nonce
to = t.to
proof
to be a Merkle Proof showing (withdrawalHash, withdrawal)
pair exists in the withdrawals state at block h.lastBlock
, where:
withdrawalHash = keccak256(abi.encodePacked(t.userAcct.keystoreAddress, t.nonce))
withdrawal = Withdrawal(t.to, t.amt)
isLeft
is a uint256
that packs all the isLeft
booleans in the Merkle proof returned by the node JSONRPC server.buildFinalizeWithdrawalArgs
that prepares the required arguments for finalizeWithdrawal
.