From fe2227ef535b411faffacc19a2fab16be8fa4e09 Mon Sep 17 00:00:00 2001 From: Gonza Montiel Date: Wed, 21 Jan 2026 16:25:57 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=94=A7=20account=20for=20storage?= =?UTF-8?q?=20reads=20on=20withdrawal=20(#407)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary ERC20 balances precompile `withdraw()` was failing to account for gas costs associated with storage reads. In fact the function was calling `usable_balance` without accounting for `record_db_read`. ## Changes - Added `116 bytes` of storage read computed like this: `Blake2128(16) + AccountId(20) + AccountInfo ((4 * 4) + AccountData(16 * 4))`, to cover for `usable_balance`, following the same that `balance_of` does. --- operator/precompiles/erc20-balances/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/operator/precompiles/erc20-balances/src/lib.rs b/operator/precompiles/erc20-balances/src/lib.rs index 3800244e..af0a0032 100644 --- a/operator/precompiles/erc20-balances/src/lib.rs +++ b/operator/precompiles/erc20-balances/src/lib.rs @@ -446,6 +446,9 @@ where let account_amount: U256 = { let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(handle.context().caller); + // frame_system::Account: + // Blake2128(16) + AccountId(20) + AccountInfo ((4 * 4) + AccountData(16 * 4)) + handle.record_db_read::(116)?; pallet_balances::Pallet::::usable_balance(&owner).into() };