Skip to content

Commit

Permalink
Backports fixes noticed elsewhere in development (#48)
Browse files Browse the repository at this point in the history
* Adds missing attributes to TransactionArgs and adjusts for suave transactions
* Deep-copies everything
* Adjusts how Wrapped is treated in suave signer Sender function
  • Loading branch information
Ruteri authored Sep 29, 2023
1 parent 49b314b commit 0a592f8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/types/confidential.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ConfidentialComputeRequest struct {
func (tx *ConfidentialComputeRequest) copy() TxData {
cpy := &ConfidentialComputeRequest{
ExecutionNode: tx.ExecutionNode,
Wrapped: tx.Wrapped,
Wrapped: *NewTx(tx.Wrapped.inner),
ChainID: new(big.Int),
}

Expand Down Expand Up @@ -83,7 +83,7 @@ type SuaveTransaction struct {
func (tx *SuaveTransaction) copy() TxData {
cpy := &SuaveTransaction{
ExecutionNode: tx.ExecutionNode,
ConfidentialComputeRequest: tx.ConfidentialComputeRequest,
ConfidentialComputeRequest: *NewTx(tx.ConfidentialComputeRequest.inner),
ConfidentialComputeResult: common.CopyBytes(tx.ConfidentialComputeResult),
ChainID: new(big.Int),
V: new(big.Int),
Expand Down
12 changes: 6 additions & 6 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ type sigCache struct {
func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint64) Signer {
var signer Signer
switch {
case config.IsCancun(blockNumber, blockTime):
signer = NewCancunSigner(config.ChainID)
case config.IsSuave(blockNumber):
signer = NewSuaveSigner(config.ChainID)
case config.IsCancun(blockNumber, blockTime):
signer = NewCancunSigner(config.ChainID)
case config.IsLondon(blockNumber):
signer = NewLondonSigner(config.ChainID)
case config.IsBerlin(blockNumber):
Expand All @@ -67,12 +67,12 @@ func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint
// have the current block number available, use MakeSigner instead.
func LatestSigner(config *params.ChainConfig) Signer {
if config.ChainID != nil {
if config.CancunTime != nil {
return NewCancunSigner(config.ChainID)
}
if config.SuaveBlock != nil {
return NewSuaveSigner(config.ChainID)
}
if config.CancunTime != nil {
return NewCancunSigner(config.ChainID)
}
if config.LondonBlock != nil {
return NewLondonSigner(config.ChainID)
}
Expand Down Expand Up @@ -271,7 +271,7 @@ func (s suaveSigner) Sender(tx *Transaction) (common.Address, error) {
var confidentialComputeRequestTx *Transaction = tx
if tx.Type() == SuaveTxType { // Verify ExecutionNode's signature
inner := tx.inner.(*SuaveTransaction)
confidentialComputeRequestTx = NewTx(&ConfidentialComputeRequest{ExecutionNode: inner.ExecutionNode, Wrapped: inner.ConfidentialComputeRequest, ChainID: inner.ChainID})
confidentialComputeRequestTx = &inner.ConfidentialComputeRequest

V, R, S := tx.RawSignatureValues()
// DynamicFee txs are defined to use 0 and 1 as their recovery
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ func (s *TransactionAPI) executeConfidentialCall(ctx context.Context, tx *types.
computeResult = result.ReturnData // Or should it be nil maybe in this case?
}

suaveResultTxData := &types.SuaveTransaction{ExecutionNode: confidentialRequestTx.ExecutionNode, ConfidentialComputeRequest: confidentialRequestTx.Wrapped, ConfidentialComputeResult: computeResult}
suaveResultTxData := &types.SuaveTransaction{ExecutionNode: confidentialRequestTx.ExecutionNode, ConfidentialComputeRequest: *tx, ConfidentialComputeResult: computeResult}

signed, err := wallet.SignTx(account, types.NewTx(suaveResultTxData), s.b.ChainConfig().ChainID)
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type TransactionArgs struct {
ExecutionNode *common.Address `json:"executionNode"`
IsConfidential bool `json:"IsConfidential"`
ConfidentialInputs *hexutil.Bytes `json:"confidentialInputs"` // TODO: testme
ConfidentialResult *hexutil.Bytes `json:"ConfidentialResult"` // TODO: testme
Nonce *hexutil.Uint64 `json:"nonce"`

// We accept "data" and "input" for backwards-compatibility reasons.
Expand Down Expand Up @@ -314,6 +315,30 @@ func (args *TransactionArgs) toTransaction() *types.Transaction {
Data: args.data(),
AccessList: *args.AccessList,
}
case args.ConfidentialResult != nil:
requestArgs := *args
requestArgs.ConfidentialResult = nil

var confResult []byte
if args.ConfidentialResult != nil {
confResult = []byte(*args.ConfidentialResult)
}

data = &types.SuaveTransaction{
ExecutionNode: *args.ExecutionNode,
ChainID: (*big.Int)(args.ChainID),
ConfidentialComputeRequest: *requestArgs.toTransaction(),
ConfidentialComputeResult: confResult,
}
case args.ExecutionNode != nil:
wrappedArgs := *args
wrappedArgs.ExecutionNode = nil

data = &types.ConfidentialComputeRequest{
ExecutionNode: *args.ExecutionNode,
Wrapped: *wrappedArgs.toTransaction(),
ChainID: (*big.Int)(args.ChainID),
}
default:
data = &types.LegacyTx{
To: args.To,
Expand Down
2 changes: 1 addition & 1 deletion suave/core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (e *ConfidentialStoreEngine) NewMessage(message DAMessage) error {

_, err = e.backend.Store(message.Bid, message.Caller, message.Key, message.Value)
if err != nil {
panic(fmt.Errorf("unexpected error while storing, the message was not validated properly: %w (%v)", err, message.Caller))
return fmt.Errorf("unexpected error while storing: %w", err)
}

return nil
Expand Down

0 comments on commit 0a592f8

Please sign in to comment.