From d5457f69296828c8bd9f91c8e0ab9d70d3f8491a Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Mon, 20 Feb 2023 14:58:41 -0300 Subject: [PATCH] remove multisig actor and some precompiles (#246) * remove multisig actor * remove get_actor_type and ripemd160 precompiles * remove useless call on test contracts * remove types not used locally and move others to the right place * apply prettier to project * remove all FIXMEs --- .github/workflows/main.yaml | 69 +----- Makefile | 5 - contracts/v0.8/AccountAPI.sol | 2 +- contracts/v0.8/DataCapAPI.sol | 2 +- contracts/v0.8/InitAPI.sol | 2 +- contracts/v0.8/MarketAPI.sol | 2 +- contracts/v0.8/MinerAPI.sol | 2 +- contracts/v0.8/MultisigAPI.sol | 235 ------------------- contracts/v0.8/PowerAPI.sol | 2 +- contracts/v0.8/PrecompilesAPI.sol | 20 +- contracts/v0.8/VerifRegAPI.sol | 2 +- contracts/v0.8/cbor/AccountCbor.sol | 8 +- contracts/v0.8/cbor/BytesCbor.sol | 3 - contracts/v0.8/cbor/DataCapCbor.sol | 10 +- contracts/v0.8/cbor/FilecoinCbor.sol | 2 +- contracts/v0.8/cbor/InitCbor.sol | 4 +- contracts/v0.8/cbor/IntCbor.sol | 1 - contracts/v0.8/cbor/MarketCbor.sol | 29 +-- contracts/v0.8/cbor/MinerCbor.sol | 20 +- contracts/v0.8/cbor/MultisigCbor.sol | 145 ------------ contracts/v0.8/cbor/PowerCbor.sol | 3 +- contracts/v0.8/cbor/VerifRegCbor.sol | 26 +-- contracts/v0.8/mocks/MarketMockAPI.sol | 2 +- contracts/v0.8/mocks/MinerMockAPI.sol | 36 ++- contracts/v0.8/tests/multisig.test.sol | 98 -------- contracts/v0.8/tests/precompiles.test.sol | 8 - contracts/v0.8/tests/verifreg.test.sol | 8 +- contracts/v0.8/types/CommonTypes.sol | 261 ---------------------- contracts/v0.8/types/MarketTypes.sol | 21 +- contracts/v0.8/types/MinerTypes.sol | 37 ++- contracts/v0.8/types/MultisigTypes.sol | 100 --------- contracts/v0.8/types/PowerTypes.sol | 16 +- contracts/v0.8/types/VerifRegTypes.sol | 30 ++- contracts/v0.8/utils/Actor.sol | 5 +- package.json | 4 +- testing/Cargo.toml | 3 +- testing/tests/multisig.rs | 198 ---------------- testing/tests/precompiles.rs | 22 +- 38 files changed, 158 insertions(+), 1285 deletions(-) delete mode 100644 contracts/v0.8/MultisigAPI.sol delete mode 100644 contracts/v0.8/cbor/MultisigCbor.sol delete mode 100644 contracts/v0.8/tests/multisig.test.sol delete mode 100644 contracts/v0.8/types/MultisigTypes.sol delete mode 100644 testing/tests/multisig.rs diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 5873ea78..008c928d 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -522,67 +522,6 @@ jobs: name: gas_results_account.csv path: testing/gas_results_account.csv - multisig-integration: - name: "Multisig API: integration tests" - timeout-minutes: 20 - runs-on: ubuntu-22.04 - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: 'true' - - name: Instal deps - run: make install-opencl - - name: Install node - uses: actions/setup-node@v2 - with: - node-version: '16.16.0' - - name: Install yarn - run: npm install -g yarn - - name: Install latest stable - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - - name: Install dependencies - run: | - yarn install - make install_solc_linux - - name: Restore crates - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - key: ${{ runner.os }}-cargo-${{ hashFiles('./testing/Cargo.lock') }} - - name: Restore previous compilation - uses: actions/cache@v3 - with: - path: | - ./testing/target - key: ${{ runner.os }}-testing-${{ hashFiles('./testing/Cargo.lock') }} - - name: Restore builtin-actors - uses: actions/cache@v3 - with: - path: | - ./testing/builtin-actors/target - key: ${{ runner.os }}-actors-${{ hashFiles('./testing/builtin-actors/Cargo.lock') }} - - name: Build builtin-actors - run: make build_builtin_actors - - name: Build contracts - run: make - - name: Run tests on multisig - run: | - cd testing - rustup target add wasm32-unknown-unknown - cargo test multisig_test - - uses: actions/upload-artifact@v3 - with: - name: gas_results_multisig.csv - path: testing/gas_results_multisig.csv - precompiles-integration: name: "Precompiles API: integration tests" timeout-minutes: 20 @@ -708,7 +647,7 @@ jobs: comment-result: name: "Comment the result on PR" runs-on: ubuntu-22.04 - needs: [account-integration, datacap-integration, init-integration, market-integration, miner-integration, multisig-integration, power-integration, precompiles-integration, send-integration, verifreg-integration] + needs: [account-integration, datacap-integration, init-integration, market-integration, miner-integration, power-integration, precompiles-integration, send-integration, verifreg-integration] steps: - name: "Get gas_results_account.csv" uses: actions/download-artifact@v3 @@ -730,10 +669,6 @@ jobs: uses: actions/download-artifact@v3 with: name: gas_results_market.csv - - name: "Get gas_results_multisig.csv" - uses: actions/download-artifact@v3 - with: - name: gas_results_multisig.csv - name: "Get gas_results_power.csv" uses: actions/download-artifact@v3 with: @@ -756,7 +691,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | pip install csv2md - MKD=$(( echo "## Account actor"; csv2md gas_results_account.csv; echo "## Datacap actor"; csv2md gas_results_datacap.csv; echo "## Init actor"; csv2md gas_results_init.csv; echo "## Market actor"; csv2md gas_results_market.csv; echo "## Multisig actor"; csv2md gas_results_multisig.csv; echo "## Power actor"; csv2md gas_results_power.csv; echo "## Precompiles actor"; csv2md gas_results_precompiles.csv; echo "## Send actor"; csv2md gas_results_send.csv; echo "## Verifreg actor"; csv2md gas_results_verifreg.csv ) | cat) + MKD=$(( echo "## Account actor"; csv2md gas_results_account.csv; echo "## Datacap actor"; csv2md gas_results_datacap.csv; echo "## Init actor"; csv2md gas_results_init.csv; echo "## Market actor"; csv2md gas_results_market.csv; echo "## Power actor"; csv2md gas_results_power.csv; echo "## Precompiles actor"; csv2md gas_results_precompiles.csv; echo "## Send actor"; csv2md gas_results_send.csv; echo "## Verifreg actor"; csv2md gas_results_verifreg.csv ) | cat) BODY=$(jq --null-input --arg body "# Gas results 🚀📝 ${MKD}" '{"body": $body}') curl \ diff --git a/Makefile b/Makefile index 25e9c13b..bc5cf6e7 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,6 @@ build_tests: ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/account.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/datacap.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/init.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi - ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/multisig.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/verifreg.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/precompiles.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/send.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi @@ -25,7 +24,6 @@ build_api: ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/DataCapAPI.sol --output-dir ./build/v0.8 --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/InitAPI.sol --output-dir ./build/v0.8 --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/AccountAPI.sol --output-dir ./build/v0.8 --overwrite --bin --hashes --opcodes --abi - ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/MultisigAPI.sol --output-dir ./build/v0.8 --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/PrecompilesAPI.sol --output-dir ./build/v0.8 --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/Utils.sol --output-dir ./build/v0.8 --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @openzeppelin=${PWD}/node_modules/@openzeppelin/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/SendAPI.sol --output-dir ./build/v0.8 --overwrite --bin --hashes --opcodes --abi @@ -91,9 +89,6 @@ test_init_integration: build build_builtin_actors test_account_integration: build build_builtin_actors cd testing && cargo test account_test -- --nocapture -test_multisig_integration: build build_builtin_actors - cd testing && cargo test multisig_test -- --nocapture - test_precompiles_integration: build build_builtin_actors cd testing && cargo test precompiles_test -- --nocapture diff --git a/contracts/v0.8/AccountAPI.sol b/contracts/v0.8/AccountAPI.sol index 0fa2696d..1f4d41fd 100644 --- a/contracts/v0.8/AccountAPI.sol +++ b/contracts/v0.8/AccountAPI.sol @@ -25,7 +25,7 @@ import "./cbor/BytesCbor.sol"; import "./utils/Misc.sol"; import "./utils/Actor.sol"; -/// @title This contract is a proxy to the Account actor. Calling one of its methods will result in a cross-actor call being performed. +/// @title This library is a proxy to the Account actor. Calling one of its methods will result in a cross-actor call being performed. /// @author Zondax AG library AccountAPI { using AccountCBOR for *; diff --git a/contracts/v0.8/DataCapAPI.sol b/contracts/v0.8/DataCapAPI.sol index 0a964994..22beb0e8 100644 --- a/contracts/v0.8/DataCapAPI.sol +++ b/contracts/v0.8/DataCapAPI.sol @@ -24,7 +24,7 @@ import "./cbor/DataCapCbor.sol"; import "./cbor/BytesCbor.sol"; import "./utils/Actor.sol"; -/// @title This contract is a proxy to the singleton DataCap actor (address: f0X). Calling one of its methods will result in a cross-actor call being performed. +/// @title This library is a proxy to the singleton DataCap actor (address: f0X). Calling one of its methods will result in a cross-actor call being performed. /// @author Zondax AG library DataCapAPI { using DataCapCBOR for *; diff --git a/contracts/v0.8/InitAPI.sol b/contracts/v0.8/InitAPI.sol index 92986e2e..018f87fd 100644 --- a/contracts/v0.8/InitAPI.sol +++ b/contracts/v0.8/InitAPI.sol @@ -24,7 +24,7 @@ import "./cbor/InitCbor.sol"; import "./utils/Misc.sol"; import "./utils/Actor.sol"; -/// @title This contract is a proxy to the singleton Init actor (address: f01). Calling one of its methods will result in a cross-actor call being performed. +/// @title This library is a proxy to the singleton Init actor (address: f01). Calling one of its methods will result in a cross-actor call being performed. /// @author Zondax AG library InitAPI { using InitCBOR for *; diff --git a/contracts/v0.8/MarketAPI.sol b/contracts/v0.8/MarketAPI.sol index e7db8c0d..d6937b59 100644 --- a/contracts/v0.8/MarketAPI.sol +++ b/contracts/v0.8/MarketAPI.sol @@ -26,7 +26,7 @@ import "./types/CommonTypes.sol"; import "./utils/Misc.sol"; import "./utils/Actor.sol"; -/// @title This contract is a proxy to the singleton Storage Market actor (address: f05). Calling one of its methods will result in a cross-actor call being performed. +/// @title This library is a proxy to the singleton Storage Market actor (address: f05). Calling one of its methods will result in a cross-actor call being performed. /// @author Zondax AG library MarketAPI { using BytesCBOR for bytes; diff --git a/contracts/v0.8/MinerAPI.sol b/contracts/v0.8/MinerAPI.sol index ea2de4e4..9d293439 100644 --- a/contracts/v0.8/MinerAPI.sol +++ b/contracts/v0.8/MinerAPI.sol @@ -25,7 +25,7 @@ import "./cbor/BytesCbor.sol"; import "./utils/Misc.sol"; import "./utils/Actor.sol"; -/// @title This contract is a proxy to a built-in Miner actor. Calling one of its methods will result in a cross-actor call being performed. +/// @title This library is a proxy to a built-in Miner actor. Calling one of its methods will result in a cross-actor call being performed. /// @notice During miner initialization, a miner actor is created on the chain, and this actor gives the miner its ID f0.... The miner actor is in charge of collecting all the payments sent to the miner. /// @dev For more info about the miner actor, please refer to https://lotus.filecoin.io/storage-providers/operate/addresses/ /// @author Zondax AG diff --git a/contracts/v0.8/MultisigAPI.sol b/contracts/v0.8/MultisigAPI.sol deleted file mode 100644 index 8c892f49..00000000 --- a/contracts/v0.8/MultisigAPI.sol +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * (c) 2022 Zondax AG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ********************************************************************************/ -// -// DRAFT!! THIS CODE HAS NOT BEEN AUDITED - USE ONLY FOR PROTOTYPING - -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.17; - -import "./types/MultisigTypes.sol"; -import "./cbor/MultisigCbor.sol"; -import "./cbor/BytesCbor.sol"; -import "./utils/Misc.sol"; -import "./utils/Actor.sol"; - -/// @title This contract is a proxy to the Multisig actor. Calling one of its methods will result in a cross-actor call being performed. -/// @author Zondax AG -library MultisigAPI { - using BytesCBOR for bytes; - using MultisigCBOR for *; - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function propose(bytes memory target, MultisigTypes.ProposeParams memory params) internal returns (MultisigTypes.ProposeReturn memory) { - bytes memory raw_request = params.serializeProposeParams(); - - bytes memory raw_response = Actor.call(MultisigTypes.ProposeMethodNum, target, raw_request, Misc.CBOR_CODEC, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - - return result.deserializeProposeReturn(); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function propose(uint64 target, MultisigTypes.ProposeParams memory params) internal returns (MultisigTypes.ProposeReturn memory) { - bytes memory raw_request = params.serializeProposeParams(); - - bytes memory raw_response = Actor.callByID(target, MultisigTypes.ProposeMethodNum, Misc.CBOR_CODEC, raw_request, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - - return result.deserializeProposeReturn(); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function approve(bytes memory target, MultisigTypes.TxnIDParams memory params) internal returns (MultisigTypes.ApproveReturn memory) { - bytes memory raw_request = params.serializeTxnIDParams(); - - bytes memory raw_response = Actor.call(MultisigTypes.ApproveMethodNum, target, raw_request, Misc.CBOR_CODEC, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - - return result.deserializeApproveReturn(); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function approve(uint64 target, MultisigTypes.TxnIDParams memory params) internal returns (MultisigTypes.ApproveReturn memory) { - bytes memory raw_request = params.serializeTxnIDParams(); - - bytes memory raw_response = Actor.callByID(target, MultisigTypes.ApproveMethodNum, Misc.CBOR_CODEC, raw_request, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - - return result.deserializeApproveReturn(); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function cancel(bytes memory target, MultisigTypes.TxnIDParams memory params) internal { - bytes memory raw_request = params.serializeTxnIDParams(); - - bytes memory raw_response = Actor.call(MultisigTypes.CancelMethodNum, target, raw_request, Misc.CBOR_CODEC, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function cancel(uint64 target, MultisigTypes.TxnIDParams memory params) internal { - bytes memory raw_request = params.serializeTxnIDParams(); - - bytes memory raw_response = Actor.callByID(target, MultisigTypes.CancelMethodNum, Misc.CBOR_CODEC, raw_request, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function addSigner(bytes memory target, MultisigTypes.AddSignerParams memory params) internal { - bytes memory raw_request = params.serializeAddSignerParams(); - - bytes memory raw_response = Actor.call(MultisigTypes.AddSignerMethodNum, target, raw_request, Misc.CBOR_CODEC, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function addSigner(uint64 target, MultisigTypes.AddSignerParams memory params) internal { - bytes memory raw_request = params.serializeAddSignerParams(); - - bytes memory raw_response = Actor.callByID(target, MultisigTypes.AddSignerMethodNum, Misc.CBOR_CODEC, raw_request, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function removeSigner(bytes memory target, MultisigTypes.RemoveSignerParams memory params) internal { - bytes memory raw_request = params.serializeRemoveSignerParams(); - - bytes memory raw_response = Actor.call(MultisigTypes.RemoveSignerMethodNum, target, raw_request, Misc.CBOR_CODEC, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function removeSigner(uint64 target, MultisigTypes.RemoveSignerParams memory params) internal { - bytes memory raw_request = params.serializeRemoveSignerParams(); - - bytes memory raw_response = Actor.callByID(target, MultisigTypes.RemoveSignerMethodNum, Misc.CBOR_CODEC, raw_request, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function swapSigner(bytes memory target, MultisigTypes.SwapSignerParams memory params) internal { - bytes memory raw_request = params.serializeSwapSignerParams(); - - bytes memory raw_response = Actor.call(MultisigTypes.SwapSignerMethodNum, target, raw_request, Misc.CBOR_CODEC, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function swapSigner(uint64 target, MultisigTypes.SwapSignerParams memory params) internal { - bytes memory raw_request = params.serializeSwapSignerParams(); - - bytes memory raw_response = Actor.callByID(target, MultisigTypes.SwapSignerMethodNum, Misc.CBOR_CODEC, raw_request, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function changeNumApprovalsThreshold(bytes memory target, MultisigTypes.ChangeNumApprovalsThresholdParams memory params) internal { - bytes memory raw_request = params.serializeChangeNumApprovalsThresholdParams(); - - bytes memory raw_response = Actor.call(MultisigTypes.ChangeNumApprovalsThresholdMethodNum, target, raw_request, Misc.CBOR_CODEC, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function changeNumApprovalsThreshold(uint64 target, MultisigTypes.ChangeNumApprovalsThresholdParams memory params) internal { - bytes memory raw_request = params.serializeChangeNumApprovalsThresholdParams(); - - bytes memory raw_response = Actor.callByID(target, MultisigTypes.ChangeNumApprovalsThresholdMethodNum, Misc.CBOR_CODEC, raw_request, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function lockBalance(bytes memory target, MultisigTypes.LockBalanceParams memory params) internal { - bytes memory raw_request = params.serializeLockBalanceParams(); - - bytes memory raw_response = Actor.call(MultisigTypes.LockBalanceMethodNum, target, raw_request, Misc.CBOR_CODEC, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function lockBalance(uint64 target, MultisigTypes.LockBalanceParams memory params) internal { - bytes memory raw_request = params.serializeLockBalanceParams(); - - bytes memory raw_response = Actor.callByID(target, MultisigTypes.LockBalanceMethodNum, Misc.CBOR_CODEC, raw_request, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function universalReceiverHook(bytes memory target, bytes memory params) internal { - bytes memory raw_request = params.serializeBytes(); - - bytes memory raw_response = Actor.call(MultisigTypes.UniversalReceiverHookMethodNum, target, raw_request, Misc.CBOR_CODEC, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } - - /// @notice TODO fill me up - /// @param target The multisig address (filecoin bytes format) you want to interact with - function universalReceiverHook(uint64 target, bytes memory params) internal { - bytes memory raw_request = params.serializeBytes(); - - bytes memory raw_response = Actor.callByID(target, MultisigTypes.UniversalReceiverHookMethodNum, Misc.CBOR_CODEC, raw_request, 0, false); - - bytes memory result = Actor.readRespData(raw_response); - require(result.length == 0, "unexpected response received"); - } -} diff --git a/contracts/v0.8/PowerAPI.sol b/contracts/v0.8/PowerAPI.sol index 954a3cfe..ab31d6f3 100644 --- a/contracts/v0.8/PowerAPI.sol +++ b/contracts/v0.8/PowerAPI.sol @@ -26,7 +26,7 @@ import "./cbor/IntCbor.sol"; import "./utils/Actor.sol"; -/// @title FIXME +/// @title This library is a proxy to a built-in Power actor. Calling one of its methods will result in a cross-actor call being performed. /// @author Zondax AG library PowerAPI { using Uint64CBOR for uint64; diff --git a/contracts/v0.8/PrecompilesAPI.sol b/contracts/v0.8/PrecompilesAPI.sol index 0d3342c3..ed153468 100644 --- a/contracts/v0.8/PrecompilesAPI.sol +++ b/contracts/v0.8/PrecompilesAPI.sol @@ -48,27 +48,9 @@ library PrecompilesAPI { } function lookupDelegatedAddress(uint64 actor_id) internal view returns (bytes memory) { - (bool success, bytes memory raw_response) = address(LOOKUP_DELEGATED_ADDRESS_PRECOMPILE_ADDR).staticcall( - abi.encodePacked(uint256(actor_id)) - ); + (bool success, bytes memory raw_response) = address(LOOKUP_DELEGATED_ADDRESS_PRECOMPILE_ADDR).staticcall(abi.encodePacked(uint256(actor_id))); require(success == true, "lookup delegated address error"); return raw_response; } - - function getActorType(uint64 actor_id) internal view returns (uint256) { - (bool success, bytes memory raw_response) = address(GET_ACTOR_TYPE_PRECOMPILE_ADDR).staticcall(abi.encodePacked(uint256(actor_id))); - require(success == true, "get actor type error"); - - uint256 builtin_type = abi.decode(raw_response, (uint256)); - - return builtin_type; - } - - function getRipemd160Hash(bytes memory input) internal view returns (bytes memory) { - (bool success, bytes memory raw_response) = address(RIPEMD160_PRECOMPILE_ADDR).staticcall(input); - require(success == true, "ripemd160 error"); - - return raw_response; - } } diff --git a/contracts/v0.8/VerifRegAPI.sol b/contracts/v0.8/VerifRegAPI.sol index 8ebc92cb..fc9c16a8 100644 --- a/contracts/v0.8/VerifRegAPI.sol +++ b/contracts/v0.8/VerifRegAPI.sol @@ -24,7 +24,7 @@ import "./cbor/VerifRegCbor.sol"; import "./utils/Actor.sol"; -/// @title FIXME +/// @title This library is a proxy to a built-in VerifReg actor. Calling one of its methods will result in a cross-actor call being performed. /// @author Zondax AG library VerifRegAPI { using VerifRegCBOR for *; diff --git a/contracts/v0.8/cbor/AccountCbor.sol b/contracts/v0.8/cbor/AccountCbor.sol index 21312e16..77833c64 100644 --- a/contracts/v0.8/cbor/AccountCbor.sol +++ b/contracts/v0.8/cbor/AccountCbor.sol @@ -25,14 +25,13 @@ import "../types/AccountTypes.sol"; import "../utils/CborDecode.sol"; import "../utils/Misc.sol"; -/// @title FIXME +/// @title This library is a set of functions meant to handle CBOR parameters serialization and return values deserialization for Account actor exported methods. /// @author Zondax AG library AccountCBOR { using CBOR for CBOR.CBORBuffer; using CBORDecoder for bytes; function serializeAuthenticateMessageParams(AccountTypes.AuthenticateMessageParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); @@ -42,9 +41,7 @@ library AccountCBOR { return buf.data(); } - function deserializeAuthenticateMessageParams( - bytes memory rawResp - ) internal pure returns (AccountTypes.AuthenticateMessageParams memory ret) { + function deserializeAuthenticateMessageParams(bytes memory rawResp) internal pure returns (AccountTypes.AuthenticateMessageParams memory ret) { uint byteIdx = 0; uint len; @@ -58,7 +55,6 @@ library AccountCBOR { } function serializeUniversalReceiverParams(AccountTypes.UniversalReceiverParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); diff --git a/contracts/v0.8/cbor/BytesCbor.sol b/contracts/v0.8/cbor/BytesCbor.sol index f9b092dc..0260453f 100644 --- a/contracts/v0.8/cbor/BytesCbor.sol +++ b/contracts/v0.8/cbor/BytesCbor.sol @@ -30,7 +30,6 @@ library BytesCBOR { using BigIntCBOR for bytes; function serializeBytes(bytes memory data) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.writeBytes(data); @@ -39,7 +38,6 @@ library BytesCBOR { } function serializeAddress(bytes memory addr) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.writeBytes(addr); @@ -48,7 +46,6 @@ library BytesCBOR { } function serializeNull() internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.writeNull(); diff --git a/contracts/v0.8/cbor/DataCapCbor.sol b/contracts/v0.8/cbor/DataCapCbor.sol index d5379a3f..bee56d56 100644 --- a/contracts/v0.8/cbor/DataCapCbor.sol +++ b/contracts/v0.8/cbor/DataCapCbor.sol @@ -27,7 +27,7 @@ import "../utils/CborDecode.sol"; import "../utils/Misc.sol"; import "./BigIntCbor.sol"; -/// @title FIXME +/// @title This library is a set of functions meant to handle CBOR parameters serialization and return values deserialization for DataCap actor exported methods. /// @author Zondax AG library DataCapCBOR { using CBOR for CBOR.CBORBuffer; @@ -36,7 +36,6 @@ library DataCapCBOR { using BigIntCBOR for bytes; function serializeGetAllowanceParams(DataCapTypes.GetAllowanceParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); @@ -47,7 +46,6 @@ library DataCapCBOR { } function serializeTransferParams(DataCapTypes.TransferParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(3); @@ -78,7 +76,6 @@ library DataCapCBOR { } function serializeTransferFromParams(DataCapTypes.TransferFromParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(4); @@ -113,7 +110,6 @@ library DataCapCBOR { } function serializeIncreaseAllowanceParams(DataCapTypes.IncreaseAllowanceParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); @@ -124,7 +120,6 @@ library DataCapCBOR { } function serializeDecreaseAllowanceParams(DataCapTypes.DecreaseAllowanceParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); @@ -135,7 +130,6 @@ library DataCapCBOR { } function serializeRevokeAllowanceParams(DataCapTypes.RevokeAllowanceParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(1); @@ -145,7 +139,6 @@ library DataCapCBOR { } function serializeBurnParams(DataCapTypes.BurnParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(1); @@ -169,7 +162,6 @@ library DataCapCBOR { } function serializeBurnFromParams(DataCapTypes.BurnFromParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); diff --git a/contracts/v0.8/cbor/FilecoinCbor.sol b/contracts/v0.8/cbor/FilecoinCbor.sol index 2d517f9f..bc4c59fc 100644 --- a/contracts/v0.8/cbor/FilecoinCbor.sol +++ b/contracts/v0.8/cbor/FilecoinCbor.sol @@ -22,7 +22,7 @@ pragma solidity ^0.8.17; import "solidity-cborutils/contracts/CBOR.sol"; import "@ensdomains/buffer/contracts/Buffer.sol"; -/// @title FIXME +/// @title This library is a set of functions meant to handle CBOR serialization and deserialization for general data types on the filecoin network. /// @author Zondax AG library FilecoinCbor { using Buffer for Buffer.buffer; diff --git a/contracts/v0.8/cbor/InitCbor.sol b/contracts/v0.8/cbor/InitCbor.sol index 1abb12bc..e0a20f11 100644 --- a/contracts/v0.8/cbor/InitCbor.sol +++ b/contracts/v0.8/cbor/InitCbor.sol @@ -26,7 +26,7 @@ import "./FilecoinCbor.sol"; import "../utils/CborDecode.sol"; import "../utils/Misc.sol"; -/// @title FIXME +/// @title This library is a set of functions meant to handle CBOR parameters serialization and return values deserialization for Init actor exported methods. /// @author Zondax AG library InitCBOR { using CBOR for CBOR.CBORBuffer; @@ -34,7 +34,6 @@ library InitCBOR { using CBORDecoder for bytes; function serializeExecParams(InitTypes.ExecParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); @@ -58,7 +57,6 @@ library InitCBOR { } function serializeExec4Params(InitTypes.Exec4Params memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(3); diff --git a/contracts/v0.8/cbor/IntCbor.sol b/contracts/v0.8/cbor/IntCbor.sol index ea39fea8..dac7d4ef 100644 --- a/contracts/v0.8/cbor/IntCbor.sol +++ b/contracts/v0.8/cbor/IntCbor.sol @@ -28,7 +28,6 @@ library Uint64CBOR { using CBORDecoder for bytes; function serialize(uint64 id) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.writeUInt64(id); diff --git a/contracts/v0.8/cbor/MarketCbor.sol b/contracts/v0.8/cbor/MarketCbor.sol index dac4da02..3902bd71 100644 --- a/contracts/v0.8/cbor/MarketCbor.sol +++ b/contracts/v0.8/cbor/MarketCbor.sol @@ -27,7 +27,7 @@ import "../utils/CborDecode.sol"; import "../utils/Misc.sol"; import "./FilecoinCbor.sol"; -/// @title FIXME +/// @title This library is a set of functions meant to handle CBOR parameters serialization and return values deserialization for Market actor exported methods. /// @author Zondax AG library MarketCBOR { using CBOR for CBOR.CBORBuffer; @@ -37,7 +37,6 @@ library MarketCBOR { using FilecoinCbor for CBOR.CBORBuffer; function serializeWithdrawBalanceParams(MarketTypes.WithdrawBalanceParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); @@ -74,9 +73,7 @@ library MarketCBOR { return ret; } - function deserializeGetDealDataCommitmentReturn( - bytes memory rawResp - ) internal pure returns (MarketTypes.GetDealDataCommitmentReturn memory ret) { + function deserializeGetDealDataCommitmentReturn(bytes memory rawResp) internal pure returns (MarketTypes.GetDealDataCommitmentReturn memory ret) { uint byteIdx = 0; uint len; @@ -129,9 +126,7 @@ library MarketCBOR { return ret; } - function deserializeGetDealEpochPriceReturn( - bytes memory rawResp - ) internal pure returns (MarketTypes.GetDealEpochPriceReturn memory ret) { + function deserializeGetDealEpochPriceReturn(bytes memory rawResp) internal pure returns (MarketTypes.GetDealEpochPriceReturn memory ret) { bytes memory tmp; uint byteIdx = 0; @@ -141,9 +136,7 @@ library MarketCBOR { return ret; } - function deserializeGetDealClientCollateralReturn( - bytes memory rawResp - ) internal pure returns (MarketTypes.GetDealClientCollateralReturn memory ret) { + function deserializeGetDealClientCollateralReturn(bytes memory rawResp) internal pure returns (MarketTypes.GetDealClientCollateralReturn memory ret) { bytes memory tmp; uint byteIdx = 0; @@ -153,9 +146,7 @@ library MarketCBOR { return ret; } - function deserializeGetDealProviderCollateralReturn( - bytes memory rawResp - ) internal pure returns (MarketTypes.GetDealProviderCollateralReturn memory ret) { + function deserializeGetDealProviderCollateralReturn(bytes memory rawResp) internal pure returns (MarketTypes.GetDealProviderCollateralReturn memory ret) { bytes memory tmp; uint byteIdx = 0; @@ -173,9 +164,7 @@ library MarketCBOR { return ret; } - function deserializeGetDealActivationReturn( - bytes memory rawResp - ) internal pure returns (MarketTypes.GetDealActivationReturn memory ret) { + function deserializeGetDealActivationReturn(bytes memory rawResp) internal pure returns (MarketTypes.GetDealActivationReturn memory ret) { uint byteIdx = 0; uint len; @@ -189,7 +178,6 @@ library MarketCBOR { } function serializePublishStorageDealsParams(MarketTypes.PublishStorageDealsParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(1); @@ -218,9 +206,7 @@ library MarketCBOR { return buf.data(); } - function deserializePublishStorageDealsReturn( - bytes memory rawResp - ) internal pure returns (MarketTypes.PublishStorageDealsReturn memory ret) { + function deserializePublishStorageDealsReturn(bytes memory rawResp) internal pure returns (MarketTypes.PublishStorageDealsReturn memory ret) { uint byteIdx = 0; uint len; @@ -237,7 +223,6 @@ library MarketCBOR { } function serializeDealID(uint64 id) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.writeUInt64(id); diff --git a/contracts/v0.8/cbor/MinerCbor.sol b/contracts/v0.8/cbor/MinerCbor.sol index afb4dc8f..71aa11d4 100644 --- a/contracts/v0.8/cbor/MinerCbor.sol +++ b/contracts/v0.8/cbor/MinerCbor.sol @@ -21,13 +21,12 @@ pragma solidity ^0.8.17; import "solidity-cborutils/contracts/CBOR.sol"; -import {CommonTypes} from "../types/CommonTypes.sol"; import {MinerTypes} from "../types/MinerTypes.sol"; import "../utils/CborDecode.sol"; import "../utils/Misc.sol"; import "./BigIntCbor.sol"; -/// @title FIXME +/// @title This library is a set of functions meant to handle CBOR parameters serialization and return values deserialization for Miner actor exported methods. /// @author Zondax AG library MinerCBOR { using CBOR for CBOR.CBORBuffer; @@ -36,7 +35,6 @@ library MinerCBOR { using BigIntCBOR for bytes; function serializeChangeBeneficiaryParams(MinerTypes.ChangeBeneficiaryParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(3); @@ -65,9 +63,7 @@ library MinerCBOR { return ret; } - function deserializeIsControllingAddressReturn( - bytes memory rawResp - ) internal pure returns (MinerTypes.IsControllingAddressReturn memory ret) { + function deserializeIsControllingAddressReturn(bytes memory rawResp) internal pure returns (MinerTypes.IsControllingAddressReturn memory ret) { uint byteIdx = 0; (ret.is_controlling, byteIdx) = rawResp.readBool(byteIdx); @@ -81,9 +77,7 @@ library MinerCBOR { return ret; } - function deserializeGetAvailableBalanceReturn( - bytes memory rawResp - ) internal pure returns (MinerTypes.GetAvailableBalanceReturn memory ret) { + function deserializeGetAvailableBalanceReturn(bytes memory rawResp) internal pure returns (MinerTypes.GetAvailableBalanceReturn memory ret) { uint byteIdx = 0; bytes memory tmp; @@ -162,21 +156,20 @@ library MinerCBOR { assert(len == 1); (len, byteIdx) = rawResp.readFixedArray(byteIdx); - ret.vesting_funds = new CommonTypes.VestingFunds[](len); + ret.vesting_funds = new MinerTypes.VestingFunds[](len); for (uint i = 0; i < len; i++) { (epoch, byteIdx) = rawResp.readInt64(byteIdx); (tmp, byteIdx) = rawResp.readBytes(byteIdx); amount = tmp.deserializeBigInt(); - ret.vesting_funds[i] = CommonTypes.VestingFunds(epoch, amount); + ret.vesting_funds[i] = MinerTypes.VestingFunds(epoch, amount); } return ret; } function serializeChangeWorkerAddressParams(MinerTypes.ChangeWorkerAddressParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); @@ -191,7 +184,6 @@ library MinerCBOR { } function serializeChangePeerIDParams(MinerTypes.ChangePeerIDParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(1); @@ -201,7 +193,6 @@ library MinerCBOR { } function serializeChangeMultiaddrsParams(MinerTypes.ChangeMultiaddrsParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(1); @@ -242,7 +233,6 @@ library MinerCBOR { } function serializeWithdrawBalanceParams(MinerTypes.WithdrawBalanceParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(1); diff --git a/contracts/v0.8/cbor/MultisigCbor.sol b/contracts/v0.8/cbor/MultisigCbor.sol deleted file mode 100644 index 8cca396e..00000000 --- a/contracts/v0.8/cbor/MultisigCbor.sol +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * (c) 2022 Zondax AG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ********************************************************************************/ -// -// DRAFT!! THIS CODE HAS NOT BEEN AUDITED - USE ONLY FOR PROTOTYPING - -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.17; - -import "solidity-cborutils/contracts/CBOR.sol"; - -import "../types/MultisigTypes.sol"; -import "../utils/CborDecode.sol"; -import "../utils/Misc.sol"; -import "./BigIntCbor.sol"; - -/// @title FIXME -/// @author Zondax AG -library MultisigCBOR { - using CBOR for CBOR.CBORBuffer; - using CBORDecoder for bytes; - using BigIntCBOR for BigInt; - - function serializeProposeParams(MultisigTypes.ProposeParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? - CBOR.CBORBuffer memory buf = CBOR.create(64); - - buf.startFixedArray(4); - buf.writeBytes(params.to); - buf.writeBytes(params.value.serializeBigInt()); - buf.writeUInt64(params.method); - buf.writeBytes(params.params); - - return buf.data(); - } - - function deserializeProposeReturn(bytes memory rawResp) internal pure returns (MultisigTypes.ProposeReturn memory ret) { - uint byteIdx = 0; - uint len; - - (len, byteIdx) = rawResp.readFixedArray(byteIdx); - assert(len == 4); - - (ret.txn_id, byteIdx) = rawResp.readInt64(byteIdx); - (ret.applied, byteIdx) = rawResp.readBool(byteIdx); - (ret.code, byteIdx) = rawResp.readUInt32(byteIdx); - (ret.ret, byteIdx) = rawResp.readBytes(byteIdx); - - return ret; - } - - function serializeTxnIDParams(MultisigTypes.TxnIDParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? - CBOR.CBORBuffer memory buf = CBOR.create(64); - - buf.startFixedArray(2); - buf.writeInt64(params.id); - buf.writeBytes(params.proposal_hash); - - return buf.data(); - } - - function deserializeApproveReturn(bytes memory rawResp) internal pure returns (MultisigTypes.ApproveReturn memory ret) { - uint byteIdx = 0; - uint len; - - (len, byteIdx) = rawResp.readFixedArray(byteIdx); - assert(len == 3); - - (ret.applied, byteIdx) = rawResp.readBool(byteIdx); - (ret.code, byteIdx) = rawResp.readUInt32(byteIdx); - (ret.ret, byteIdx) = rawResp.readBytes(byteIdx); - - return ret; - } - - function serializeAddSignerParams(MultisigTypes.AddSignerParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? - CBOR.CBORBuffer memory buf = CBOR.create(64); - - buf.startFixedArray(2); - buf.writeBytes(params.signer); - buf.writeBool(params.increase); - - return buf.data(); - } - - function serializeRemoveSignerParams(MultisigTypes.RemoveSignerParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? - CBOR.CBORBuffer memory buf = CBOR.create(64); - - buf.startFixedArray(2); - buf.writeBytes(params.signer); - buf.writeBool(params.decrease); - - return buf.data(); - } - - function serializeSwapSignerParams(MultisigTypes.SwapSignerParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? - CBOR.CBORBuffer memory buf = CBOR.create(64); - - buf.startFixedArray(2); - buf.writeBytes(params.from); - buf.writeBytes(params.to); - - return buf.data(); - } - - function serializeChangeNumApprovalsThresholdParams( - MultisigTypes.ChangeNumApprovalsThresholdParams memory params - ) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? - CBOR.CBORBuffer memory buf = CBOR.create(64); - - buf.startFixedArray(1); - buf.writeUInt64(params.new_threshold); - - return buf.data(); - } - - function serializeLockBalanceParams(MultisigTypes.LockBalanceParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? - CBOR.CBORBuffer memory buf = CBOR.create(64); - - buf.startFixedArray(3); - buf.writeInt64(params.start_epoch); - buf.writeInt64(params.unlock_duration); - buf.writeBytes(params.amount.serializeBigInt()); - - return buf.data(); - } -} diff --git a/contracts/v0.8/cbor/PowerCbor.sol b/contracts/v0.8/cbor/PowerCbor.sol index 2a0af94d..c33e0e0b 100644 --- a/contracts/v0.8/cbor/PowerCbor.sol +++ b/contracts/v0.8/cbor/PowerCbor.sol @@ -26,7 +26,7 @@ import "../utils/CborDecode.sol"; import "../utils/Misc.sol"; import "./BigIntCbor.sol"; -/// @title FIXME +/// @title This library is a set of functions meant to handle CBOR parameters serialization and return values deserialization for Power actor exported methods. /// @author Zondax AG library PowerCBOR { using CBOR for CBOR.CBORBuffer; @@ -35,7 +35,6 @@ library PowerCBOR { using BigIntCBOR for bytes; function serializeCreateMinerParams(PowerTypes.CreateMinerParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); uint multiaddrsLen = params.multiaddrs.length; diff --git a/contracts/v0.8/cbor/VerifRegCbor.sol b/contracts/v0.8/cbor/VerifRegCbor.sol index 91ba1a94..9842f244 100644 --- a/contracts/v0.8/cbor/VerifRegCbor.sol +++ b/contracts/v0.8/cbor/VerifRegCbor.sol @@ -27,7 +27,7 @@ import "../utils/CborDecode.sol"; import "../utils/Misc.sol"; import "./BigIntCbor.sol"; -/// @title FIXME +/// @title This library is a set of functions meant to handle CBOR parameters serialization and return values deserialization for VerifReg actor exported methods. /// @author Zondax AG library VerifRegCBOR { using CBOR for CBOR.CBORBuffer; @@ -36,7 +36,6 @@ library VerifRegCBOR { using BigIntCBOR for bytes; function serializeGetClaimsParams(VerifRegTypes.GetClaimsParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); uint claimIdsLen = params.claim_ids.length; @@ -75,7 +74,7 @@ library VerifRegCBOR { } (len, byteIdx) = rawResp.readFixedArray(byteIdx); - ret.claims = new CommonTypes.Claim[](len); + ret.claims = new VerifRegTypes.Claim[](len); for (uint i = 0; i < len; i++) { (len, byteIdx) = rawResp.readFixedArray(byteIdx); @@ -95,7 +94,6 @@ library VerifRegCBOR { } function serializeAddVerifierClientParams(VerifRegTypes.AddVerifierClientParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); @@ -105,10 +103,7 @@ library VerifRegCBOR { return buf.data(); } - function serializeRemoveExpiredAllocationsParams( - VerifRegTypes.RemoveExpiredAllocationsParams memory params - ) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? + function serializeRemoveExpiredAllocationsParams(VerifRegTypes.RemoveExpiredAllocationsParams memory params) internal pure returns (bytes memory) { CBOR.CBORBuffer memory buf = CBOR.create(64); uint allocationIdsLen = params.allocation_ids.length; @@ -123,9 +118,7 @@ library VerifRegCBOR { return buf.data(); } - function deserializeRemoveExpiredAllocationsReturn( - bytes memory rawResp - ) internal pure returns (VerifRegTypes.RemoveExpiredAllocationsReturn memory ret) { + function deserializeRemoveExpiredAllocationsReturn(bytes memory rawResp) internal pure returns (VerifRegTypes.RemoveExpiredAllocationsReturn memory ret) { uint byteIdx = 0; uint len; @@ -163,7 +156,6 @@ library VerifRegCBOR { } function serializeExtendClaimTermsParams(VerifRegTypes.ExtendClaimTermsParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); uint termsLen = params.terms.length; @@ -203,10 +195,7 @@ library VerifRegCBOR { return ret; } - function serializeRemoveExpiredClaimsParams( - VerifRegTypes.RemoveExpiredClaimsParams memory params - ) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? + function serializeRemoveExpiredClaimsParams(VerifRegTypes.RemoveExpiredClaimsParams memory params) internal pure returns (bytes memory) { CBOR.CBORBuffer memory buf = CBOR.create(64); uint claimIdsLen = params.claim_ids.length; @@ -221,9 +210,7 @@ library VerifRegCBOR { return buf.data(); } - function deserializeRemoveExpiredClaimsReturn( - bytes memory rawResp - ) internal pure returns (VerifRegTypes.RemoveExpiredClaimsReturn memory ret) { + function deserializeRemoveExpiredClaimsReturn(bytes memory rawResp) internal pure returns (VerifRegTypes.RemoveExpiredClaimsReturn memory ret) { uint byteIdx = 0; uint len; @@ -257,7 +244,6 @@ library VerifRegCBOR { } function serializeUniversalReceiverParams(VerifRegTypes.UniversalReceiverParams memory params) internal pure returns (bytes memory) { - // FIXME what should the max length be on the buffer? CBOR.CBORBuffer memory buf = CBOR.create(64); buf.startFixedArray(2); diff --git a/contracts/v0.8/mocks/MarketMockAPI.sol b/contracts/v0.8/mocks/MarketMockAPI.sol index 0b5a3cf5..337a240f 100644 --- a/contracts/v0.8/mocks/MarketMockAPI.sol +++ b/contracts/v0.8/mocks/MarketMockAPI.sol @@ -24,7 +24,7 @@ import "./types/MockTypes.sol"; import {BigNumbers, BigNumber} from "@zondax/solidity-bignumber/src/BigNumbers.sol"; -/// @title This contract is a proxy to the singleton Storage Market actor (address: f05). Calling one of its methods will result in a cross-actor call being performed. However, in this mock library, no actual call is performed. +/// @title This library is a proxy to the singleton Storage Market actor (address: f05). Calling one of its methods will result in a cross-actor call being performed. However, in this mock library, no actual call is performed. /// @author Zondax AG /// @dev Methods prefixed with mock_ will not be available in the real library. These methods are merely used to set mock state. Note that this interface will likely break in the future as we align it // with that of the real library! diff --git a/contracts/v0.8/mocks/MinerMockAPI.sol b/contracts/v0.8/mocks/MinerMockAPI.sol index db9c28eb..cd11b180 100644 --- a/contracts/v0.8/mocks/MinerMockAPI.sol +++ b/contracts/v0.8/mocks/MinerMockAPI.sol @@ -23,25 +23,25 @@ import {BigNumbers, BigNumber} from "@zondax/solidity-bignumber/src/BigNumbers.s import "../types/MinerTypes.sol"; -/// @title This contract is a proxy to a built-in Miner actor. Calling one of its methods will result in a cross-actor call being performed. However, in this mock library, no actual call is performed. +/// @title This library is a proxy to a built-in Miner actor. Calling one of its methods will result in a cross-actor call being performed. However, in this mock library, no actual call is performed. /// @author Zondax AG /// @dev Methods prefixed with mock_ will not be available in the real library. These methods are merely used to set mock state. Note that this interface will likely break in the future as we align it // with that of the real library! contract MinerMockAPI { bytes owner; bool isBeneficiarySet = false; - CommonTypes.ActiveBeneficiary activeBeneficiary; - mapping(CommonTypes.SectorSize => uint64) sectorSizesBytes; + MinerTypes.ActiveBeneficiary activeBeneficiary; + mapping(MinerTypes.SectorSize => uint64) sectorSizesBytes; /// @notice (Mock method) Sets the owner of a Miner on contract deployment, which will be returned via get_owner(). constructor(bytes memory _owner) { owner = _owner; - sectorSizesBytes[CommonTypes.SectorSize._2KiB] = 2 << 10; - sectorSizesBytes[CommonTypes.SectorSize._8MiB] = 8 << 20; - sectorSizesBytes[CommonTypes.SectorSize._512MiB] = 512 << 20; - sectorSizesBytes[CommonTypes.SectorSize._32GiB] = 32 << 30; - sectorSizesBytes[CommonTypes.SectorSize._64GiB] = 2 * (32 << 30); + sectorSizesBytes[MinerTypes.SectorSize._2KiB] = 2 << 10; + sectorSizesBytes[MinerTypes.SectorSize._8MiB] = 8 << 20; + sectorSizesBytes[MinerTypes.SectorSize._512MiB] = 512 << 20; + sectorSizesBytes[MinerTypes.SectorSize._32GiB] = 32 << 30; + sectorSizesBytes[MinerTypes.SectorSize._64GiB] = 2 * (32 << 30); } /// @notice (Mock method) Sets the owner of a Miner, which will be returned via get_owner(). @@ -70,9 +70,7 @@ contract MinerMockAPI { /// @param params The "controlling" addresses are the Owner, the Worker, and all Control Addresses. /// @return Whether the provided address is "controlling". - function isControllingAddress( - MinerTypes.IsControllingAddressParam memory params - ) public pure returns (MinerTypes.IsControllingAddressReturn memory) { + function isControllingAddress(MinerTypes.IsControllingAddressParam memory params) public pure returns (MinerTypes.IsControllingAddressReturn memory) { require(params.addr[0] >= 0x00); return MinerTypes.IsControllingAddressReturn(false); @@ -80,7 +78,7 @@ contract MinerMockAPI { /// @return the miner's sector size. function getSectorSize() public view returns (MinerTypes.GetSectorSizeReturn memory) { - return MinerTypes.GetSectorSizeReturn(sectorSizesBytes[CommonTypes.SectorSize._8MiB]); + return MinerTypes.GetSectorSizeReturn(sectorSizesBytes[MinerTypes.SectorSize._8MiB]); } /// @notice This is calculated as actor balance - (vesting funds + pre-commit deposit + initial pledge requirement + fee debt) @@ -92,8 +90,8 @@ contract MinerMockAPI { /// @return the funds vesting in this miner as a list of (vesting_epoch, vesting_amount) tuples. function getVestingFunds() public pure returns (MinerTypes.GetVestingFundsReturn memory) { - CommonTypes.VestingFunds[] memory vesting_funds = new CommonTypes.VestingFunds[](1); - vesting_funds[0] = CommonTypes.VestingFunds(1668514825, BigInt(hex"6C6B935B8BBD400000", false)); + MinerTypes.VestingFunds[] memory vesting_funds = new MinerTypes.VestingFunds[](1); + vesting_funds[0] = MinerTypes.VestingFunds(1668514825, BigInt(hex"6C6B935B8BBD400000", false)); return MinerTypes.GetVestingFundsReturn(vesting_funds); } @@ -104,12 +102,8 @@ contract MinerMockAPI { function changeBeneficiary(MinerTypes.ChangeBeneficiaryParams memory params) public { if (!isBeneficiarySet) { BigNumber memory zero = BigNumbers.zero(); - CommonTypes.BeneficiaryTerm memory term = CommonTypes.BeneficiaryTerm( - params.new_quota, - BigInt(zero.val, zero.neg), - params.new_expiration - ); - activeBeneficiary = CommonTypes.ActiveBeneficiary(params.new_beneficiary, term); + MinerTypes.BeneficiaryTerm memory term = MinerTypes.BeneficiaryTerm(params.new_quota, BigInt(zero.val, zero.neg), params.new_expiration); + activeBeneficiary = MinerTypes.ActiveBeneficiary(params.new_beneficiary, term); isBeneficiarySet = true; } else { activeBeneficiary.beneficiary = params.new_beneficiary; @@ -123,7 +117,7 @@ contract MinerMockAPI { function getBeneficiary() public view returns (MinerTypes.GetBeneficiaryReturn memory) { require(isBeneficiarySet); - CommonTypes.PendingBeneficiaryChange memory proposed; + MinerTypes.PendingBeneficiaryChange memory proposed; return MinerTypes.GetBeneficiaryReturn(activeBeneficiary, proposed); } } diff --git a/contracts/v0.8/tests/multisig.test.sol b/contracts/v0.8/tests/multisig.test.sol deleted file mode 100644 index b99cdaef..00000000 --- a/contracts/v0.8/tests/multisig.test.sol +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * (c) 2022 Zondax AG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ********************************************************************************/ -// -// DRAFT!! THIS CODE HAS NOT BEEN AUDITED - USE ONLY FOR PROTOTYPING - -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.17; - -import "../types/MultisigTypes.sol"; -import "../MultisigAPI.sol"; - -/// @author Zondax AG -contract MultisigApiTest { - function propose(bytes memory target, MultisigTypes.ProposeParams memory params) public returns (MultisigTypes.ProposeReturn memory) { - return MultisigAPI.propose(target, params); - } - - function propose(uint64 target, MultisigTypes.ProposeParams memory params) public returns (MultisigTypes.ProposeReturn memory) { - return MultisigAPI.propose(target, params); - } - - function approve(bytes memory target, MultisigTypes.TxnIDParams memory params) public returns (MultisigTypes.ApproveReturn memory) { - return MultisigAPI.approve(target, params); - } - - function approve(uint64 target, MultisigTypes.TxnIDParams memory params) public returns (MultisigTypes.ApproveReturn memory) { - return MultisigAPI.approve(target, params); - } - - function cancel(bytes memory target, MultisigTypes.TxnIDParams memory params) public { - return MultisigAPI.cancel(target, params); - } - - function cancel(uint64 target, MultisigTypes.TxnIDParams memory params) public { - return MultisigAPI.cancel(target, params); - } - - function add_signer(bytes memory target, MultisigTypes.AddSignerParams memory params) public { - return MultisigAPI.addSigner(target, params); - } - - function add_signer(uint64 target, MultisigTypes.AddSignerParams memory params) public { - return MultisigAPI.addSigner(target, params); - } - - function remove_signer(bytes memory target, MultisigTypes.RemoveSignerParams memory params) public { - return MultisigAPI.removeSigner(target, params); - } - - function remove_signer(uint64 target, MultisigTypes.RemoveSignerParams memory params) public { - return MultisigAPI.removeSigner(target, params); - } - - function swap_signer(bytes memory target, MultisigTypes.SwapSignerParams memory params) public { - return MultisigAPI.swapSigner(target, params); - } - - function swap_signer(uint64 target, MultisigTypes.SwapSignerParams memory params) public { - return MultisigAPI.swapSigner(target, params); - } - - function change_num_approvals_threshold(bytes memory target, MultisigTypes.ChangeNumApprovalsThresholdParams memory params) public { - return MultisigAPI.changeNumApprovalsThreshold(target, params); - } - - function change_num_approvals_threshold(uint64 target, MultisigTypes.ChangeNumApprovalsThresholdParams memory params) public { - return MultisigAPI.changeNumApprovalsThreshold(target, params); - } - - function lock_balance(bytes memory target, MultisigTypes.LockBalanceParams memory params) public { - return MultisigAPI.lockBalance(target, params); - } - - function lock_balance(uint64 target, MultisigTypes.LockBalanceParams memory params) public { - return MultisigAPI.lockBalance(target, params); - } - - function universal_receiver_hook(bytes memory target, bytes memory params) public { - return MultisigAPI.universalReceiverHook(target, params); - } - - function universal_receiver_hook(uint64 target, bytes memory params) public { - return MultisigAPI.universalReceiverHook(target, params); - } -} diff --git a/contracts/v0.8/tests/precompiles.test.sol b/contracts/v0.8/tests/precompiles.test.sol index 4c5f04e9..288fb7db 100644 --- a/contracts/v0.8/tests/precompiles.test.sol +++ b/contracts/v0.8/tests/precompiles.test.sol @@ -34,12 +34,4 @@ contract PrecompilesApiTest { function lookup_delegated_address(uint64 actor_id) public view returns (bytes memory) { return PrecompilesAPI.lookupDelegatedAddress(actor_id); } - - function get_actor_type(uint64 actor_id) public view returns (uint256) { - return PrecompilesAPI.getActorType(actor_id); - } - - function get_ripemd160_hash(bytes memory input) public view returns (bytes memory) { - return PrecompilesAPI.getRipemd160Hash(input); - } } diff --git a/contracts/v0.8/tests/verifreg.test.sol b/contracts/v0.8/tests/verifreg.test.sol index c81aae3e..6d2780d7 100644 --- a/contracts/v0.8/tests/verifreg.test.sol +++ b/contracts/v0.8/tests/verifreg.test.sol @@ -42,15 +42,11 @@ contract VerifRegApiTest { return VerifRegAPI.extendClaimTerms(params); } - function remove_expired_claims( - VerifRegTypes.RemoveExpiredClaimsParams memory params - ) public returns (VerifRegTypes.RemoveExpiredClaimsReturn memory) { + function remove_expired_claims(VerifRegTypes.RemoveExpiredClaimsParams memory params) public returns (VerifRegTypes.RemoveExpiredClaimsReturn memory) { return VerifRegAPI.removeExpiredClaims(params); } - function universal_receiver_hook( - VerifRegTypes.UniversalReceiverParams memory params - ) public returns (VerifRegTypes.AllocationsResponse memory) { + function universal_receiver_hook(VerifRegTypes.UniversalReceiverParams memory params) public returns (VerifRegTypes.AllocationsResponse memory) { return VerifRegAPI.universalReceiverHook(params); } } diff --git a/contracts/v0.8/types/CommonTypes.sol b/contracts/v0.8/types/CommonTypes.sol index c572b6b6..bed42db3 100644 --- a/contracts/v0.8/types/CommonTypes.sol +++ b/contracts/v0.8/types/CommonTypes.sol @@ -24,243 +24,6 @@ import "../cbor/BigIntCbor.sol"; /// @title Filecoin actors' common types for Solidity. /// @author Zondax AG library CommonTypes { - enum RegisteredSealProof { - StackedDRG2KiBV1, - StackedDRG512MiBV1, - StackedDRG8MiBV1, - StackedDRG32GiBV1, - StackedDRG64GiBV1, - StackedDRG2KiBV1P1, - StackedDRG512MiBV1P1, - StackedDRG8MiBV1P1, - StackedDRG32GiBV1P1, - StackedDRG64GiBV1P1, - Invalid - } - - enum RegisteredPoStProof { - StackedDRGWinning2KiBV1, - StackedDRGWinning8MiBV1, - StackedDRGWinning512MiBV1, - StackedDRGWinning32GiBV1, - StackedDRGWinning64GiBV1, - StackedDRGWindow2KiBV1, - StackedDRGWindow8MiBV1, - StackedDRGWindow512MiBV1, - StackedDRGWindow32GiBV1, - StackedDRGWindow64GiBV1, - Invalid - } - - enum RegisteredUpdateProof { - StackedDRG2KiBV1, - StackedDRG8MiBV1, - StackedDRG512MiBV1, - StackedDRG32GiBV1, - StackedDRG64GiBV1, - Invalid - } - enum ExtensionKind { - ExtendCommittmentLegacy, - ExtendCommittment - } - - enum SectorSize { - _2KiB, - _8MiB, - _512MiB, - _32GiB, - _64GiB - } - - struct ValidatedExpirationExtension { - uint64 deadline; - uint64 partition; - uint8 sectors; - int64 new_expiration; - } - - struct ExtendExpirationsInner { - ValidatedExpirationExtension[] extensions; - bytes claims; // FIXME this is a BTreeMap on rust - } - - struct PendingBeneficiaryChange { - bytes new_beneficiary; - BigInt new_quota; - uint64 new_expiration; - bool approved_by_beneficiary; - bool approved_by_nominee; - } - - struct BeneficiaryTerm { - BigInt quota; - BigInt used_quota; - uint64 expiration; - } - - struct ActiveBeneficiary { - bytes beneficiary; - BeneficiaryTerm term; - } - - struct RecoveryDeclaration { - uint64 deadline; - uint64 partition; - uint8 sectors; - } - - struct FaultDeclaration { - uint64 deadline; - uint64 partition; - uint8 sectors; - } - - struct TerminationDeclaration { - uint64 deadline; - uint64 partition; - uint8 sectors; - } - - struct SectorClaim { - uint64 sector_number; - uint64[] maintain_claims; - uint64[] drop_claims; - } - - struct ExpirationExtension2 { - uint64 deadline; - uint64 partition; - uint8 sectors; - SectorClaim[] sectors_with_claims; - int64 new_expiration; - } - - struct ExpirationExtension { - uint64 deadline; - uint64 partition; - uint8 sectors; - int64 new_expiration; - } - - struct SectorPreCommitInfoInner { - RegisteredSealProof seal_proof; - uint64 sector_number; - bytes sealed_cid; - int64 seal_rand_epoch; - uint64[] deal_ids; - int64 expiration; - bytes unsealed_cid; - } - - struct SectorPreCommitInfo { - RegisteredSealProof seal_proof; - uint64 sector_number; - bytes sealed_cid; - int64 seal_rand_epoch; - uint64[] deal_ids; - int64 expiration; - bytes unsealed_cid; - } - struct ReplicaUpdateInner { - uint64 sector_number; - uint64 deadline; - uint64 partition; - bytes new_sealed_cid; - bytes new_unsealed_cid; - uint64[] deals; - RegisteredUpdateProof update_proof_type; - bytes replica_proof; - } - - struct ReplicaUpdate { - uint64 sector_number; - uint64 deadline; - uint64 partition; - bytes new_sealed_cid; - uint64 deals; - RegisteredUpdateProof update_proof_type; - bytes replica_proof; - } - - struct ReplicaUpdate2 { - uint64 sector_number; - uint64 deadline; - uint64 partition; - bytes new_sealed_cid; - bytes new_unsealed_cid; - uint64 deals; - RegisteredUpdateProof update_proof_type; - bytes replica_proof; - } - - struct PoStPartition { - uint64 index; - int8 skipped; - } - - struct PoStProof { - RegisteredPoStProof post_proof; - bytes proof_bytes; - } - - struct VestingFunds { - int64 epoch; - BigInt amount; - } - struct SectorDeals { - int64 sector_type; - int64 sector_expiry; - uint64[] deal_ids; - } - - struct DealProposal { - bytes piece_cid; - uint64 piece_size; - bool verified_deal; - bytes client; - bytes provider; - string label; - int64 start_epoch; - int64 end_epoch; - BigInt storage_price_per_epoch; - BigInt provider_collateral; - BigInt client_collateral; - } - - struct ClientDealProposal { - DealProposal proposal; - bytes client_signature; - } - - struct SectorDealData { - bytes commd; - } - - struct CID { - uint8 version; - uint64 codec; - Multihash hash; - } - - struct Multihash { - uint64 code; - uint8 size; - bytes digest; - } - - struct VerifiedDealInfo { - uint64 client; - uint64 allocation_id; - bytes data; - uint64 size; - } - - struct SectorDataSpec { - uint64[] deal_ids; - int64 sector_type; - } - struct FailCode { uint32 idx; uint32 code; @@ -272,28 +35,4 @@ library CommonTypes { // Failure code and index for each failure in batch FailCode[] fail_codes; } - - struct Claim { - // The provider storing the data (from allocation). - uint64 provider; - // The client which allocated the DataCap (from allocation). - uint64 client; - // Identifier of the data committed (from allocation). - bytes data; - // The (padded) size of data (from allocation). - uint64 size; - // The min period after term_start which the provider must commit to storing data - int64 term_min; - // The max period after term_start for which provider can earn QA-power for the data - int64 term_max; - // The epoch at which the (first range of the) piece was committed. - int64 term_start; - // ID of the provider's sector in which the data is committed. - uint64 sector; - } - struct ClaimTerm { - uint64 provider; - uint64 claim_id; - int64 term_max; - } } diff --git a/contracts/v0.8/types/MarketTypes.sol b/contracts/v0.8/types/MarketTypes.sol index f31348a7..2fd2a608 100644 --- a/contracts/v0.8/types/MarketTypes.sol +++ b/contracts/v0.8/types/MarketTypes.sol @@ -99,11 +99,30 @@ library MarketTypes { } struct PublishStorageDealsParams { - CommonTypes.ClientDealProposal[] deals; + ClientDealProposal[] deals; } struct PublishStorageDealsReturn { uint64[] ids; bytes valid_deals; } + + struct DealProposal { + bytes piece_cid; + uint64 piece_size; + bool verified_deal; + bytes client; + bytes provider; + string label; + int64 start_epoch; + int64 end_epoch; + BigInt storage_price_per_epoch; + BigInt provider_collateral; + BigInt client_collateral; + } + + struct ClientDealProposal { + DealProposal proposal; + bytes client_signature; + } } diff --git a/contracts/v0.8/types/MinerTypes.sol b/contracts/v0.8/types/MinerTypes.sol index 417dbacb..a23c9d8a 100644 --- a/contracts/v0.8/types/MinerTypes.sol +++ b/contracts/v0.8/types/MinerTypes.sol @@ -63,7 +63,7 @@ library MinerTypes { } struct GetVestingFundsReturn { - CommonTypes.VestingFunds[] vesting_funds; + VestingFunds[] vesting_funds; } struct ChangeBeneficiaryParams { @@ -73,8 +73,8 @@ library MinerTypes { } struct GetBeneficiaryReturn { - CommonTypes.ActiveBeneficiary active; - CommonTypes.PendingBeneficiaryChange proposed; + ActiveBeneficiary active; + PendingBeneficiaryChange proposed; } struct ChangeWorkerAddressParams { @@ -105,4 +105,35 @@ library MinerTypes { struct WithdrawBalanceReturn { bytes amount_withdrawn; } + + struct VestingFunds { + int64 epoch; + BigInt amount; + } + struct BeneficiaryTerm { + BigInt quota; + BigInt used_quota; + uint64 expiration; + } + + struct ActiveBeneficiary { + bytes beneficiary; + BeneficiaryTerm term; + } + + struct PendingBeneficiaryChange { + bytes new_beneficiary; + BigInt new_quota; + uint64 new_expiration; + bool approved_by_beneficiary; + bool approved_by_nominee; + } + + enum SectorSize { + _2KiB, + _8MiB, + _512MiB, + _32GiB, + _64GiB + } } diff --git a/contracts/v0.8/types/MultisigTypes.sol b/contracts/v0.8/types/MultisigTypes.sol deleted file mode 100644 index c0c2b094..00000000 --- a/contracts/v0.8/types/MultisigTypes.sol +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * (c) 2022 Zondax AG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ********************************************************************************/ -// -// DRAFT!! THIS CODE HAS NOT BEEN AUDITED - USE ONLY FOR PROTOTYPING - -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.17; - -import "../cbor/BigIntCbor.sol"; -import "./CommonTypes.sol"; - -/// @title Filecoin multisig actor types for Solidity. -/// @author Zondax AG -library MultisigTypes { - uint constant ProposeMethodNum = 1696838335; - uint constant ApproveMethodNum = 1289044053; - uint constant CancelMethodNum = 3365893656; - uint constant AddSignerMethodNum = 3028530033; - uint constant RemoveSignerMethodNum = 21182899; - uint constant SwapSignerMethodNum = 3968117037; - uint constant ChangeNumApprovalsThresholdMethodNum = 3375931653; - uint constant LockBalanceMethodNum = 1999470977; - uint constant UniversalReceiverHookMethodNum = 3726118371; - - struct ProposeParams { - bytes to; - BigInt value; - uint64 method; - bytes params; - } - - struct ProposeReturn { - /// TxnID is the ID of the proposed transaction. - int64 txn_id; - /// Applied indicates if the transaction was applied as opposed to proposed but not applied - /// due to lack of approvals. - bool applied; - /// Code is the exitcode of the transaction, if Applied is false this field should be ignored. - uint32 code; - /// Ret is the return value of the transaction, if Applied is false this field should - /// be ignored. - bytes ret; - } - - struct TxnIDParams { - int64 id; - /// Optional hash of proposal to ensure an operation can only apply to a - /// specific proposal. - bytes proposal_hash; - } - - struct ApproveReturn { - /// Applied indicates if the transaction was applied as opposed to proposed but not applied - /// due to lack of approvals - bool applied; - /// Code is the exitcode of the transaction, if Applied is false this field should be ignored. - uint32 code; - /// Ret is the return value of the transaction, if Applied is false this field should - /// be ignored. - bytes ret; - } - - struct AddSignerParams { - bytes signer; - bool increase; - } - - struct RemoveSignerParams { - bytes signer; - bool decrease; - } - - struct SwapSignerParams { - bytes from; - bytes to; - } - - struct ChangeNumApprovalsThresholdParams { - uint64 new_threshold; - } - - struct LockBalanceParams { - int64 start_epoch; - int64 unlock_duration; - BigInt amount; - } -} diff --git a/contracts/v0.8/types/PowerTypes.sol b/contracts/v0.8/types/PowerTypes.sol index 5ea06735..38d19791 100644 --- a/contracts/v0.8/types/PowerTypes.sol +++ b/contracts/v0.8/types/PowerTypes.sol @@ -35,7 +35,7 @@ library PowerTypes { struct CreateMinerParams { bytes owner; bytes worker; - CommonTypes.RegisteredPoStProof window_post_proof_type; + RegisteredPoStProof window_post_proof_type; bytes peer; bytes[] multiaddrs; } @@ -51,4 +51,18 @@ library PowerTypes { BigInt raw_byte_power; bool meets_consensus_minimum; } + + enum RegisteredPoStProof { + StackedDRGWinning2KiBV1, + StackedDRGWinning8MiBV1, + StackedDRGWinning512MiBV1, + StackedDRGWinning32GiBV1, + StackedDRGWinning64GiBV1, + StackedDRGWindow2KiBV1, + StackedDRGWindow8MiBV1, + StackedDRGWindow512MiBV1, + StackedDRGWindow32GiBV1, + StackedDRGWindow64GiBV1, + Invalid + } } diff --git a/contracts/v0.8/types/VerifRegTypes.sol b/contracts/v0.8/types/VerifRegTypes.sol index 7b8d2781..6a74b853 100644 --- a/contracts/v0.8/types/VerifRegTypes.sol +++ b/contracts/v0.8/types/VerifRegTypes.sol @@ -39,7 +39,7 @@ library VerifRegTypes { } struct GetClaimsReturn { CommonTypes.BatchReturn batch_info; - CommonTypes.Claim[] claims; + Claim[] claims; } struct AddVerifierClientParams { bytes addr; @@ -74,8 +74,9 @@ library VerifRegTypes { CommonTypes.BatchReturn results; } struct ExtendClaimTermsParams { - CommonTypes.ClaimTerm[] terms; + ClaimTerm[] terms; } + struct UniversalReceiverParams { /// Asset type uint32 type_; @@ -91,4 +92,29 @@ library VerifRegTypes { // IDs of new allocations created. uint64[] new_allocations; } + + struct ClaimTerm { + uint64 provider; + uint64 claim_id; + int64 term_max; + } + + struct Claim { + // The provider storing the data (from allocation). + uint64 provider; + // The client which allocated the DataCap (from allocation). + uint64 client; + // Identifier of the data committed (from allocation). + bytes data; + // The (padded) size of data (from allocation). + uint64 size; + // The min period after term_start which the provider must commit to storing data + int64 term_min; + // The max period after term_start for which provider can earn QA-power for the data + int64 term_max; + // The epoch at which the (first range of the) piece was committed. + int64 term_start; + // ID of the provider's sector in which the data is committed. + uint64 sector; + } } diff --git a/contracts/v0.8/utils/Actor.sol b/contracts/v0.8/utils/Actor.sol index 1ba6b3f8..5b477e60 100644 --- a/contracts/v0.8/utils/Actor.sol +++ b/contracts/v0.8/utils/Actor.sol @@ -41,7 +41,10 @@ library Actor { bool read_only ) internal returns (bytes memory) { // Address in bytes format only start by 0, 1, 2, 3 or 4 - require(actor_address[0] == 0x00 || actor_address[0] == 0x01 || actor_address[0] == 0x02 || actor_address[0] == 0x03 || actor_address[0] == 0x04, "actor_address address should be bytes format"); + require( + actor_address[0] == 0x00 || actor_address[0] == 0x01 || actor_address[0] == 0x02 || actor_address[0] == 0x03 || actor_address[0] == 0x04, + "actor_address address should be bytes format" + ); (bool success, bytes memory data) = address(CALL_ACTOR_ADDRESS).delegatecall( abi.encode(uint64(method_num), amount, read_only ? READ_ONLY_FLAG : DEFAULT_FLAG, codec, raw_request, actor_address) diff --git a/package.json b/package.json index 01542a8f..afd0fca3 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "directories": { "doc": "docs" }, - "scripts": {}, + "scripts": { + "format": "prettier --write contracts" + }, "repository": { "type": "git", "url": "git+https://github.com/Zondax/filecoin-solidity.git" diff --git a/testing/Cargo.toml b/testing/Cargo.toml index 1648b0b7..b1679e2a 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -27,11 +27,10 @@ prettytable-rs = "0.10" fil_actors_runtime = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230206-pre-rc.6" } fil_actor_eam = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230206-pre-rc.6" } fil_actor_datacap = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230206-pre-rc.6" } -fil_actor_multisig = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230206-pre-rc.6" } fil_actor_init = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230206-pre-rc.6" } fil_actor_miner = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230206-pre-rc.6" } fil_actor_evm = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230206-pre-rc.6" } fvm_actor_utils = { version = "4.0.0" } frc46_token = { version = "4.0.0" } -frc42_dispatch = { version = "3.0.1-alpha.1" } \ No newline at end of file +frc42_dispatch = { version = "3.0.1-alpha.1" } diff --git a/testing/tests/multisig.rs b/testing/tests/multisig.rs deleted file mode 100644 index 02e56ca0..00000000 --- a/testing/tests/multisig.rs +++ /dev/null @@ -1,198 +0,0 @@ -use bls_signatures::Serialize; -use fil_actor_eam::Return; -use fil_actor_evm::Method as EvmMethods; -use fil_actor_init::ExecReturn; -use fil_actors_runtime::{runtime::builtins, EAM_ACTOR_ADDR, INIT_ACTOR_ADDR}; -use fvm::executor::{ApplyKind, Executor}; -use fvm::state_tree::ActorState; -use fvm_integration_tests::dummy::DummyExterns; -use fvm_integration_tests::tester::Account; -use fvm_ipld_encoding::strict_bytes; -use fvm_ipld_encoding::CborStore; -use fvm_ipld_encoding::RawBytes; -use fvm_shared::address::Address; -use fvm_shared::econ::TokenAmount; -use fvm_shared::message::Message; -use multihash::Code; -use rand_core::OsRng; -use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize}; - -use testing::setup; -use testing::GasResult; - -const WASM_COMPILED_PATH: &str = "../build/v0.8/tests/MultisigApiTest.bin"; - -#[derive(SerdeSerialize, SerdeDeserialize)] -#[serde(transparent)] -pub struct CreateExternalParams(#[serde(with = "strict_bytes")] pub Vec); - -#[test] -fn multisig_tests() { - println!("Testing solidity API"); - - let mut gas_result: GasResult = vec![]; - let (mut tester, manifest) = setup::setup_tester(); - - let sender: [Account; 1] = tester.create_accounts().unwrap(); - - println!("Sender address id"); - dbg!(&sender[0].0); - println!("Sender address bytes"); - dbg!(hex::encode(&sender[0].1.to_bytes())); - /*********************************************** - * - * Instantiate Account Actor with a BLS address - * - ***********************************************/ - - let bls_private_key = bls_signatures::PrivateKey::generate(&mut OsRng); - let worker = Address::new_bls(&bls_private_key.public_key().as_bytes()).unwrap(); - - let state_tree = tester.state_tree.as_mut().unwrap(); - let assigned_addr = state_tree.register_new_address(&worker).unwrap(); - let state = fvm::account_actor::State { address: worker }; - - let cid = state_tree - .store() - .put_cbor(&state, Code::Blake2b256) - .unwrap(); - - let actor_state = ActorState { - // CID of Accounts actor. You get this as output from builtin-actors compiling process - code: *manifest - .code_by_id(builtins::Type::Multisig as u32) - .unwrap(), - state: cid, - sequence: 0, - balance: TokenAmount::from_atto(10000), - delegated_address: Some(worker), - }; - - state_tree.set_actor(assigned_addr, actor_state).unwrap(); - // Instantiate machine - tester.instantiate_machine(DummyExterns).unwrap(); - - let executor = tester.executor.as_mut().unwrap(); - - /************************** - * - * Machine instantiated - * - **************************/ - - println!("Calling init actor (EVM)"); - - let evm_bin = setup::load_evm(WASM_COMPILED_PATH); - - let constructor_params = CreateExternalParams(evm_bin); - - let message = Message { - from: sender[0].1, - to: EAM_ACTOR_ADDR, - gas_limit: 1000000000, - method_num: 4, - sequence: 0, - params: RawBytes::serialize(constructor_params).unwrap(), - ..Message::default() - }; - - let res = executor - .execute_message(message, ApplyKind::Explicit, 100) - .unwrap(); - - assert_eq!(res.msg_receipt.exit_code.value(), 0); - - let exec_return: Return = RawBytes::deserialize(&res.msg_receipt.return_data).unwrap(); - - println!("Contract actor id"); - dbg!(&exec_return.actor_id); - let contract_actor_id = exec_return.actor_id; - - println!("Create Multisig actor for solidity contract to interact with"); - - let constructor_params = fil_actor_multisig::ConstructorParams { - num_approvals_threshold: 1, - signers: vec![ - Address::new_id(sender[0].0), - Address::new_id(contract_actor_id), - ], - start_epoch: 1670873233, - unlock_duration: 1670873234, - }; - - let exec_params = fil_actor_init::ExecParams { - // CID of MultiSig actor. You get this as output from builtin-actors compiling process - code_cid: *manifest - .code_by_id(builtins::Type::Multisig as u32) - .unwrap(), - constructor_params: RawBytes::serialize(constructor_params).unwrap(), - }; - - let message = Message { - from: sender[0].1, - to: INIT_ACTOR_ADDR, - gas_limit: 1000000000, - method_num: 2, - sequence: 1, - params: RawBytes::serialize(exec_params).unwrap(), - ..Message::default() - }; - - let res = executor - .execute_message(message, ApplyKind::Explicit, 100) - .unwrap(); - - let exec_return: ExecReturn = RawBytes::deserialize(&res.msg_receipt.return_data).unwrap(); - - println!("Multisig actor address bytes"); - dbg!(hex::encode(&exec_return.id_address.to_bytes())); - - assert_eq!(res.msg_receipt.exit_code.value(), 0); - - println!("Calling `propose`"); - - let message = Message { - from: sender[0].1, - to: Address::new_id(contract_actor_id), - gas_limit: 1000000000, - method_num: EvmMethods::InvokeContract as u64, - sequence: 2, - params: RawBytes::new(hex::decode("590164C0987260000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002006600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000457000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000000200640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap()), - ..Message::default() - }; - - let res = executor - .execute_message(message, ApplyKind::Explicit, 100) - .unwrap(); - - gas_result.push(("propose".into(), res.msg_receipt.gas_used)); - // FIXME - assert_eq!(res.msg_receipt.exit_code.value(), 33); - - println!("Calling `add_signer`"); - - let message = Message { - from: sender[0].1, - to: Address::new_id(contract_actor_id), - gas_limit: 1000000000, - method_num: EvmMethods::InvokeContract as u64, - sequence: 3, - params: RawBytes::new(hex::decode("5901041339400D00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000200670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020064000000000000000000000000000000000000000000000000000000000000").unwrap()), - ..Message::default() - }; - - let res = executor - .execute_message(message, ApplyKind::Explicit, 100) - .unwrap(); - - gas_result.push(("add_signer".into(), res.msg_receipt.gas_used)); - // FIXME - assert_eq!(res.msg_receipt.exit_code.value(), 33); - - // FIXME: As propose is failing, we cannot execute the rest of the methods... - - let table = testing::create_gas_table(gas_result); - testing::save_gas_table(&table, "multisig"); - - table.printstd(); -} diff --git a/testing/tests/precompiles.rs b/testing/tests/precompiles.rs index 09324f4b..8f7ecc9c 100644 --- a/testing/tests/precompiles.rs +++ b/testing/tests/precompiles.rs @@ -214,26 +214,6 @@ fn precompiles_tests() { assert_eq!(res.msg_receipt.exit_code.value(), 0); assert_eq!(hex::encode(res.msg_receipt.return_data.bytes()), "586000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000016040adafea492d9c6733ae3d56b7ed1adb60692c98bc500000000000000000000"); - println!("Calling `get_ripemd160_hash`"); - - let message = Message { - from: sender[0].1, - to: Address::new_id(contract_actor_id), - gas_limit: 1000000000, - method_num: EvmMethods::InvokeContract as u64, - sequence: 4, - params: RawBytes::new(hex::decode("586417C9F02D000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000071212121212344400000000000000000000000000000000000000000000000000").unwrap()), - ..Message::default() - }; - - let res = executor - .execute_message(message, ApplyKind::Explicit, 100) - .unwrap(); - - gas_result.push(("get_ripemd160_hash".into(), res.msg_receipt.gas_used)); - assert_eq!(res.msg_receipt.exit_code.value(), 0); - assert_eq!(hex::encode(res.msg_receipt.return_data.bytes()), "5860000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000001b8cf5bc0e542a1620184208f78c0cff516cce96"); - println!("Calling `resolve_eth_address`"); let message = Message { @@ -241,7 +221,7 @@ fn precompiles_tests() { to: Address::new_id(contract_actor_id), gas_limit: 1000000000, method_num: EvmMethods::InvokeContract as u64, - sequence: 5, + sequence: 4, params: RawBytes::new(hex::decode("58640D6B2CE40000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001476C499BE8821B5B9860144D292FFF728611BFD1A000000000000000000000000").unwrap()), ..Message::default() };