Skip to content

Conversation

@chillhacker
Copy link
Contributor

@chillhacker chillhacker commented Sep 10, 2025

Overview

This PR implements significant optimizations and improvements for genesis smart contracts, focusing on cryptographic precompiles including BLS12-381, BN256, and secp256r1 operations. The changes enhance performance, reduce code duplication, and improve the overall architecture of the genesis contract system. Moreover, the sha256 and ecrecover implementations are rewritten using the fluentbase sdk

Key Changes

BLS12-381 Optimizations

  • Reduced repetitive patterns: Streamlined BLS12-381 operations by eliminating code duplication
  • Enhanced G2 operations: Improved g2_add and g2_msm (multi-scalar multiplication) implementations
  • Dynamic gas calculation: Added intelligent gas cost calculation for BLS12-381 operations
  • BLST integration: Added BLST library for efficient field-to-group mapping (map_to_g2)
  • Comprehensive testing: Added extensive test coverage for BLS12-381 operations including fail cases

BN256 Pairing Improvements

  • Precompile integration: Moved BN256 precompile functionality to crate::fluent_sdk
  • Pairing instruction: Added dedicated bn256_pairing instruction with optimized implementation
  • Edge case handling: Improved handling of infinity elements in G1 and G2 operations
  • Gas optimization: Enhanced gas calculation for BN256 operations

secp256r1 Implementation

  • Complete verification: Implemented full secp256r1 signature verification (EIP-7212)
  • Input validation: Added robust input length validation and gas checking
  • Test coverage: Comprehensive test suite including valid/invalid signatures and edge cases
  • Performance optimization: Streamlined verification process with efficient gas consumption

SHA256 & ecrecover Rewrites

  • SDK integration: Rewrote SHA256 and ecrecover implementations using fluentbase SDK
  • Performance improvements: Enhanced efficiency through native SDK integration
  • Code consistency: Aligned implementations with fluentbase architecture patterns

Technical Details

Dependencies Fixed

# contracts/Cargo.toml
[workspace.dependencies]
fluentbase-types = { path = "../crates/types", default-features = false }

Testing

  • ✅ All BLS12-381 operations pass comprehensive test suite
  • ✅ BN256 pairing tests pass with edge case coverage
  • ✅ secp256r1 verification tests pass for valid and invalid signatures
  • ✅ Gas calculation tests verify correct fuel consumption

Breaking Changes

  • None

@dmitry123 dmitry123 changed the title Feat/optimize genesis sc feat(optimize-genesis-sc): optimization for genesis smart contracts Sep 10, 2025
@dmitry123 dmitry123 merged commit 9ed9bd5 into devel Sep 22, 2025
4 checks passed
@dmitry123 dmitry123 deleted the feat/optimize-genesis-sc branch September 22, 2025 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants