filecoin-project / filecoin-solidity

Filecoin Solidity API Library
Other
17 stars 11 forks source link

Getting `ActorNotFound()` Error whenever calling market api to check deals #17

Closed EmanHerawy closed 11 months ago

EmanHerawy commented 11 months ago

Hey guys I'm hacking in open data Hack. Whenever I try to check deals from my smart contract I got ActorNotFound() error. I create the below test function to make sure it's not related to my logic. What I tried ?

  1. I tried many deal ids from filFox deal list
  2. I tried each of these calls alone [getDealClient,getDealTotalPrice, getDealProvider ,getDealDataCommitment] But I got the same error.

 function dealCheck(uint64 dealId) public returns(uint64 clientRet, uint64 providerRet, CommonTypes.BigInt  memory totalPrice, CommonTypes.FilActorId  clientActor , MarketTypes.GetDealDataCommitmentReturn memory commitmentRet) {

        commitmentRet = MarketAPI
            .getDealDataCommitment(dealId);

              // get dealer (bounty hunter client)
          clientRet = MarketAPI.getDealClient(dealId);
          totalPrice = MarketAPI.getDealTotalPrice(dealId);
           clientActor = CommonTypes.FilActorId.wrap(clientRet);
         providerRet = MarketAPI.getDealProvider(dealId);

   }

Unfortunately the error desc is not much helpful and by tracing the code I found

  1. it's throwing in the below function in the return function payload

    
    
    function callByIDReadOnly(CommonTypes.FilActorId target, uint256 method_num, uint64 codec, bytes memory raw_request) internal view returns (bytes memory) {
        function(CommonTypes.FilActorId, uint256, uint64, bytes memory, uint256, bool) internal view returns (bytes memory) callFn;
        function(CommonTypes.FilActorId, uint256, uint64, bytes memory, uint256, bool) internal returns (bytes memory) helper = callByID;
        assembly {
            callFn := helper
        }
        return callFn(target, method_num, codec, raw_request, 0, true); //<----------- here 
    }


2. It's only called [here](https://github.com/filecoin-project/filecoin-solidity/blob/75d000db5a4b62c7282e9cbea058147b831c9c0f/contracts/v0.8/utils/Actor.sol#L148) 

Your help is much appreciated 
EmanHerawy commented 11 months ago

I created this repo for this issue

wertikalk commented 11 months ago

Hi @EmanHerawy,

the forge script command should be run with the --broadcast --skip-simulation flags.

Additionally, something that can be useful is to check out the fevm-foundry-kit (section about common errors and possible resolutions).

Best of luck in the hackathon! :)

EmanHerawy commented 11 months ago

Thanks @bojinovic for your help. I tried to run it with --broadcast --skip-simulation flags but I got the same result Screenshot from 2023-09-26 19-18-14

wertikalk commented 11 months ago

I am not sure exactly why the forge-script is doing this, but I suspect it has to do with the Filecoin's Deffered execution model.

As a workaround, you could use forge-create to deploy the contract and forge-cast to call the method. Modified contract would look something like this:

contract DealChecker  {

  function test() public view returns (uint){
    dealCheck(137671);
    return 1301; //Note: you could unpack and return any value from the `dealCheck` call
  }

  //Note: this function was modified to be `view`
  function dealCheck(uint64 dealId) public view returns(uint64 clientRet, uint64 providerRet, CommonTypes.BigInt  memory totalPrice, CommonTypes.FilActorId  clientActor , MarketTypes.GetDealDataCommitmentReturn memory commitmentRet) {

    commitmentRet = MarketAPI.getDealDataCommitment(dealId);
    clientRet = MarketAPI.getDealClient(dealId);
    totalPrice = MarketAPI.getDealTotalPrice(dealId);
    clientActor = CommonTypes.FilActorId.wrap(clientRet);
    providerRet = MarketAPI.getDealProvider(dealId);

  }
}

And the commands would be:

  1. forge create DealChecker --rpc-url $CALIBRATIONNET_RPC_URL --private-key $PRIVATE_KEY --gas-limit 1000000000 --evm-version paris
    • Note: foundry will report that the contract deployment has failed, but if you check the filfox explorer you will see that the transaction was successful. Then, expand on the latest transaction and go to the Others section (example), scroll to the bottom and you will see the "EthAddress" of the deployed contract.
  2. cast call <ContractEthAddress> "test()" --rpc-url $CALIBRATIONNET_RPC_URL --private-key $PRIVATE_KEY

Also, be sure to wait longer than the block time between executing those commands - around 1 minute should do the job.

EmanHerawy commented 11 months ago

Thank you @bojinovic for highlighting this issue with foundry. I think you are right because I was even unable to ship my contracts with foundry while by moving to hardhat the contracts were deployed and everything went well. Thank you