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

Add get_block_hash_syscall skeleton to syscalls and libfuncs. #3228

Conversation

ArniStarkware
Copy link
Contributor

@ArniStarkware ArniStarkware commented May 23, 2023

This change is Reviewable

@ArniStarkware ArniStarkware force-pushed the arni/get_block_hash/placeholders branch from 1c8645e to edc8b49 Compare May 23, 2023 10:20
@ArniStarkware
Copy link
Contributor Author

crates/cairo-lang-runner/src/casm_run/mod.rs line 714 at r1 (raw file):

        block_number: u64,
    ) -> Result<SyscallResult, HintError> {
        // TODO(Arni, 28/5/2023): Replace the temporary return value with the required value.

Here is the point of discussion from Monday - 22/5/2023.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 9 files at r1, all commit messages.
Reviewable status: 4 of 9 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware)


crates/cairo-lang-runner/src/casm_run/mod.rs line 714 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Here is the point of discussion from Monday - 22/5/2023.

if it is some storage read - and no actual OS support - this should still be a contract call.

aside from this - the pr structure is fine.


crates/cairo-lang-sierra-gas/src/starknet_libfunc_cost_base.rs line 42 at r1 (raw file):

        // TODO(Arni, 28/5/2023): Fix to the correct cost. For now aligned with the cost of
        // StorageRead.
        StarkNetConcreteLibfunc::GetBlockHash(_) => syscall_cost(2),

this is validated - cost is calculated by arg count only.

Suggestion:

        StarkNetConcreteLibfunc::GetBlockHash(_) => syscall_cost(1),

@ArniStarkware ArniStarkware force-pushed the arni/get_block_hash/placeholders branch from edc8b49 to 6934e33 Compare May 23, 2023 10:55
@ArniStarkware
Copy link
Contributor Author

crates/cairo-lang-sierra-gas/src/starknet_libfunc_cost_base.rs line 42 at r1 (raw file):

Previously, orizi wrote…

this is validated - cost is calculated by arg count only.

Done.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r2.
Reviewable status: 4 of 9 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware)


tests/e2e_test_data/libfuncs/starknet/syscalls line 83 at r2 (raw file):

test::foo@0([0]: GasBuiltin, [1]: System, [2]: core::array::Span::<core::felt252>, [3]: core::array::Span::<core::felt252>) -> (GasBuiltin, System, core::result::Result::<(), core::array::Array::<core::felt252>>);

// TODO(Arni, 28/5/2023): Add test for get_block_hash_syscall.

adding the test is about as easy as adding the todo :)

Code quote:

// TODO(Arni, 28/5/2023): Add test for get_block_hash_syscall.

@ArniStarkware ArniStarkware force-pushed the arni/get_block_hash/placeholders branch from 6934e33 to a49d8f3 Compare May 24, 2023 08:56
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 9 files at r1, all commit messages.
Reviewable status: 5 of 9 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware)


crates/cairo-lang-runner/src/casm_run/mod.rs line 718 at r3 (raw file):

        //      One design suggestion - to preform a storage read. Have an arbitrary, hardcoded
        //      (For example, addr=1) contain the mapping from block number to block hash.
        Ok(SyscallResult::Success(vec![0.into()]))

can you add a better placeholder impl?
either some random value based on the block number or just:
fail_syscall!(b"GET_BLOCK_HASH_UNIMPLEMENTED");

Code quote:

        // TODO(Arni, 28/5/2023): Replace the temporary return value with the required value.
        //      One design suggestion - to preform a storage read. Have an arbitrary, hardcoded
        //      (For example, addr=1) contain the mapping from block number to block hash.
        Ok(SyscallResult::Success(vec![0.into()]))

@ArniStarkware ArniStarkware force-pushed the arni/get_block_hash/placeholders branch from a49d8f3 to 9a9f5e5 Compare May 24, 2023 11:50
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 9 files at r1, 2 of 4 files at r4, all commit messages.
Reviewable status: 7 of 11 files reviewed, 3 unresolved discussions (waiting on @ArniStarkware)


crates/cairo-lang-sierra/src/extensions/modules/starknet/getter.rs line 172 at r4 (raw file):

#[derive(Default)]
pub struct GetBlockHashTrait {}
impl GetterTraitsEx for GetBlockHashTrait {

this isn't a getter - this should be implemented more like storage_read.

Code quote:

impl GetterTraitsEx for GetBlockHashTrait

@ArniStarkware
Copy link
Contributor Author

crates/cairo-lang-runner/src/casm_run/mod.rs line 718 at r3 (raw file):

Previously, orizi wrote…

can you add a better placeholder impl?
either some random value based on the block number or just:
fail_syscall!(b"GET_BLOCK_HASH_UNIMPLEMENTED");

Done.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 7 of 11 files reviewed, 4 unresolved discussions (waiting on @ArniStarkware)

a discussion (no related file):
also - add a test with

#[should_panic(expected: ('Out of gas', 'GET_BLOCK_HASH_UNIMPLEMENTED', ))]

in the cairo_level_tests library.



tests/e2e_test_data/libfuncs/starknet/syscalls line 83 at r2 (raw file):

Previously, orizi wrote…

adding the test is about as easy as adding the todo :)

this test is definitely not valid yet (probably because of the other requested changes)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 9 files at r1, 1 of 2 files at r3, 2 of 4 files at r4.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ArniStarkware)

@ArniStarkware ArniStarkware force-pushed the arni/get_block_hash/placeholders branch from 9a9f5e5 to b22f3fe Compare May 29, 2023 08:44
@ArniStarkware
Copy link
Contributor Author

crates/cairo-lang-sierra/src/extensions/modules/starknet/getter.rs line 172 at r4 (raw file):

Previously, orizi wrote…

this isn't a getter - this should be implemented more like storage_read.

Done. Removed.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r5, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ArniStarkware)


crates/cairo-lang-sierra/src/extensions/modules/starknet/storage.rs line 233 at r5 (raw file):

        context: &dyn SignatureSpecializationContext,
    ) -> Result<Vec<crate::ids::ConcreteTypeId>, SpecializationError> {
        Ok(vec![

The input is u64, the output is felt252, fix all.


crates/cairo-lang-starknet/cairo_level_tests/interoperability.cairo line 169 at r5 (raw file):

// #[test]
// #[should_panic(expected: ('Out of gas', 'GET_BLOCK_HASH_UNIMPLEMENTED', ))]

Uncomment

@ArniStarkware ArniStarkware force-pushed the arni/get_block_hash/placeholders branch from b22f3fe to 9005265 Compare May 29, 2023 12:24
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ArniStarkware)

@ArniStarkware
Copy link
Contributor Author

tests/e2e_test_data/libfuncs/starknet/syscalls line 83 at r2 (raw file):

Previously, orizi wrote…

this test is definitely not valid yet (probably because of the other requested changes)

Done! Finally

@ArniStarkware
Copy link
Contributor Author

crates/cairo-lang-sierra/src/extensions/modules/starknet/storage.rs line 233 at r5 (raw file):

Previously, orizi wrote…

The input is u64, the output is felt252, fix all.

Done.

@ArniStarkware ArniStarkware force-pushed the arni/get_block_hash/placeholders branch from 9005265 to 9bfa5e5 Compare May 29, 2023 13:42
Copy link
Contributor Author

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 12 of 13 files reviewed, 1 unresolved discussion (waiting on @orizi)

a discussion (no related file):

Previously, orizi wrote…

also - add a test with

#[should_panic(expected: ('Out of gas', 'GET_BLOCK_HASH_UNIMPLEMENTED', ))]

in the cairo_level_tests library.

Done.



crates/cairo-lang-starknet/cairo_level_tests/interoperability.cairo line 169 at r5 (raw file):

Previously, orizi wrote…

Uncomment

Done.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: 12 of 13 files reviewed, 1 unresolved discussion (waiting on @ArniStarkware)


crates/cairo-lang-starknet/cairo_level_tests/interoperability.cairo line 169 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Done.

I think unwrapping and 'should_panic' would be nicer for when you actually add an implementation

@ArniStarkware ArniStarkware force-pushed the arni/get_block_hash/placeholders branch from 9bfa5e5 to 9b25838 Compare May 29, 2023 15:25
@ArniStarkware
Copy link
Contributor Author

crates/cairo-lang-starknet/cairo_level_tests/interoperability.cairo line 169 at r5 (raw file):

Previously, orizi wrote…

I think unwrapping and 'should_panic' would be nicer for when you actually add an implementation

Now with nicer should_panic.

@ArniStarkware ArniStarkware force-pushed the arni/get_block_hash/placeholders branch from 9b25838 to e08a8b4 Compare May 29, 2023 15:29
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArniStarkware)

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 3 of 9 files at r1, 1 of 1 files at r2, 2 of 4 files at r4, 3 of 6 files at r5, 2 of 3 files at r6, 2 of 2 files at r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArniStarkware)

@ilyalesokhin-starkware ilyalesokhin-starkware added this pull request to the merge queue May 31, 2023
Merged via the queue into starkware-libs:main with commit c7b6c06 May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants