-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Account abstraction #9831
Merged
Merged
Account abstraction #9831
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package itests | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/exitcode" | ||
|
||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/chain/actors/builtin" | ||
"github.com/filecoin-project/lotus/chain/eth" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/filecoin-project/lotus/chain/wallet/key" | ||
"github.com/filecoin-project/lotus/itests/kit" | ||
) | ||
|
||
// TestEthAccountAbstraction goes over the account abstraction workflow: | ||
// - an embryo is created when it receives a message | ||
// - the embryo turns into an EOA when it sends a message | ||
func TestEthAccountAbstraction(t *testing.T) { | ||
kit.QuietMiningLogs() | ||
|
||
blockTime := 100 * time.Millisecond | ||
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC()) | ||
ens.InterconnectAll().BeginMining(blockTime) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
|
||
secpKey, err := key.GenerateKey(types.KTDelegated) | ||
require.NoError(t, err) | ||
|
||
embryoAddress, err := client.WalletImport(ctx, &secpKey.KeyInfo) | ||
require.NoError(t, err) | ||
|
||
fmt.Println(embryoAddress) | ||
|
||
// create an embryo actor at the target address | ||
msgCreateEmbryo := &types.Message{ | ||
From: client.DefaultKey.Address, | ||
To: embryoAddress, | ||
Value: abi.TokenAmount(types.MustParseFIL("100")), | ||
} | ||
smCreateEmbryo, err := client.MpoolPushMessage(ctx, msgCreateEmbryo, nil) | ||
require.NoError(t, err) | ||
mLookup, err := client.StateWaitMsg(ctx, smCreateEmbryo.Cid(), 3, api.LookbackNoLimit, true) | ||
require.NoError(t, err) | ||
require.Equal(t, exitcode.Ok, mLookup.Receipt.ExitCode) | ||
|
||
// confirm the embryo is an embryo | ||
embryoActor, err := client.StateGetActor(ctx, embryoAddress, types.EmptyTSK) | ||
require.NoError(t, err) | ||
|
||
require.True(t, builtin.IsEmbryoActor(embryoActor.Code)) | ||
|
||
// send a message from the embryo address | ||
msgFromEmbryo := &types.Message{ | ||
From: embryoAddress, | ||
// self-send because an "eth tx payload" can't be to a filecoin address? | ||
To: embryoAddress, | ||
} | ||
msgFromEmbryo, err = client.GasEstimateMessageGas(ctx, msgFromEmbryo, nil, types.EmptyTSK) | ||
require.NoError(t, err) | ||
|
||
txArgs, err := eth.NewEthTxArgsFromMessage(msgFromEmbryo) | ||
require.NoError(t, err) | ||
|
||
digest, err := txArgs.OriginalRlpMsg() | ||
require.NoError(t, err) | ||
|
||
siggy, err := client.WalletSign(ctx, embryoAddress, digest) | ||
require.NoError(t, err) | ||
|
||
smFromEmbryoCid, err := client.MpoolPush(ctx, &types.SignedMessage{Message: *msgFromEmbryo, Signature: *siggy}) | ||
require.NoError(t, err) | ||
|
||
mLookup, err = client.StateWaitMsg(ctx, smFromEmbryoCid, 3, api.LookbackNoLimit, true) | ||
require.NoError(t, err) | ||
require.Equal(t, exitcode.Ok, mLookup.Receipt.ExitCode) | ||
|
||
// confirm ugly Embryo duckling has turned into a beautiful EthAccount swan | ||
|
||
eoaActor, err := client.StateGetActor(ctx, embryoAddress, types.EmptyTSK) | ||
require.NoError(t, err) | ||
|
||
require.False(t, builtin.IsEmbryoActor(eoaActor.Code)) | ||
require.True(t, builtin.IsEthAccountActor(eoaActor.Code)) | ||
|
||
// Send another message, it should succeed without any code CID changes | ||
|
||
msgFromEmbryo = &types.Message{ | ||
From: embryoAddress, | ||
To: embryoAddress, | ||
} | ||
|
||
msgFromEmbryo, err = client.GasEstimateMessageGas(ctx, msgFromEmbryo, nil, types.EmptyTSK) | ||
require.NoError(t, err) | ||
|
||
txArgs, err = eth.NewEthTxArgsFromMessage(msgFromEmbryo) | ||
require.NoError(t, err) | ||
|
||
digest, err = txArgs.OriginalRlpMsg() | ||
require.NoError(t, err) | ||
|
||
siggy, err = client.WalletSign(ctx, embryoAddress, digest) | ||
require.NoError(t, err) | ||
|
||
smFromEmbryoCid, err = client.MpoolPush(ctx, &types.SignedMessage{Message: *msgFromEmbryo, Signature: *siggy}) | ||
require.NoError(t, err) | ||
|
||
mLookup, err = client.StateWaitMsg(ctx, smFromEmbryoCid, 3, api.LookbackNoLimit, true) | ||
require.NoError(t, err) | ||
require.Equal(t, exitcode.Ok, mLookup.Receipt.ExitCode) | ||
|
||
// confirm no changes in code CID | ||
|
||
eoaActor, err = client.StateGetActor(ctx, embryoAddress, types.EmptyTSK) | ||
require.NoError(t, err) | ||
|
||
require.False(t, builtin.IsEmbryoActor(eoaActor.Code)) | ||
require.True(t, builtin.IsEthAccountActor(eoaActor.Code)) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to put this behind a version check? I guess the actor couldn't exist on-chain... but I wanted to double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we shouldn't need to as written.