Back to home
ZKredit Demo
Explore how ZKredit enables cross-chain operations with various verification methods.
ZKredit Core Contract
The foundation of ZKredit is a smart contract that handles deposits, withdrawals, and validates operations through a registry of validators.
Deployed at: 0x4d967ae3e0ccb462582b46891d92f0d7efe5e522
Contract Architecture
ZKreditCore implements a robust system for asset handling with validator-based approval flow, ERC-4337 compatibility, and upgradability.
Key Features
- Deposits for ETH and ERC20 tokens
- Validator-based approval system
- ERC-4337 account abstraction integration
- UUPS upgradable contract architecture
Contract Flow
- User deposits assets (ETH or ERC20 tokens)
- Assets are locked in the contract
- Withdrawal requires validation (user or validator)
- Validator evaluates withdrawal requests
- Contract completes transfer to recipient
Contract Code
// SPDX-License-Identifier: MIT pragma solidity ^0.8.29; contract ZKreditCore is IZKreditCore, Initializable, UUPSUpgradeable, OwnableUpgradeable { // Balances mapping (depositor => token => amount) mapping(address => mapping(address => uint256)) private _balances; // Deposit ETH function depositNative( address depositor ) external payable override whenNotPaused { require( msg.value > 0, "ZKreditCore: deposit amount must be greater than zero" ); // Update balance _balances[depositor][address(0)] += msg.value; emit Deposited(msg.sender, depositor, address(0), msg.value); } // Withdraw ETH function withdrawNative( address depositor, uint256 amount, address payable recipient, bytes calldata validationData ) external override nonReentrant whenNotPaused { require( amount > 0, "ZKreditCore: withdraw amount must be greater than zero" ); require( _balances[depositor][address(0)] >= amount, "ZKreditCore: insufficient balance" ); // Validate withdrawal require( _validateWithdrawal( msg.sender, depositor, address(0), amount, validationData ), "ZKreditCore: withdrawal validation failed" ); // Update balance _balances[depositor][address(0)] -= amount; // Transfer ETH to recipient (bool success, ) = recipient.call{value: amount}(""); require(success, "ZKreditCore: native transfer failed"); emit Withdrawn(msg.sender, depositor, address(0), recipient, amount); }