feat: add LOOKUP_DELEGATED_ADDRESS precompile wrapper#9
feat: add LOOKUP_DELEGATED_ADDRESS precompile wrapper#9pali101 wants to merge 14 commits intofilecoin-project:mainfrom
Conversation
|
I think it could be more natural to return |
- Replaced `msg.data.length` checks with `address(this)` routing to prevent accidental payload collisions.
…ompile mocks - introduce FVMResolveAddress and FVMDelegatedAddress mock contracts - update MockFVMTest to etch both precompile mocks independently - update tests to use RESOLVE_ADDRESS_PRECOMPILE and LOOKUP_DELEGATED_ADDRESS_PRECOMPILE - remove legacy shared FVMActor mock
e85b4bf to
7ff91ad
Compare
|
This is very close to merging. Can you link a deployed Demo contract with your next push? |
- Combined BigBrain code blocks in README.md for clarity. - Moved _toEthAddress under the correct test banner in Address.t.sol.
|
Here is the deployed Demo contract on the Calibration testnet: 0x09f149b6AeCFCeF271fA2E84b01205373c84c16D I also ran a quick profiling trick: by using Before: Saving: |
| assertEq(result, ethAddr, "EVM address should match for max uint64 actor ID"); | ||
| } | ||
|
|
||
| function testPrecompileRevertOnLargeId() public { |
There was a problem hiding this comment.
Warning (2018): Function state mutability can be restricted to view
--> test/Actor.t.sol:335:5:
|
335 | function testPrecompileRevertOnLargeId() public {
| ^ (Relevant source part starts here and spans across multiple lines).
There was a problem hiding this comment.
| function testPrecompileRevertOnLargeId() public { | |
| function testPrecompileRevertOnLargeId() public view { |
| // Validate that actor ID fits in u64 (max u64 = 2^64 - 1) | ||
| require(actorIdFull <= type(uint64).max, "Invalid actor ID: exceeds max u64"); |
There was a problem hiding this comment.
should revert with empty data
| // Validate that actor ID fits in u64 (max u64 = 2^64 - 1) | |
| require(actorIdFull <= type(uint64).max, "Invalid actor ID: exceeds max u64"); | |
| // Validate that actor ID fits in u64 (max u64 = 2^64 - 1) | |
| if (actorIdFull > type(uint64).max) { | |
| assembly ("memory-safe") { | |
| revert(0, 0) | |
| } | |
| } |
There was a problem hiding this comment.
also, add test coverage for this case
There was a problem hiding this comment.
Claude explains:
For lookup_delegated_address (precompile 0xfe...02), read_value::<u64>() reads a 256-bit word from the ABI-encoded input and calls drop_zeros::<24>() on the upper 24
bytes. If any of those bytes are non-zero (i.e., the value exceeds u64::MAX), drop_zeros returns OverflowError, which converts to PrecompileError::InvalidInput, which
causes call_precompile to return Err.
That Err path in call.rs:189-193 maps to: success = 0 (revert), empty return data.
Summary
Implements the
LOOKUP_DELEGATED_ADDRESSprecompile wrapper (0xfe...02) to retrieve an actor's delegated address (f4) and extract the Ethereum-style address using optimized inline assembly.The primary API returns
addressfor ergonomic use in Solidity while preserving raw bytes helpers for applications that require the f4 encoding.Addresses all reviewer feedback from the initial submission (#6).
Key Changes
src/FVMActor.soltryLookupDelegatedAddress(uint64) → (bool, address): returns empty andexists=falseif actor has no delegated addresslookupDelegatedAddress(uint64) → address: strict variant, reverts withDelegatedAddressNotFound(actorId)if no delegated address existstryLookupDelegatedAddressBytes(uint64) → (bool, bytes): returns empty andexists=falseif actor has no delegated address; defaults to zero slot (0x60) to safely represent empty bytes without allocationlookupDelegatedAddressBytes(uint64) → bytes: strict raw-bytes variantsrc/FVMAddress.soltoEthAddress(bytes) → address: validatesf410format (length 22, prefix0x040a) and extracts the last 20 bytes as an Ethereum addressInvalidDelegatedAddresserrorsrc/mocks/FVMActor.soldelegatedAddressMocksmapping to supportLOOKUP_DELEGATED_ADDRESSin the unified fallbackmockLookupDelegatedAddress(uint64, bytes)andmockLookupDelegatedAddress(uint64, address)overloadsmsg.data.length == 32to distinguish lookup from resolve callssrc/mocks/MockFVMTest.solLOOKUP_DELEGATED_ADDRESSalongsideRESOLVE_ADDRESSsrc/Demo.soltryLookupDelegatedAddress,lookupDelegatedAddress,tryLookupDelegatedAddressBytes,lookupDelegatedAddressBytes,toEthAddressReviewer Notes
FVMLookupDelegatedAddressmerged intoFVMActorper feedbacktoEthAddressmoved toFVMAddressper feedbackreturndatacopy+revert(0, returnSize), consistent with feat: add RESOLVE_ADDRESS precompile wrapper #5Update (after review feedback)
Based on reviewer feedback, the delegated address API has been updated to return
addressby default since delegated addresses are native to the FEVM.The raw bytes helpers are still available for callers that need the f4/f410 encoding.
Updated API:
tryLookupDelegatedAddress(uint64)→(bool, address)lookupDelegatedAddress(uint64)→addresstryLookupDelegatedAddressBytes(uint64)→(bool, bytes)lookupDelegatedAddressBytes(uint64)→bytesCloses #2