Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ optimizer = true
optimizer_runs = 200
via_ir = true

ignored_error_codes = [
2519, # shadowed declarations
3628, # https://github.com/argotorg/solidity/issues/10159
]

# For dependencies
remappings = [
]

[lint]
exclude_lints = [
"incorrect-shift",
"mixed-case-function",
#"unsafe-typecast",
]
23 changes: 23 additions & 0 deletions src/FVMAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity ^0.8.30;

library FVMAddress {
error NotMaskedIdAddress(address addr);

/// @notice Creates an f0 (ID) address in bytes using unsigned LEB128 encoding
function f0(uint64 actorId) internal pure returns (bytes memory buffer) {
// Max size: 1 protocol byte + 10 bytes for uint64 LEB128 encoding
Expand Down Expand Up @@ -34,4 +36,25 @@ library FVMAddress {
function f410(address addr) internal pure returns (bytes memory) {
return f4(0x0a, bytes20(addr));
}

/// @notice Creates a masked ID address (the EVM encoding of an f0 actor ID)
/// @dev Format: 0xff + 11 zero bytes + big-endian uint64 actor ID (20 bytes total)
function maskedAddress(uint64 actorId) internal pure returns (address maskedAddr) {
assembly ("memory-safe") {
maskedAddr := or(actorId, 0xff00000000000000000000000000000000000000)
}
}

/// @notice Extracts the actor ID from a masked ID address without prefix validation
/// @dev Only call when the address is known to have the 0xff000...000 prefix
function actorId(address maskedAddr) internal pure returns (uint64) {
return uint64(uint160(maskedAddr));
}

/// @notice Extracts the actor ID from a masked ID address, reverting if the prefix is wrong
/// @dev Use FVMActor.tryGetActorId to test if the actorId is valid
function safeActorId(address maskedAddr) internal pure returns (uint64) {
require(uint160(maskedAddr) >> 64 == 0xff0000000000000000000000, NotMaskedIdAddress(maskedAddr));
return actorId(maskedAddr);
}
}
6 changes: 3 additions & 3 deletions src/FVMCodec.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity ^0.8.30;
// @dev empty returned data
uint64 constant EMPTY_CODEC = 0;

// @dev CBOR-encoded data
uint64 constant CBOR_CODEC = 0x51;

// @dev actor returned unencoded raw data
uint64 constant RAW_CODEC = 0x55;

// @dev CBOR encoded data (IPLD dag-cbor)
uint64 constant CBOR_CODEC = 0x51;
8 changes: 8 additions & 0 deletions src/FVMErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pragma solidity ^0.8.30;

int256 constant EXIT_SUCCESS = 0;

// Syscall error numbers (negative exit codes, ErrorNumber in ref-fvm)

// @dev A syscall parameters was invalid.
int256 constant ILLEGAL_ARGUMENT = -1;
// @dev The actor is not in the correct state to perform the requested operation.
Expand All @@ -31,3 +33,9 @@ int256 constant FORBIDDEN = -11;
int256 constant BUFFER_TOO_SMALL = -12;
// @dev The actor is executing in a read-only context.
int256 constant READ_ONLY = -13;

// Actor user exit codes (positive, ExitCode in fvm_shared::error)
// See https://docs.rs/fvm_shared/latest/fvm_shared/error/struct.ExitCode.html
uint32 constant USR_NOT_FOUND = 14;
Comment thread
wjmelements marked this conversation as resolved.
Outdated
uint32 constant USR_ILLEGAL_ARGUMENT = 16;
uint32 constant USR_UNHANDLED_MESSAGE = 22;
3 changes: 3 additions & 0 deletions src/FVMMethod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pragma solidity ^0.8.30;
uint64 constant SEND = 0;
uint64 constant CONSTRUCT = 1;

// Storage power actor methods
uint64 constant MINER_POWER = 36284446;

// FRC-0042 hashed method numbers (https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0042.md)
uint64 constant AUTHENTICATE_MESSAGE = 2643134072;
uint64 constant UNIVERSAL_RECEIVER_HOOK = 118350608;
Expand Down
Loading
Loading