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? |
| bytes memory tooShort = abi.encodePacked(uint8(0x04), uint8(0x0a), bytes19(0)); | ||
|
|
||
| vm.expectRevert(FVMAddress.InvalidDelegatedAddress.selector); | ||
| this._toEthAddress(tooShort); |
There was a problem hiding this comment.
I don't think you have to explicitly this.
There was a problem hiding this comment.
We need to keep this. Foundry's vm.expectRevert() only catches reverts on external calls by default. Without it, it becomes an internal call, which crashes the test and fails with: [FAIL: call didn't revert at a lower depth than cheatcode call depth]
That said, Foundry recently added a config to allow testing internal reverts. I can add /// forge-config: default.allow_internal_expect_revert = true above these tests and drop the this. if you prefer that pattern! Let me know what you think is cleaner.
- 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: |
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