Skip to content

Commit

Permalink
Merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Dec 18, 2023
2 parents 558733d + c53dc1c commit 2463e06
Show file tree
Hide file tree
Showing 18 changed files with 700 additions and 1,016 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.20
go-version: 1.21.1
id: go

- name: Check out code into the Go module directory
Expand All @@ -32,6 +32,9 @@ jobs:
- name: Lint
run: make lint

- name: Lint contracts
run: cd suave && forge fmt --check

- name: Build contracts
run: cd suave && forge build

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ devnet-up:

devnet-down:
docker-compose -f ./suave/devenv/docker-compose.yml down

fmt-contracts:
cd suave && forge fmt
593 changes: 8 additions & 585 deletions README.md

Large diffs are not rendered by default.

123 changes: 123 additions & 0 deletions accounts/abi/type2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package abi

import (
"fmt"
"reflect"
"strings"
)

func NewTypeFromString(s string) (Type, error) {
if strings.HasPrefix(s, "tuple") {
sig, args, err := newTypeForTuple(s)
if err != nil {
return Type{}, err
}
return NewType(sig, "", args)
}
return NewType(s, "", nil)
}

func (t Type) Pack(v interface{}) ([]byte, error) {
return t.pack(reflect.ValueOf(v))
}

func (t Type) Unpack(data []byte, obj interface{}) error {
fmt.Println(toGoType(0, t, data))

return nil
}

// newTypeForTuple implements the format described in https://blog.ricmoo.com/human-readable-contract-abis-in-ethers-js-141902f4d917
func newTypeForTuple(s string) (string, []ArgumentMarshaling, error) {
if !strings.HasPrefix(s, "tuple") {
return "", nil, fmt.Errorf("'tuple' prefix not found")
}

pos := strings.Index(s, "(")
if pos == -1 {
return "", nil, fmt.Errorf("not a tuple, '(' not found")
}

// this is the type of the tuple. It can either be
// tuple, tuple[] or tuple[x]
sig := s[:pos]
s = s[pos:]

// Now, decode the arguments of the tuple
// tuple(arg1, arg2, tuple(arg3, arg4)).
// We need to find the commas that are not inside a nested tuple.
// We do this by keeping a counter of the number of open parens.

var (
parenthesisCount int
fields []string
)

lastComma := 1
for indx, c := range s {
switch c {
case '(':
parenthesisCount++
case ')':
parenthesisCount--
if parenthesisCount == 0 {
fields = append(fields, s[lastComma:indx])

// this should be the end of the tuple
if indx != len(s)-1 {
return "", nil, fmt.Errorf("invalid tuple, it does not end with ')'")
}
}
case ',':
if parenthesisCount == 1 {
fields = append(fields, s[lastComma:indx])
lastComma = indx + 1
}
}
}

// trim the args of spaces
for i := range fields {
fields[i] = strings.TrimSpace(fields[i])
}

// decode the type of each field
var args []ArgumentMarshaling
for _, field := range fields {
// anonymous fields are not supported so the first
// string should be the identifier of the field.

spacePos := strings.Index(field, " ")
if spacePos == -1 {
return "", nil, fmt.Errorf("invalid tuple field name not found '%s'", field)
}

name := field[:spacePos]
field = field[spacePos+1:]

if strings.HasPrefix(field, "tuple") {
// decode a recursive tuple
sig, elems, err := newTypeForTuple(field)
if err != nil {
return "", nil, err
}
args = append(args, ArgumentMarshaling{
Name: name,
Type: sig,
Components: elems,
})
} else {
// basic type. Try to decode it to see
// if it is a correct abi type.
if _, err := NewType(field, "", nil); err != nil {
return "", nil, fmt.Errorf("invalid tuple basic field '%s': %v", field, err)
}
args = append(args, ArgumentMarshaling{
Name: name,
Type: field,
})
}
}

return sig, args, nil
}
94 changes: 94 additions & 0 deletions accounts/abi/type2_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package abi

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestNewType2FromString(t *testing.T) {
type struct1 struct {
A uint64
B []struct {
X struct {
C uint64
}
D uint64
}
E struct {
F uint64
G uint64
}
}

cases := []struct {
input string
want string
obj interface{}
}{
{
"uint64[]",
"uint64[]",
[]uint64{1, 2, 3},
},
{
"tuple(a uint64, b uint64)",
"(uint64,uint64)",
&struct {
A uint64
B uint64
}{A: 1, B: 2},
},
{
"tuple(a uint64, b tuple(c uint64), d uint64)",
"(uint64,(uint64),uint64)",
&struct {
A uint64
B struct {
C uint64
}
D uint64
}{A: 1, B: struct{ C uint64 }{C: 2}, D: 3},
},
{
"tuple(a uint64, b tuple[](x tuple(c uint64), d uint64), e tuple(f uint64, g uint64))",
"(uint64,((uint64),uint64)[],(uint64,uint64))",
&struct1{
A: 1,
B: []struct {
X struct {
C uint64
}
D uint64
}{
{
X: struct {
C uint64
}{C: 2},
D: 3,
},
{
X: struct {
C uint64
}{C: 4},
D: 5,
},
},
E: struct {
F uint64
G uint64
}{F: 6, G: 7},
},
},
}

for _, c := range cases {
typ, err := NewTypeFromString(c.input)

require.NoError(t, err)
require.Equal(t, c.want, typ.String())

_, err = typ.Pack(c.obj)
require.NoError(t, err)
}
}
19 changes: 10 additions & 9 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ func main() {
// prepare manipulates memory cache allowance and setups metric system.
// This function should be called before launching devp2p stack.
func prepare(ctx *cli.Context) {
if err := prepareSuaveDev(ctx); err != nil {
log.Error("failed to setup suave dev mode", "err", err)
os.Exit(1)
}

if err := prepareSuaveNetworksRemapping(ctx); err != nil {
log.Error("failed to setup suave networks remapping", "err", err)
os.Exit(1)
}

// If we're running a known preset, log it for convenience.
switch {
case ctx.IsSet(utils.RinkebyFlag.Name):
Expand Down Expand Up @@ -341,14 +351,6 @@ func geth(ctx *cli.Context) error {
return fmt.Errorf("invalid command: %q", args[0])
}

if err := prepareSuaveDev(ctx); err != nil {
return fmt.Errorf("failed to setup suave development mode: %v", err)
}

if err := prepareSuaveNetworksRemapping(ctx); err != nil {
return err
}

prepare(ctx)
stack, backend := makeFullNode(ctx)
defer stack.Close()
Expand Down Expand Up @@ -532,7 +534,6 @@ func prepareSuaveDev(ctx *cli.Context) error {
utils.DeveloperFlag.Name: "true",
utils.DeveloperGasLimitFlag.Name: "30000000",
utils.HTTPEnabledFlag.Name: "true",
utils.HTTPPortFlag.Name: "8545",
utils.HTTPVirtualHostsFlag.Name: "*",
utils.HTTPCORSDomainFlag.Name: "*",
utils.WSEnabledFlag.Name: "true",
Expand Down
6 changes: 5 additions & 1 deletion core/types/sbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import (

type SBundle struct {
BlockNumber *big.Int `json:"blockNumber,omitempty"` // if BlockNumber is set it must match DecryptionCondition!
MaxBlock *big.Int `json:"maxBlock,omitempty"`
Txs Transactions `json:"txs"`
RevertingHashes []common.Hash `json:"revertingHashes,omitempty"`
RefundPercent *int `json:"percent,omitempty"`
}

type RpcSBundle struct {
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
MaxBlock *hexutil.Big `json:"maxBlock,omitempty"`
Txs []hexutil.Bytes `json:"txs"`
RevertingHashes []common.Hash `json:"revertingHashes,omitempty"`
RefundPercent *int `json:"percent,omitempty"`
Expand Down Expand Up @@ -66,6 +68,7 @@ func (s *SBundle) UnmarshalJSON(data []byte) error {
}

s.BlockNumber = (*big.Int)(rpcSBundle.BlockNumber)
s.MaxBlock = (*big.Int)(rpcSBundle.MaxBlock)
s.Txs = txs
s.RevertingHashes = rpcSBundle.RevertingHashes
s.RefundPercent = rpcSBundle.RefundPercent
Expand All @@ -76,7 +79,8 @@ func (s *SBundle) UnmarshalJSON(data []byte) error {
type RPCMevShareBundle struct {
Version string `json:"version"`
Inclusion struct {
Block string `json:"block"`
Block string `json:"block"`
MaxBlock string `json:"maxBlock"`
} `json:"inclusion"`
Body []struct {
Tx string `json:"tx"`
Expand Down
1 change: 1 addition & 0 deletions core/vm/contracts_suave_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ func (c *suaveRuntime) fillMevShareBundle(bidId types.BidId) ([]byte, error) {
}

shareBundle.Inclusion.Block = hexutil.EncodeUint64(bid.DecryptionCondition)
shareBundle.Inclusion.MaxBlock = hexutil.EncodeUint64(bid.DecryptionCondition + 25) // Assumes 25 block inclusion range

for _, tx := range append(userBundle.Txs, matchBundle.Txs...) {
txBytes, err := tx.MarshalBinary()
Expand Down
Loading

0 comments on commit 2463e06

Please sign in to comment.