From f35d88f480b46623287b7aca6d8e3df89b98b990 Mon Sep 17 00:00:00 2001 From: Thiago Ribeiro <62709592+thiagodeev@users.noreply.github.com> Date: Mon, 30 Sep 2024 06:19:04 -0300 Subject: [PATCH 1/8] Thiagodeev/rpcv08 write methods, blockHeader and error 53 (#626) Update write methods, error 53 and block header for rpc08 --- rpc/errors.go | 4 ++-- rpc/types_block.go | 2 ++ rpc/write.go | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/rpc/errors.go b/rpc/errors.go index b11dce85..337f4d42 100644 --- a/rpc/errors.go +++ b/rpc/errors.go @@ -150,9 +150,9 @@ var ( Code: 52, Message: "Invalid transaction nonce", } - ErrInsufficientMaxFee = &RPCError{ + ErrInsufficientResourcesForValidate = &RPCError{ Code: 53, - Message: "Max fee is smaller than the minimal transaction cost (validation plus fee transfer)", + Message: "The transaction's resources don't cover validation or the minimal transaction fee", } ErrInsufficientAccountBalance = &RPCError{ Code: 54, diff --git a/rpc/types_block.go b/rpc/types_block.go index a58f0821..d54a63f3 100644 --- a/rpc/types_block.go +++ b/rpc/types_block.go @@ -174,6 +174,8 @@ type BlockHeader struct { SequencerAddress *felt.Felt `json:"sequencer_address"` // The price of l1 gas in the block L1GasPrice ResourcePrice `json:"l1_gas_price"` + // The price of l2 gas in the block + L2GasPrice ResourcePrice `json:"l2_gas_price"` // The price of l1 data gas in the block L1DataGasPrice ResourcePrice `json:"l1_data_gas_price"` // Specifies whether the data of this block is published via blob data or calldata diff --git a/rpc/write.go b/rpc/write.go index e91b3d52..123af2fc 100644 --- a/rpc/write.go +++ b/rpc/write.go @@ -18,7 +18,7 @@ func (provider *Provider) AddInvokeTransaction(ctx context.Context, invokeTxn Br return nil, tryUnwrapToRPCErr( err, ErrInsufficientAccountBalance, - ErrInsufficientMaxFee, + ErrInsufficientResourcesForValidate, ErrInvalidTransactionNonce, ErrValidationFailure, ErrNonAccount, @@ -47,7 +47,7 @@ func (provider *Provider) AddDeclareTransaction(ctx context.Context, declareTran ErrCompilationFailed, ErrCompiledClassHashMismatch, ErrInsufficientAccountBalance, - ErrInsufficientMaxFee, + ErrInsufficientResourcesForValidate, ErrInvalidTransactionNonce, ErrValidationFailure, ErrNonAccount, @@ -73,7 +73,7 @@ func (provider *Provider) AddDeployAccountTransaction(ctx context.Context, deplo return nil, tryUnwrapToRPCErr( err, ErrInsufficientAccountBalance, - ErrInsufficientMaxFee, + ErrInsufficientResourcesForValidate, ErrInvalidTransactionNonce, ErrValidationFailure, ErrNonAccount, From b97a14987ea495453b0a2f947f433796e8dc68d5 Mon Sep 17 00:00:00 2001 From: thiagodeev Date: Mon, 30 Sep 2024 09:31:31 -0300 Subject: [PATCH 2/8] Adjusts TransactionStatus --- rpc/transaction_test.go | 2 ++ rpc/types_transaction_receipt.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rpc/transaction_test.go b/rpc/transaction_test.go index a674738a..6fb914a2 100644 --- a/rpc/transaction_test.go +++ b/rpc/transaction_test.go @@ -179,6 +179,8 @@ func TestTransactionReceipt(t *testing.T) { // TestGetTransactionStatus tests starknet_getTransactionStatus func TestGetTransactionStatus(t *testing.T) { + //TODO: implement a test case to 'failure_reason' before merge + testConfig := beforeEach(t) type testSetType struct { diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index d9d04d4a..755734a9 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -176,8 +176,9 @@ const ( ) type TxnStatusResp struct { - ExecutionStatus TxnExecutionStatus `json:"execution_status,omitempty"` FinalityStatus TxnStatus `json:"finality_status"` + ExecutionStatus TxnExecutionStatus `json:"execution_status,omitempty"` + FailureReason string `json:"failure_reason,omitempty"` } type TransactionReceiptWithBlockInfo struct { From de722c1a9ffbac060ddefd0e5dcdaa72ef185e84 Mon Sep 17 00:00:00 2001 From: thiagodeev Date: Mon, 30 Sep 2024 10:07:56 -0300 Subject: [PATCH 3/8] Adjusts EstimateFee --- rpc/contract_test.go | 347 ++++++++++++++++++++++--------------------- rpc/mock_test.go | 36 +++-- rpc/types.go | 16 +- 3 files changed, 210 insertions(+), 189 deletions(-) diff --git a/rpc/contract_test.go b/rpc/contract_test.go index 5b621e5c..36762474 100644 --- a/rpc/contract_test.go +++ b/rpc/contract_test.go @@ -397,6 +397,7 @@ func TestNonce(t *testing.T) { // // none func TestEstimateMessageFee(t *testing.T) { + //TODO: upgrade the testnet test case before merge testConfig := beforeEach(t) type testSetType struct { @@ -426,25 +427,27 @@ func TestEstimateMessageFee(t *testing.T) { MsgFromL1: MsgFromL1{FromAddress: "0x0", ToAddress: &felt.Zero, Selector: &felt.Zero, Payload: []*felt.Felt{&felt.Zero}}, BlockID: BlockID{Tag: "latest"}, ExpectedFeeEst: &FeeEstimation{ - GasConsumed: new(felt.Felt).SetUint64(1), - GasPrice: new(felt.Felt).SetUint64(2), - OverallFee: new(felt.Felt).SetUint64(3), + L1GasConsumed: utils.RANDOM_FELT, + L1GasPrice: utils.RANDOM_FELT, + L2GasConsumed: utils.RANDOM_FELT, + L2GasPrice: utils.RANDOM_FELT, + OverallFee: utils.RANDOM_FELT, }, }, }, "testnet": { - { - MsgFromL1: l1Handler, - BlockID: WithBlockNumber(122476), - ExpectedFeeEst: &FeeEstimation{ - GasConsumed: utils.TestHexToFelt(t, "0x567b"), - GasPrice: utils.TestHexToFelt(t, "0x28fb3be9e"), - DataGasConsumed: &felt.Zero, - DataGasPrice: utils.TestHexToFelt(t, "0x216251c284"), - OverallFee: utils.TestHexToFelt(t, "0xdd816d65a9ea"), - FeeUnit: UnitWei, - }, - }, + // { + // MsgFromL1: l1Handler, + // BlockID: WithBlockNumber(122476), + // ExpectedFeeEst: &FeeEstimation{ + // GasConsumed: utils.TestHexToFelt(t, "0x567b"), + // GasPrice: utils.TestHexToFelt(t, "0x28fb3be9e"), + // DataGasConsumed: &felt.Zero, + // DataGasPrice: utils.TestHexToFelt(t, "0x216251c284"), + // OverallFee: utils.TestHexToFelt(t, "0xdd816d65a9ea"), + // FeeUnit: UnitWei, + // }, + // }, { // invalid msg data MsgFromL1: MsgFromL1{ FromAddress: "0x8453fc6cd1bcfe8d4dfc069c400b433054d47bdc", @@ -475,6 +478,8 @@ func TestEstimateMessageFee(t *testing.T) { } func TestEstimateFee(t *testing.T) { + //TODO: upgrade the mainnet and testnet test cases before merge + testConfig := beforeEach(t) type testSetType struct { @@ -492,86 +497,86 @@ func TestEstimateFee(t *testing.T) { require.NoError(t, err) testSet := map[string][]testSetType{ - "mainnet": { - { - txs: []BroadcastTxn{ - InvokeTxnV0{ - Type: TransactionType_Invoke, - Version: TransactionV0, - MaxFee: utils.TestHexToFelt(t, "0x95e566845d000"), - FunctionCall: FunctionCall{ - ContractAddress: utils.TestHexToFelt(t, "0x45e92c365ba0908382bc346159f896e528214470c60ae2cd4038a0fff747b1e"), - EntryPointSelector: utils.TestHexToFelt(t, "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad"), - Calldata: utils.TestHexArrToFelt(t, []string{ - "0x1", - "0x4a3621276a83251b557a8140e915599ae8e7b6207b067ea701635c0d509801e", - "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354", - "0x0", - "0x3", - "0x3", - "0x697066733a2f2f516d57554c7a475135556a52616953514776717765347931", - "0x4731796f4757324e6a5a76564e77776a66514577756a", - "0x0", - "0x2"}), - }, - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x63e4618ca2e323a45b9f860f12a4f5c4984648f1d110aa393e79d596d82abcc"), - utils.TestHexToFelt(t, "0x2844257b088ad4f49e2fe3df1ea6a8530aa2d21d8990112b7e88c4bd0ce9d50"), - }, - }, - }, - simFlags: []SimulationFlag{}, - blockID: WithBlockNumber(15643), - expectedError: nil, - expectedResp: []FeeEstimation{ - { - GasConsumed: utils.TestHexToFelt(t, "0x3074"), - GasPrice: utils.TestHexToFelt(t, "0x350da9915"), - DataGasConsumed: &felt.Zero, - DataGasPrice: new(felt.Felt).SetUint64(1), - OverallFee: utils.TestHexToFelt(t, "0xa0a99fc14d84"), - FeeUnit: UnitWei, - }, - }, - }, - { - txs: []BroadcastTxn{ - DeployAccountTxn{ - - Type: TransactionType_DeployAccount, - Version: TransactionV1, - MaxFee: utils.TestHexToFelt(t, "0xdec823b1380c"), - Nonce: utils.TestHexToFelt(t, "0x0"), - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x41dbc4b41f6506502a09eb7aea85759de02e91f49d0565776125946e54a2ec6"), - utils.TestHexToFelt(t, "0x85dcf2bc8e3543071a6657947cc9c157a9f6ad7844a686a975b588199634a9"), - }, - ContractAddressSalt: utils.TestHexToFelt(t, "0x74ddc51af144d1bd805eb4184d07453d7c4388660270a7851fec387e654a50e"), - ClassHash: utils.TestHexToFelt(t, "0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918"), - ConstructorCalldata: utils.TestHexArrToFelt(t, []string{ - "0x33434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2", - "0x79dc0da7c54b95f10aa182ad0a46400db63156920adb65eca2654c0945a463", - "0x2", - "0x74ddc51af144d1bd805eb4184d07453d7c4388660270a7851fec387e654a50e", - "0x0", - }), - }, - }, - simFlags: []SimulationFlag{}, - blockID: WithBlockHash(utils.TestHexToFelt(t, "0x1b0df1bafcb826b1fc053495aef5cdc24d0345cbfa1259b15939d01b89dc6d9")), - expectedError: nil, - expectedResp: []FeeEstimation{ - { - GasConsumed: utils.TestHexToFelt(t, "0x1154"), - GasPrice: utils.TestHexToFelt(t, "0x378f962c4"), - DataGasConsumed: &felt.Zero, - DataGasPrice: new(felt.Felt).SetUint64(1), - OverallFee: utils.TestHexToFelt(t, "0x3c2c41636c50"), - FeeUnit: UnitWei, - }, - }, - }, - }, + // "mainnet": { + // { + // txs: []BroadcastTxn{ + // InvokeTxnV0{ + // Type: TransactionType_Invoke, + // Version: TransactionV0, + // MaxFee: utils.TestHexToFelt(t, "0x95e566845d000"), + // FunctionCall: FunctionCall{ + // ContractAddress: utils.TestHexToFelt(t, "0x45e92c365ba0908382bc346159f896e528214470c60ae2cd4038a0fff747b1e"), + // EntryPointSelector: utils.TestHexToFelt(t, "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad"), + // Calldata: utils.TestHexArrToFelt(t, []string{ + // "0x1", + // "0x4a3621276a83251b557a8140e915599ae8e7b6207b067ea701635c0d509801e", + // "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354", + // "0x0", + // "0x3", + // "0x3", + // "0x697066733a2f2f516d57554c7a475135556a52616953514776717765347931", + // "0x4731796f4757324e6a5a76564e77776a66514577756a", + // "0x0", + // "0x2"}), + // }, + // Signature: []*felt.Felt{ + // utils.TestHexToFelt(t, "0x63e4618ca2e323a45b9f860f12a4f5c4984648f1d110aa393e79d596d82abcc"), + // utils.TestHexToFelt(t, "0x2844257b088ad4f49e2fe3df1ea6a8530aa2d21d8990112b7e88c4bd0ce9d50"), + // }, + // }, + // }, + // simFlags: []SimulationFlag{}, + // blockID: WithBlockNumber(15643), + // expectedError: nil, + // expectedResp: []FeeEstimation{ + // { + // GasConsumed: utils.TestHexToFelt(t, "0x3074"), + // GasPrice: utils.TestHexToFelt(t, "0x350da9915"), + // DataGasConsumed: &felt.Zero, + // DataGasPrice: new(felt.Felt).SetUint64(1), + // OverallFee: utils.TestHexToFelt(t, "0xa0a99fc14d84"), + // FeeUnit: UnitWei, + // }, + // }, + // }, + // { + // txs: []BroadcastTxn{ + // DeployAccountTxn{ + + // Type: TransactionType_DeployAccount, + // Version: TransactionV1, + // MaxFee: utils.TestHexToFelt(t, "0xdec823b1380c"), + // Nonce: utils.TestHexToFelt(t, "0x0"), + // Signature: []*felt.Felt{ + // utils.TestHexToFelt(t, "0x41dbc4b41f6506502a09eb7aea85759de02e91f49d0565776125946e54a2ec6"), + // utils.TestHexToFelt(t, "0x85dcf2bc8e3543071a6657947cc9c157a9f6ad7844a686a975b588199634a9"), + // }, + // ContractAddressSalt: utils.TestHexToFelt(t, "0x74ddc51af144d1bd805eb4184d07453d7c4388660270a7851fec387e654a50e"), + // ClassHash: utils.TestHexToFelt(t, "0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918"), + // ConstructorCalldata: utils.TestHexArrToFelt(t, []string{ + // "0x33434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2", + // "0x79dc0da7c54b95f10aa182ad0a46400db63156920adb65eca2654c0945a463", + // "0x2", + // "0x74ddc51af144d1bd805eb4184d07453d7c4388660270a7851fec387e654a50e", + // "0x0", + // }), + // }, + // }, + // simFlags: []SimulationFlag{}, + // blockID: WithBlockHash(utils.TestHexToFelt(t, "0x1b0df1bafcb826b1fc053495aef5cdc24d0345cbfa1259b15939d01b89dc6d9")), + // expectedError: nil, + // expectedResp: []FeeEstimation{ + // { + // GasConsumed: utils.TestHexToFelt(t, "0x1154"), + // GasPrice: utils.TestHexToFelt(t, "0x378f962c4"), + // DataGasConsumed: &felt.Zero, + // DataGasPrice: new(felt.Felt).SetUint64(1), + // OverallFee: utils.TestHexToFelt(t, "0x3c2c41636c50"), + // FeeUnit: UnitWei, + // }, + // }, + // }, + // }, "mock": { { // without flag txs: []BroadcastTxn{ @@ -582,12 +587,14 @@ func TestEstimateFee(t *testing.T) { expectedError: nil, expectedResp: []FeeEstimation{ { - GasConsumed: utils.RANDOM_FELT, - GasPrice: utils.RANDOM_FELT, - DataGasConsumed: utils.RANDOM_FELT, - DataGasPrice: utils.RANDOM_FELT, - OverallFee: utils.RANDOM_FELT, - FeeUnit: UnitWei, + L1GasConsumed: utils.RANDOM_FELT, + L1GasPrice: utils.RANDOM_FELT, + L2GasConsumed: utils.RANDOM_FELT, + L2GasPrice: utils.RANDOM_FELT, + L1DataGasConsumed: utils.RANDOM_FELT, + L1DataGasPrice: utils.RANDOM_FELT, + OverallFee: utils.RANDOM_FELT, + FeeUnit: UnitWei, }, }, }, @@ -600,78 +607,80 @@ func TestEstimateFee(t *testing.T) { expectedError: nil, expectedResp: []FeeEstimation{ { - GasConsumed: new(felt.Felt).SetUint64(1234), - GasPrice: new(felt.Felt).SetUint64(1234), - DataGasConsumed: new(felt.Felt).SetUint64(1234), - DataGasPrice: new(felt.Felt).SetUint64(1234), - OverallFee: new(felt.Felt).SetUint64(1234), - FeeUnit: UnitWei, + L1GasConsumed: new(felt.Felt).SetUint64(1234), + L1GasPrice: new(felt.Felt).SetUint64(1234), + L2GasConsumed: new(felt.Felt).SetUint64(1234), + L2GasPrice: new(felt.Felt).SetUint64(1234), + L1DataGasConsumed: new(felt.Felt).SetUint64(1234), + L1DataGasPrice: new(felt.Felt).SetUint64(1234), + OverallFee: new(felt.Felt).SetUint64(1234), + FeeUnit: UnitWei, }, }, }, }, - "testnet": { - { // without flag - txs: []BroadcastTxn{ - bradcastInvokeV1, - }, - simFlags: []SimulationFlag{}, - blockID: WithBlockNumber(100000), - expectedError: nil, - expectedResp: []FeeEstimation{ - { - GasConsumed: utils.TestHexToFelt(t, "0x123c"), - GasPrice: utils.TestHexToFelt(t, "0x831211d3b"), - DataGasConsumed: &felt.Zero, - DataGasPrice: utils.TestHexToFelt(t, "0x1b10c"), - OverallFee: utils.TestHexToFelt(t, "0x955fd7d0ffd4"), - FeeUnit: UnitWei, - }, - }, - }, - { // with flag - txs: []BroadcastTxn{ - bradcastInvokeV1, - }, - simFlags: []SimulationFlag{SKIP_VALIDATE}, - blockID: WithBlockNumber(100000), - expectedError: nil, - expectedResp: []FeeEstimation{ - { - GasConsumed: utils.TestHexToFelt(t, "0x1239"), - GasPrice: utils.TestHexToFelt(t, "0x831211d3b"), - DataGasConsumed: &felt.Zero, - DataGasPrice: utils.TestHexToFelt(t, "0x1b10c"), - OverallFee: utils.TestHexToFelt(t, "0x9547446da823"), - FeeUnit: UnitWei, - }, - }, - }, - { // invalid transaction - txs: []BroadcastTxn{ - InvokeTxnV1{ - MaxFee: utils.RANDOM_FELT, - Type: TransactionType_Invoke, - Version: TransactionV1, - SenderAddress: utils.RANDOM_FELT, - Nonce: utils.RANDOM_FELT, - Calldata: []*felt.Felt{}, - Signature: []*felt.Felt{}, - }, - }, - simFlags: []SimulationFlag{}, - blockID: WithBlockNumber(100000), - expectedError: ErrTxnExec, - }, - { // invalid block - txs: []BroadcastTxn{ - bradcastInvokeV1, - }, - simFlags: []SimulationFlag{}, - blockID: WithBlockNumber(9999999999999999999), - expectedError: ErrBlockNotFound, - }, - }, + // "testnet": { + // { // without flag + // txs: []BroadcastTxn{ + // bradcastInvokeV1, + // }, + // simFlags: []SimulationFlag{}, + // blockID: WithBlockNumber(100000), + // expectedError: nil, + // expectedResp: []FeeEstimation{ + // { + // GasConsumed: utils.TestHexToFelt(t, "0x123c"), + // GasPrice: utils.TestHexToFelt(t, "0x831211d3b"), + // DataGasConsumed: &felt.Zero, + // DataGasPrice: utils.TestHexToFelt(t, "0x1b10c"), + // OverallFee: utils.TestHexToFelt(t, "0x955fd7d0ffd4"), + // FeeUnit: UnitWei, + // }, + // }, + // }, + // { // with flag + // txs: []BroadcastTxn{ + // bradcastInvokeV1, + // }, + // simFlags: []SimulationFlag{SKIP_VALIDATE}, + // blockID: WithBlockNumber(100000), + // expectedError: nil, + // expectedResp: []FeeEstimation{ + // { + // GasConsumed: utils.TestHexToFelt(t, "0x1239"), + // GasPrice: utils.TestHexToFelt(t, "0x831211d3b"), + // DataGasConsumed: &felt.Zero, + // DataGasPrice: utils.TestHexToFelt(t, "0x1b10c"), + // OverallFee: utils.TestHexToFelt(t, "0x9547446da823"), + // FeeUnit: UnitWei, + // }, + // }, + // }, + // { // invalid transaction + // txs: []BroadcastTxn{ + // InvokeTxnV1{ + // MaxFee: utils.RANDOM_FELT, + // Type: TransactionType_Invoke, + // Version: TransactionV1, + // SenderAddress: utils.RANDOM_FELT, + // Nonce: utils.RANDOM_FELT, + // Calldata: []*felt.Felt{}, + // Signature: []*felt.Felt{}, + // }, + // }, + // simFlags: []SimulationFlag{}, + // blockID: WithBlockNumber(100000), + // expectedError: ErrTxnExec, + // }, + // { // invalid block + // txs: []BroadcastTxn{ + // bradcastInvokeV1, + // }, + // simFlags: []SimulationFlag{}, + // blockID: WithBlockNumber(9999999999999999999), + // expectedError: ErrBlockNotFound, + // }, + // }, }[testEnv] for _, test := range testSet { diff --git a/rpc/mock_test.go b/rpc/mock_test.go index cee0a729..71d009ef 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -682,21 +682,25 @@ func mock_starknet_estimateFee(result interface{}, args ...interface{}) error { if len(flags) > 0 { output = FeeEstimation{ - GasConsumed: new(felt.Felt).SetUint64(1234), - GasPrice: new(felt.Felt).SetUint64(1234), - DataGasConsumed: new(felt.Felt).SetUint64(1234), - DataGasPrice: new(felt.Felt).SetUint64(1234), - OverallFee: new(felt.Felt).SetUint64(1234), - FeeUnit: UnitWei, + L1GasConsumed: new(felt.Felt).SetUint64(1234), + L1GasPrice: new(felt.Felt).SetUint64(1234), + L2GasConsumed: new(felt.Felt).SetUint64(1234), + L2GasPrice: new(felt.Felt).SetUint64(1234), + L1DataGasConsumed: new(felt.Felt).SetUint64(1234), + L1DataGasPrice: new(felt.Felt).SetUint64(1234), + OverallFee: new(felt.Felt).SetUint64(1234), + FeeUnit: UnitWei, } } else { output = FeeEstimation{ - GasConsumed: utils.RANDOM_FELT, - GasPrice: utils.RANDOM_FELT, - DataGasConsumed: utils.RANDOM_FELT, - DataGasPrice: utils.RANDOM_FELT, - OverallFee: utils.RANDOM_FELT, - FeeUnit: UnitWei, + L1GasConsumed: utils.RANDOM_FELT, + L1GasPrice: utils.RANDOM_FELT, + L2GasConsumed: utils.RANDOM_FELT, + L2GasPrice: utils.RANDOM_FELT, + L1DataGasConsumed: utils.RANDOM_FELT, + L1DataGasPrice: utils.RANDOM_FELT, + OverallFee: utils.RANDOM_FELT, + FeeUnit: UnitWei, } } @@ -738,9 +742,11 @@ func mock_starknet_estimateMessageFee(result interface{}, args ...interface{}) e } output := FeeEstimation{ - GasConsumed: new(felt.Felt).SetUint64(1), - GasPrice: new(felt.Felt).SetUint64(2), - OverallFee: new(felt.Felt).SetUint64(3), + L1GasConsumed: utils.RANDOM_FELT, + L1GasPrice: utils.RANDOM_FELT, + L2GasConsumed: utils.RANDOM_FELT, + L2GasPrice: utils.RANDOM_FELT, + OverallFee: utils.RANDOM_FELT, } outputContent, err := json.Marshal(output) if err != nil { diff --git a/rpc/types.go b/rpc/types.go index 9634ea66..a412afae 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -188,17 +188,23 @@ type TxDetails struct { } type FeeEstimation struct { - // The Ethereum gas consumption of the transaction - GasConsumed *felt.Felt `json:"gas_consumed"` + // The Ethereum gas consumption of the transaction, charged for L1->L2 messages and, depending on the block's DA_MODE, state diffs + L1GasConsumed *felt.Felt `json:"l1_gas_consumed"` // The gas price (in wei or fri, depending on the tx version) that was used in the cost estimation. - GasPrice *felt.Felt `json:"gas_price"` + L1GasPrice *felt.Felt `json:"l1_gas_price"` + + // The L2 gas consumption of the transaction + L2GasConsumed *felt.Felt `json:"l2_gas_consumed"` + + // The L2 gas price (in wei or fri, depending on the tx version) that was used in the cost estimation. + L2GasPrice *felt.Felt `json:"l2_gas_price"` // The Ethereum data gas consumption of the transaction. - DataGasConsumed *felt.Felt `json:"data_gas_consumed"` + L1DataGasConsumed *felt.Felt `json:"l1_data_gas_consumed"` // The data gas price (in wei or fri, depending on the tx version) that was used in the cost estimation. - DataGasPrice *felt.Felt `json:"data_gas_price"` + L1DataGasPrice *felt.Felt `json:"l1_data_gas_price"` // The estimated fee for the transaction (in wei or fri, depending on the tx version), equals to gas_consumed*gas_price + data_gas_consumed*data_gas_price. OverallFee *felt.Felt `json:"overall_fee"` From 75425d387bc3c90dc95605bf2cf107a05afa880a Mon Sep 17 00:00:00 2001 From: thiagodeev Date: Mon, 30 Sep 2024 10:08:19 -0300 Subject: [PATCH 4/8] Fixes blockTest error --- rpc/block_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/rpc/block_test.go b/rpc/block_test.go index 5256bcdd..fd5e7fc5 100644 --- a/rpc/block_test.go +++ b/rpc/block_test.go @@ -655,5 +655,4 @@ func validatePendingBlockHeader(t *testing.T, pBlock *PendingBlockHeader) { require.NotZero(t, pBlock.L1GasPrice) require.NotZero(t, pBlock.StarknetVersion) require.NotZero(t, pBlock.L1DataGasPrice) - require.NotNil(t, pBlock.L1DAMode) } From ae6e233c70318871f5687f001794ec79c83960b8 Mon Sep 17 00:00:00 2001 From: Thiago Ribeiro <62709592+thiagodeev@users.noreply.github.com> Date: Mon, 28 Oct 2024 07:20:01 -0300 Subject: [PATCH 5/8] Adds GetStorageProof method (#635) * implement rpcv8 GetStorageProof method --- mocks/mock_rpc_provider.go | 15 +++++ rpc/contract.go | 18 ++++++ rpc/contract_test.go | 4 ++ rpc/errors.go | 4 ++ rpc/provider.go | 1 + rpc/types_contract.go | 110 +++++++++++++++++++++++++++++++++++++ 6 files changed, 152 insertions(+) diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index 6e86bf39..a8edd76f 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -296,6 +296,21 @@ func (mr *MockRpcProviderMockRecorder) Events(ctx, input any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Events", reflect.TypeOf((*MockRpcProvider)(nil).Events), ctx, input) } +// GetStorageProof mocks base method. +func (m *MockRpcProvider) GetStorageProof(ctx context.Context, storageProofInput rpc.StorageProofInput) (*rpc.StorageProofResult, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorageProof", ctx, storageProofInput) + ret0, _ := ret[0].(*rpc.StorageProofResult) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorageProof indicates an expected call of GetStorageProof. +func (mr *MockRpcProviderMockRecorder) GetStorageProof(ctx, storageProofInput any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageProof", reflect.TypeOf((*MockRpcProvider)(nil).GetStorageProof), ctx, storageProofInput) +} + // GetTransactionStatus mocks base method. func (m *MockRpcProvider) GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*rpc.TxnStatusResp, error) { m.ctrl.T.Helper() diff --git a/rpc/contract.go b/rpc/contract.go index 8dcbe64e..0cf00ba7 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -160,3 +160,21 @@ func (provider *Provider) EstimateMessageFee(ctx context.Context, msg MsgFromL1, } return &raw, nil } + +// Get merkle paths in one of the state tries: global state, classes, individual contract. +// A single request can query for any mix of the three types of storage proofs (classes, contracts, and storage) +// +// Parameters: +// - ctx: The context of the function call +// - storageProofInput: an input containing at least one of the fields filled +// Returns: +// - *StorageProofResult: the proofs of the field passed in the input +// - error: an error if any occurred during the execution +func (provider *Provider) GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error) { + var raw StorageProofResult + if err := do(ctx, provider.c, "starknet_getStorageProof", &raw, storageProofInput); err != nil { + + return nil, tryUnwrapToRPCErr(err, ErrBlockNotFound, ErrStorageProofNotSupported) + } + return &raw, nil +} diff --git a/rpc/contract_test.go b/rpc/contract_test.go index 36762474..7c0a23c2 100644 --- a/rpc/contract_test.go +++ b/rpc/contract_test.go @@ -692,3 +692,7 @@ func TestEstimateFee(t *testing.T) { } } } + +func TestGetStorageProof(t *testing.T) { + t.Skip("TODO: create a test before merge") +} diff --git a/rpc/errors.go b/rpc/errors.go index 337f4d42..d0effbf6 100644 --- a/rpc/errors.go +++ b/rpc/errors.go @@ -138,6 +138,10 @@ var ( Code: 41, Message: "Transaction execution error", } + ErrStorageProofNotSupported = &RPCError{ + Code: 42, + Message: "the node doesn't support storage proofs for blocks that are too far in the past", + } ErrInvalidContractClass = &RPCError{ Code: 50, Message: "Invalid contract class", diff --git a/rpc/provider.go b/rpc/provider.go index f7a5e53a..9159e7cc 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -59,6 +59,7 @@ type RpcProvider interface { EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimation, error) Events(ctx context.Context, input EventsInput) (*EventChunk, error) BlockWithReceipts(ctx context.Context, blockID BlockID) (interface{}, error) + GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error) GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*TxnStatusResp, error) Nonce(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*felt.Felt, error) SimulateTransactions(ctx context.Context, blockID BlockID, txns []BroadcastTxn, simulationFlags []SimulationFlag) ([]SimulatedTransaction, error) diff --git a/rpc/types_contract.go b/rpc/types_contract.go index 7dc88b25..d7ea97b7 100644 --- a/rpc/types_contract.go +++ b/rpc/types_contract.go @@ -74,6 +74,79 @@ type ContractClass struct { ABI string `json:"abi,omitempty"` } +type StorageProofInput struct { + // The hash of the requested block, or number (height) of the requested block, or a block tag + BlockID BlockID `json:"block_id"` + // A list of the class hashes for which we want to prove membership in the classes trie + ClassHashes []*felt.Felt `json:"class_hashes,omitempty"` + // A list of contracts for which we want to prove membership in the global state trie + ContractAddresses []*felt.Felt `json:"contract_addresses,omitempty"` + // A list of (contract_address, storage_keys) pairs + ContractsStorageKeys []ContractStorageKeys `json:"contracts_storage_keys,omitempty"` +} + +type ContractStorageKeys struct { + ContractAddress *felt.Felt `json:"contract_address"` + StorageKeys []*felt.Felt `json:"storage_keys"` +} + +// The requested storage proofs. Note that if a requested leaf has the default value, +// the path to it may end in an edge node whose path is not a prefix of the requested leaf, +// thus effecitvely proving non-membership +type StorageProofResult struct { + ClassesProof NodeHashToNode `json:"classes_proof"` + ContractsProof ContractsProof `json:"contracts_proof"` + ContractsStorageProofs []NodeHashToNode `json:"contracts_storage_proofs"` + GlobalRoots []NodeHashToNode `json:"global_roots"` +} + +type ContractsProof struct { + // The nodes in the union of the paths from the contracts tree root to the requested leaves + Nodes NodeHashToNode `json:"nodes"` + ContractLeavesData []ContractLeavesData `json:"contract_leaves_data"` +} + +// The nonce and class hash for each requested contract address, in the order in which +// they appear in the request. These values are needed to construct the associated leaf node +type ContractLeavesData struct { + Nonce *felt.Felt `json:"nonce"` + ClassHash *felt.Felt `json:"class_hash"` +} + +type GlobalRoots struct { + ContractsTreeRoot *felt.Felt `json:"contracts_tree_root"` + ClassesTreeRoot *felt.Felt `json:"classes_tree_root"` + // the associated block hash (needed in case the caller used a block tag for the block_id parameter) + BlockHash *felt.Felt `json:"block_hash"` +} + +// A node_hash -> node mapping of all the nodes in the union of the paths between the requested leaves and the root +type NodeHashToNode struct { + NodeHash *felt.Felt `json:"node_hash"` + Node MerkleNode `json:"node"` +} + +// A node in the Merkle-Patricia tree, can be a leaf, binary node, or an edge node +type MerkleNode interface{} // it should be an EdgeNode or BinaryNode + +// Represents a path to the highest non-zero descendant node +type EdgeNode struct { + // an integer whose binary representation represents the path from the current node to its highest non-zero descendant (bounded by 2^251) + Path NumAsHex `json:"path"` + // the length of the path (bounded by 251) + Length uint `json:"length"` + // the hash of the unique non-zero maximal-height descendant node + Child *felt.Felt `json:"child"` +} + +// An internal node whose both children are non-zero +type BinaryNode struct { + // the hash of the left child + Left *felt.Felt `json:"left"` + // the hash of the right child + Right *felt.Felt `json:"right"` +} + // UnmarshalJSON unmarshals the JSON content into the DeprecatedContractClass struct. // // It takes a byte array `content` as a parameter and returns an error if there is any. @@ -168,6 +241,43 @@ func (c *DeprecatedContractClass) UnmarshalJSON(content []byte) error { return nil } +func (nodeHashToNode *NodeHashToNode) UnmarshalJSON(bytes []byte) error { + valueMap := make(map[string]any) + if err := json.Unmarshal(bytes, &valueMap); err != nil { + return err + } + + nodeHash, ok := valueMap["node_hash"] + if !ok { + return fmt.Errorf("missing 'node_hash' in json object") + } + nodeHashFelt, ok := nodeHash.(felt.Felt) + if !ok { + return fmt.Errorf("error casting 'node_hash' to felt.Felt") + } + + node, ok := valueMap["node"] + if !ok { + return fmt.Errorf("missing 'node' in json object") + } + var merkleNode MerkleNode + switch nodeT := node.(type) { + case BinaryNode: + merkleNode = nodeT + case EdgeNode: + merkleNode = nodeT + default: + return fmt.Errorf("'node' should be an EdgeNode or BinaryNode") + } + + *nodeHashToNode = NodeHashToNode{ + NodeHash: &nodeHashFelt, + Node: merkleNode, + } + + return nil +} + type SierraEntryPoint struct { // The index of the function in the program FunctionIdx int `json:"function_idx"` From 98d2b5c2c4421549d35aa561adc56ea491981c86 Mon Sep 17 00:00:00 2001 From: Thiago Ribeiro <62709592+thiagodeev@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:24:53 -0300 Subject: [PATCH 6/8] Adds GetMessagesStatus method (#634) * Added GetMessagesStatus method * PR comment fixes --- mocks/mock_rpc_provider.go | 15 +++++++++++++++ rpc/provider.go | 3 ++- rpc/transaction.go | 17 +++++++++++++++++ rpc/transaction_test.go | 4 ++++ rpc/types_transaction_receipt.go | 9 +++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index a8edd76f..9a62fc94 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -296,6 +296,21 @@ func (mr *MockRpcProviderMockRecorder) Events(ctx, input any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Events", reflect.TypeOf((*MockRpcProvider)(nil).Events), ctx, input) } +// GetMessagesStatus mocks base method. +func (m *MockRpcProvider) GetMessagesStatus(ctx context.Context, transactionHash rpc.NumAsHex) ([]rpc.MessageStatusResp, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMessagesStatus", ctx, transactionHash) + ret0, _ := ret[0].([]rpc.MessageStatusResp) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetMessagesStatus indicates an expected call of GetMessagesStatus. +func (mr *MockRpcProviderMockRecorder) GetMessagesStatus(ctx, transactionHash any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMessagesStatus", reflect.TypeOf((*MockRpcProvider)(nil).GetMessagesStatus), ctx, transactionHash) +} + // GetStorageProof mocks base method. func (m *MockRpcProvider) GetStorageProof(ctx context.Context, storageProofInput rpc.StorageProofInput) (*rpc.StorageProofResult, error) { m.ctrl.T.Helper() diff --git a/rpc/provider.go b/rpc/provider.go index 9159e7cc..36852c5a 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -48,6 +48,7 @@ type RpcProvider interface { BlockHashAndNumber(ctx context.Context) (*BlockHashAndNumberOutput, error) BlockNumber(ctx context.Context) (uint64, error) BlockTransactionCount(ctx context.Context, blockID BlockID) (uint64, error) + BlockWithReceipts(ctx context.Context, blockID BlockID) (interface{}, error) BlockWithTxHashes(ctx context.Context, blockID BlockID) (interface{}, error) BlockWithTxs(ctx context.Context, blockID BlockID) (interface{}, error) Call(ctx context.Context, call FunctionCall, block BlockID) ([]*felt.Felt, error) @@ -58,9 +59,9 @@ type RpcProvider interface { EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimation, error) EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimation, error) Events(ctx context.Context, input EventsInput) (*EventChunk, error) - BlockWithReceipts(ctx context.Context, blockID BlockID) (interface{}, error) GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error) GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*TxnStatusResp, error) + GetMessagesStatus(ctx context.Context, transactionHash NumAsHex) ([]MessageStatusResp, error) Nonce(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*felt.Felt, error) SimulateTransactions(ctx context.Context, blockID BlockID, txns []BroadcastTxn, simulationFlags []SimulationFlag) ([]SimulatedTransaction, error) StateUpdate(ctx context.Context, blockID BlockID) (*StateUpdateOutput, error) diff --git a/rpc/transaction.go b/rpc/transaction.go index 7d2743e4..32485d10 100644 --- a/rpc/transaction.go +++ b/rpc/transaction.go @@ -71,3 +71,20 @@ func (provider *Provider) GetTransactionStatus(ctx context.Context, transactionH } return &receipt, nil } + +// Given an L1 tx hash, returns the associated l1_handler tx hashes and statuses for all L1 -> L2 messages sent by the l1 transaction, ordered by the L1 tx sending order +// +// Parameters: +// - ctx: the context.Context object for cancellation and timeouts. +// - transactionHash: The hash of the L1 transaction that sent L1->L2 messages +// Returns: +// - [] MessageStatusResp: An array containing the status of the messages sent by the L1 transaction +// - error, if one arose. +func (provider *Provider) GetMessagesStatus(ctx context.Context, transactionHash NumAsHex) ([]MessageStatusResp, error) { + var response []MessageStatusResp + err := do(ctx, provider.c, "starknet_getMessagesStatus", &response, transactionHash) + if err != nil { + return nil, tryUnwrapToRPCErr(err, ErrHashNotFound) + } + return response, nil +} diff --git a/rpc/transaction_test.go b/rpc/transaction_test.go index 6fb914a2..8525cc8d 100644 --- a/rpc/transaction_test.go +++ b/rpc/transaction_test.go @@ -205,3 +205,7 @@ func TestGetTransactionStatus(t *testing.T) { require.Equal(t, *resp, test.ExpectedResp) } } + +func TestGetMessagesStatus(t *testing.T) { + t.Skip("TODO: create a test before merge") +} diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index 755734a9..969c4fbd 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -28,6 +28,15 @@ type MsgFromL1 struct { Payload []*felt.Felt `json:"payload"` } +type MessageStatusResp struct { + // The hash of a L1 handler transaction + TransactionHash *felt.Felt `json:"transaction_hash"` + // The finality status of the transaction, including the case the txn is still in the mempool or failed validation during the block construction phase + FinalityStatus TxnStatus `json:"finality_status"` + // The failure reason, only appears if finality_status is REJECTED + FailureReason string `json:"failure_reason,omitempty"` +} + type OrderedMsg struct { // The order of the message within the transaction Order int `json:"order"` From 9007483f7af0750e1dfcd3af81fc68363c1b1c5b Mon Sep 17 00:00:00 2001 From: Thiago Ribeiro <62709592+thiagodeev@users.noreply.github.com> Date: Wed, 6 Nov 2024 11:26:01 -0300 Subject: [PATCH 7/8] starknet_getCompiledCasm (#642) * implement starknet_getCompiledCasm for RPCv8 --- mocks/mock_rpc_provider.go | 15 ++ rpc/errors.go | 4 + rpc/executables.go | 24 +++ rpc/executables_test.go | 7 + rpc/provider.go | 1 + rpc/types_contract.go | 4 +- rpc/types_executables.go | 362 +++++++++++++++++++++++++++++++++++++ utils/data.go | 4 +- 8 files changed, 418 insertions(+), 3 deletions(-) create mode 100644 rpc/executables.go create mode 100644 rpc/executables_test.go create mode 100644 rpc/types_executables.go diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index 9a62fc94..cbaa68f6 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -251,6 +251,21 @@ func (mr *MockRpcProviderMockRecorder) ClassHashAt(ctx, blockID, contractAddress return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClassHashAt", reflect.TypeOf((*MockRpcProvider)(nil).ClassHashAt), ctx, blockID, contractAddress) } +// CompiledCasm mocks base method. +func (m *MockRpcProvider) CompiledCasm(ctx context.Context, classHash *felt.Felt) (*rpc.CasmCompiledContractClass, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CompiledCasm", ctx, classHash) + ret0, _ := ret[0].(*rpc.CasmCompiledContractClass) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CompiledCasm indicates an expected call of CompiledCasm. +func (mr *MockRpcProviderMockRecorder) CompiledCasm(ctx, classHash any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CompiledCasm", reflect.TypeOf((*MockRpcProvider)(nil).CompiledCasm), ctx, classHash) +} + // EstimateFee mocks base method. func (m *MockRpcProvider) EstimateFee(ctx context.Context, requests []rpc.BroadcastTxn, simulationFlags []rpc.SimulationFlag, blockID rpc.BlockID) ([]rpc.FeeEstimation, error) { m.ctrl.T.Helper() diff --git a/rpc/errors.go b/rpc/errors.go index d0effbf6..d8d1cb49 100644 --- a/rpc/errors.go +++ b/rpc/errors.go @@ -198,4 +198,8 @@ var ( Code: 63, Message: "An unexpected error occurred", } + ErrCompilationError = &RPCError{ + Code: 9999, //placeholder number as this error has no code so far. TODO: change this with the next updates + Message: "More data about the compilation failure", + } ) diff --git a/rpc/executables.go b/rpc/executables.go new file mode 100644 index 00000000..48fcc686 --- /dev/null +++ b/rpc/executables.go @@ -0,0 +1,24 @@ +package rpc + +import ( + "context" + + "github.com/NethermindEth/juno/core/felt" +) + +// Get the contract class definition in the given block associated with the given hash +// +// Parameters: +// - ctx: The context.Context used for the request +// - classHash: The hash of the contract class whose CASM will be returned +// Returns: +// - CasmCompiledContractClass: The compiled contract class +// - error: An error if any occurred during the execution +func (provider *Provider) CompiledCasm(ctx context.Context, classHash *felt.Felt) (*CasmCompiledContractClass, error) { + var result CasmCompiledContractClass + if err := do(ctx, provider.c, "starknet_getCompiledCasm", &result, classHash); err != nil { + + return nil, tryUnwrapToRPCErr(err, ErrClassHashNotFound, ErrCompilationError) + } + return &result, nil +} diff --git a/rpc/executables_test.go b/rpc/executables_test.go new file mode 100644 index 00000000..f09e44fc --- /dev/null +++ b/rpc/executables_test.go @@ -0,0 +1,7 @@ +package rpc + +import "testing" + +func TestCompiledCasm(t *testing.T) { + t.Skip("TODO: create a test before merge") +} diff --git a/rpc/provider.go b/rpc/provider.go index 36852c5a..f29ab549 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -56,6 +56,7 @@ type RpcProvider interface { Class(ctx context.Context, blockID BlockID, classHash *felt.Felt) (ClassOutput, error) ClassAt(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (ClassOutput, error) ClassHashAt(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*felt.Felt, error) + CompiledCasm(ctx context.Context, classHash *felt.Felt) (*CasmCompiledContractClass, error) EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimation, error) EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimation, error) Events(ctx context.Context, input EventsInput) (*EventChunk, error) diff --git a/rpc/types_contract.go b/rpc/types_contract.go index d7ea97b7..affc336c 100644 --- a/rpc/types_contract.go +++ b/rpc/types_contract.go @@ -69,7 +69,7 @@ type ContractClass struct { // The version of the contract class object. Currently, the Starknet OS supports version 0.1.0 ContractClassVersion string `json:"contract_class_version"` - EntryPointsByType EntryPointsByType `json:"entry_points_by_type"` + EntryPointsByType SierraEntryPointsByType `json:"entry_points_by_type"` ABI string `json:"abi,omitempty"` } @@ -285,7 +285,7 @@ type SierraEntryPoint struct { Selector *felt.Felt `json:"selector"` } -type EntryPointsByType struct { +type SierraEntryPointsByType struct { Constructor []SierraEntryPoint `json:"CONSTRUCTOR"` External []SierraEntryPoint `json:"EXTERNAL"` L1Handler []SierraEntryPoint `json:"L1_HANDLER"` diff --git a/rpc/types_executables.go b/rpc/types_executables.go new file mode 100644 index 00000000..b320e4f9 --- /dev/null +++ b/rpc/types_executables.go @@ -0,0 +1,362 @@ +package rpc + +import ( + "github.com/NethermindEth/juno/core/felt" +) + +type CasmCompiledContractClass struct { + EntryPointsByType CasmEntryPointsByType `json:"entry_points_by_type"` + ByteCode []*felt.Felt `json:"bytecode"` + Prime NumAsHex `json:"prime"` + CompilerVersion string `json:"compiler_version"` + Hints []Hints `json:"hints"` + // a list of sizes of segments in the bytecode, each segment is hashed invidually when computing the bytecode hash + BytecodeSegmentLengths []int `json:"bytecode_segment_lengths,omitempty"` +} + +type CasmEntryPointsByType struct { + Constructor []CasmEntryPoint `json:"CONSTRUCTOR"` + External []CasmEntryPoint `json:"EXTERNAL"` + L1Handler []CasmEntryPoint `json:"L1_HANDLER"` +} + +type CasmEntryPoint struct { + DeprecatedCairoEntryPoint + // the hash of the right child + Builtin []string `json:"builtins"` +} + +// 2-tuple of pc value and an array of hints to execute, but adapted to a golang struct +type Hints struct { + Int int + HintArr []Hint +} + +func (hints *Hints) Values() (int, []Hint) { + return hints.Int, hints.HintArr +} + +func (hints *Hints) Tuple() [2]any { + return [2]any{hints.Int, hints.HintArr} +} + +type Hint struct { + DeprecatedHint + CoreHint + StarknetHint +} + +type DeprecatedHint struct { + DeprecatedHintEnum + AssertAllAccessesUsed AssertAllAccessesUsed `json:",omitempty"` + AssertLtAssertValidInput AssertLtAssertValidInput `json:",omitempty"` + Felt252DictRead Felt252DictRead `json:",omitempty"` + Felt252DictWrite Felt252DictWrite `json:",omitempty"` +} + +type CoreHint struct { + AllocConstantSize AllocConstantSize `json:",omitempty"` + AllocFelt252Dict AllocFelt252Dict `json:",omitempty"` + AllocSegment AllocSegment `json:",omitempty"` + AssertLeFindSmallArcs AssertLeFindSmallArcs `json:",omitempty"` + AssertLeIsFirstArcExcluded AssertLeIsFirstArcExcluded `json:",omitempty"` + AssertLeIsSecondArcExcluded AssertLeIsSecondArcExcluded `json:",omitempty"` + DebugPrint DebugPrint `json:",omitempty"` + DivMod DivMod `json:",omitempty"` + EvalCircuit EvalCircuit `json:",omitempty"` + Felt252DictEntryInit Felt252DictEntryInit `json:",omitempty"` + Felt252DictEntryUpdate Felt252DictEntryUpdate `json:",omitempty"` + FieldSqrt FieldSqrt `json:",omitempty"` + GetCurrentAccessDelta GetCurrentAccessDelta `json:",omitempty"` + GetCurrentAccessIndex GetCurrentAccessIndex `json:",omitempty"` + GetNextDictKey GetNextDictKey `json:",omitempty"` + GetSegmentArenaIndex GetSegmentArenaIndex `json:",omitempty"` + InitSquashData InitSquashData `json:",omitempty"` + LinearSplit LinearSplit `json:",omitempty"` + RandomEcPoint RandomEcPoint `json:",omitempty"` + ShouldContinueSquashLoop ShouldContinueSquashLoop `json:",omitempty"` + ShouldSkipSquashLoop ShouldSkipSquashLoop `json:",omitempty"` + SquareRoot SquareRoot `json:",omitempty"` + TestLessThan TestLessThan `json:",omitempty"` + TestLessThanOrEqual TestLessThanOrEqual `json:",omitempty"` + TestLessThanOrEqualAddress TestLessThanOrEqualAddress `json:",omitempty"` + U256InvModN U256InvModN `json:",omitempty"` + Uint256DivMod Uint256DivMod `json:",omitempty"` + Uint256SquareRoot Uint256SquareRoot `json:",omitempty"` + Uint512DivModByUint256 Uint512DivModByUint256 `json:",omitempty"` + WideMul128 WideMul128 `json:",omitempty"` +} + +type StarknetHint struct { + Cheatcode Cheatcode `json:",omitempty"` + SystemCall SystemCall `json:",omitempty"` +} + +type DeprecatedHintEnum string + +const ( + AssertCurrentAccessIndicesIsEmpty DeprecatedHintEnum = "AssertCurrentAccessIndicesIsEmpty" + AssertAllKeysUsed DeprecatedHintEnum = "AssertAllKeysUsed" + AssertLeAssertThirdArcExcluded DeprecatedHintEnum = "AssertLeAssertThirdArcExcluded" +) + +type AssertAllAccessesUsed struct { + NotUsedAccesses CellRef `json:"n_used_accesses"` +} + +type CellRef struct { + Register Register `json:"register"` + Offset int `json:"offset"` +} + +type Register string + +const ( + AP Register = "AP" + FP Register = "FP" +) + +type AssertLtAssertValidInput struct { + A ResOperand `json:"a"` + B ResOperand `json:"b"` +} + +type felt252Dict struct { + DictPtr ResOperand `json:"dict_ptr"` + Key ResOperand `json:"key"` +} + +type Felt252DictRead struct { + felt252Dict + ValueDst CellRef `json:"value_dst"` +} + +type Felt252DictWrite struct { + felt252Dict + Value ResOperand `json:"value"` +} + +type Felt252DictEntryInit felt252Dict + +type Felt252DictEntryUpdate struct { + DictPtr ResOperand `json:"dict_ptr"` + Value ResOperand `json:"value"` +} + +type ResOperand struct { + BinOp BinOp `json:",omitempty"` + Deref Deref `json:",omitempty"` + DoubleDeref DoubleDeref `json:",omitempty"` + Immediate Immediate `json:",omitempty"` +} + +type Deref CellRef + +// A (CellRef, offsest) tuple, but adapted to a golang struct +type DoubleDeref struct { + CellRef CellRef + Offset int +} + +func (dd *DoubleDeref) Values() (CellRef, int) { + return dd.CellRef, dd.Offset +} + +func (dd *DoubleDeref) Tuple() [2]any { + return [2]any{dd.CellRef, dd.Offset} +} + +type Immediate NumAsHex + +type Operation string + +const ( + Add Operation = "Add" + Mul Operation = "Mul" +) + +type BinOp struct { + Operation Operation `json:"op"` + A CellRef `json:"a"` + B B `json:"b"` +} + +type B struct { + Deref Deref `json:",omitempty"` + Immediate Immediate `json:",omitempty"` +} + +type AllocSegment struct { + Dst CellRef `json:"dst"` +} + +type baseLhsRhs struct { + Lhs ResOperand `json:"lhs"` + Rhs ResOperand `json:"rhs"` +} + +type TestLessThan struct { + baseLhsRhs + Dst CellRef `json:"dst"` +} + +type TestLessThanOrEqual TestLessThan + +type TestLessThanOrEqualAddress TestLessThan + +type WideMul128 struct { + baseLhsRhs + High CellRef `json:"high"` + Low CellRef `json:"low"` +} + +type DivMod struct { + baseLhsRhs + Quotient CellRef `json:"quotient"` + Remainder CellRef `json:"remainder"` +} + +type Uint256DivMod struct { + Dividend0 ResOperand `json:"dividend0"` + Dividend1 ResOperand `json:"dividend1"` + Divisor0 ResOperand `json:"divisor0"` + Divisor1 ResOperand `json:"divisor1"` + Quotient0 CellRef `json:"quotient0"` + Quotient1 CellRef `json:"quotient1"` + Remainder0 CellRef `json:"remainder0"` + Remainder1 CellRef `json:"remainder1"` +} + +type Uint512DivModByUint256 struct { + Uint256DivMod + Dividend2 ResOperand `json:"dividend2"` + Dividend3 ResOperand `json:"dividend3"` + Quotient2 CellRef `json:"quotient2"` + Quotient3 CellRef `json:"quotient3"` +} + +type SquareRoot struct { + Value ResOperand `json:"value"` + Dst CellRef `json:"dst"` +} + +type Uint256SquareRoot struct { + ValueLow ResOperand `json:"value_low"` + ValueHigh ResOperand `json:"value_high"` + Sqrt0 CellRef `json:"sqrt0"` + Sqrt1 CellRef `json:"sqrt1"` + RemainderLow CellRef `json:"remainder_low"` + RemainderHigh CellRef `json:"remainder_high"` + SqrtMul2MinusRemainderGeU128 CellRef `json:"sqrt_mul_2_minus_remainder_ge_u128"` +} + +type LinearSplit struct { + Value ResOperand `json:"value"` + Scalar ResOperand `json:"scalar"` + MaxX ResOperand `json:"max_x"` + X CellRef `json:"x"` + Y CellRef `json:"y"` +} + +type AllocFelt252Dict struct { + SegmentArenaPtr ResOperand `json:"segment_arena_ptr"` +} + +type GetSegmentArenaIndex struct { + DictEndPtr ResOperand `json:"dict_end_ptr"` + DictIndex CellRef `json:"dict_index"` +} + +type InitSquashData struct { + DictAccess ResOperand `json:"dict_access"` + PtrDiff ResOperand `json:"ptr_diff"` + NAccesses ResOperand `json:"n_accesses"` + BigKeys CellRef `json:"big_keys"` + FirstKeys CellRef `json:"first_key"` +} + +type GetCurrentAccessIndex struct { + RangeCheckPtr ResOperand `json:"range_check_ptr"` +} + +type GetCurrentAccessDelta struct { + IndexDeltaMinus1 CellRef `json:"index_delta_minus1"` +} + +type GetNextDictKey struct { + NextKey CellRef `json:"next_key"` +} + +type ShouldSkipSquashLoop struct { + ShouldSkipLoop CellRef `json:"should_skip_loop"` +} + +type ShouldContinueSquashLoop struct { + ShouldContinue CellRef `json:"should_continue"` +} + +type AssertLeFindSmallArcs struct { + RangeCheckPtr ResOperand `json:"range_check_ptr"` + A ResOperand `json:"a"` + B ResOperand `json:"b"` +} + +type AssertLeIsFirstArcExcluded struct { + SkipExcludeAFlag CellRef `json:"skip_exclude_a_flag"` +} + +type AssertLeIsSecondArcExcluded struct { + SkipExcludeBMinusA CellRef `json:"skip_exclude_b_minus_a"` +} + +type RandomEcPoint struct { + X CellRef `json:"x"` + Y CellRef `json:"y"` +} + +type FieldSqrt struct { + Val ResOperand `json:"val"` + Sqrt CellRef `json:"sqrt"` +} + +type DebugPrint struct { + Start ResOperand `json:"start"` + End ResOperand `json:"end"` +} + +type AllocConstantSize struct { + Size ResOperand `json:"size"` + Dst CellRef `json:"dst"` +} + +type U256InvModN struct { + B0 ResOperand `json:"b0"` + B1 ResOperand `json:"b1"` + N0 ResOperand `json:"n0"` + N1 ResOperand `json:"n1"` + G0OrNoInv CellRef `json:"g0_or_no_inv"` + G1Option CellRef `json:"g1_option"` + SOrR0 CellRef `json:"s_or_r0"` + SOrR1 CellRef `json:"s_or_r1"` + TOrR0 CellRef `json:"t_or_k0"` + TOrR1 CellRef `json:"t_or_k1"` +} + +type EvalCircuit struct { + NAddMods ResOperand `json:"n_add_mods"` + AddModBuiltin ResOperand `json:"add_mod_builtin"` + NMulMods ResOperand `json:"n_mul_mods"` + MulModBuiltin ResOperand `json:"mul_mod_builtin"` +} + +type SystemCall struct { + System ResOperand `json:"system"` +} + +type Cheatcode struct { + Selector NumAsHex `json:"selector"` + InputStart ResOperand `json:"input_start"` + InputEnd ResOperand `json:"input_end"` + OutputStart CellRef `json:"output_start"` + OutputEnd CellRef `json:"output_end"` +} diff --git a/utils/data.go b/utils/data.go index ce5d2098..2f94bcef 100644 --- a/utils/data.go +++ b/utils/data.go @@ -1,6 +1,8 @@ package utils -import "encoding/json" +import ( + "encoding/json" +) func UnwrapJSON(data map[string]interface{}, tag string) (map[string]interface{}, error) { if data[tag] != nil { From 9cb940bf45cfafc63d40ac5849cdddd0fc16d3cb Mon Sep 17 00:00:00 2001 From: Thiago Ribeiro <62709592+thiagodeev@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:10:28 -0300 Subject: [PATCH 8/8] Thiagodeev/rpcv08 final changes (#644) * Adjusts TransactionStatus * Adjusts EstimateFee * Fixes blockTest error * Adds GetStorageProof method (#635) * implement rpcv8 GetStorageProof method * Adds GetMessagesStatus method (#634) * Added GetMessagesStatus method * PR comment fixes * Fix MerkleNode type * Updates PendingBlockReader type * Updates ExecutionResources and remove ComputationResources * Fixes failing tests and improves Error() resp * Adds TODO comments and set a pointer to Marshal method * Thiagodeev/rpcv08 write methods, blockHeader and error 53 (#626) Update write methods, error 53 and block header for rpc08 * Adjusts EstimateFee --- rpc/contract.go | 12 ++++++++- rpc/errors.go | 4 +-- rpc/trace.go | 12 ++++++++- rpc/types_block.go | 2 ++ rpc/types_contract.go | 9 ++++--- rpc/types_executables.go | 4 +-- rpc/types_trace.go | 11 ++++++-- rpc/types_transaction.go | 3 +++ rpc/types_transaction_receipt.go | 43 +++----------------------------- 9 files changed, 50 insertions(+), 50 deletions(-) diff --git a/rpc/contract.go b/rpc/contract.go index 0cf00ba7..2ea4d5fb 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -135,6 +135,15 @@ func (provider *Provider) Nonce(ctx context.Context, blockID BlockID, contractAd // Estimates the resources required by a given sequence of transactions when applied on a given state. // If one of the transactions reverts or fails due to any reason (e.g. validation failure or an internal error), // a TRANSACTION_EXECUTION_ERROR is returned. For v0-2 transactions the estimate is given in wei, and for v3 transactions it is given in fri. +// +// Parameters: +// - ctx: The context of the function call +// - requests: A sequence of transactions to estimate, running each transaction on the state resulting from applying all the previous ones +// - simulationFlags: Describes what parts of the transaction should be executed +// - blockID: The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on +// Returns: +// - []FeeEstimation: A sequence of fee estimation where the i'th estimate corresponds to the i'th transaction +// - error: An error if any occurred during the execution func (provider *Provider) EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimation, error) { var raw []FeeEstimation if err := do(ctx, provider.c, "starknet_estimateFee", &raw, requests, simulationFlags, blockID); err != nil { @@ -168,7 +177,8 @@ func (provider *Provider) EstimateMessageFee(ctx context.Context, msg MsgFromL1, // - ctx: The context of the function call // - storageProofInput: an input containing at least one of the fields filled // Returns: -// - *StorageProofResult: the proofs of the field passed in the input +// - *StorageProofResult: The requested storage proofs. Note that if a requested leaf has the default value, +// the path to it may end in an edge node whose path is not a prefix of the requested leaf, thus effectively proving non-membership // - error: an error if any occurred during the execution func (provider *Provider) GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error) { var raw StorageProofResult diff --git a/rpc/errors.go b/rpc/errors.go index d8d1cb49..0b7dd6b5 100644 --- a/rpc/errors.go +++ b/rpc/errors.go @@ -199,7 +199,7 @@ var ( Message: "An unexpected error occurred", } ErrCompilationError = &RPCError{ - Code: 9999, //placeholder number as this error has no code so far. TODO: change this with the next updates - Message: "More data about the compilation failure", + Code: 100, + Message: "Failed to compile the contract", } ) diff --git a/rpc/trace.go b/rpc/trace.go index 0868af0b..e7858b09 100644 --- a/rpc/trace.go +++ b/rpc/trace.go @@ -81,7 +81,17 @@ func (provider *Provider) TraceBlockTransactions(ctx context.Context, blockID Bl // SimulateTransactions simulates transactions on the blockchain. // Simulate a given sequence of transactions on the requested state, and generate the execution traces. // Note that some of the transactions may revert, in which case no error is thrown, but revert details can be seen on the returned trace object. -// Note that some of the transactions may revert, this will be reflected by the revert_error property in the trace. Other types of failures (e.g. unexpected error or failure in the validation phase) will result in TRANSACTION_EXECUTION_ERROR. +// Note that some of the transactions may revert, this will be reflected by the revert_error property in the trace. Other +// types of failures (e.g. unexpected error or failure in the validation phase) will result in TRANSACTION_EXECUTION_ERROR. +// +// Parameters: +// - ctx: The context of the function call +// - blockID: The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on. +// - txns: A sequence of transactions to simulate, running each transaction on the state resulting from applying all the previous ones +// - simulationFlags: Describes what parts of the transaction should be executed +// Returns: +// - []SimulatedTransaction: The execution trace and consumed resources of the required transactions +// - error: An error if any occurred during the execution func (provider *Provider) SimulateTransactions(ctx context.Context, blockID BlockID, txns []BroadcastTxn, simulationFlags []SimulationFlag) ([]SimulatedTransaction, error) { var output []SimulatedTransaction diff --git a/rpc/types_block.go b/rpc/types_block.go index d54a63f3..c8acb86c 100644 --- a/rpc/types_block.go +++ b/rpc/types_block.go @@ -227,6 +227,8 @@ type PendingBlockHeader struct { SequencerAddress *felt.Felt `json:"sequencer_address"` // The price of l1 gas in the block L1GasPrice ResourcePrice `json:"l1_gas_price"` + // The price of l2 gas in the block + L2GasPrice ResourcePrice `json:"l2_gas_price"` // Semver of the current Starknet protocol StarknetVersion string `json:"starknet_version"` // The price of l1 data gas in the block diff --git a/rpc/types_contract.go b/rpc/types_contract.go index affc336c..09e8c180 100644 --- a/rpc/types_contract.go +++ b/rpc/types_contract.go @@ -127,7 +127,10 @@ type NodeHashToNode struct { } // A node in the Merkle-Patricia tree, can be a leaf, binary node, or an edge node -type MerkleNode interface{} // it should be an EdgeNode or BinaryNode +type MerkleNode struct { + EdgeNode `json:",omitempty"` + BinaryNode `json:",omitempty"` +} // Represents a path to the highest non-zero descendant node type EdgeNode struct { @@ -263,9 +266,9 @@ func (nodeHashToNode *NodeHashToNode) UnmarshalJSON(bytes []byte) error { var merkleNode MerkleNode switch nodeT := node.(type) { case BinaryNode: - merkleNode = nodeT + merkleNode = MerkleNode{BinaryNode: nodeT} case EdgeNode: - merkleNode = nodeT + merkleNode = MerkleNode{EdgeNode: nodeT} default: return fmt.Errorf("'node' should be an EdgeNode or BinaryNode") } diff --git a/rpc/types_executables.go b/rpc/types_executables.go index b320e4f9..b7d23a5a 100644 --- a/rpc/types_executables.go +++ b/rpc/types_executables.go @@ -10,7 +10,7 @@ type CasmCompiledContractClass struct { Prime NumAsHex `json:"prime"` CompilerVersion string `json:"compiler_version"` Hints []Hints `json:"hints"` - // a list of sizes of segments in the bytecode, each segment is hashed invidually when computing the bytecode hash + // a list of sizes of segments in the bytecode, each segment is hashed individually when computing the bytecode hash BytecodeSegmentLengths []int `json:"bytecode_segment_lengths,omitempty"` } @@ -152,7 +152,7 @@ type ResOperand struct { type Deref CellRef -// A (CellRef, offsest) tuple, but adapted to a golang struct +// A (CellRef, offset) tuple, but adapted to a golang struct type DoubleDeref struct { CellRef CellRef Offset int diff --git a/rpc/types_trace.go b/rpc/types_trace.go index 0cc44807..6c833730 100644 --- a/rpc/types_trace.go +++ b/rpc/types_trace.go @@ -122,8 +122,15 @@ type FnInvocation struct { L1Messages []OrderedMsg `json:"messages"` // Resources consumed by the internal call - // https://github.com/starkware-libs/starknet-specs/blob/v0.7.0-rc0/api/starknet_trace_api_openrpc.json#L374C1-L374C29 - ComputationResources ComputationResources `json:"execution_resources"` + ExecutionResources InnerCallExecutionResources `json:"execution_resources"` +} + +// the resources consumed by an inner call (does not account for state diffs since data is squashed across the transaction) +type InnerCallExecutionResources struct { + // l1 gas consumed by this transaction, used for l2-->l1 messages and state updates if blobs are not used + L1Gas uint `json:"l1_gas"` + // l2 gas consumed by this transaction, used for computation and calldata + L2Gas uint `json:"l2_gas"` } // A single pair of transaction hash and corresponding trace diff --git a/rpc/types_transaction.go b/rpc/types_transaction.go index b36627e9..3235f9ae 100644 --- a/rpc/types_transaction.go +++ b/rpc/types_transaction.go @@ -145,10 +145,13 @@ type DeclareTxnV3 struct { type ResourceBoundsMapping struct { // The max amount and max price per unit of L1 gas used in this tx L1Gas ResourceBounds `json:"l1_gas"` + // The max amount and max price per unit of L1 blob gas used in this tx + L1DataGas ResourceBounds `json:"l1_data_gas"` // The max amount and max price per unit of L2 gas used in this tx L2Gas ResourceBounds `json:"l2_gas"` } +// DA_MODE: Specifies a storage domain in Starknet. Each domain has different guarantees regarding availability type DataAvailabilityMode string const ( diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index 969c4fbd..7a6e9e33 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -131,48 +131,13 @@ func (tt TransactionType) MarshalJSON() ([]byte, error) { return []byte(strconv.Quote(string(tt))), nil } -type ComputationResources struct { - // The number of Cairo steps used - Steps int `json:"steps"` - // The number of unused memory cells (each cell is roughly equivalent to a step) - MemoryHoles int `json:"memory_holes,omitempty"` - // The number of RANGE_CHECK builtin instances - RangeCheckApps int `json:"range_check_builtin_applications,omitempty"` - // The number of Pedersen builtin instances - PedersenApps int `json:"pedersen_builtin_applications,omitempty"` - // The number of Poseidon builtin instances - PoseidonApps int `json:"poseidon_builtin_applications,omitempty"` - // The number of EC_OP builtin instances - ECOPApps int `json:"ec_op_builtin_applications,omitempty"` - // The number of ECDSA builtin instances - ECDSAApps int `json:"ecdsa_builtin_applications,omitempty"` - // The number of BITWISE builtin instances - BitwiseApps int `json:"bitwise_builtin_applications,omitempty"` - // The number of KECCAK builtin instances - KeccakApps int `json:"keccak_builtin_applications,omitempty"` - // The number of accesses to the segment arena - SegmentArenaBuiltin int `json:"segment_arena_builtin,omitempty"` -} - -func (er *ComputationResources) Validate() bool { - if er.Steps == 0 || er.MemoryHoles == 0 || er.RangeCheckApps == 0 || er.PedersenApps == 0 || - er.PoseidonApps == 0 || er.ECOPApps == 0 || er.ECDSAApps == 0 || er.BitwiseApps == 0 || - er.KeccakApps == 0 || er.SegmentArenaBuiltin == 0 { - return false - } - return true -} - type ExecutionResources struct { - ComputationResources - DataAvailability `json:"data_availability"` -} - -type DataAvailability struct { - // the gas consumed by this transaction's data, 0 if it uses data gas for DA + // l1 gas consumed by this transaction, used for l2-->l1 messages and state updates if blobs are not used L1Gas uint `json:"l1_gas"` - // the data gas consumed by this transaction's data, 0 if it uses gas for DA + // data gas consumed by this transaction, 0 if blobs are not used L1DataGas uint `json:"l1_data_gas"` + // l2 gas consumed by this transaction, used for computation and calldata + L2Gas uint `json:"l2_gas"` } type TxnStatus string