Skip to content

Commit 3417ee3

Browse files
committed
Cairo v0.13.0a1 (pre).
1 parent 351e92a commit 3417ee3

File tree

9 files changed

+149
-73
lines changed

9 files changed

+149
-73
lines changed

src/starkware/cairo/lang/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.13.0a0
1+
0.13.0a1

src/starkware/starknet/business_logic/state/state.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,13 @@ async def get_compiled_class(self, compiled_class_hash: int) -> CompiledClassBas
277277

278278
return self.compiled_classes[compiled_class_hash]
279279

280-
async def get_raw_compiled_class(self, compiled_class_hash: int) -> RawCompiledClass:
281-
if compiled_class_hash not in self.raw_compiled_classes:
282-
self.raw_compiled_classes[
283-
compiled_class_hash
284-
] = await self.state_reader.get_raw_compiled_class(
285-
compiled_class_hash=compiled_class_hash
280+
async def get_raw_compiled_class(self, class_hash: int) -> RawCompiledClass:
281+
if class_hash not in self.raw_compiled_classes:
282+
self.raw_compiled_classes[class_hash] = await self.state_reader.get_raw_compiled_class(
283+
class_hash=class_hash
286284
)
287285

288-
return self.raw_compiled_classes[compiled_class_hash]
286+
return self.raw_compiled_classes[class_hash]
289287

290288
async def get_compiled_class_hash(self, class_hash: int) -> int:
291289
if class_hash not in self.cache.class_hash_to_compiled_class_hash:
@@ -444,13 +442,13 @@ def get_compiled_class(self, compiled_class_hash: int) -> CompiledClassBase:
444442

445443
return self.compiled_classes[compiled_class_hash]
446444

447-
def get_raw_compiled_class(self, compiled_class_hash: int) -> RawCompiledClass:
448-
if compiled_class_hash not in self.raw_compiled_classes:
449-
self.raw_compiled_classes[
450-
compiled_class_hash
451-
] = self.state_reader.get_raw_compiled_class(compiled_class_hash=compiled_class_hash)
445+
def get_raw_compiled_class(self, class_hash: int) -> RawCompiledClass:
446+
if class_hash not in self.raw_compiled_classes:
447+
self.raw_compiled_classes[class_hash] = self.state_reader.get_raw_compiled_class(
448+
class_hash=class_hash
449+
)
452450

453-
return self.raw_compiled_classes[compiled_class_hash]
451+
return self.raw_compiled_classes[class_hash]
454452

455453
def get_compiled_class_hash(self, class_hash: int) -> int:
456454
if class_hash not in self.cache.class_hash_to_compiled_class_hash:

src/starkware/starknet/business_logic/state/state_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ async def get_compiled_class(self, compiled_class_hash: int) -> CompiledClassBas
2828
Raises an exception if said class was not declared.
2929
"""
3030

31-
async def get_raw_compiled_class(self, compiled_class_hash: int) -> RawCompiledClass:
31+
async def get_raw_compiled_class(self, class_hash: int) -> RawCompiledClass:
3232
"""
33-
Returns the raw compiled class of the given compiled class hash.
33+
Returns the raw compiled class of the given class hash.
3434
Raises an exception if said class was not declared.
3535
"""
36-
compiled_class = await self.get_compiled_class(compiled_class_hash=compiled_class_hash)
36+
compiled_class = await self.get_compiled_class_by_class_hash(class_hash=class_hash)
3737
if isinstance(compiled_class, CompiledClass):
3838
return RawCompiledClass(
3939
raw_compiled_class=CompiledClass.Schema().dumps(compiled_class), version=1
@@ -172,8 +172,8 @@ class SyncStateReader(ABC):
172172
def get_compiled_class(self, compiled_class_hash: int) -> CompiledClassBase:
173173
pass
174174

175-
def get_raw_compiled_class(self, compiled_class_hash: int) -> RawCompiledClass:
176-
compiled_class = self.get_compiled_class(compiled_class_hash=compiled_class_hash)
175+
def get_raw_compiled_class(self, class_hash: int) -> RawCompiledClass:
176+
compiled_class = self.get_compiled_class_by_class_hash(class_hash=class_hash)
177177
if isinstance(compiled_class, CompiledClass):
178178
return RawCompiledClass(
179179
raw_compiled_class=CompiledClass.Schema().dumps(compiled_class), version=1

src/starkware/starknet/core/os/execution/execute_entry_point.cairo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ func execute_entry_point{
237237
%}
238238

239239
// Check that the execution was successful.
240+
%{
241+
return_values = ids.entry_point_return_values
242+
if return_values.failure_flag != 0:
243+
# Fetch the error, up to 100 elements.
244+
retdata_size = return_values.retdata_end - return_values.retdata_start
245+
error = memory.get_range(return_values.retdata_start, max(0, min(100, retdata_size)))
246+
247+
print("Invalid return value in execute_entry_point:")
248+
print(f" Class hash: {hex(ids.execution_context.class_hash)}")
249+
print(f" Selector: {hex(ids.execution_context.execution_info.selector)}")
250+
print(f" Size: {retdata_size}")
251+
print(f" Error (at most 100 elements): {error}")
252+
%}
240253
assert entry_point_return_values.failure_flag = 0;
241254

242255
let remaining_gas = entry_point_return_values.gas_builtin;

src/starkware/starknet/core/os/execution/execute_transactions.cairo

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func execute_transactions_inner{
197197
contract_class_changes: DictAccess*,
198198
outputs: OsCarriedOutputs*,
199199
}(block_context: BlockContext*, n_txs) {
200+
%{ print(f"execute_transactions_inner: {ids.n_txs} transactions remaining.") %}
200201
if (n_txs == 0) {
201202
return ();
202203
}
@@ -641,7 +642,7 @@ func check_and_increment_nonce{contract_state_changes: DictAccess*}(tx_info: TxI
641642
%}
642643

643644
tempvar current_nonce = state_entry.nonce;
644-
with_attr error_message("Unexpected nonce. Expected {current_nonce}, got {tx_info.nonce}.") {
645+
with_attr error_message("Unexpected nonce.") {
645646
assert current_nonce = tx_info.nonce;
646647
}
647648

@@ -701,6 +702,15 @@ func run_validate{
701702
block_context=block_context, execution_context=validate_execution_context
702703
);
703704
if (is_deprecated == 0) {
705+
%{
706+
# Fetch the result, up to 100 elements.
707+
result = memory.get_range(ids.retdata, min(100, ids.retdata_size))
708+
709+
if result != [ids.VALIDATED]:
710+
print("Invalid return value from __validate__:")
711+
print(f" Size: {ids.retdata_size}")
712+
print(f" Result (at most 100 elements): {result}")
713+
%}
704714
assert retdata_size = 1;
705715
assert retdata[0] = VALIDATED;
706716
}
@@ -805,8 +815,10 @@ func execute_deploy_account_transaction{
805815
local constructor_execution_context: ExecutionContext*, local salt
806816
) = prepare_constructor_execution_context(block_info=block_context.block_info_for_validate);
807817
local constructor_execution_info: ExecutionInfo* = constructor_execution_context.execution_info;
818+
local sender_address = constructor_execution_info.contract_address;
808819

809820
// Prepare validate_deploy calldata.
821+
local validate_deploy_calldata_size = constructor_execution_context.calldata_size + 2;
810822
let (validate_deploy_calldata: felt*) = alloc();
811823
assert validate_deploy_calldata[0] = constructor_execution_context.class_hash;
812824
assert validate_deploy_calldata[1] = salt;
@@ -816,24 +828,6 @@ func execute_deploy_account_transaction{
816828
len=constructor_execution_context.calldata_size,
817829
);
818830

819-
// Note that the members of execution_info.tx_info are not initialized at this point.
820-
local tx_info: TxInfo* = constructor_execution_info.tx_info;
821-
local deprecated_tx_info: DeprecatedTxInfo* = constructor_execution_context.deprecated_tx_info;
822-
local validate_deploy_execution_context: ExecutionContext* = new ExecutionContext(
823-
entry_point_type=ENTRY_POINT_TYPE_EXTERNAL,
824-
class_hash=constructor_execution_context.class_hash,
825-
calldata_size=constructor_execution_context.calldata_size + 2,
826-
calldata=validate_deploy_calldata,
827-
execution_info=new ExecutionInfo(
828-
block_info=block_context.block_info_for_validate,
829-
tx_info=tx_info,
830-
caller_address=constructor_execution_info.caller_address,
831-
contract_address=constructor_execution_info.contract_address,
832-
selector=VALIDATE_DEPLOY_ENTRY_POINT_SELECTOR,
833-
),
834-
deprecated_tx_info=deprecated_tx_info,
835-
);
836-
837831
// Guess tx fields.
838832
// Compute transaction hash and prepare transaction info.
839833
// The version validation is done in `compute_deploy_account_transaction_hash()`.
@@ -853,7 +847,7 @@ func execute_deploy_account_transaction{
853847
local common_tx_fields: CommonTxFields = CommonTxFields(
854848
tx_hash_prefix=DEPLOY_ACCOUNT_HASH_PREFIX,
855849
version=nondet %{ tx.version %},
856-
sender_address=constructor_execution_info.contract_address,
850+
sender_address=sender_address,
857851
max_fee=nondet %{ tx.max_fee if tx.version < 3 else 0 %},
858852
chain_id=block_context.starknet_os_config.chain_id,
859853
nonce=nondet %{ tx.nonce %},
@@ -875,7 +869,9 @@ func execute_deploy_account_transaction{
875869
let poseidon_ptr = builtin_ptrs.selectable.poseidon;
876870
with pedersen_ptr, poseidon_ptr {
877871
let transaction_hash = compute_deploy_account_transaction_hash(
878-
common_fields=&common_tx_fields, execution_context=validate_deploy_execution_context
872+
common_fields=&common_tx_fields,
873+
calldata_size=validate_deploy_calldata_size,
874+
calldata=validate_deploy_calldata,
879875
);
880876
}
881877
update_builtin_ptrs(pedersen_ptr=pedersen_ptr, poseidon_ptr=poseidon_ptr);
@@ -886,9 +882,10 @@ func execute_deploy_account_transaction{
886882
f"Computed hash = {ids.transaction_hash}, Expected hash = {tx.hash_value}.")
887883
%}
888884

889-
// Assign the transaction info to both calls.
890-
// Note that both constructor_execution_context and
891-
// validate_deploy_execution_context hold this pointer.
885+
// Initialize and fill the transaction info structs.
886+
local tx_info: TxInfo* = constructor_execution_info.tx_info;
887+
local deprecated_tx_info: DeprecatedTxInfo* = constructor_execution_context.deprecated_tx_info;
888+
892889
local signature_start: felt*;
893890
local signature_len: felt;
894891
%{
@@ -898,7 +895,7 @@ func execute_deploy_account_transaction{
898895
assert_nn_le(signature_len, SIERRA_ARRAY_LEN_BOUND - 1);
899896
assert [tx_info] = TxInfo(
900897
version=common_tx_fields.version,
901-
account_contract_address=constructor_execution_info.contract_address,
898+
account_contract_address=sender_address,
902899
max_fee=common_tx_fields.max_fee,
903900
signature_start=signature_start,
904901
signature_end=&signature_start[signature_len],
@@ -923,23 +920,38 @@ func execute_deploy_account_transaction{
923920
deploy_contract(
924921
block_context=block_context, constructor_execution_context=constructor_execution_context
925922
);
926-
let updated_execution_context = update_class_hash_in_execution_context(
927-
execution_context=validate_deploy_execution_context
928-
);
929923

930924
// Handle nonce here since 'deploy_contract' verifies that the nonce is zeroed.
931925
check_and_increment_nonce(tx_info=tx_info);
932926

933-
// Runs the account contract's "__validate_deploy__" entry point,
934-
// which is responsible for signature verification.
927+
// Run the account contract's "__validate_deploy__" entry point.
928+
929+
// Fetch the newest state entry, after constructor invocation.
930+
let (state_entry: StateEntry*) = dict_read{dict_ptr=contract_state_changes}(key=sender_address);
931+
// Prepare execution context.
932+
local validate_deploy_execution_context: ExecutionContext* = new ExecutionContext(
933+
entry_point_type=ENTRY_POINT_TYPE_EXTERNAL,
934+
class_hash=state_entry.class_hash,
935+
calldata_size=validate_deploy_calldata_size,
936+
calldata=validate_deploy_calldata,
937+
execution_info=new ExecutionInfo(
938+
block_info=block_context.block_info_for_validate,
939+
tx_info=tx_info,
940+
caller_address=constructor_execution_info.caller_address,
941+
contract_address=sender_address,
942+
selector=VALIDATE_DEPLOY_ENTRY_POINT_SELECTOR,
943+
),
944+
deprecated_tx_info=deprecated_tx_info,
945+
);
946+
// Run the entrypoint.
935947
let (retdata_size, retdata, is_deprecated) = select_execute_entry_point_func(
936-
block_context=block_context, execution_context=updated_execution_context
948+
block_context=block_context, execution_context=validate_deploy_execution_context
937949
);
938950
if (is_deprecated == 0) {
939951
assert retdata_size = 1;
940952
assert retdata[0] = VALIDATED;
941953
}
942-
charge_fee(block_context=block_context, tx_execution_context=updated_execution_context);
954+
charge_fee(block_context=block_context, tx_execution_context=validate_deploy_execution_context);
943955

944956
%{ execution_helper.end_tx() %}
945957
return ();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"program_hash": "0x45bb5419b84aa6706e6d14eec6dc25ec95eb94f0320414076d1526e81aaecaf"
2+
"program_hash": "0x157ffd1dd481d6b307b53d990cf351ed87dea0fddbd96f8320f60c802cc4451"
33
}

src/starkware/starknet/core/os/transaction_hash/transaction_hash.cairo

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func compute_l1_handler_transaction_hash{pedersen_ptr: HashBuiltin*}(
252252
// See comment above `compute_invoke_transaction_hash()`.
253253
func compute_deploy_account_transaction_hash{
254254
range_check_ptr, pedersen_ptr: HashBuiltin*, poseidon_ptr: PoseidonBuiltin*
255-
}(common_fields: CommonTxFields*, execution_context: ExecutionContext*) -> felt {
255+
}(common_fields: CommonTxFields*, calldata_size: felt, calldata: felt*) -> felt {
256256
alloc_locals;
257257

258258
local version = common_fields.version;
@@ -263,8 +263,8 @@ func compute_deploy_account_transaction_hash{
263263
version=version,
264264
contract_address=common_fields.sender_address,
265265
entry_point_selector=0,
266-
calldata_size=execution_context.calldata_size,
267-
calldata=execution_context.calldata,
266+
calldata_size=calldata_size,
267+
calldata=calldata,
268268
max_fee=common_fields.max_fee,
269269
chain_id=common_fields.chain_id,
270270
additional_data_size=1,
@@ -283,11 +283,9 @@ func compute_deploy_account_transaction_hash{
283283
with hash_state {
284284
hash_tx_common_fields(common_fields=common_fields);
285285
// Hash and add the constructor calldata to the hash state.
286-
poseidon_hash_update_with_nested_hash(
287-
data_ptr=&execution_context.calldata[2], data_length=execution_context.calldata_size - 2
288-
);
286+
poseidon_hash_update_with_nested_hash(data_ptr=&calldata[2], data_length=calldata_size - 2);
289287
// Add the class hash and the contract address salt to the hash state.
290-
poseidon_hash_update(data_ptr=execution_context.calldata, data_length=2);
288+
poseidon_hash_update(data_ptr=calldata, data_length=2);
291289
}
292290
let transaction_hash = poseidon_hash_finalize(hash_state=hash_state);
293291

src/starkware/starknet/core/os/transaction_hash/transaction_hash_test_utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,8 @@ def run_cairo_deploy_account_transaction_hash(
205205
n_resource_bounds=n_resource_bounds,
206206
resource_bounds=resource_bounds,
207207
),
208-
execution_context=create_execution_context(
209-
program=program,
210-
contract_address=contract_address,
211-
calldata=calldata,
212-
),
208+
calldata_size=len(calldata),
209+
calldata=calldata,
213210
use_full_name=True,
214211
verify_secure=False,
215212
)

0 commit comments

Comments
 (0)