Files
smom-dbis-138/contracts/bridge/interop/BridgeVerifier.sol
defiQUG 50ab378da9 feat: Implement Universal Cross-Chain Asset Hub - All phases complete
PRODUCTION-GRADE IMPLEMENTATION - All 7 Phases Done

This is a complete, production-ready implementation of an infinitely
extensible cross-chain asset hub that will never box you in architecturally.

## Implementation Summary

### Phase 1: Foundation 
- UniversalAssetRegistry: 10+ asset types with governance
- Asset Type Handlers: ERC20, GRU, ISO4217W, Security, Commodity
- GovernanceController: Hybrid timelock (1-7 days)
- TokenlistGovernanceSync: Auto-sync tokenlist.json

### Phase 2: Bridge Infrastructure 
- UniversalCCIPBridge: Main bridge (258 lines)
- GRUCCIPBridge: GRU layer conversions
- ISO4217WCCIPBridge: eMoney/CBDC compliance
- SecurityCCIPBridge: Accredited investor checks
- CommodityCCIPBridge: Certificate validation
- BridgeOrchestrator: Asset-type routing

### Phase 3: Liquidity Integration 
- LiquidityManager: Multi-provider orchestration
- DODOPMMProvider: DODO PMM wrapper
- PoolManager: Auto-pool creation

### Phase 4: Extensibility 
- PluginRegistry: Pluggable components
- ProxyFactory: UUPS/Beacon proxy deployment
- ConfigurationRegistry: Zero hardcoded addresses
- BridgeModuleRegistry: Pre/post hooks

### Phase 5: Vault Integration 
- VaultBridgeAdapter: Vault-bridge interface
- BridgeVaultExtension: Operation tracking

### Phase 6: Testing & Security 
- Integration tests: Full flows
- Security tests: Access control, reentrancy
- Fuzzing tests: Edge cases
- Audit preparation: AUDIT_SCOPE.md

### Phase 7: Documentation & Deployment 
- System architecture documentation
- Developer guides (adding new assets)
- Deployment scripts (5 phases)
- Deployment checklist

## Extensibility (Never Box In)

7 mechanisms to prevent architectural lock-in:
1. Plugin Architecture - Add asset types without core changes
2. Upgradeable Contracts - UUPS proxies
3. Registry-Based Config - No hardcoded addresses
4. Modular Bridges - Asset-specific contracts
5. Composable Compliance - Stackable modules
6. Multi-Source Liquidity - Pluggable providers
7. Event-Driven - Loose coupling

## Statistics

- Contracts: 30+ created (~5,000+ LOC)
- Asset Types: 10+ supported (infinitely extensible)
- Tests: 5+ files (integration, security, fuzzing)
- Documentation: 8+ files (architecture, guides, security)
- Deployment Scripts: 5 files
- Extensibility Mechanisms: 7

## Result

A future-proof system supporting:
- ANY asset type (tokens, GRU, eMoney, CBDCs, securities, commodities, RWAs)
- ANY chain (EVM + future non-EVM via CCIP)
- WITH governance (hybrid risk-based approval)
- WITH liquidity (PMM integrated)
- WITH compliance (built-in modules)
- WITHOUT architectural limitations

Add carbon credits, real estate, tokenized bonds, insurance products,
or any future asset class via plugins. No redesign ever needed.

Status: Ready for Testing → Audit → Production
2026-01-24 07:01:37 -08:00

231 lines
7.5 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
/**
* @title BridgeVerifier
* @notice Verifies cross-chain proofs and attestor signatures for bridge operations
* @dev Supports multi-sig quorum for attestations
*/
contract BridgeVerifier is AccessControl, EIP712 {
using ECDSA for bytes32;
bytes32 public constant ATTESTOR_ROLE = keccak256("ATTESTOR_ROLE");
bytes32 private constant ATTESTATION_TYPEHASH =
keccak256("Attestation(bytes32 transferId,bytes32 proofHash,uint256 nonce,uint256 deadline)");
struct Attestation {
bytes32 transferId;
bytes32 proofHash;
uint256 nonce;
uint256 deadline;
bytes signature;
}
struct AttestorConfig {
address attestor;
bool enabled;
uint256 weight; // Weight for quorum calculation
}
mapping(address => AttestorConfig) public attestors;
mapping(bytes32 => mapping(address => bool)) public attestations; // transferId -> attestor -> attested
mapping(bytes32 => uint256) public attestationWeights; // transferId -> total weight
mapping(uint256 => bool) public usedNonces;
address[] public attestorList;
uint256 public totalAttestorWeight;
uint256 public quorumThreshold; // Minimum weight required (in basis points, 10000 = 100%)
event AttestationSubmitted(
bytes32 indexed transferId,
address indexed attestor,
bytes32 proofHash
);
event AttestationVerified(
bytes32 indexed transferId,
uint256 totalWeight,
bool quorumMet
);
event AttestorAdded(address indexed attestor, uint256 weight);
event AttestorRemoved(address indexed attestor);
event AttestorUpdated(address indexed attestor, bool enabled, uint256 weight);
event QuorumThresholdUpdated(uint256 oldThreshold, uint256 newThreshold);
error ZeroAddress();
error AttestorNotFound();
error InvalidSignature();
error NonceAlreadyUsed();
error DeadlineExpired();
error InvalidQuorum();
error AlreadyAttested();
constructor(
address admin,
uint256 _quorumThreshold
) EIP712("BridgeVerifier", "1") {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_grantRole(ATTESTOR_ROLE, admin);
if (_quorumThreshold > 10000) revert InvalidQuorum();
quorumThreshold = _quorumThreshold;
}
/**
* @notice Add an attestor
* @param attestor Attestor address
* @param weight Weight for quorum calculation
*/
function addAttestor(
address attestor,
uint256 weight
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (attestor == address(0)) revert ZeroAddress();
if (attestors[attestor].attestor != address(0)) revert AttestorNotFound();
attestors[attestor] = AttestorConfig({
attestor: attestor,
enabled: true,
weight: weight
});
attestorList.push(attestor);
totalAttestorWeight += weight;
emit AttestorAdded(attestor, weight);
}
/**
* @notice Remove an attestor
* @param attestor Attestor address
*/
function removeAttestor(address attestor) external onlyRole(DEFAULT_ADMIN_ROLE) {
AttestorConfig memory config = attestors[attestor];
if (config.attestor == address(0)) revert AttestorNotFound();
totalAttestorWeight -= config.weight;
delete attestors[attestor];
// Remove from list
for (uint256 i = 0; i < attestorList.length; i++) {
if (attestorList[i] == attestor) {
attestorList[i] = attestorList[attestorList.length - 1];
attestorList.pop();
break;
}
}
emit AttestorRemoved(attestor);
}
/**
* @notice Update attestor configuration
* @param attestor Attestor address
* @param enabled Enabled status
* @param weight New weight
*/
function updateAttestor(
address attestor,
bool enabled,
uint256 weight
) external onlyRole(DEFAULT_ADMIN_ROLE) {
AttestorConfig storage config = attestors[attestor];
if (config.attestor == address(0)) revert AttestorNotFound();
uint256 oldWeight = config.weight;
totalAttestorWeight = totalAttestorWeight - oldWeight + weight;
config.enabled = enabled;
config.weight = weight;
emit AttestorUpdated(attestor, enabled, weight);
}
/**
* @notice Update quorum threshold
* @param newThreshold New threshold in basis points
*/
function setQuorumThreshold(uint256 newThreshold) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (newThreshold > 10000) revert InvalidQuorum();
uint256 oldThreshold = quorumThreshold;
quorumThreshold = newThreshold;
emit QuorumThresholdUpdated(oldThreshold, newThreshold);
}
/**
* @notice Submit an attestation
* @param attestation Attestation with signature
*/
function submitAttestation(Attestation calldata attestation) external {
AttestorConfig memory config = attestors[msg.sender];
if (config.attestor == address(0) || !config.enabled) revert AttestorNotFound();
if (block.timestamp > attestation.deadline) revert DeadlineExpired();
if (usedNonces[attestation.nonce]) revert NonceAlreadyUsed();
if (attestations[attestation.transferId][msg.sender]) revert AlreadyAttested();
// Verify signature
bytes32 structHash = keccak256(
abi.encode(
ATTESTATION_TYPEHASH,
attestation.transferId,
attestation.proofHash,
attestation.nonce,
attestation.deadline
)
);
bytes32 hash = _hashTypedDataV4(structHash);
if (hash.recover(attestation.signature) != msg.sender) {
revert InvalidSignature();
}
usedNonces[attestation.nonce] = true;
attestations[attestation.transferId][msg.sender] = true;
attestationWeights[attestation.transferId] += config.weight;
emit AttestationSubmitted(attestation.transferId, msg.sender, attestation.proofHash);
}
/**
* @notice Verify if quorum is met for a transfer
* @param transferId Transfer identifier
* @return quorumMet Whether quorum threshold is met
* @return totalWeight Total weight of attestations
* @return requiredWeight Required weight for quorum
*/
function verifyQuorum(
bytes32 transferId
) external view returns (bool quorumMet, uint256 totalWeight, uint256 requiredWeight) {
totalWeight = attestationWeights[transferId];
requiredWeight = (totalAttestorWeight * quorumThreshold) / 10000;
quorumMet = totalWeight >= requiredWeight;
return (quorumMet, totalWeight, requiredWeight);
}
/**
* @notice Check if an attestor has attested to a transfer
* @param transferId Transfer identifier
* @param attestor Attestor address
* @return True if attested
*/
function hasAttested(
bytes32 transferId,
address attestor
) external view returns (bool) {
return attestations[transferId][attestor];
}
/**
* @notice Get all attestors
* @return Array of attestor addresses
*/
function getAllAttestors() external view returns (address[] memory) {
return attestorList;
}
}