Solidity libraries for using the FVM precompiles
forge install filecoin-project/fvm-soliditygit submodule add https://github.com/filecoin-project/fvm-solidity lib/fvm-solidityimport { FVMPay } from "fvm-solidity/FVMPay.sol";
contract BigBrain {
using FVMPay for address;
function payEfficiently(address recipient) external payable {
recipient.pay(msg.value);
}
using FVMPay for uint256;
function burnEfficiently() external payable {
msg.value.burn();
}
}Resolve Filecoin or EVM (f410 / masked ID) addresses to their on-chain actor ID.
import { FVMActor } from "fvm-solidity/FVMActor.sol";
contract BigBrain {
using FVMActor for bytes;
using FVMActor for address;
// Resolve a Filecoin byte address
function resolveFilAddress(bytes calldata filAddress) external view returns (uint64 actorId) {
return filAddress.getActorId(); // reverts with ActorNotFound if not found
}
// Safely attempt to resolve (no revert on missing actor)
function tryResolveFilAddress(bytes calldata filAddress) external view returns (bool exists, uint64 actorId) {
return filAddress.tryGetActorId();
}
// Resolve an EVM address (f410 delegated) or masked ID (0xff) address
function resolveEvmAddress(address addr) external view returns (bool exists, uint64 actorId) {
return addr.tryGetActorId();
}
}import {MockFVMTest} from "fvm-solidity/mocks/MockFVMTest.sol";
import {FVMActor} from "fvm-solidity/FVMActor.sol";
import {FVMAddress} from "fvm-solidity/FVMAddress.sol";
// MockFVMTest is Test
contract BigBrainTest is MockFVMTest {
using FVMAddress for uint64;
using FVMActor for bytes;
function setUp() public override {
// Mock the FVM precompiles for forge test
super.setUp();
/* ... */
}
function test_resolveAddress() public {
uint64 actorId = 1234;
bytes memory filAddress = actorId.f0();
ACTOR_PRECOMPILE.mockResolveAddress(filAddress, actorId);
(bool exists, uint64 resolved) = filAddress.tryGetActorId();
assertTrue(exists);
assertEq(resolved, actorId);
}
}These measurements were performed on the Demo contract with the gas-profile script. Note that gas costs are roughly 444x higher in the FEVM compared to the EVM.
| Method | Demo.sol estimateGas |
|---|---|
| Soldity payable.send(uint256) | 5383103 |
| Solidity payable.transfer(uint256) | 5379173 |
| FVMPay address.pay(uint256) | 4856475 |
| FVMPay uint64.pay(uint256) | 4847666 |
| FVMPay uint256.burn() | 3561540 |
Additional FVM support can be found in the filecoin-solidity library.
| Supported | Name | Address |
|---|---|---|
| ✅ | ResolveAddress | 0xfe00000000000000000000000000000000000001 |
| ❌ | LookupDelegatedAddress | 0xfe00000000000000000000000000000000000002 |
| ✅ | CallActorByAddress | 0xfe00000000000000000000000000000000000003 |
| ✅ | CallActorById | 0xfe00000000000000000000000000000000000005 |
| ✅ | GetBeaconRandomness | 0xfe00000000000000000000000000000000000006 |
| Supported | Name | Number |
|---|---|---|
| ✅ | Send | 0 |
| ❌ | Constructor | 1 |