# Precompiles
Precompiled contracts, also called precompiles for short, extend the Nibiru EVM to have functionality beyond what's present in the Ethereum Virtual Machine by default. For example, Nibiru EVM contracts are interoperable with the Wasm VM and can interact with and modify state outside the EVM.
This page covers the basics on precompiles overall. You can skip ahead to the following sections if you're already familiar with the fundamentals.
Related Page | Synopsis |
---|---|
Nibiru-Specific Precompiled Contracts | Documentation on custom Nibiru precompiles |
Precompiles Common Between Ethereum and Nibiru | Precompiled contracts that Nibiru inherits from Ethereum |
# Intro to EVM Precompiled Contracts
Precompiled contracts are special contracts that exist at predefined addresses and implement functions that are computationally expensive or require going outside the standard set of operations in the EVM.
These contracts are "precompiled" in the sense that their functionality is built directly into the Ethereum Virtual Machine (EVM), allowing for more efficient execution and the full flexibility of regular Golang logic.
# Common Characteristics of Precompiled Contracts
EVM Interface: Precompiles implement ABI methods and feel like normal contracts when you interact with them.
Fixed Addresses: Each precompile is assigned a fixed address, allowing contracts to call them directly without the need for address resolution.
Gas Cost Calculation: Precompiles implement a
RequiredGas
function that calculates the gas cost based on the contract callinput
. This ensures that complex operations are appropriately priced.Deterministic Execution: Like all EVM operations, precompiles must execute deterministically, producing the same output for the same input across all nodes.
Each precompile implements this interface from Geth.
# The Need for Custom Precompiles
Ethereum’s standard precompiles cover basic operations and useful cryptographic functions, but more specialized functionalities are needed to cater to the use cases of the Nibiru ecosystem. Custom precompiles allow for optimized, tailored operations at the protocol level.
Nibiru-specific precompiled contracts address several key needs:
- Performance Optimization: Implementing complex operations directly in the VM can significantly reduce gas costs and improve overall network efficiency.
- Purpose-built Custom Functionality: Nibiru has a unique architecture and functionality that caters specifically to the Nibiru ecosystem. The EVM is not the only area of Nibiru that holds state. In order to express this external, non-EVM state or modify it from the EVM, there needs to be smart contracts that makes it possible to do so. Precompiles are those contracts.
- Enhanced Interoperability: Custom precompiles can facilitate seamless interaction between different blockchain environments or virtual machines. The toolkit and application surface available to developers
- Modular Account Operations: Account types that were not created on the
EVMare important to the overall blockchain state. Examples include standard
BaseAccounts
created from interchain wallets and Wasm smart contract accounts. - Asset Composability: The ability to easily convert between ERC20 tokens and a canonical Bank Coin representation opens up possibilities for cross-VM applications and opens up Ethereum functionality to the broader interchain/IBC landscape. For instance, Nibiru acts as a hub for officially supported USDC from Circle similar like Noble and can open LayerZero assets in the same manner.
# The Significance of Nibiru's Approach
Nibiru's implementation of custom precompiles represents a significant leap forward in blockchain interoperability and functionality. By bridging the EVM and Cosmos ecosystems, Nibiru offers several key advantages:
- Enhanced Interoperability: Developers can create applications that seamlessly utilize features from both EVM and Cosmos environments.
- Expanded Functionality: EVM contracts can access Cosmos-SDK features, and vice versa, greatly expanding the toolkit available to developers.
- Improved Performance: By implementing complex cross-environment operations at the protocol level, Nibiru achieves significant performance improvements and gas efficiency.
When working with Nibiru’s precompiles, developers should keep the following in mind:
- Address Formats: Be aware of the differences between the hexadecimal Ethereum address and "nibi"-prefixed Bech32 address formats.
# Future Implications and Possibilities
Nibiru's innovative use of custom precompiles opens up exciting possibilities for the future of blockchain technology:
- Further Custom Precompiles: There's potential for additional precompiles that could further enhance interoperability, such as IBC (Inter-Blockchain Communication) precompiles.
- Multi-VM Architectures: Nibiru's approach could serve as a model for future blockchain platforms looking to integrate multiple virtual machine environments.