-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into vm-ctx-revert
- Loading branch information
Showing
88 changed files
with
3,744 additions
and
733 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package core2p2p | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/NethermindEth/juno/core" | ||
"github.com/NethermindEth/juno/core/felt" | ||
"github.com/NethermindEth/juno/p2p/starknet/spec" | ||
"github.com/NethermindEth/juno/utils" | ||
"google.golang.org/protobuf/types/known/timestamppb" | ||
) | ||
|
||
func AdaptBlockID(header *core.Header) *spec.BlockID { | ||
if header == nil { | ||
return nil | ||
} | ||
|
||
return &spec.BlockID{ | ||
Number: header.Number, | ||
Header: AdaptHash(header.Hash), | ||
} | ||
} | ||
|
||
func AdaptSignature(sig []*felt.Felt) *spec.ConsensusSignature { | ||
return &spec.ConsensusSignature{ | ||
R: AdaptFelt(sig[0]), | ||
S: AdaptFelt(sig[1]), | ||
} | ||
} | ||
|
||
func AdaptHeader(header *core.Header, commitments *core.BlockCommitments) *spec.BlockHeader { | ||
return &spec.BlockHeader{ | ||
ParentHeader: AdaptHash(header.ParentHash), | ||
Number: header.Number, | ||
Time: timestamppb.New(time.Unix(int64(header.Timestamp), 0)), | ||
SequencerAddress: AdaptAddress(header.SequencerAddress), | ||
ProofFact: nil, // not defined yet | ||
Receipts: nil, // not defined yet | ||
StateDiffs: nil, // not defined yet | ||
State: &spec.Patricia{ | ||
Height: 251, // fixed | ||
Root: AdaptHash(header.GlobalStateRoot), | ||
}, | ||
Transactions: &spec.Merkle{ | ||
NLeaves: uint32(header.TransactionCount), | ||
Root: AdaptHash(commitments.TransactionCommitment), | ||
}, | ||
Events: &spec.Merkle{ | ||
NLeaves: uint32(header.EventCount), | ||
Root: AdaptHash(commitments.EventCommitment), | ||
}, | ||
} | ||
} | ||
|
||
func AdaptEvent(e *core.Event) *spec.Event { | ||
if e == nil { | ||
return nil | ||
} | ||
|
||
return &spec.Event{ | ||
FromAddress: AdaptFelt(e.From), | ||
Keys: utils.Map(e.Keys, AdaptFelt), | ||
Data: utils.Map(e.Data, AdaptFelt), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package core2p2p | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/NethermindEth/juno/core" | ||
"github.com/NethermindEth/juno/core/felt" | ||
"github.com/NethermindEth/juno/p2p/starknet/spec" | ||
) | ||
|
||
func AdaptClass(class core.Class, compiledHash *felt.Felt) *spec.Class { | ||
if class == nil { | ||
return nil | ||
} | ||
|
||
switch v := class.(type) { | ||
case *core.Cairo0Class: | ||
return &spec.Class{ | ||
CompiledHash: AdaptHash(compiledHash), | ||
Definition: []byte(v.Program), | ||
} | ||
case *core.Cairo1Class: | ||
return &spec.Class{ | ||
CompiledHash: AdaptHash(compiledHash), | ||
Definition: v.Compiled, | ||
} | ||
default: | ||
panic(fmt.Errorf("unsupported cairo class %T (version=%d)", v, class.Version())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package core2p2p | ||
|
||
import ( | ||
"github.com/NethermindEth/juno/core" | ||
"github.com/NethermindEth/juno/p2p/starknet/spec" | ||
"github.com/NethermindEth/juno/utils" | ||
) | ||
|
||
// Core Transaction receipt does not contain all the information required to create p2p spec Receipt, therefore, | ||
// we have to pass the transaction as well. | ||
func AdaptReceipt(r *core.TransactionReceipt, txn core.Transaction) *spec.Receipt { | ||
if r == nil || txn == nil { | ||
return nil | ||
} | ||
switch t := txn.(type) { | ||
case *core.InvokeTransaction: | ||
return &spec.Receipt{ | ||
Receipt: &spec.Receipt_Invoke_{ | ||
Invoke: &spec.Receipt_Invoke{ | ||
Common: receiptCommon(r), | ||
}, | ||
}, | ||
} | ||
case *core.L1HandlerTransaction: | ||
return &spec.Receipt{ | ||
Receipt: &spec.Receipt_L1Handler_{ | ||
L1Handler: &spec.Receipt_L1Handler{ | ||
Common: receiptCommon(r), | ||
MsgHash: &spec.Hash{Elements: t.MessageHash()}, | ||
}, | ||
}, | ||
} | ||
case *core.DeclareTransaction: | ||
return &spec.Receipt{ | ||
Receipt: &spec.Receipt_Declare_{ | ||
Declare: &spec.Receipt_Declare{ | ||
Common: receiptCommon(r), | ||
}, | ||
}, | ||
} | ||
case *core.DeployTransaction: | ||
return &spec.Receipt{ | ||
Receipt: &spec.Receipt_DeprecatedDeploy{ | ||
DeprecatedDeploy: &spec.Receipt_Deploy{ | ||
Common: receiptCommon(r), | ||
ContractAddress: AdaptFelt(t.ContractAddress), | ||
}, | ||
}, | ||
} | ||
case *core.DeployAccountTransaction: | ||
return &spec.Receipt{ | ||
Receipt: &spec.Receipt_DeployAccount_{ | ||
DeployAccount: &spec.Receipt_DeployAccount{ | ||
Common: receiptCommon(r), | ||
ContractAddress: AdaptFelt(t.ContractAddress), | ||
}, | ||
}, | ||
} | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
func receiptCommon(r *core.TransactionReceipt) *spec.Receipt_Common { | ||
return &spec.Receipt_Common{ | ||
TransactionHash: AdaptHash(r.TransactionHash), | ||
ActualFee: AdaptFelt(r.Fee), | ||
MessagesSent: utils.Map(r.L2ToL1Message, AdaptMessageToL1), | ||
ExecutionResources: AdaptExecutionResources(r.ExecutionResources), | ||
RevertReason: r.RevertReason, | ||
} | ||
} | ||
|
||
func AdaptMessageToL1(mL1 *core.L2ToL1Message) *spec.MessageToL1 { | ||
return &spec.MessageToL1{ | ||
FromAddress: AdaptFelt(mL1.From), | ||
Payload: utils.Map(mL1.Payload, AdaptFelt), | ||
ToAddress: &spec.EthereumAddress{Elements: mL1.To.Bytes()}, | ||
} | ||
} | ||
|
||
func AdaptExecutionResources(er *core.ExecutionResources) *spec.Receipt_ExecutionResources { | ||
return &spec.Receipt_ExecutionResources{ | ||
Builtins: &spec.Receipt_ExecutionResources_BuiltinCounter{ | ||
Bitwise: uint32(er.BuiltinInstanceCounter.Bitwise), | ||
Ecdsa: uint32(er.BuiltinInstanceCounter.Ecsda), | ||
EcOp: uint32(er.BuiltinInstanceCounter.EcOp), | ||
Pedersen: uint32(er.BuiltinInstanceCounter.Pedersen), | ||
RangeCheck: uint32(er.BuiltinInstanceCounter.RangeCheck), | ||
Poseidon: uint32(er.BuiltinInstanceCounter.Poseidon), | ||
Keccak: uint32(er.BuiltinInstanceCounter.Keccak), | ||
}, | ||
Steps: uint32(er.Steps), | ||
MemoryHoles: uint32(er.MemoryHoles), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package core2p2p | ||
|
||
import ( | ||
"github.com/NethermindEth/juno/core" | ||
"github.com/NethermindEth/juno/core/felt" | ||
"github.com/NethermindEth/juno/p2p/starknet/spec" | ||
"github.com/NethermindEth/juno/utils" | ||
) | ||
|
||
func AdaptStateDiff(addr, classHash, nonce *felt.Felt, diff []core.StorageDiff) *spec.StateDiff_ContractDiff { | ||
return &spec.StateDiff_ContractDiff{ | ||
Address: AdaptAddress(addr), | ||
Nonce: AdaptFelt(nonce), | ||
ClassHash: AdaptFelt(classHash), | ||
Values: AdaptStorageDiff(diff), | ||
} | ||
} | ||
|
||
func AdaptStorageDiff(diff []core.StorageDiff) []*spec.ContractStoredValue { | ||
return utils.Map(diff, func(item core.StorageDiff) *spec.ContractStoredValue { | ||
return &spec.ContractStoredValue{ | ||
Key: AdaptFelt(item.Key), | ||
Value: AdaptFelt(item.Value), | ||
} | ||
}) | ||
} |
Oops, something went wrong.