Skip to content

Commit d278c2a

Browse files
committed
separate authorization
1 parent 7e169ef commit d278c2a

File tree

8 files changed

+22
-3981
lines changed

8 files changed

+22
-3981
lines changed

cmd/serve.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,6 @@ func CommandServe(cfg *config.Config) *cli.Command {
160160
Value: "TEEServiceRegistered(address,bytes,bool)",
161161
},
162162

163-
&cli.StringFlag{ // --l2-builder-policy-owner-private-key
164-
Category: strings.ToUpper(categoryL2),
165-
Destination: &cfg.L2.AuthorizeWorkloadIdTx.PrivateKey,
166-
EnvVars: []string{envPrefix + strings.ToUpper(categoryL2) + "_BUILDER_POLICY_OWNER_PRIVATE_KEY"},
167-
Name: categoryL2 + "-builder-policy-owner-private-key",
168-
Usage: "builder policy owner private `key` to authorize the builder's workload id",
169-
},
170-
171163
&cli.StringFlag{ // --l2-monitor-flashblock-number-contract
172164
Category: strings.ToUpper(categoryL2),
173165
Destination: &cfg.L2.MonitorFlashblockNumberContract,

config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func New() *Config {
2626
L2: &L2{
2727
Dir: dir,
2828
ProbeTx: &ProbeTx{},
29-
AuthorizeWorkloadIdTx: &AuthorizeWorkloadIdTx{},
3029
},
3130
}
3231
}

config/l2.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type L2 struct {
3434
MonitorWalletAddresses map[string]string `yaml:"monitor_wallet_addresses"`
3535

3636
ProbeTx *ProbeTx `yaml:"probe"`
37-
AuthorizeWorkloadIdTx *AuthorizeWorkloadIdTx `yaml:"authorize_workload_id"`
3837
}
3938

4039
const (

config/workload_id_tx.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

contracts/BlockBuilderPolicy.go

Lines changed: 0 additions & 1950 deletions
This file was deleted.

contracts/FlashtestationsRegistry.go

Lines changed: 0 additions & 1904 deletions
This file was deleted.

contracts/types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package contracts
2+
3+
// TD10ReportBody is an auto generated low-level Go binding around an user-defined struct.
4+
type TD10ReportBody struct {
5+
TeeTcbSvn [16]byte
6+
MrSeam []byte
7+
MrsignerSeam []byte
8+
SeamAttributes [8]byte
9+
TdAttributes [8]byte
10+
XFAM [8]byte
11+
MrTd []byte
12+
MrConfigId []byte
13+
MrOwner []byte
14+
MrOwnerConfig []byte
15+
RtMr0 []byte
16+
RtMr1 []byte
17+
RtMr2 []byte
18+
RtMr3 []byte
19+
ReportData []byte
20+
}

server/l2.go

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"crypto/ecdsa"
66
"encoding/binary"
7-
"encoding/hex"
87
"encoding/json"
98
"errors"
109
"fmt"
@@ -24,16 +23,12 @@ import (
2423

2524
"go.uber.org/zap"
2625

27-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2826
ethcommon "github.com/ethereum/go-ethereum/common"
2927
ethtypes "github.com/ethereum/go-ethereum/core/types"
3028
"github.com/ethereum/go-ethereum/crypto"
3129

3230
"go.opentelemetry.io/otel/attribute"
3331
otelapi "go.opentelemetry.io/otel/metric"
34-
35-
// from https://github.com/flashbots/flashtestations/blob/7cc7f68492fe672a823dd2dead649793aac1f216/flashtestations/src/contracts/BlockBuilderPolicy.sol
36-
"github.com/flashbots/chain-monitor/contracts"
3732
)
3833

3934
type L2 struct {
@@ -49,12 +44,8 @@ type L2 struct {
4944
flashtestationsRegistryAddr ethcommon.Address
5045
flashtestationsRegistrySignature [4]byte
5146
flashtestationsRegistryEventSignature ethcommon.Hash
52-
blockBuilderOwnerKey *ecdsa.PrivateKey
5347
registeredTx chan ethcommon.Hash
5448

55-
registryContract *contracts.FlashtestationsRegistry
56-
blockBuilderPolicyContract *contracts.BlockBuilderPolicy
57-
5849
flashblockNumberAddr ethcommon.Address
5950
flashblockNumberSignature [4]byte
6051

@@ -134,11 +125,6 @@ func newL2(cfg *config.L2) (*L2, error) {
134125
)
135126
}
136127
copy(l2.builderPolicyAddr[:], addr)
137-
blockBuilderPolicyContract, err := contracts.NewBlockBuilderPolicy(ethcommon.BytesToAddress(addr), l2.rpc.Main)
138-
if err != nil {
139-
return nil, err
140-
}
141-
l2.blockBuilderPolicyContract = blockBuilderPolicyContract
142128
}
143129

144130
if cfg.MonitorBuilderPolicyContractFunctionSignature != "" {
@@ -158,11 +144,6 @@ func newL2(cfg *config.L2) (*L2, error) {
158144
)
159145
}
160146
copy(l2.flashtestationsRegistryAddr[:], addr)
161-
flashtestationsRegistryContract, err := contracts.NewFlashtestationsRegistry(ethcommon.BytesToAddress(addr), l2.rpc.Main)
162-
if err != nil {
163-
return nil, err
164-
}
165-
l2.registryContract = flashtestationsRegistryContract
166147
}
167148

168149
if cfg.MonitorFlashtestationRegistryFunctionSignature != "" {
@@ -205,15 +186,6 @@ func newL2(cfg *config.L2) (*L2, error) {
205186
l2.monitorResetTicker = time.NewTicker(cfg.ProbeTx.ResetInterval)
206187
}
207188

208-
if cfg.AuthorizeWorkloadIdTx.PrivateKey != "" { // blockBuilderOwnerKey
209-
blockBuilderOwnerKey, err := crypto.HexToECDSA(cfg.AuthorizeWorkloadIdTx.PrivateKey)
210-
if err != nil {
211-
return nil, err
212-
}
213-
l2.blockBuilderOwnerKey = blockBuilderOwnerKey
214-
l2.registeredTx = make(chan ethcommon.Hash)
215-
}
216-
217189
for name, addrStr := range cfg.MonitorWalletAddresses { // wallets
218190
var addr ethcommon.Address
219191
addrBytes, err := ethcommon.ParseHexOrString(addrStr)
@@ -957,33 +929,6 @@ func (l2 *L2) observeWallets(ctx context.Context, o otelapi.Observer) error {
957929
return utils.FlattenErrors(errs)
958930
}
959931

960-
func (l2 *L2) authorizeWorkloadId(ctx context.Context, workloadId [32]byte) error {
961-
l := logutils.LoggerFromContext(ctx)
962-
from := crypto.PubkeyToAddress(l2.blockBuilderOwnerKey.PublicKey)
963-
tx, err := l2.blockBuilderPolicyContract.AddWorkloadToPolicy(&bind.TransactOpts{Context: ctx, From: from}, workloadId, "commitHash", []string{"sourceLocator"})
964-
if err != nil {
965-
l.Warn("Failed to authorize workload id",
966-
zap.Error(err),
967-
)
968-
return err
969-
}
970-
signedTx, err := ethtypes.SignTx(tx, l2.signer, l2.blockBuilderOwnerKey)
971-
if err != nil {
972-
l.Warn("Failed to sign a transaction",
973-
zap.Error(err),
974-
)
975-
return err
976-
}
977-
err = l2.rpc.SendTransaction(ctx, signedTx)
978-
if err != nil {
979-
l.Warn("Failed to send a transaction",
980-
zap.Error(err),
981-
)
982-
return err
983-
}
984-
return nil
985-
}
986-
987932
func (l2 *L2) observerProbes(_ context.Context, o otelapi.Observer) error {
988933
if l2.cfg.ProbeTx.PrivateKey == "" {
989934
return nil
@@ -1166,45 +1111,17 @@ func (l2 *L2) handleRegistrationTx(ctx context.Context, txHash ethcommon.Hash) {
11661111

11671112
teeAddress, err := l2.getTEEAddressFromTx(ctx, txHash)
11681113
if err != nil {
1169-
l.Warn("Failed to get register tee transaction receipt",
1114+
l.Warn("Failed to get register flashtestations transaction receipt",
11701115
zap.Error(err),
11711116
zap.String("tx", txHash.Hex()),
11721117
)
11731118
return
11741119
}
11751120

1176-
_, registration, err := l2.registryContract.GetRegistration(&bind.CallOpts{Context: ctx}, teeAddress)
1177-
if err != nil {
1178-
l.Warn("Failed to get registration",
1179-
zap.Error(err),
1180-
zap.String("teeAddress", teeAddress.Hex()),
1181-
)
1182-
return
1183-
}
1184-
workloadId, err := l2.blockBuilderPolicyContract.WorkloadIdForTDRegistration(&bind.CallOpts{Context: ctx}, registration)
1185-
if err != nil {
1186-
l.Warn("Failed to get workload id",
1187-
zap.Error(err),
1188-
zap.String("teeAddress", teeAddress.Hex()),
1189-
)
1190-
return
1191-
}
1192-
1193-
if l2.blockBuilderOwnerKey != nil {
1194-
err = l2.authorizeWorkloadId(ctx, workloadId)
1195-
if err != nil {
1196-
l.Warn("Failed to authorize workload id",
1197-
zap.Error(err),
1198-
)
1199-
}
1200-
}
1201-
1202-
l2.workloadId = workloadId
1203-
12041121
metrics.RegisteredFlashtestationsCount.Record(ctx, 1, otelapi.WithAttributes(
12051122
attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")},
12061123
attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(l2.chainID.Int64())},
1207-
attribute.KeyValue{Key: "workload_id", Value: attribute.StringValue(hex.EncodeToString(workloadId[:]))},
1124+
attribute.KeyValue{Key: "tee_address", Value: attribute.StringValue(teeAddress.Hex())},
12081125
))
12091126

12101127
return

0 commit comments

Comments
 (0)