|
| 1 | +# **Filecoin Solidity Library FAQ** |
| 2 | + |
| 3 | +This FAQ provides guidance on using the **Filecoin Solidity Library**, answering common developer questions about **interacting with Filecoin actors, handling serialization, managing balances, and working with allowances**. |
| 4 | + |
| 5 | +For up-to-date documentation and the latest version of the library, visit the **[official repository](https://github.com/filecoin-project/filecoin-solidity).** |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## **General Usage** |
| 10 | + |
| 11 | +### What is the Filecoin Solidity Library? |
| 12 | +The **Filecoin Solidity Library** provides EVM-compatible smart contracts that allow developers to interact with **Filecoin actors**, making it easier to integrate with the Filecoin blockchain’s **storage market, miner actors, verified registry, and more**. |
| 13 | + |
| 14 | +### Where can I find the latest version of the library? |
| 15 | +The official repository is available at: |
| 16 | +📌 [Filecoin Solidity Repository](https://github.com/filecoin-project/filecoin-solidity) |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## **Serialization and Address Handling** |
| 21 | + |
| 22 | +### What is the difference between `serializeAddress` and `serializeBytes`? |
| 23 | +The `serializeAddress` function is implemented in two variations: |
| 24 | + |
| 25 | +1. **`BytesCBOR.serializeAddress`** – Behaves identically to `serializeBytes`, encoding a byte array without additional validation. |
| 26 | +2. **`FilecoinCBOR.serializeAddress`** – Specifically designed to serialize a **CommonTypes.FilAddress**. |
| 27 | + |
| 28 | +Both functions **encode** addresses, but neither **validates** that the input represents a valid Filecoin address. Developers should ensure they pass correctly formatted addresses before serialization. |
| 29 | + |
| 30 | +### How should buffer allocation be handled in serialization? |
| 31 | +Efficient buffer allocation helps optimize **gas costs**. When working with serialization: |
| 32 | +- Always **precompute the expected buffer size** to avoid unnecessary resizing. |
| 33 | +- Ensure all **fields are accounted for** in capacity calculations. |
| 34 | +- Validate serialized output against expected structures to avoid inconsistencies. |
| 35 | + |
| 36 | +By following these practices, developers can ensure **efficient** and **gas-optimized** serialization. |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +### **How should zero values be handled in `BigInt`?** |
| 41 | + |
| 42 | +In the **Filecoin Solidity Library**, a `BigInt` can represent zero in two ways: |
| 43 | + |
| 44 | +1. **An empty `BigInt`** (no sign or value field) is interpreted as **zero**. |
| 45 | +2. **A `BigInt` with a value field set to `0`** is also considered **zero**, regardless of the sign field. |
| 46 | + |
| 47 | +Developers should ensure that: |
| 48 | +- **Both representations of zero** are handled **consistently** in serialization and deserialization. |
| 49 | +- Functions processing `BigInt` correctly **interpret the sign and value fields**, ensuring that a zero value does not lead to unintended behavior. |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## **Allowance and Token Transfers** |
| 54 | + |
| 55 | +### How does `transferFrom` handle allowances in the Filecoin Solidity Library? |
| 56 | +The library follows an **allowance-based transfer model**, similar to Ethereum’s ERC-20 standard, but developers should verify: |
| 57 | +- Whether **allowances decrease** after transactions when set to `type(uint256).max`. |
| 58 | +- The **exact behavior of `transferFrom`** in different execution contexts within Filecoin’s FVM. |
| 59 | + |
| 60 | +Checking allowance changes after transactions ensures **proper integration** when handling delegated token transfers. |
| 61 | + |
| 62 | +### What happens if `withdrawBalance` or `addBalance` is called with an amount exceeding available funds? |
| 63 | +- **`withdrawBalance`**: If the requested withdrawal exceeds the user’s balance, the function **withdraws the maximum available amount**. |
| 64 | +- **`addBalance`**: If the specified amount **exceeds available funds**, the transaction **fails** rather than partially completing. |
| 65 | + |
| 66 | +Understanding these behaviors helps ensure **predictable fund management** within contracts. |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## **Filecoin Actor Calls** |
| 71 | + |
| 72 | +### What happens when querying Filecoin actors for non-existent data? |
| 73 | +Different Filecoin actor calls handle missing data in distinct ways: |
| 74 | +- Some calls **return success with an empty entry** if the queried data does not exist. |
| 75 | +- Others **return an error code**, requiring explicit error handling. |
| 76 | + |
| 77 | +Developers should check the expected behavior of each Filecoin actor when integrating their contracts. |
| 78 | + |
| 79 | +### How does `publishStorageDeals` handle invalid signatures? |
| 80 | +If a **signature is invalid**, the function **does not revert the entire transaction**. Instead: |
| 81 | +- Valid deals **continue processing** as expected. |
| 82 | +- Invalid deals **are skipped** but do not trigger a contract revert. |
| 83 | +- If **all deals** are invalid, an **error code is returned** rather than a full transaction failure. |
| 84 | + |
| 85 | +Developers should **always check transaction results** after execution to verify deal statuses. |
| 86 | + |
| 87 | +### Can `GetDealDataCommitmentReturn` return large amounts of data? |
| 88 | +Yes. Depending on **commitment size**, return data may be **substantial**. |
| 89 | +- Contracts handling large commitments should **optimize memory usage**. |
| 90 | +- Consider **potential Solidity memory limitations** when working with extensive data sets. |
| 91 | + |
| 92 | +### What happens if `changeOwnerAddress` is called with the same address? |
| 93 | +If **no existing ownership change proposal** exists, calling `changeOwnerAddress` with the same owner **has no effect**. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## **Miner API** |
| 98 | + |
| 99 | +### How does the Filecoin network handle slashed or terminated miners? |
| 100 | +- **Slashed miners** remain in the network but may have **restricted functionality**. |
| 101 | +- Some API calls **return data for slashed miners**, while others **exclude them**. |
| 102 | + |
| 103 | +When integrating with **miner-related functions**, confirm whether specific calls include or omit terminated miners. |
| 104 | + |
| 105 | +### Is a multi-address operator required when calling `CreateMiner`? |
| 106 | +No. If no **multi-address operator** is provided, the **owner automatically assumes control** of the miner. |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## **Power API** |
| 111 | + |
| 112 | +### Does `minerCount` include terminated miners? |
| 113 | +- **`minerConsensusCount`** includes **only active miners** that meet **consensus power requirements**. |
| 114 | +- **`minerCount`** returns **all miners ever created**, including terminated ones. |
| 115 | + |
| 116 | +### Can `CreateMiner` be called without specifying a multi-address? |
| 117 | +Yes. If a **multi-address is not provided**, the **owner automatically takes control**. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## **Security and Error Handling** |
| 122 | + |
| 123 | +### Should I use `require` or `assert` for error handling? |
| 124 | +In Solidity: |
| 125 | +- **`require`** is used for **expected errors** (e.g., invalid user input). |
| 126 | +- **`assert`** is used for **internal invariants** (unexpected conditions). |
| 127 | + |
| 128 | +For **consistent and predictable error handling**, developers should **use `require` where possible**. |
| 129 | + |
| 130 | +### Can Filecoin precompiles hold native ETH? |
| 131 | +This behavior is **not explicitly defined**. Developers should verify: |
| 132 | +- Whether **precompile accounts** can hold **native ETH balances**. |
| 133 | +- How balances are tracked and **retrieved**. |
| 134 | + |
| 135 | +Until further clarification, **assume precompiles do not store ETH** unless explicitly stated. |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## **Additional Resources** |
| 140 | + |
| 141 | +### Where can I find more information on Filecoin Solidity development? |
| 142 | +📌 **Official Filecoin Solidity Repository:** |
| 143 | +[https://github.com/filecoin-project/filecoin-solidity](https://github.com/filecoin-project/filecoin-solidity) |
| 144 | + |
| 145 | +📌 **Filecoin Documentation:** |
| 146 | +[https://docs.filecoin.io](https://docs.filecoin.io) |
| 147 | + |
| 148 | +📌 **FVM Developer Resources:** |
| 149 | +[https://fvm.filecoin.io](https://fvm.filecoin.io) |
0 commit comments