From 702ad72279df78cedf777db1b09487bb1885695f Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Tue, 21 Dec 2021 16:59:30 +0400 Subject: [PATCH] Fix batch deposit script for different BLS withdrawal credentials (#19) --- scripts/.env.example | 11 +++++++---- scripts/deposit.js | 27 ++++++++++++++++++--------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/scripts/.env.example b/scripts/.env.example index ea8755c..604812c 100644 --- a/scripts/.env.example +++ b/scripts/.env.example @@ -4,13 +4,16 @@ RPC_URL=https://dai.poa.network GAS_PRICE=1000000000 # number of deposits in one transaction, should be in range [1, 128] +# NOTE: put 1 here if withdrawal credentials were generated with the BLS12-381 keys BATCH_SIZE=128 # total number of deposits to read from file N=256 # index of the first deposit to read from file OFFSET=0 -# address of the wrapped SBC token -TOKEN_ADDRESS=0x0000000000000000000000000000000000000000 -# address of the SBC deposit contract -DEPOSIT_CONTRACT_ADDRESS=0x0000000000000000000000000000000000000000 +# address of the wrapped GBC token +TOKEN_ADDRESS=0x722fc4DAABFEaff81b97894fC623f91814a1BF68 +# address of the GBC deposit contract +DEPOSIT_CONTRACT_ADDRESS=0x0B98057eA310F4d31F2a452B414647007d1645d9 +# block where the deposit contract was deployed at +START_BLOCK_NUMBER=19469077 \ No newline at end of file diff --git a/scripts/deposit.js b/scripts/deposit.js index 33a0032..db916e0 100644 --- a/scripts/deposit.js +++ b/scripts/deposit.js @@ -29,10 +29,15 @@ async function main() { const depositContract = new web3.eth.Contract(depositABI, DEPOSIT_CONTRACT_ADDRESS) const deposits = depositData.slice(offset, offset + n) - const wc = deposits[0].withdrawal_credentials - if (!deposits.every(d => d.withdrawal_credentials === wc)) { - console.log('Withdrawal credentials do not match') - return + if (batchSize > 1) { + for (let i = 0; i < deposits.length; i += batchSize) { + const wc = deposits[i].withdrawal_credentials + const endIndex = Math.min(i + batchSize, deposits.length) + if (!deposits.slice(i, endIndex).every(d => d.withdrawal_credentials === wc)) { + console.log(`Withdrawal credentials for batch [${i}..${endIndex - 1}] do not match`) + return + } + } } if (!deposits.every(d => d.amount === 32000000000)) { @@ -40,11 +45,12 @@ async function main() { return } - const depositAmountBN = web3.utils.toBN(32).mul(web3.utils.toBN('1000000000000000000')) + const depositAmountBN = web3.utils.toBN(32).mul(web3.utils.toBN('1000000000000000000')) + const totalDepositAmountBN = depositAmountBN.muln(deposits.length) const tokenBalance = await token.methods.balanceOf(address).call() - if (web3.utils.toBN(tokenBalance).lt(depositAmountBN)) { - console.log(`Token balance is not enough to cover all deposits, have ${tokenBalance}, required ${depositAmountBN.toString()}`) + if (web3.utils.toBN(tokenBalance).lt(totalDepositAmountBN)) { + console.log(`Token balance is not enough to cover all deposits, have ${tokenBalance}, required ${totalDepositAmountBN.toString()}`) return } @@ -69,9 +75,12 @@ async function main() { let balance = await web3.eth.getBalance(address).then(web3.utils.toBN) let nonce = await web3.eth.getTransactionCount(address) let count = 0 - let data = '0x' + wc + let data = '0x' for (let i = 0; i < deposits.length; i++) { const deposit = deposits[i] + if (i % batchSize === 0) { + data += deposit.withdrawal_credentials + } data += deposit.pubkey data += deposit.signature data += deposit.deposit_data_root @@ -101,7 +110,7 @@ async function main() { }) balance = balance.sub(web3.utils.toBN(GAS_PRICE).muln(receipt.gasUsed)) console.log(`\t${count} next deposits: ${receipt.transactionHash}`) - data = '0x' + wc + data = '0x' count = 0 } }