Skip to content

Commit

Permalink
working implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xvv committed Sep 28, 2023
1 parent 0062908 commit fb74559
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/BatchDepositCompact.huff
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 6 additions & 5 deletions test/BatchDepositHuff.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions test/mock/DepositContractNoop.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: BUSL-1.1
// SPDX-FileCopyrightText: 2023 Kiln <contact@kiln.fi>
//
// ██╗ ██╗██╗██╗ ███╗ ██╗
// ██║ ██╔╝██║██║ ████╗ ██║
// █████╔╝ ██║██║ ██╔██╗ ██║
// ██╔═██╗ ██║██║ ██║╚██╗██║
// ██║ ██╗██║███████╗██║ ╚████║
// ╚═╝ ╚═╝╚═╝╚══════╝╚═╝ ╚═══╝
//
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 {}
}

0 comments on commit fb74559

Please sign in to comment.