code4rena-2023-01-biconomy-l12
[L-12] The minimum transaction value of 21,000 gas may change in the future
Summary
미래에 최소 gas 21000이 변경되면 가스 환급 계산이 틀어지므로 상수가 아닌 변수를 이용하자 제안했다.
Keyword
gas
Vulnerability
gas 환급을 위해 사용 gas를 계산할 때, base gas를 21000로 잡는다. 21000 gas는 트랜잭션의 서명에서 발신자 주소를 복구하는 타원 곡선 작업 비용과 트랜잭션을 저장하는 디스크 공간을 충당하기 위한 비용으로 들어간다고 이더리움 백서에서 명시되어 있다. geth 코드 를 참고하라.
contracts/smart-contract-wallet/SmartAccount.sol:
192: function execTransaction(
193: Transaction memory _tx,
194: uint256 batchId,
195: FeeRefund memory refundInfo,
196: bytes memory signatures
197: ) public payable virtual override returns (bool success) {
198: // initial gas = 21k + non_zero_bytes * 16 + zero_bytes * 4
199: // ~= 21k + calldata.length * [1/3 * 16 + 2/3 * 4]
200: uint256 startGas = gasleft() + 21000 + msg.data.length * 8;
201: //console.log("init %s", 21000 + msg.data.length * 8);
202: bytes32 txHash;
203: // Use scope here to limit variable lifetime and prevent `stack too deep` errors
204: {
205: bytes memory txHashData =
206: encodeTransactionData(
207: // Transaction info
208: _tx,
209: // Payment info
210: refundInfo,
211: // Signature info
212: nonces[batchId]
213: );
214: // Increase nonce and execute transaction.
215: // Default space aka batchId is 0
216: nonces[batchId]++;
217: txHash = keccak256(txHashData);
218: checkSignatures(txHash, txHashData, signatures);
219: }하지만 이는 미래에 변경될 여지가 있다. 따라서 이 값을 업데이트 할 수 있도록 변수로 두는 게 좋다고 제안했다.
Impact
미래에 최소 gas가 변경되면 가스 환급 계산이 틀어진다.
Mitigation
21000 상수를 사용하지 말고 변수로 설정할 수 있게 한다.
tags: bughunting, smart contract, biconomy, account abstraction, erc4337, wallet, severity low