filecoin-project / testnet-wallaby

Meta info about the Wallaby testnet for FVM developers
Apache License 2.0
20 stars 4 forks source link

Lotus release hand-off: FVM Selenium (r2) #4

Closed maciejwitowski closed 2 years ago

maciejwitowski commented 2 years ago

Request

Please reset the Wallaby testnet with the following Lotus release.

Git reference

https://github.com/filecoin-project/lotus/tree/experimental/fvm-m2 Commit: https://github.com/filecoin-project/lotus/commit/c54145e337b8e21e22ea9bb45006122d0e13aa49

Features

This release adds multiple functionalities on top of the new EVM actor introduced in Talc release

Deployment of a simple smart contract can be tested with the attached example (Solidity source, and EVM compiled bytecode)

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.25 <= 0.8.15;

contract SimpleCoin {
        mapping (address => uint) balances;

        event Transfer(address indexed _from, address indexed _to, uint256 _value);

        constructor() {
                balances[tx.origin] = 10000;
        }

        function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
                if (balances[msg.sender] < amount) return false;
                balances[msg.sender] -= amount;
                balances[receiver] += amount;
                emit Transfer(msg.sender, receiver, amount);
                return true;
        }

        function getBalanceInEth(address addr) public view returns(uint){
                return getBalance(addr) * 2;
        }

        function getBalance(address addr) public view returns(uint) {
                return balances[addr];
        }
}

Verification tests

  1. Uncompress the below bytecode.
  2. Deploy the smart contract.
⟩ ./lotus chain create-evm-actor ~/simplecoin.bin
sending message...
waiting for message to execute...
ID Address: t01001
Robust Address: t2fzzgpskwwzddllhrf35scsuqkrszrrnhmlesuwa
Return: gkMA6QdVAi5yZ8lWtkY1rPEu+yFKkFRlmMWn
  1. Invoke the smart contract with two different addresses (owner and non owner, you will find they have different balances).
⟩ ./lotus chain invoke-evm-actor t01001 f8b2cb4f 000000000000000000000000ff00000000000000000000000000000000000064
sending message...
waiting for message to execute...
0000000000000000000000000000000000000000000000000000000000002710

⟩ ./lotus chain invoke-evm-actor t01001 f8b2cb4f 000000000000000000000000ff00000000000000000000000000000000000065
sending message...
waiting for message to execute...
0000000000000000000000000000000000000000000000000000000000000000

Compiled EVM bytecode

simplecoin.bin.zip

f8-ptrk commented 2 years ago

@maciejwitowski

please adjust

- Lotus commit: [94895fbdf0f7a970e3c4a1a111172d7ddfc50e12](https://github.com/filecoin-project/lotus/commit/94895fbdf0f7a970e3c4a1a111172d7ddfc50e12)

i am not really sure what to link

in the readme when our PR is merged into mainline

thanks

jimpick commented 2 years ago

The "verification test" isn't passing for me using wallabynet:

$ ./lotus version
Daemon:  1.17.1-dev+wallabynet+git.bab009bb7.dirty+api1.5.0
Local: lotus version 1.17.1-dev+wallabynet+git.bab009bb7.dirty

$ ./lotus chain list --count=1 --height=0
0: (Sep  6 15:22:45) [ bafy2bzaceaxkepuvjenqk7go7iemehzffdb3bv46ib4njz2je6hp5poyysa46: t00, ]

$ md5sum ../simplecoin.bin 
dd1a45822c513b9e41973f8cb85cdd87  ../simplecoin.bin

$ ./lotus chain create-evm-actor ../simplecoin.bin 
sending message...
waiting for message to execute...
ID Address: t01048
Robust Address: t24p5lu5ctl6i4kurbdf2sqz2a7xw3ix4xzbyb3bi
Return: gkMAmAhVAuP6unRTX5HFUiEZdShnQP3ttF+X

$ ./lotus chain invoke-evm-actor t01048 f8b2cb4f 000000000000000000000000ff00000000000000000000000000000000000064
sending message...
waiting for message to execute...
0000000000000000000000000000000000000000000000000000000000000000

The expected result is 0000000000000000000000000000000000000000000000000000000000002710

I'm seeing the same thing via the GLIF API.

It does seem to work on my standalone demo that has it's own localnet:

https://observablehq.com/@jimpick/fvm-actor-code-playground-simplecoin-evm-contract?collection=@jimpick/filecoin-virtual-machine

maciejwitowski commented 2 years ago

@f8-ptrk any idea why ^ is different than on localnet?

f8-ptrk commented 2 years ago

@jimpick @maciejwitowski

i am not sure whats going on - but jim is running on wallaby. see the genesis cid

i deployed a few - and only t010048 seems to make problems - t01002 is the original deploy to test the network i did after genesis

[silicon-0] wallaby-keep-alive [~]$ md5sum genesis/simplecoin.bin 
dd1a45822c513b9e41973f8cb85cdd87  genesis/simplecoin.bin

[silicon-0] wallaby-keep-alive [~]$ lotus chain invoke-evm-actor t01048 f8b2cb4f 000000000000000000000000ff00000000000000000000000000000000000064
sending message...
waiting for message to execute...
0000000000000000000000000000000000000000000000000000000000000000

[silicon-0] wallaby-keep-alive [~]$ lotus chain invoke-evm-actor t01002 f8b2cb4f 000000000000000000000000ff00000000000000000000000000000000000064
sending message...
waiting for message to execute...
0000000000000000000000000000000000000000000000000000000000002710

[silicon-0] wallaby-keep-alive [~]$ lotus chain create-evm-actor ~/genesis/simplecoin.bin
sending message...
waiting for message to execute...
ID Address: t01058
Robust Address: t2reiegpmf3wubxftnxrbztxp6pnqc2jys2z543oa
Return: gkMAoghVAokQQz2F3agblm28Q5nd/ntgLScS

[silicon-0] wallaby-keep-alive [~]$ lotus chain invoke-evm-actor t01058 f8b2cb4f 000000000000000000000000ff00000000000000000000000000000000000064
sending message...
waiting for message to execute...
0000000000000000000000000000000000000000000000000000000000002710

[silicon-0] wallaby-keep-alive [~]$ lotus chain create-evm-actor ~/genesis/simplecoin.bin
sending message...
waiting for message to execute...
ID Address: t01059
Robust Address: t2pd3jtjgcdzxxfkpp77isyvq4cqerpgiu22nxdli
Return: gkMAowhVAnj2maTCHm9yqe//0SxWHBQJF5kU

[silicon-0] wallaby-keep-alive [~]$ lotus chain invoke-evm-actor t01059 f8b2cb4f 000000000000000000000000ff00000000000000000000000000000000000064
sending message...
waiting for message to execute...
0000000000000000000000000000000000000000000000000000000000002710
maciejwitowski commented 2 years ago

Hm, @jimpick, you are fetching the balance for ID address t0100 (...0064). Are you sure this is your address on Wallaby?

raulk commented 2 years ago

It most certainly isn't because t100 is very likely to be the account actor of the first miner in the network :-)

f8-ptrk commented 2 years ago

this call is a problem - i am not sure if jim really deployed what he says he did - but the return would be wrong if its the test actor

./lotus chain invoke-evm-actor t01048 f8b2cb4f 000000000000000000000000ff00000000000000000000000000000000000064

maciejwitowski commented 2 years ago

The thing is that this ^ command says: "give me the balance of address t100", which will be all zeros unless t100 was the actor who deployed t01048 in the first place. So when using Wallaby, most users (except the 1st one who deployed their contract after network reset) shouldn't pass ...0064 as the parameter, but their own hex-encoded ID address.

f8-ptrk commented 2 years ago

oh ok!

then it's interesting that i get the expected values - because it's the same address deploying as the first time? i deployed like 3 or 4 times and they all look fine with the expected return vals

maciejwitowski commented 2 years ago

This is because you were probably the 1st miner after the network reset and your ID is t100 (...0064) in hex :) You can deploy as many times as you want - this example will always work for your ID.

f8-ptrk commented 2 years ago
lotus wallet list -i
Address                                                                                 ID     Balance                          Nonce  Default  
t3skf2wbxbxmqvzeyblhbd53azrbpaom73afrz4ojsc6q2xc2e37bwubdcyj5jc7demlt27e2adyvrvo7nkwda  t0100  44999986.401727952451927465 FIL  48     X  

mystery solved!

maciejwitowski commented 2 years ago

But anyone who joins the network later will get IDs like t101, t102 and will need to call invoke-evm-actor with 0065, 0066 and so on.

maciejwitowski commented 2 years ago

@f8-ptrk You are The One!

f8-ptrk commented 2 years ago

good to know - it was a "mistake" that i used the t0100 address tbh - planned to deploy from another host and not with the t0100 address

f8-ptrk commented 2 years ago

are there any docs about the simplecoin contract we use here that would have told us ^^^ all that?

[edit]

forget that - the smart contracts code is posted in the issue opening post - sry

jimpick commented 2 years ago

Confirmed. Here's a modified SimpleCoin.js:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.25 <= 0.8.16;

contract SimpleCoin {
        mapping (address => uint) balances;

        event Transfer(address indexed _from, address indexed _to, uint256 _value);

        constructor() {
                balances[tx.origin] = 10000;
        }

        function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
                if (balances[msg.sender] < amount) return false;
                balances[msg.sender] -= amount;
                balances[receiver] += amount;
                emit Transfer(msg.sender, receiver, amount);
                return true;
        }

        function getBalanceInEth(address addr) public view returns(uint){
                return getBalance(addr) * 2;
        }

        function getBalance(address addr) public view returns(uint) {
                return balances[addr];
        }

        function getOrigin() public view returns(address) {
                return tx.origin;
        }
}

Signatures:

Function signatures:
f8b2cb4f: getBalance(address)
7bd703e8: getBalanceInEth(address)
df1f29ee: getOrigin()
90b98a11: sendCoin(address,uint256)

Deployed to t01065

$ ./lotus chain invoke-evm-actor t01065 df1f29ee
sending message...
waiting for message to execute...
000000000000000000000000ff000000000000000000000000000000000003ed

So I executed this method and got back 0x3ed = t01005

$ ./lotus state lookup -r t01005
t1ybjfphyqcsqblk2ceikpvmyaqy3ov5c6v2j2ewq

$ ./lotus wallet list
Address                                                                                 Balance                      Nonce  Default  
t1ybjfphyqcsqblk2ceikpvmyaqy3ov5c6v2j2ewq                                               999.999985862509792182 FIL   14     X        
t3sqt4lobkilb3q7xl3ybxxc3plt2xssqumxufg5roelg66igyfr4oti26bobvqarhvvese7ek25kfhrbkri4a  3998.937057468714422919 FIL  120   

That looks like my default wallet.

$ ./lotus chain invoke-evm-actor t01065 f8b2cb4f 000000000000000000000000ff000000000000000000000000000000000003ed
sending message...
waiting for message to execute...
0000000000000000000000000000000000000000000000000000000000002710

All good!

maciejwitowski commented 2 years ago

Perfect, thanks @jimpick!

f8-ptrk commented 2 years ago

network switched to rc3-copper