Skip to content

Commit

Permalink
Merge pull request #69 from FastLane-Labs/atlas_postAudit_deployment_…
Browse files Browse the repository at this point in the history
…update

update operations relay with new Atlas deployment
  • Loading branch information
jj1980a authored Jul 7, 2024
2 parents 6b8b6ec + be20a67 commit 2919dc8
Show file tree
Hide file tree
Showing 47 changed files with 3,892 additions and 8,026 deletions.
5 changes: 3 additions & 2 deletions auction/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/FastLane-Labs/atlas-operations-relay/operation"
"github.com/FastLane-Labs/atlas-operations-relay/relayerror"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
)

var (
Expand Down Expand Up @@ -186,7 +187,7 @@ func (a *Auction) addSolverStatusesCompletionSub(solverOpHash common.Hash, subCh
a.solverStatusesCompletionSubs[solverOpHash] = append(a.solverStatusesCompletionSubs[solverOpHash], subChan)
}

func (a *Auction) addSolverOp(solverOp *operation.SolverOperationWithScore) (common.Hash, *relayerror.Error) {
func (a *Auction) addSolverOp(solverOp *operation.SolverOperationWithScore, eip712Domain *apitypes.TypedDataDomain) (common.Hash, *relayerror.Error) {
a.mu.Lock()
defer a.mu.Unlock()

Expand All @@ -200,7 +201,7 @@ func (a *Auction) addSolverOp(solverOp *operation.SolverOperationWithScore) (com
return common.Hash{}, ErrSolverAlreadyParticipating
}

solverOpHash, relayErr := solverOp.SolverOperation.Hash()
solverOpHash, relayErr := solverOp.SolverOperation.Hash(eip712Domain)
if relayErr != nil {
return common.Hash{}, relayErr
}
Expand Down
19 changes: 10 additions & 9 deletions auction/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ type Manager struct {

solverOpHashToAuction map[common.Hash]*Auction

atlasDomainSeparator common.Hash

solverGasLimit solverGasLimitFn
balanceOfBonded balanceOfBondedFn
reputationScore reputationScoreFn
Expand All @@ -58,13 +56,12 @@ type Manager struct {
mu sync.RWMutex
}

func NewManager(ethClient *ethclient.Client, config *config.Config, atlasDomainSeparator common.Hash, solverGasLimit solverGasLimitFn, balanceOfBonded balanceOfBondedFn, reputationScore reputationScoreFn, getDAppConfig getDAppConfigFn, auctionCompleteCallback auctionCompleteCallbackFn) *Manager {
func NewManager(ethClient *ethclient.Client, config *config.Config, solverGasLimit solverGasLimitFn, balanceOfBonded balanceOfBondedFn, reputationScore reputationScoreFn, getDAppConfig getDAppConfigFn, auctionCompleteCallback auctionCompleteCallbackFn) *Manager {
am := &Manager{
ethClient: ethClient,
config: config,
auctions: make(map[common.Hash]*Auction),
solverOpHashToAuction: make(map[common.Hash]*Auction),
atlasDomainSeparator: atlasDomainSeparator,
solverGasLimit: solverGasLimit,
balanceOfBonded: balanceOfBonded,
reputationScore: reputationScore,
Expand Down Expand Up @@ -95,13 +92,13 @@ func (am *Manager) NewUserOperation(userOp *operation.UserOperation, hints []com
return common.Hash{}, nil, relayErr
}

userOpHash, relayErr := userOp.Hash(utils.FlagTrustedOpHash(dAppConfig.CallConfig))
userOpHash, relayErr := userOp.Hash(utils.FlagTrustedOpHash(dAppConfig.CallConfig), &am.config.Relay.Eip712.Domain)
if relayErr != nil {
log.Info("failed to compute user operation hash", "err", relayErr.Message)
return common.Hash{}, nil, relayErr
}

if relayErr := userOp.Validate(am.ethClient, am.config.Contracts.Atlas, am.atlasDomainSeparator, am.config.Relay.Gas.MaxPerUserOperation); relayErr != nil {
if relayErr := userOp.Validate(am.ethClient, am.config.Contracts.Atlas, &am.config.Relay.Eip712.Domain, am.config.Relay.Gas.MaxPerUserOperation); relayErr != nil {
log.Info("invalid user operation", "err", relayErr.Message, "userOpHash", userOpHash.Hex())
return common.Hash{}, nil, relayErr
}
Expand Down Expand Up @@ -170,7 +167,7 @@ func (am *Manager) NewSolverOperation(solverOp *operation.SolverOperation) (comm
return common.Hash{}, ErrAuctionNotFound
}

relayErr := solverOp.Validate(auction.userOp, am.config.Contracts.Atlas, am.atlasDomainSeparator, auction.solverGasLimit)
relayErr := solverOp.Validate(auction.userOp, am.config.Contracts.Atlas, &am.config.Relay.Eip712.Domain, auction.solverGasLimit)
if relayErr != nil {
log.Info("invalid solver operation", "err", relayErr.Message, "userOpHash", auction.userOpHash.Hex())
return common.Hash{}, relayErr
Expand All @@ -193,7 +190,7 @@ func (am *Manager) NewSolverOperation(solverOp *operation.SolverOperation) (comm
Score: am.reputationScore(solverOp.From),
}

solverOpHash, relayErr := auction.addSolverOp(solverOpWithScore)
solverOpHash, relayErr := auction.addSolverOp(solverOpWithScore, &am.config.Relay.Eip712.Domain)
if relayErr != nil {
return common.Hash{}, relayErr
}
Expand Down Expand Up @@ -268,7 +265,11 @@ func (am *Manager) simulateSolverOperation(userOp *operation.UserOperation, user
return nil
}

dAppOp := operation.GenerateSimulationDAppOperation(userOpHash, userOp)
dAppOp, err := operation.GenerateSimulationDAppOperation(userOpHash, userOp, []*operation.SolverOperation{solverOp})
if err != nil {
log.Info("failed to generate simulation dapp operation", "err", err, "userOpHash", userOpHash.Hex())
return relayerror.ErrServerInternal
}

pData, err := contract.SimulatorAbi.Pack("simSolverCall", *userOp, *solverOp, *dAppOp)
if err != nil {
Expand Down
27 changes: 14 additions & 13 deletions bundle/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,19 @@ type Manager struct {
// Indexed by userOpHash
bundles map[common.Hash]*Bundle

atlasDomainSeparator common.Hash

getDAppConfig getDAppConfigFn
isAuctionOngoing isAuctionOngoingFn

mu sync.RWMutex
}

func NewManager(ethClient *ethclient.Client, config *config.Config, atlasDomainSeparator common.Hash, getDAppConfig getDAppConfigFn, isAuctionOngoing isAuctionOngoingFn) *Manager {
func NewManager(ethClient *ethclient.Client, config *config.Config, getDAppConfig getDAppConfigFn, isAuctionOngoing isAuctionOngoingFn) *Manager {
bm := &Manager{
ethClient: ethClient,
config: config,
bundles: make(map[common.Hash]*Bundle),
atlasDomainSeparator: atlasDomainSeparator,
getDAppConfig: getDAppConfig,
isAuctionOngoing: isAuctionOngoing,
ethClient: ethClient,
config: config,
bundles: make(map[common.Hash]*Bundle),
getDAppConfig: getDAppConfig,
isAuctionOngoing: isAuctionOngoing,
}

go bm.bundlesCleaner()
Expand All @@ -77,7 +74,7 @@ func (bm *Manager) NewBundle(bundleOps *operation.BundleOperations) (common.Hash
return common.Hash{}, nil, relayErr
}

userOpHash, relayErr := bundleOps.UserOperation.Hash(utils.FlagTrustedOpHash(dAppConfig.CallConfig))
userOpHash, relayErr := bundleOps.UserOperation.Hash(utils.FlagTrustedOpHash(dAppConfig.CallConfig), &bm.config.Relay.Eip712.Domain)
if relayErr != nil {
log.Info("failed to compute user operation hash", "err", relayErr.Message)
return common.Hash{}, nil, relayErr
Expand All @@ -88,7 +85,7 @@ func (bm *Manager) NewBundle(bundleOps *operation.BundleOperations) (common.Hash
return common.Hash{}, nil, auction.ErrAuctionOngoing
}

relayErr = bundleOps.Validate(bm.ethClient, userOpHash, bm.config.Contracts.Atlas, bm.atlasDomainSeparator, bm.config.Relay.Gas.MaxPerUserOperation, bm.config.Relay.Gas.MaxPerDAppOperation, dAppConfig)
relayErr = bundleOps.Validate(bm.ethClient, userOpHash, bm.config.Contracts.Atlas, &bm.config.Relay.Eip712.Domain, bm.config.Relay.Gas.MaxPerUserOperation, dAppConfig)
if relayErr != nil {
log.Info("invalid dApp operation", "err", relayErr.Message, "userOpHash", userOpHash.Hex())
return common.Hash{}, nil, relayErr
Expand Down Expand Up @@ -136,14 +133,15 @@ func (bm *Manager) simulateBundle(bundleOps *operation.BundleOperations, userOpH
gasPrice.Set(solverOp.MaxFeePerGas)
}
}
gasLimit += bm.config.Relay.Gas.MaxPerDAppOperation.Uint64()

gasLimit += 1000000 // Add gas for validateCalls and others

_, err = bm.ethClient.CallContract(
context.Background(),
ethereum.CallMsg{
From: bundleOps.DAppOperation.Bundler,
To: &bm.config.Contracts.Atlas,
Gas: gasLimit + 1000000, // Add gas for validateCalls and others
Gas: gasLimit,
GasFeeCap: gasPrice,
Data: pData,
},
Expand All @@ -153,6 +151,9 @@ func (bm *Manager) simulateBundle(bundleOps *operation.BundleOperations, userOpH
if err != nil {
log.Info("metacall simulation failed", "err", err, "userOpHash", userOpHash.Hex())
log.Debug("metacall pData", "pData", hex.EncodeToString(pData))
log.Debug("metacall gasLimit", "gasLimit", gasLimit)
log.Debug("metacall gasPrice", "gasPrice", gasPrice)

return ErrBundleFailedSimulation.AddError(err)
}

Expand Down
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"network": {
"chain_id": 0,
"rpc_url": ""
},
"contracts": {
Expand All @@ -14,8 +15,7 @@
"max_solutions": 0
},
"gas": {
"max_per_user_operation": 0,
"max_per_dApp_operation": 0
"max_per_user_operation": 0
}
}
}
39 changes: 25 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
)

var (
Expand All @@ -21,7 +23,8 @@ var (

type configJson struct {
Network struct {
RpcUrl string `json:"rpc_url"`
ChainId uint64 `json:"chain_id"`
RpcUrl string `json:"rpc_url"`
} `json:"network"`

Contracts struct {
Expand All @@ -38,13 +41,13 @@ type configJson struct {
} `json:"auction,omitempty"`
Gas struct {
MaxPerUserOperation uint64 `json:"max_per_user_operation,omitempty"`
MaxPerDAppOperation uint64 `json:"max_per_dApp_operation,omitempty"`
} `json:"gas,omitempty"`
} `json:"relay,omitempty"`
}

type Network struct {
RpcUrl string
ChainId uint64
RpcUrl string
}

type Contracts struct {
Expand All @@ -60,14 +63,18 @@ type Auction struct {

type Gas struct {
MaxPerUserOperation *big.Int
MaxPerDAppOperation *big.Int
}

type Eip712 struct {
Domain apitypes.TypedDataDomain
}

type Relay struct {
Simulations bool
Auction Auction
Gas Gas
Signatories map[common.Address]*ecdsa.PrivateKey
Eip712 Eip712
}

type Config struct {
Expand All @@ -88,6 +95,13 @@ func Load() *Config {
config.parseEnv()
config.Validate()

config.Relay.Eip712.Domain = apitypes.TypedDataDomain{
Name: "AtlasVerification",
Version: "1.0",
ChainId: math.NewHexOrDecimal256(int64(config.Network.ChainId)),
VerifyingContract: config.Contracts.AtlasVerification.Hex(),
}

return config
}

Expand Down Expand Up @@ -132,10 +146,10 @@ func (c *Config) parseConfigFile() {

c.Relay.Auction.Duration = time.Duration(configJson.Relay.Auction.Duration * uint64(time.Millisecond))
c.Relay.Gas.MaxPerUserOperation = new(big.Int).SetUint64(configJson.Relay.Gas.MaxPerUserOperation)
c.Relay.Gas.MaxPerDAppOperation = new(big.Int).SetUint64(configJson.Relay.Gas.MaxPerDAppOperation)
}

func (c *Config) parseFlags() {
chainIdPtr := flag.Uint64("network.chain_id", 0, "Chain ID")
networkRpcUrlPtr := flag.String("network.rpc_url", "", "Ethereum RPC URL")
contractsAtlasPtr := flag.String("contracts.atlas", "", "Atlas contract address")
contractsAtlasVerificationPtr := flag.String("contracts.atlasVerification", "", "AtlasVerification contract address")
Expand All @@ -144,9 +158,10 @@ func (c *Config) parseFlags() {
relayAuctionDurationPtr := flag.Uint64("relay.auction.duration", 0, "Auction duration in milliseconds")
relayAuctionMaxSolutionsPtr := flag.Uint64("relay.auction.max_solutions", 0, "Max solutions per auction")
relayGasMaxPerUserOperationPtr := flag.Uint64("relay.gas.max_per_user_operation", 0, "Max gas per user operation")
relayGasMaxPerDAppOperationPtr := flag.Uint64("relay.gas.max_per_dApp_operation", 0, "Max gas per dApp operation")
flag.Parse()

c.Network.ChainId = *chainIdPtr

if len(*networkRpcUrlPtr) > 0 {
c.Network.RpcUrl = *networkRpcUrlPtr
}
Expand Down Expand Up @@ -185,10 +200,6 @@ func (c *Config) parseFlags() {
if *relayGasMaxPerUserOperationPtr > 0 {
c.Relay.Gas.MaxPerUserOperation = new(big.Int).SetUint64(*relayGasMaxPerUserOperationPtr)
}

if *relayGasMaxPerDAppOperationPtr > 0 {
c.Relay.Gas.MaxPerDAppOperation = new(big.Int).SetUint64(*relayGasMaxPerDAppOperationPtr)
}
}

func (c *Config) parseEnv() {
Expand All @@ -209,6 +220,10 @@ func (c *Config) parseEnv() {
}

func (c *Config) Validate() {
if c.Network.ChainId == 0 {
panic("network.chain_id is required")
}

if len(c.Network.RpcUrl) == 0 {
panic("network.rpc_url is required")
}
Expand Down Expand Up @@ -236,8 +251,4 @@ func (c *Config) Validate() {
if c.Relay.Gas.MaxPerUserOperation == nil || c.Relay.Gas.MaxPerUserOperation.Cmp(common.Big0) == 0 {
c.Relay.Gas.MaxPerUserOperation = new(big.Int).Set(defaultOperationGasLimit)
}

if c.Relay.Gas.MaxPerDAppOperation == nil || c.Relay.Gas.MaxPerDAppOperation.Cmp(common.Big0) == 0 {
c.Relay.Gas.MaxPerDAppOperation = new(big.Int).Set(defaultOperationGasLimit)
}
}
1 change: 1 addition & 0 deletions contract/atlas/atlas.abi

Large diffs are not rendered by default.

1,881 changes: 989 additions & 892 deletions contract/atlas/atlas.go

Large diffs are not rendered by default.

Loading

0 comments on commit 2919dc8

Please sign in to comment.