Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec updated #1985

Merged
merged 16 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
15 changes: 13 additions & 2 deletions adapters/core2p2p/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func AdaptClass(class core.Class) *spec.Class {

switch v := class.(type) {
case *core.Cairo0Class:
hash, err := v.Hash()
if err != nil {
panic(fmt.Errorf("failed to hash Cairo0Class: %w", err))
}
AdaptHash(hash)
AnkushinDaniil marked this conversation as resolved.
Show resolved Hide resolved
return &spec.Class{
Class: &spec.Class_Cairo0{
Cairo0: &spec.Cairo0Class{
Expand All @@ -25,9 +30,14 @@ func AdaptClass(class core.Class) *spec.Class {
Program: v.Program,
},
},
Domain: 0, // todo(kirill) recheck
Domain: 0, // todo(kirill) recheck
ClassHash: AdaptHash(hash),
}
case *core.Cairo1Class:
hash, err := v.Hash()
if err != nil {
panic(fmt.Errorf("failed to hash Cairo1Class: %w", err))
}
AnkushinDaniil marked this conversation as resolved.
Show resolved Hide resolved
return &spec.Class{
Class: &spec.Class_Cairo1{
Cairo1: &spec.Cairo1Class{
Expand All @@ -41,7 +51,8 @@ func AdaptClass(class core.Class) *spec.Class {
ContractClassVersion: v.SemanticVersion,
},
},
Domain: 0, // todo(kirill) recheck
Domain: 0, // todo(kirill) recheck
ClassHash: AdaptHash(hash),
}
default:
panic(fmt.Errorf("unsupported cairo class %T (version=%d)", v, class.Version()))
Expand Down
23 changes: 14 additions & 9 deletions adapters/core2p2p/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,30 @@ func AdaptExecutionResources(er *core.ExecutionResources) *spec.Receipt_Executio
return nil
}

var l1Gas, l1DataGas *spec.Felt252
var l1Gas, l1DataGas, totalL1Gas *spec.Felt252
if da := er.DataAvailability; da != nil { // todo(kirill) check that it might be null
l1Gas = AdaptFelt(new(felt.Felt).SetUint64(da.L1Gas))
l1DataGas = AdaptFelt(new(felt.Felt).SetUint64(da.L1DataGas))
totalL1Gas = AdaptFelt(new(felt.Felt).SetUint64(da.L1Gas + da.L1DataGas))
}
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),
Output: uint32(er.BuiltinInstanceCounter.Output),
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),
Output: uint32(er.BuiltinInstanceCounter.Output),
AddMod: uint32(er.BuiltinInstanceCounter.AddMod),
MulMod: uint32(er.BuiltinInstanceCounter.MulMod),
RangeCheck96: uint32(er.BuiltinInstanceCounter.RangeCheck96),
},
Steps: uint32(er.Steps),
MemoryHoles: uint32(er.MemoryHoles),
L1Gas: l1Gas,
L1DataGas: l1DataGas,
TotalL1Gas: totalL1Gas,
AnkushinDaniil marked this conversation as resolved.
Show resolved Hide resolved
}
}
55 changes: 28 additions & 27 deletions p2p/starknet/p2p/proto/class.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,54 @@ option go_package = "github.com/NethermindEth/juno/p2p/starknet/spec";


message EntryPoint {
Felt252 selector = 1;
uint64 offset = 2;
Felt252 selector = 1;
uint64 offset = 2;
}

message Cairo0Class {
string abi = 1;
repeated EntryPoint externals = 2;
repeated EntryPoint l1_handlers = 3;
repeated EntryPoint constructors = 4;
// Compressed in base64 representation.
string program = 5;
string abi = 1;
repeated EntryPoint externals = 2;
repeated EntryPoint l1_handlers = 3;
repeated EntryPoint constructors = 4;
// Compressed in base64 representation.
string program = 5;
}

message SierraEntryPoint {
uint64 index = 1;
Felt252 selector = 2;
uint64 index = 1;
Felt252 selector = 2;
}

message Cairo1EntryPoints {
repeated SierraEntryPoint externals = 1;
repeated SierraEntryPoint l1_handlers = 2;
repeated SierraEntryPoint constructors = 3;
repeated SierraEntryPoint externals = 1;
repeated SierraEntryPoint l1_handlers = 2;
repeated SierraEntryPoint constructors = 3;
}

message Cairo1Class {
string abi = 1;
Cairo1EntryPoints entry_points = 2;
repeated Felt252 program = 3;
string contract_class_version = 4;
string abi = 1;
Cairo1EntryPoints entry_points = 2;
repeated Felt252 program = 3;
string contract_class_version = 4;
}

message Class {
oneof class {
Cairo0Class cairo0 = 1;
Cairo1Class cairo1 = 2;
}
uint32 domain = 3;
oneof class {
Cairo0Class cairo0 = 1;
Cairo1Class cairo1 = 2;
}
uint32 domain = 3;
Hash class_hash = 4;
}

message ClassesRequest {
Iteration iteration = 1;
Iteration iteration = 1;
}

// Responses are sent ordered by the order given in the request.
message ClassesResponse {
oneof class_message {
Class class = 1;
Fin fin = 2; // Fin is sent after the peer sent all the data or when it encountered a block that it doesn't have its classes.
}
oneof class_message {
Class class = 1;
Fin fin = 2; // Fin is sent after the peer sent all the data or when it encountered a block that it doesn't have its classes.
}
}
2 changes: 1 addition & 1 deletion p2p/starknet/p2p/proto/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ message ConsensusSignature {

message Patricia {
uint64 n_leaves = 1; // needed to know the height, so as to how many nodes to expect in a proof.
// and also when receiving all leaves, how many to expect
// and also when receiving all leaves, how many to expect
Hash root = 2;
}

Expand Down
62 changes: 31 additions & 31 deletions p2p/starknet/p2p/proto/header.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,51 @@ option go_package = "github.com/NethermindEth/juno/p2p/starknet/spec";
// Note: commitments may change to be for the previous blocks like comet/tendermint
// hash of block header sent to L1
message SignedBlockHeader {
Hash block_hash = 1; // For the structure of the block hash, see https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/header/#block_hash
Hash parent_hash = 2;
uint64 number = 3; // This can be deduced from context. We can consider removing this field.
uint64 time = 4; // Encoded in Unix time.
Address sequencer_address = 5;
Hash state_root = 6; // Patricia root of contract and class patricia tries. Each of those tries are of height 251. Same as in L1. Later more trees will be included
StateDiffCommitment state_diff_commitment = 7; // The state diff commitment returned by the Starknet Feeder Gateway
// For more info, see https://community.starknet.io/t/introducing-p2p-authentication-and-mismatch-resolution-in-v0-12-2/97993
// The leaves contain a hash of the transaction hash and transaction signature.
Patricia transactions = 8; // By order of execution. TBD: required? the client can execute (powerful machine) and match state diff
Patricia events = 9; // By order of issuance. TBD: in receipts?
Hash receipts = 10; // By order of issuance. This is a patricia root. No need for length because it's the same length as transactions.
string protocol_version = 11; // Starknet version
Uint128 gas_price_fri = 12;
Uint128 gas_price_wei = 13;
Uint128 data_gas_price_fri = 14;
Uint128 data_gas_price_wei = 15;
L1DataAvailabilityMode l1_data_availability_mode = 16;
// for now, we assume a small consensus, so this fits in 1M. Else, these will be repeated and extracted from this message.
repeated ConsensusSignature signatures = 17;
// can be more explicit here about the signature structure as this is not part of account abstraction
Hash block_hash = 1; // For the structure of the block hash, see https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/header/#block_hash
Hash parent_hash = 2;
uint64 number = 3; // This can be deduced from context. We can consider removing this field.
uint64 time = 4; // Encoded in Unix time.
Address sequencer_address = 5;
Hash state_root = 6; // Patricia root of contract and class patricia tries. Each of those tries are of height 251. Same as in L1. Later more trees will be included
StateDiffCommitment state_diff_commitment = 7; // The state diff commitment returned by the Starknet Feeder Gateway
// For more info, see https://community.starknet.io/t/introducing-p2p-authentication-and-mismatch-resolution-in-v0-12-2/97993
// The leaves contain a hash of the transaction hash and transaction signature.
Patricia transactions = 8; // By order of execution. TBD: required? the client can execute (powerful machine) and match state diff
Patricia events = 9; // By order of issuance. TBD: in receipts?
Hash receipts = 10; // By order of issuance. This is a patricia root. No need for length because it's the same length as transactions.
string protocol_version = 11; // Starknet version
Uint128 gas_price_fri = 12;
Uint128 gas_price_wei = 13;
Uint128 data_gas_price_fri = 14;
Uint128 data_gas_price_wei = 15;
L1DataAvailabilityMode l1_data_availability_mode = 16;
// for now, we assume a small consensus, so this fits in 1M. Else, these will be repeated and extracted from this message.
repeated ConsensusSignature signatures = 17;
// can be more explicit here about the signature structure as this is not part of account abstraction
}

// sent to all peers (except the ones this was received from, if any).
// for a fraction of peers, also send the GetBlockHeaders response (as if they asked for it for this block)
message NewBlock {
oneof maybe_full {
BlockID id = 1;
BlockHeadersResponse header = 2;
}
oneof maybe_full {
BlockID id = 1;
BlockHeadersResponse header = 2;
}
}


message BlockHeadersRequest {
Iteration iteration = 1;
Iteration iteration = 1;
}

// Responses are sent ordered by the order given in the request.
message BlockHeadersResponse {
oneof header_message {
SignedBlockHeader header = 1;
Fin fin = 2; // Fin is sent after the peer sent all the data or when it encountered a block that it doesn't have its header.
}
oneof header_message {
SignedBlockHeader header = 1;
Fin fin = 2; // Fin is sent after the peer sent all the data or when it encountered a block that it doesn't have its header.
}
}

message BlockProof {
repeated bytes proof = 1;
repeated bytes proof = 1;
}
8 changes: 6 additions & 2 deletions p2p/starknet/p2p/proto/receipt.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ message MessageToL1 {
}

enum PriceUnit {
Wei = 0;
Fri = 1;
Wei = 0;
Fri = 1;
}

message EthereumAddress {
Expand All @@ -29,13 +29,17 @@ message Receipt {
uint32 poseidon = 6;
uint32 keccak = 7;
uint32 output = 8;
uint32 add_mod = 9;
uint32 mul_mod = 10;
uint32 range_check96 = 11;
}

BuiltinCounter builtins = 1;
uint32 steps = 2;
uint32 memory_holes = 3;
Felt252 l1_gas = 4;
Felt252 l1_data_gas = 5;
Felt252 total_l1_gas = 6;
}

message Common {
Expand Down
1 change: 1 addition & 0 deletions p2p/starknet/p2p/proto/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ message Transaction
InvokeV3 invoke_v3 = 10;
L1HandlerV0 l1_handler = 11;
}
Hash transaction_hash = 12;
kirugan marked this conversation as resolved.
Show resolved Hide resolved
}

message TransactionWithReceipt {
Expand Down
Loading
Loading