Skip to content

Commit

Permalink
Add missing v3 transaction fields
Browse files Browse the repository at this point in the history
Paymaster and AccountDeploymentData have different types, which cannot
be easily converted between core and p2p types; therefore, they have
been left as nil.
  • Loading branch information
IronGauntlets committed Feb 27, 2024
1 parent 6e8c601 commit 4333394
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 21 deletions.
33 changes: 15 additions & 18 deletions adapters/core2p2p/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ func AdaptTransaction(transaction core.Transaction) *spec.Transaction {
L1Gas: adaptResourceLimits(tx.ResourceBounds[core.ResourceL1Gas]),
L2Gas: adaptResourceLimits(tx.ResourceBounds[core.ResourceL2Gas]),
Tip: AdaptFelt(new(felt.Felt).SetUint64(tx.Tip)),
// todo fill rest of V3 fields:
Paymaster: nil,
NonceDomain: "",
FeeDomain: "",
NonceDomain: fmt.Sprintf("%v", tx.NonceDAMode),
FeeDomain: fmt.Sprintf("%v", tx.FeeDAMode),
},
}
default:
Expand Down Expand Up @@ -97,10 +96,9 @@ func AdaptTransaction(transaction core.Transaction) *spec.Transaction {
L1Gas: adaptResourceLimits(tx.ResourceBounds[core.ResourceL1Gas]),
L2Gas: adaptResourceLimits(tx.ResourceBounds[core.ResourceL2Gas]),
Tip: AdaptFelt(new(felt.Felt).SetUint64(tx.Tip)),
// todo fill rest of V3 fields:
Paymaster: nil,
NonceDomain: "",
FeeDomain: "",
Paymaster: nil,
NonceDomain: fmt.Sprintf("%v", tx.NonceDAMode),
FeeDomain: fmt.Sprintf("%v", tx.FeeDAMode),
},
}
default:
Expand Down Expand Up @@ -131,18 +129,17 @@ func AdaptTransaction(transaction core.Transaction) *spec.Transaction {
case tx.Version.Is(3):
specTx.Txn = &spec.Transaction_InvokeV3_{
InvokeV3: &spec.Transaction_InvokeV3{
Sender: AdaptAddress(tx.SenderAddress),
MaxFee: AdaptFelt(tx.MaxFee),
Signature: AdaptAccountSignature(tx.Signature()),
Calldata: AdaptFeltSlice(tx.CallData),
Nonce: AdaptFelt(tx.Nonce),
L1Gas: adaptResourceLimits(tx.ResourceBounds[core.ResourceL1Gas]),
L2Gas: adaptResourceLimits(tx.ResourceBounds[core.ResourceL2Gas]),
Tip: AdaptFelt(new(felt.Felt).SetUint64(tx.Tip)),
// todo fill rest of V3 fields:
Sender: AdaptAddress(tx.SenderAddress),
MaxFee: AdaptFelt(tx.MaxFee),
Signature: AdaptAccountSignature(tx.Signature()),
Calldata: AdaptFeltSlice(tx.CallData),
Nonce: AdaptFelt(tx.Nonce),
L1Gas: adaptResourceLimits(tx.ResourceBounds[core.ResourceL1Gas]),
L2Gas: adaptResourceLimits(tx.ResourceBounds[core.ResourceL2Gas]),
Tip: AdaptFelt(new(felt.Felt).SetUint64(tx.Tip)),
Paymaster: nil,
NonceDomain: "",
FeeDomain: "",
NonceDomain: fmt.Sprintf("%v", tx.NonceDAMode),
FeeDomain: fmt.Sprintf("%v", tx.FeeDAMode),
},
}
default:
Expand Down
62 changes: 59 additions & 3 deletions adapters/p2p2core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package p2p2core

import (
"fmt"
"strconv"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils"
)

//nolint:funlen
//nolint:funlen,gocyclo
func AdaptTransaction(t *spec.Transaction, network *utils.Network) core.Transaction {
if t == nil {
return nil
Expand Down Expand Up @@ -57,7 +58,6 @@ func AdaptTransaction(t *spec.Transaction, network *utils.Network) core.Transact
case *spec.Transaction_DeclareV2_:
tx := t.GetDeclareV2()
declareTx := &core.DeclareTransaction{
TransactionHash: nil, // todo where to get it?
ClassHash: AdaptHash(tx.ClassHash),
SenderAddress: AdaptAddress(tx.Sender),
MaxFee: AdaptFelt(tx.MaxFee),
Expand All @@ -71,13 +71,34 @@ func AdaptTransaction(t *spec.Transaction, network *utils.Network) core.Transact
return declareTx
case *spec.Transaction_DeclareV3_:
tx := t.GetDeclareV3()

nDAMode, err := strconv.ParseUint(tx.GetNonceDomain(), 10, 32)
if err != nil {
panic(fmt.Sprintf("Failed to convert Nonce DA mode: %v to uint32", tx.GetNonceDomain()))
}

fDAMode, err := strconv.ParseUint(tx.GetFeeDomain(), 10, 32)
if err != nil {
panic(fmt.Sprintf("Failed to convert Fee DA mode: %v to uint32", tx.GetFeeDomain()))
}

declareTx := &core.DeclareTransaction{
ClassHash: AdaptHash(tx.ClassHash),
SenderAddress: AdaptAddress(tx.Sender),
MaxFee: AdaptFelt(tx.MaxFee),
TransactionSignature: adaptAccountSignature(tx.Signature),
Nonce: AdaptFelt(tx.Nonce),
Version: txVerion(2),
Version: txVerion(3),
CompiledClassHash: AdaptFelt(tx.CompiledClassHash),
Tip: AdaptFelt(tx.Tip).Uint64(),
ResourceBounds: map[core.Resource]core.ResourceBounds{
core.ResourceL1Gas: adaptResourceLimits(tx.L1Gas),
core.ResourceL2Gas: adaptResourceLimits(tx.L2Gas),
},
PaymasterData: nil, // Todo: P2P needs to change the pay master data to a list
AccountDeploymentData: nil, // Todo: update p2p spec to include this
NonceDAMode: core.DataAvailabilityMode(nDAMode),
FeeDAMode: core.DataAvailabilityMode(fDAMode),
}
declareTx.TransactionHash = hash(declareTx)

Expand Down Expand Up @@ -122,6 +143,16 @@ func AdaptTransaction(t *spec.Transaction, network *utils.Network) core.Transact
case *spec.Transaction_DeployAccountV3_:
tx := t.GetDeployAccountV3()

nDAMode, err := strconv.ParseUint(tx.GetNonceDomain(), 10, 32)
if err != nil {
panic(fmt.Sprintf("Failed to convert Nonce DA mode: %v to uint32", tx.GetNonceDomain()))
}

fDAMode, err := strconv.ParseUint(tx.GetFeeDomain(), 10, 32)
if err != nil {
panic(fmt.Sprintf("Failed to convert Fee DA mode: %v to uint32", tx.GetFeeDomain()))
}

addressSalt := AdaptFelt(tx.AddressSalt)
classHash := AdaptHash(tx.ClassHash)
callData := utils.Map(tx.Calldata, AdaptFelt)
Expand All @@ -133,8 +164,17 @@ func AdaptTransaction(t *spec.Transaction, network *utils.Network) core.Transact
ConstructorCallData: callData,
Version: txVerion(3),
},
MaxFee: AdaptFelt(tx.MaxFee),
TransactionSignature: adaptAccountSignature(tx.Signature),
Nonce: AdaptFelt(tx.Nonce),
Tip: AdaptFelt(tx.Tip).Uint64(),
ResourceBounds: map[core.Resource]core.ResourceBounds{
core.ResourceL1Gas: adaptResourceLimits(tx.L1Gas),
core.ResourceL2Gas: adaptResourceLimits(tx.L2Gas),
},
PaymasterData: nil, // Todo: P2P needs to change the pay master data to a list
NonceDAMode: core.DataAvailabilityMode(nDAMode),
FeeDAMode: core.DataAvailabilityMode(fDAMode),
}
deployAccTx.DeployTransaction.TransactionHash = hash(deployAccTx)

Expand Down Expand Up @@ -171,18 +211,34 @@ func AdaptTransaction(t *spec.Transaction, network *utils.Network) core.Transact
return invTx
case *spec.Transaction_InvokeV3_:
tx := t.GetInvokeV3()

nDAMode, err := strconv.ParseUint(tx.GetNonceDomain(), 10, 32)
if err != nil {
panic(fmt.Sprintf("Failed to convert Nonce DA mode: %v to uint32", tx.GetNonceDomain()))
}

fDAMode, err := strconv.ParseUint(tx.GetFeeDomain(), 10, 32)
if err != nil {
panic(fmt.Sprintf("Failed to convert Fee DA mode: %v to uint32", tx.GetFeeDomain()))
}

invTx := &core.InvokeTransaction{
ContractAddress: nil, // is it ok?
CallData: utils.Map(tx.Calldata, AdaptFelt),
TransactionSignature: adaptAccountSignature(tx.Signature),
MaxFee: AdaptFelt(tx.MaxFee),
Version: txVerion(3),
Nonce: AdaptFelt(tx.Nonce),
SenderAddress: AdaptAddress(tx.Sender),
EntryPointSelector: nil,
Tip: AdaptFelt(tx.Tip).Uint64(),
ResourceBounds: map[core.Resource]core.ResourceBounds{
core.ResourceL1Gas: adaptResourceLimits(tx.L1Gas),
core.ResourceL2Gas: adaptResourceLimits(tx.L2Gas),
},
PaymasterData: nil, // Todo: P2P needs to change the pay master data to a list
NonceDAMode: core.DataAvailabilityMode(nDAMode),
FeeDAMode: core.DataAvailabilityMode(fDAMode),
}
invTx.TransactionHash = hash(invTx)

Expand Down

0 comments on commit 4333394

Please sign in to comment.