FVM — Custody Your Miner’s Owner to Native Actor through peggy

Web3 Eye
CoinsBench
Published in
7 min readDec 3, 2022

--

From Hack FEVM to the end of the first live demo, Peggy can finally do something. In this article, we will describe the steps of custody Miner’s Owner to Native Actor through Peggy, and withdrawing the balance of Miner to Native Actor by invocation of the method of Native Actor.

Since the m2-native feature is disabled on the latest wallaby testnet, the wallaby testnet can only deploy FEVM contracts and does not support the deployment of FVM contracts, so we still use working commits to building local testnet. In the future, Peggy will align each dependency repository version to the latest stable branch. At the time of writing this article, the commits of each repository are as follows:

https://github.com/NpoolFilecoin/fil-peggy.git

e8a34897de448f23fff37454fcc547a5803ad9ad

https://github.com/filecoin-project/lotus.git

1a06485a8c0463ea6a7a0604d0ad421bdcc2c953

https://github.com/kikakkz/fvm-actor-example.git

ce09ee345e0ca8f6bdbc441840138d653d29e616

1 Peggy’s application architecture

The ultimate goal of Peggy is to realize a management tool covering console, desktop, web, mobile application, and dApp, to provide Filecoin Miner with convenient hosting methods and tools suitable for different scenarios. The purpose of Peggy is to provide unified protocols and tools. Peggy will not try to be a lending platform. Lending platforms and lending networks are Peggy’s application scenarios, but not Peggy’s goals.

When we execute Peggy we will see the following output

This is Peggy’s current implementation, we currently implement Peggy’s cli version based on the clap framework. In parallel with the cli in the future, there will be desktop and service versions, as well as dApp version that can be packaged and released to the browser plugin market, and a mobile app version that can be packaged and released to the application market. The reason why the mobile app version is considered is that the adaptability of dApps on mobile browsers has so far failed to achieve a good application experience. The app version is also a dApp, but it is packaged into respective application software packages based on different platforms.

2 Custody Miner to Native Actor through Peggy

Current implemented functions of the Peggy client mainly include custody prototypes for miners. Execute the Peggy cli, we will see the following output

We have created Miner, created Native Actor, changed the Owner of Miner to Native Actor, Native Actor took over the miner, and withdraw the balance of the miner to Native Actor. We implemented Change Worker, but because Change Worker needs to wait for a long delay to take effect when we verify Change Worker, we need to wait for a long time to see the modification take effect.

2.1 Create a miner

peggy cli create-miner

Since we are creating a new miner, we don’t have a saved runner, we need to create a new runner. Since we cannot directly create a miner from a Native Actor, we will first use the BLS account as the owner to create a new miner. You can choose to create a new BLS account or use an existing BLS account. Since the balance of the newly created BLS account is 0, we need to set up a fund account, and Peggy will automatically transfer 0.1FIL from the fund account to the newly created account as the gas for the new account. The best practice in production is that the fund account should not have too much balance. Although Peggy can ensure that these private keys will not be uploaded, Peggy still needs to broadcast the signature result to the chain through the networked rpc node, so the fund account only needs to keep a small amount It can be used as the FIL fee of gas. The Peggy cli needs to connect to the rpc broadcast signature message. The rpc node can be the lotus service that provides the bearer token, or it can be a restful API that hides the lotus and bearer token behind the proxy service. All of Peggy’s signatures are offline signatures, and there is no need to obtain the store information in the lotus wallet.

After the account is completed, we can create the Miner after confirming the Miner creation information again

After the Miner is successfully created, we need to remember the path where the runner file is saved and the created Miner ID for use in subsequent steps.

2.2 Creating Native Actors

peggy cli create-actor

Since the subsequent steps will be based on the previous steps, we need to select the runner saved when creating the miner as input.

Enter the contract code repository information to be deployed and created, and Peggy will automatically download the code warehouse, compile the contract code, deploy the contract, and then create a contract instance, which will be used as the Owner of the Miner created in the previous step in the next step.

Similarly, we need to remember the created Actor ID and the runner save path containing the created Actor.

2.3 Change miner Owner to Actor ID

peggy cli change-owner

Here we need to select the runner save file that contains the contract after the contract was created in the previous step.

2.4 Invoke the contract method to approve miner Owner

peggy cli custody-miner

After the execution is completed, the Owner of the Miner becomes the ActorID. At this time, the Miner can no longer be operated through the original Owner Account, and all operations of the Miner can only be completed by invocation the contract.

3 Withdraw the balance in Miner to Native Actor

On the one hand, we verify that the above operation has entrusted the Miner to the Native Actor by withdrawing the balance of the Miner to the Native Actor. On the other hand, we verify the ability of the Native Actor to manage the funds on the Miner through the withdrawal operation.

Since the Miner we just created is only the account number and ID on the chain, we have not run a miner node for the Miner, so the Miner does not have the ability to produce blocks, but we can charge the amount to the Miner account to simulate the block production behavior, after all, all we need is a balance in the Miner, which can and can only be withdrawn by its Owner Actor ID.

Before execution, we check the balance of Miner and the balance of Actor

peggy cli withdraw-miner

After the execution is completed, we have extracted 122 FIL from the Miner to the Owner Actor, check balance again.

4 Open Issues

Q1: we know we cannot create a miner through a native actor, but we can change the miner’s owner to a native actor. Is it a design or only an implementation flaw?

Q2: we know we cannot use a native actor as a miner’s worker currently, is it possible to use a native actor as a miner’s work in the future?

Q3: how about issue #835? will we be able to detect method 0 invocation in native actor code? will we be able to get who sent to the native actor?

Q4: do you have any suggestion about the security if we implement all miner’s owner functionalities with a native actor?

Q5: Is self-destruct the only way to destroy an actor? Does it mean that if the actor does not implement self_destruct, then it won’t be deleted forever?

5 What do we do next

We have some plans for the next step, which can be found at https://github.com/NpoolFilecoin/fil-peggy.git. Of course, if you feel that what we are doing is valuable, it will be more grateful to give us a star.

All functionalities to manage miner

Detect deposit to smart contract address inside the smart contract

Mining reward distribution according to the amount ratio

NFT minting and transferring of the deposited amount

Upgrade governance process

6 Finally… about Peggy’s Zhao KK and his team

Well, it’s a bit embarrassing to say, but Zhao KK and his team have never done anything amazing before. They never thought (and certainly no one else did) that they were genius programmers and genius teams. Peggy originated from solving our own problems, and won the award by chance. If it is succeeds, it will not be based on genius ideas and genius realizations, but on the persistence of doing things completely and only doing things of value. As for the future, we really don’t know and really have no concept whether doing what we think are valuable will bring material rewards and success in the secular sense.

--

--