From fb7455963dc63cefc1af72fb2baf4838abe998db Mon Sep 17 00:00:00 2001 From: 0xvv Date: Fri, 29 Sep 2023 01:58:54 +0200 Subject: [PATCH] working implementation --- src/BatchDepositCompact.huff | 12 ++++++------ test/BatchDepositHuff.t.sol | 11 ++++++----- test/mock/DepositContractNoop.sol | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 test/mock/DepositContractNoop.sol diff --git a/src/BatchDepositCompact.huff b/src/BatchDepositCompact.huff index f03c8bf..81eaa44 100644 --- a/src/BatchDepositCompact.huff +++ b/src/BatchDepositCompact.huff @@ -30,12 +30,12 @@ #define macro MAIN() = takes(0) returns(0) { // checking pubkeys length is the expected length and count > 0 - 0x24 calldataload // [deposit_length] - [DEPOSIT_LEN] // [DEPOSIT_LEN, deposit_length] - dup1 dup3 // [deposit_length, DEPOSIT_LEN, DEPOSIT_LEN, deposit_length] - mod // [deposit_length % DEPOSIT_LEN, DEPOSIT_LEN, deposit_length] - fail jumpi // revert if not equal to 0 [DEPOSIT_LEN, deposit_length] - swap1 // [deposit_length, DEPOSIT_LEN] + 0x24 calldataload // [deposits_length] + [DEPOSIT_LEN] // [DEPOSIT_LEN, deposits_length] + dup1 dup3 // [deposits_length, DEPOSIT_LEN, DEPOSIT_LEN, deposits_length] + mod // [deposits_length % DEPOSIT_LEN, DEPOSIT_LEN, deposits_length] + fail jumpi // revert if not equal to 0 [DEPOSIT_LEN, deposits_length] + swap1 // [deposits_length, DEPOSIT_LEN] div // [deposit_count] dup1 // [deposit_count, deposit_count] iszero fail jumpi // revert if zero [deposit_count] diff --git a/test/BatchDepositHuff.t.sol b/test/BatchDepositHuff.t.sol index 7312599..8e224cc 100644 --- a/test/BatchDepositHuff.t.sol +++ b/test/BatchDepositHuff.t.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.20; import {HuffDeployer} from "foundry-huff/HuffDeployer.sol"; import "forge-std/Test.sol"; import "./mock//DepositContractTestable.sol"; +import "./mock/DepositContractNoop.sol"; import "./utils/BytesGenerator.sol"; import "../src/lib/LibBytes.sol"; @@ -16,7 +17,7 @@ contract BatchDepositHuffTest is Test, BytesGenerator { address constant officialDepositContract = 0x00000000219ab540356cBB839Cbe05303d7705Fa; DepositContractTestable huffDepMock = DepositContractTestable(officialDepositContract); - DepositContractTestable implem = new DepositContractTestable(); + DepositContractNoop implem = new DepositContractNoop(); function deployHuff() public { vm.etch(officialDepositContract, address(implem).code); @@ -61,13 +62,13 @@ contract BatchDepositHuffTest is Test, BytesGenerator { } bytes memory args = new bytes(0); for (uint256 i = 0; i < COUNT; i++) { - args = bytes.concat(args, pubkeys[i]); - args = bytes.concat(args, withdrawal_credentials[i]); - args = bytes.concat(args, signatures[i]); + args = bytes.concat(args, pubkeysList[i]); + args = bytes.concat(args, withdrawalCredentialsList[i]); + args = bytes.concat(args, signaturesList[i]); args = bytes.concat(args, deposit_data_roots[i]); } - vm.deal(address(this), 32 ether * COUNT); + console2.log(args.length); vm.deal(address(this), 32 ether * COUNT); // HUFF huffbdo.deposit{value: 32 ether * COUNT}(args); diff --git a/test/mock/DepositContractNoop.sol b/test/mock/DepositContractNoop.sol new file mode 100644 index 0000000..d2e4921 --- /dev/null +++ b/test/mock/DepositContractNoop.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: BUSL-1.1 +// SPDX-FileCopyrightText: 2023 Kiln +// +// ██╗ ██╗██╗██╗ ███╗ ██╗ +// ██║ ██╔╝██║██║ ████╗ ██║ +// █████╔╝ ██║██║ ██╔██╗ ██║ +// ██╔═██╗ ██║██║ ██║╚██╗██║ +// ██║ ██╗██║███████╗██║ ╚████║ +// ╚═╝ ╚═╝╚═╝╚══════╝╚═╝ ╚═══╝ +// +pragma solidity >=0.8.17; + +import "../../src/interface/IDeposit.sol"; + +contract DepositContractNoop is IDeposit { + uint256 i; + + function deposit_count() external view returns (uint256) { + return i; + } + + function deposit( + bytes calldata pubkey, + bytes calldata withdrawal_credentials, + bytes calldata signature, + bytes32 deposit_data_root + ) external payable override {} +}