Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions adapters/p2p2core/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ func AdaptSierraClass(cairo1 *class.Cairo1Class) (core.SierraClass, error) {
return core.SierraClass{
Abi: cairo1.Abi,
AbiHash: &abiHash,
EntryPoints: struct {
Constructor []core.SierraEntryPoint
External []core.SierraEntryPoint
L1Handler []core.SierraEntryPoint
}{
EntryPoints: core.SierraEntryPointsByType{
Constructor: adaptEP(entryPoints.Constructors),
External: adaptEP(entryPoints.Externals),
L1Handler: adaptEP(entryPoints.L1Handlers),
Expand Down
44 changes: 22 additions & 22 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ import (

type Header struct {
// The hash of this block
Hash *felt.Felt
Hash *felt.Felt `cbor:"1,keyasint,omitempty"`
// The hash of this block’s parent
ParentHash *felt.Felt
ParentHash *felt.Felt `cbor:"2,keyasint,omitempty"`
// The number (height) of this block
Number uint64
Number uint64 `cbor:"3,keyasint,omitempty"`
// The state commitment after this block
GlobalStateRoot *felt.Felt
GlobalStateRoot *felt.Felt `cbor:"4,keyasint,omitempty"`
// The Starknet address of the sequencer who created this block
SequencerAddress *felt.Felt
SequencerAddress *felt.Felt `cbor:"5,keyasint,omitempty"`
// The amount Transactions and Receipts stored in this block
TransactionCount uint64
TransactionCount uint64 `cbor:"6,keyasint,omitempty"`
// The amount of events stored in transaction receipts
EventCount uint64
EventCount uint64 `cbor:"7,keyasint,omitempty"`
// The time the sequencer created this block before executing transactions
Timestamp uint64
Timestamp uint64 `cbor:"8,keyasint,omitempty"`
// Todo(rdr): It makes more sense for Protocol version to be stored in semver.Version instead
// The version of the Starknet protocol used when creating this block
ProtocolVersion string
ProtocolVersion string `cbor:"9,keyasint,omitempty"`
// Bloom filter on the events emitted this block
EventsBloom *bloom.BloomFilter
EventsBloom *bloom.BloomFilter `cbor:"10,keyasint,omitempty"`
// Amount of WEI charged per Gas spent on L1
L1GasPriceETH *felt.Felt `cbor:"gasprice"`
L1GasPriceETH *felt.Felt `cbor:"11,keyasint,omitempty"`
// Amount of STRK charged per Gas spent on L2
Signatures [][]*felt.Felt
Signatures [][]*felt.Felt `cbor:"12,keyasint,omitempty"`
// Amount of STRK charged per Gas spent on L1
L1GasPriceSTRK *felt.Felt `cbor:"gaspricestrk"`
L1GasPriceSTRK *felt.Felt `cbor:"13,keyasint,omitempty"`
// Amount of STRK charged per Gas spent on L2
L1DAMode L1DAMode
L1DAMode L1DAMode `cbor:"14,keyasint,omitempty"`
// The gas price for L1 data availability
L1DataGasPrice *GasPrice
L2GasPrice *GasPrice
L1DataGasPrice *GasPrice `cbor:"15,keyasint,omitempty"`
L2GasPrice *GasPrice `cbor:"16,keyasint,omitempty"`
}

type L1DAMode uint
Expand All @@ -62,8 +62,8 @@ var (
)

type GasPrice struct {
PriceInWei *felt.Felt
PriceInFri *felt.Felt
PriceInWei *felt.Felt `cbor:"1,keyasint,omitempty"`
PriceInFri *felt.Felt `cbor:"2,keyasint,omitempty"`
}

type Block struct {
Expand All @@ -81,10 +81,10 @@ func (b *Block) L2GasConsumed() uint64 {
}

type BlockCommitments struct {
TransactionCommitment *felt.Felt
EventCommitment *felt.Felt
ReceiptCommitment *felt.Felt
StateDiffCommitment *felt.Felt
TransactionCommitment *felt.Felt `cbor:"1,keyasint,omitempty"`
EventCommitment *felt.Felt `cbor:"2,keyasint,omitempty"`
ReceiptCommitment *felt.Felt `cbor:"3,keyasint,omitempty"`
StateDiffCommitment *felt.Felt `cbor:"4,keyasint,omitempty"`
}

// VerifyBlockHash verifies the block hash. Due to bugs in Starknet alpha, not all blocks have
Expand Down
66 changes: 33 additions & 33 deletions core/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ type ClassDefinition interface {
}

type DeprecatedCairoClass struct {
Abi json.RawMessage
Abi json.RawMessage `cbor:"1,keyasint,omitempty"`
// External functions defined in the class.
Externals []DeprecatedEntryPoint
Externals []DeprecatedEntryPoint `cbor:"2,keyasint,omitempty"`
// Functions that receive L1 messages. See
// https://www.cairo-lang.org/docs/hello_starknet/l1l2.html#receiving-a-message-from-l1
L1Handlers []DeprecatedEntryPoint
L1Handlers []DeprecatedEntryPoint `cbor:"3,keyasint,omitempty"`
// Constructors for the class. Currently, only one is allowed.
Constructors []DeprecatedEntryPoint
Constructors []DeprecatedEntryPoint `cbor:"4,keyasint,omitempty"`
// Base64 encoding of compressed Program
Program string
Program string `cbor:"5,keyasint,omitempty"`
}

type DeprecatedEntryPoint struct {
// starknet_keccak hash of the function signature.
Selector *felt.Felt
Selector *felt.Felt `cbor:"1,keyasint,omitempty"`
// The offset of the instruction in the class's bytecode.
Offset *felt.Felt
Offset *felt.Felt `cbor:"2,keyasint,omitempty"`
}

func (c *DeprecatedCairoClass) Version() uint64 {
Expand All @@ -68,48 +68,48 @@ func (c *DeprecatedCairoClass) SierraVersion() string {
}

type SierraClass struct {
Abi string
AbiHash *felt.Felt
EntryPoints SierraEntryPointsByType
Program []*felt.Felt
ProgramHash *felt.Felt
Abi string `cbor:"1,keyasint,omitempty"`
AbiHash *felt.Felt `cbor:"2,keyasint,omitempty"`
EntryPoints SierraEntryPointsByType `cbor:"3,keyasint,omitempty"`
Program []*felt.Felt `cbor:"4,keyasint,omitempty"`
ProgramHash *felt.Felt `cbor:"5,keyasint,omitempty"`
// TODO: Remove this semantic version on a follow up PR. Let's put Sierra version instead
SemanticVersion string
Compiled *CasmClass
SemanticVersion string `cbor:"6,keyasint,omitempty"`
Compiled *CasmClass `cbor:"7,keyasint,omitempty"`
}

type SegmentLengths struct {
Children []SegmentLengths
Length uint64
Children []SegmentLengths `cbor:"1,keyasint,omitempty"`
Length uint64 `cbor:"2,keyasint,omitempty"`
}

type CasmClass struct {
Bytecode []*felt.Felt
PythonicHints json.RawMessage
CompilerVersion string
Hints json.RawMessage
Prime *big.Int
External []CasmEntryPoint
L1Handler []CasmEntryPoint
Constructor []CasmEntryPoint
BytecodeSegmentLengths SegmentLengths
Bytecode []*felt.Felt `cbor:"1,keyasint,omitempty"`
PythonicHints json.RawMessage `cbor:"2,keyasint,omitempty"`
CompilerVersion string `cbor:"3,keyasint,omitempty"`
Hints json.RawMessage `cbor:"4,keyasint,omitempty"`
Prime *big.Int `cbor:"5,keyasint,omitempty"`
External []CasmEntryPoint `cbor:"6,keyasint,omitempty"`
L1Handler []CasmEntryPoint `cbor:"7,keyasint,omitempty"`
Constructor []CasmEntryPoint `cbor:"8,keyasint,omitempty"`
BytecodeSegmentLengths SegmentLengths `cbor:"9,keyasint,omitempty"`
}

type CasmEntryPoint struct {
Offset uint64
Builtins []string
Selector *felt.Felt
Offset uint64 `cbor:"1,keyasint,omitempty"`
Builtins []string `cbor:"2,keyasint,omitempty"`
Selector *felt.Felt `cbor:"3,keyasint,omitempty"`
}

type SierraEntryPointsByType struct {
Constructor []SierraEntryPoint
External []SierraEntryPoint
L1Handler []SierraEntryPoint
Constructor []SierraEntryPoint `cbor:"1,keyasint,omitempty"`
External []SierraEntryPoint `cbor:"2,keyasint,omitempty"`
L1Handler []SierraEntryPoint `cbor:"3,keyasint,omitempty"`
}

type SierraEntryPoint struct {
Index uint64
Selector *felt.Felt
Index uint64 `cbor:"1,keyasint,omitempty"`
Selector *felt.Felt `cbor:"2,keyasint,omitempty"`
}

func (c *SierraClass) Version() uint64 {
Expand Down
6 changes: 1 addition & 5 deletions core/class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ func TestClassEncoding(t *testing.T) {
class: &core.SierraClass{
Abi: "abi",
AbiHash: felt.NewUnsafeFromString[felt.Felt]("0xDEADBEEF"),
EntryPoints: struct {
Constructor []core.SierraEntryPoint
External []core.SierraEntryPoint
L1Handler []core.SierraEntryPoint
}{
EntryPoints: core.SierraEntryPointsByType{
Constructor: []core.SierraEntryPoint{},
External: []core.SierraEntryPoint{
{
Expand Down
6 changes: 3 additions & 3 deletions core/l1_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package core
import "github.com/NethermindEth/juno/core/felt"

type L1Head struct {
BlockNumber uint64
BlockHash *felt.Felt
StateRoot *felt.Felt
BlockNumber uint64 `cbor:"1,keyasint,omitempty"`
BlockHash *felt.Felt `cbor:"2,keyasint,omitempty"`
StateRoot *felt.Felt `cbor:"3,keyasint,omitempty"`
}
24 changes: 12 additions & 12 deletions core/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import (
)

type GasConsumed struct {
L1Gas uint64
L1DataGas uint64
L2Gas uint64
L1Gas uint64 `cbor:"1,keyasint,omitempty"`
L1DataGas uint64 `cbor:"2,keyasint,omitempty"`
L2Gas uint64 `cbor:"3,keyasint,omitempty"`
}

type TransactionReceipt struct {
Fee *felt.Felt
FeeUnit FeeUnit
Events []*Event
ExecutionResources *ExecutionResources
L1ToL2Message *L1ToL2Message
L2ToL1Message []*L2ToL1Message
TransactionHash *felt.Felt
Reverted bool
RevertReason string
Fee *felt.Felt `cbor:"1,keyasint,omitempty"`
FeeUnit FeeUnit `cbor:"2,keyasint,omitempty"`
Events []*Event `cbor:"3,keyasint,omitempty"`
ExecutionResources *ExecutionResources `cbor:"4,keyasint,omitempty"`
L1ToL2Message *L1ToL2Message `cbor:"5,keyasint,omitempty"`
L2ToL1Message []*L2ToL1Message `cbor:"6,keyasint,omitempty"`
TransactionHash *felt.Felt `cbor:"7,keyasint,omitempty"`
Reverted bool `cbor:"8,keyasint,omitempty"`
RevertReason string `cbor:"9,keyasint,omitempty"`
}

func (r *TransactionReceipt) hash() felt.Felt {
Expand Down
8 changes: 4 additions & 4 deletions core/state/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
)

type stateContract struct {
Nonce felt.Felt // Contract's nonce
ClassHash felt.Felt // Hash of the contract's class
DeployedHeight uint64 // Block height at which the contract is deployed
StorageRoot felt.Felt // Root hash of the contract's storage
Nonce felt.Felt `cbor:"1,keyasint,omitempty"` // Contract's nonce
ClassHash felt.Felt `cbor:"2,keyasint,omitempty"` // Hash of the contract's class
DeployedHeight uint64 `cbor:"3,keyasint,omitempty"` // Block height at which the contract is deployed

Check failure on line 19 in core/state/contract.go

View workflow job for this annotation

GitHub Actions / lint

The line is 105 characters long, which exceeds the maximum of 100 characters. (lll)
StorageRoot felt.Felt `cbor:"4,keyasint,omitempty"` // Root hash of the contract's storage
}

func newContractDeployed(classHash felt.Felt, deployHeight uint64) stateContract {
Expand Down
6 changes: 1 addition & 5 deletions core/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,7 @@ func TestRevert(t *testing.T) {
sierra := &core.SierraClass{
Abi: "some sierra class abi",
AbiHash: felt.NewUnsafeFromString[felt.Felt]("0xcd98"),
EntryPoints: struct {
Constructor []core.SierraEntryPoint
External []core.SierraEntryPoint
L1Handler []core.SierraEntryPoint
}{
EntryPoints: core.SierraEntryPointsByType{
Constructor: []core.SierraEntryPoint{{
Index: 1,
Selector: new(felt.Felt).SetBytes([]byte("c1")),
Expand Down
6 changes: 1 addition & 5 deletions core/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,7 @@ func TestRevert(t *testing.T) {
cairo1 := &core.SierraClass{
Abi: "some cairo 1 class abi",
AbiHash: felt.NewUnsafeFromString[felt.Felt]("0xcd98"),
EntryPoints: struct {
Constructor []core.SierraEntryPoint
External []core.SierraEntryPoint
L1Handler []core.SierraEntryPoint
}{
EntryPoints: core.SierraEntryPointsByType{
Constructor: []core.SierraEntryPoint{{
1,
felt.NewFromBytes[felt.Felt]([]byte("c1")),
Expand Down
22 changes: 11 additions & 11 deletions core/state_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@
)

type StateUpdate struct {
BlockHash *felt.Felt
NewRoot *felt.Felt
OldRoot *felt.Felt
StateDiff *StateDiff
BlockHash *felt.Felt `cbor:"1,keyasint,omitempty"`
NewRoot *felt.Felt `cbor:"2,keyasint,omitempty"`
OldRoot *felt.Felt `cbor:"3,keyasint,omitempty"`
StateDiff *StateDiff `cbor:"4,keyasint,omitempty"`
}

type StateDiff struct {
// todo(rdr): replace felt.Felt for the right types (felt.Address to felt.What? to felt.What?)
// felt.What? means I'm not sure which type, but if it doesn't exist, create it.
StorageDiffs map[felt.Felt]map[felt.Felt]*felt.Felt // addr -> {key -> value, ...}
StorageDiffs map[felt.Felt]map[felt.Felt]*felt.Felt `cbor:"1,keyasint,omitempty"` // addr -> {key -> value, ...}

Check failure on line 21 in core/state_update.go

View workflow job for this annotation

GitHub Actions / lint

The line is 113 characters long, which exceeds the maximum of 100 characters. (lll)
// todo(rdr): felt.Address to felt.Nonce (`Nonce` is a new type that should be created?)
Nonces map[felt.Felt]*felt.Felt
Nonces map[felt.Felt]*felt.Felt `cbor:"2,keyasint,omitempty"`
// todo(rdr): felt.Addr to felt.ClassHash (do we know if it will be `SierraClassHash or
// `CasmClassHash`)
DeployedContracts map[felt.Felt]*felt.Felt
DeployedContracts map[felt.Felt]*felt.Felt `cbor:"3,keyasint,omitempty"`
// todo(rdr): an array of felt.ClassHash, or perhaps, felt.DeprecatedCairoClassHash
// Also, change the name from `DeclaredV0Classes` to `DeprecatedDeclaredClasses`
DeclaredV0Classes []*felt.Felt
DeclaredV0Classes []*felt.Felt `cbor:"4,keyasint,omitempty"`
// todo(rdr): felt.SierraClassHash to felt.CasmClassHash
DeclaredV1Classes map[felt.Felt]*felt.Felt // class hash -> compiled class hash
DeclaredV1Classes map[felt.Felt]*felt.Felt `cbor:"5,keyasint,omitempty"` // class hash -> compiled class hash

Check failure on line 31 in core/state_update.go

View workflow job for this annotation

GitHub Actions / lint

The line is 110 characters long, which exceeds the maximum of 100 characters. (lll)
// todo(rdr): felt.Address to (felt.SierraClassHash or felt.CasmClassHash, I'm unsure)
ReplacedClasses map[felt.Felt]*felt.Felt // addr -> class hash
ReplacedClasses map[felt.Felt]*felt.Felt `cbor:"6,keyasint,omitempty"` // addr -> class hash
// Sierra Class definitions which had their compiled class hash definition (CASM)
// migrated from poseidon hash to blake2s hash (Starknet 0.14.1)
MigratedClasses map[felt.SierraClassHash]felt.CasmClassHash
MigratedClasses map[felt.SierraClassHash]felt.CasmClassHash `cbor:"7,keyasint,omitempty"`
}

func (d *StateDiff) Length() uint64 {
Expand Down
Loading
Loading