Fujicracy / fuji-v2

Cross-chain money market aggregator
https://fuji-v2-frontend.vercel.app
15 stars 10 forks source link

Update signing process after permits with router actions #477

Open 0xdcota opened 1 year ago

0xdcota commented 1 year ago

A new argument "actionArgsHash" was added to the struct of the permit

struct Permit {
    uint256 chainid;
    address owner;
    address operator;
    address receiver;
    uint256 amount;
    uint256 nonce;
    uint256 deadline;
    bytes32 actionArgsHash;
  }

In where:

actionArgsHash = keccak256(abi.encode(IRouter.Actions[] memory, bytes[] memory))

However: the IRouter.Action.PermitWithdraw, and IRouter.Action.PermitBorrow in the hash need to be substitute with the "ZeroPermitArgs"

Where "ZeroPermitArgs" is defined as follows:

function getZeroPermitEncodedArgs(
    address vault,
    address owner,
    address receiver,
    uint256 amount
  )
    public
    view
    returns (bytes memory)
  {
    bytes32 ZERO_BYTES32 = 0x0000000000000000000000000000000000000000000000000000000000000000;
    return abi.encode(vault, owner, receiver, amount, 0, 0, ZERO_BYTES32, ZERO_BYTES32);
  }

At the smart contract level the actionArgsHash is constructed inside the router.internalBundle and therefore it cannot be faked.

This was implemented in pr #446 , and require the SDK to be updated appropriately.