Skip to content
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

Add new methods and types for FEVM #143

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions abi/cbor_bytes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package abi

import (
"fmt"
"io"

cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
)

type CborBytes []byte
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider putting this into cbor-gen (and using cborgen's ReadByteArray/WriteByteArray.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...future...improvement...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


func (t *CborBytes) MarshalCBOR(w io.Writer) error {
if len(*t) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("byte array was too long")
}

if err := cbg.WriteMajorTypeHeader(w, cbg.MajByteString, uint64(len(*t))); err != nil {
return err
}

_, err := w.Write((*t)[:])
return err
}

func (t *CborBytes) UnmarshalCBOR(r io.Reader) error {

br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}

if extra > cbg.ByteArrayMaxLen {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably too small (e.g., it won't fit an entire smart contract).

Copy link
Contributor Author

@arajasek arajasek Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if so we have a more serious problem -- this limit applies to pretty much every type in Filecoin (as implemented by Golang clients), including the Message itself. That means Lotus won't consider such messages valid.

(what happens here in GST is less important since it's only used for UX)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Steven is confused. Steven will go back to the caverns of rust.

(the max here is ~2MiB and isn't a problem)

return fmt.Errorf("byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}

if extra > 0 {
ret := make([]byte, extra)
if _, err := io.ReadFull(br, ret[:]); err != nil {
return err
}

*t = ret
}

return nil
}
10 changes: 10 additions & 0 deletions builtin/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,13 @@ var MethodsEAM = struct {
2,
3,
}

geoff-vball marked this conversation as resolved.
Show resolved Hide resolved
var MethodsEmbryo = struct {
Constructor abi.MethodNum
}{}

var MethodsEthAccount = struct {
Constructor abi.MethodNum
}{
MethodConstructor,
}
12 changes: 12 additions & 0 deletions builtin/v10/eam/methods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package eam

import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
)

var Methods = map[abi.MethodNum]builtin.MethodMeta{
1: {"Constructor", *new(func(*abi.EmptyValue) *abi.EmptyValue)}, // Constructor
2: {"Create", *new(func(*CreateParams) *CreateReturn)}, // Create
3: {"Create2", *new(func(*Create2Params) *Create2Return)}, // Create2
}
9 changes: 9 additions & 0 deletions builtin/v10/embryo/methods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package embryo

import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
)

// Placeholder has no methods, not even a constructor
var Methods = map[abi.MethodNum]builtin.MethodMeta{}
10 changes: 10 additions & 0 deletions builtin/v10/ethaccount/methods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ethaccount

import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
)

var Methods = map[abi.MethodNum]builtin.MethodMeta{
1: {"Constructor", *new(func(value *abi.EmptyValue) *abi.EmptyValue)},
}
88 changes: 88 additions & 0 deletions builtin/v10/evm/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package evm

import "github.com/ipfs/go-cid"

type ConstructorParams struct {
Creator []byte
Initcode []byte
Expand All @@ -8,3 +10,8 @@ type ConstructorParams struct {
type GetStorageAtParams struct {
StorageKey []byte
}

type DelegateCallParams struct {
Code cid.Cid
Input []byte
}
17 changes: 17 additions & 0 deletions builtin/v10/evm/methods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package evm

import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin"
typegen "github.com/whyrusleeping/cbor-gen"
)

var Methods = map[abi.MethodNum]builtin.MethodMeta{
1: {"Constructor", *new(func(*ConstructorParams) *abi.EmptyValue)},
2: {"InvokeContract", *new(func(bytes *abi.CborBytes) *abi.CborBytes)},
3: {"GetBytecode", *new(func(*abi.EmptyValue) *typegen.CborCid)},
4: {"GetStorageAt", *new(func(*GetStorageAtParams) *big.Int)},
5: {"InvokeContractDelegate", *new(func(params *DelegateCallParams) *abi.CborBytes)},
6: {"GetBytecodeHash", *new(func(*abi.EmptyValue) *typegen.CborCid)},
}
1 change: 1 addition & 0 deletions builtin/v10/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func main() {
// method params and returns
evm.ConstructorParams{},
evm.GetStorageAtParams{},
evm.DelegateCallParams{},
); err != nil {
panic(err)
}
Expand Down