Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Add a test calling a contract that uses keccak in testnet submodule #1110

Merged

Conversation

fguthmann
Copy link
Contributor

@fguthmann fguthmann commented Oct 30, 2023

TITLE

Description

Write a simple Cairo 2 contract that calls Keccak. Declare it on testnet, deploy it and then invoke it using starkli .
Contract hash: 0x048ffc49f04504710e984923980fb63c4f17fb3022467251329adc75aae93c4b
Block number: 900796
Created a test that check the fee and the retdata

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
  • Documentation has been added/updated.

fannyguthmann and others added 14 commits November 2, 2023 11:39
* Added a usage target to makefile

* Fixed typo
* wip

* Minor improvements + add test

* Improve make clippy

* Clippy + fmt

* Update error messages

* Add failure flag test

* Fix typo

* Apply suggestions + run formatter

* Add llvm setup so we can run clippy with `cairo-native` feature

* Fix

* Remove todo

* Use a proper class_hash

* Fix test assertion

---------

Co-authored-by: Juan Bono <juanbono94@gmail.com>
* update cairo native to use gas consumed

* gas consumed

* update native rev

* fix gas consumed

* remove comments

* fixes

---------

Co-authored-by: Juan Bono <juanbono94@gmail.com>
…ctClass` in `CompiledProgram` (#1112)

* Save Program + EntryPoints instead of ContractClass

* clippy
* Added cairo native flag

* Added cairo_native as dependency

* Partial progress

* Progress

* Partial progress

* Point to newly created branch on cairo native

* Use updated version of cairo native and make test pass

* Run test with storage_write and storage_read with cairo native

* Tidy up code

* Start unhardcoding stuff

* Handle return values

* Tidy up code a little

* Added sierra programs cache

* Add impl for emit_event and send_l1_message

* Fix tests

* Install LLVM on CI

* Test

* Test CI

* Fix lint step

* Save work in progress

* Unhardcode calldata and entry point

* Unhardcode more stuff

* Fix test

* Add basic implementation for call_contract

* Add call to get_name to integration test

* Make call_contract impl compile

* Fix test

* Pass the correct amount of builtins for every function

* Improve test legibility

* Write call_contract test skeleton

* Finish writing test, still bugs to fix

* implement get_execution_info, make increase_allowance work

* More debugging

* Basic test for call_contract working

* More progress on testing ERC20

* More progress on test

* Add caller and callee contracts

* Fix call_contract test after merge

* Fix callee address in tests

* Polish some details

* Remove use_cairo_native from TransactionExecutionContext

* Write test skeleton

* Add test contracts

* Fix tests

* Readd deleted contracts

* Echo contract test passing

* Update cairo compiler to version 2.2.0

* Calling another contract with events test is passing

* Fix failing tests

* Remove internal_calls field TODO in CallInfo returned by native_execute

* Add event_emitter contract

* Add cairo vm execution to the erc20 test for comparison

* Add simple implementation for panics in native execution

* Add some documentation in code

* Assert equality between events, accessed_storage_keys and l1_l2 messages between native and vm runs

* Add event_emitter contract

* Remove print

* Remove comments

* Move native syscall handler to its own file

* Add felt decode to string when program panics

* Make cairo native an optional dependency behind a feature

* Move execution result to cairo native

* Add a README section explaining how to setup cairo native

* Fix some clippy issues

* Fix test compilation

* CI test

* Revert "CI test"

This reverts commit 4631e5e.

* CI test

* Test

* Test

* Address comment about multiple cfgs

* Remove unnecessary clone

* Test

* Test

* Switch to special workflow for native integration tests

* Fix workflow

* Fix stuff after merge.

* Fix clippy warnings.

* Fix after merge.

* Fix comments.

* Fix `Makefile`.

* Remove unused import.

* Use transactional state.

* update cairo native to llvm 17 and remove nightly requirement

* update ci

* upd ci

* try to fix ci

* use ubuntu on native

* try to fix ci

* not needed?

* fix ci

* update cairo native

* fix nightly usage

* try to fix ci

* dont need a transactional state reader, simply clone the state reader

* try to fix ci

* format

* fix again

* fix if

* values

* force rebuild

* make cache track cairo 2 version to trigger rebuilds

* try no restore key

* Added get_execution_info test

* mend

* fix test + update native latest

* add deleted test

* mend

* delete unused struct

---------

Co-authored-by: Javier Chatruc <jrchatruc@gmail.com>
Co-authored-by: Mariano Nicolini <mariano.nicolini.91@gmail.com>
Co-authored-by: Esteve Soler Arderiu <esteve.soler@fratilia.com>
Co-authored-by: Edgar Luque <git@edgarluque.com>
Co-authored-by: toni-calvin <antonio.calvin@lambdaclass.com>
* cairo-native initial implementation of library call

* rebase

* clippy

* fix

* library call test

* suggestion
* update cairo native to use gas consumed

* implement native replace class syscall

* gas consumed

* add test

* update native rev

* add failing test

* fix gas consumed

* remove comments

* minor changes

* update cairo-native dependency

* improve test

* update latest native version

* use add sierra contract to cache method

* update latest native version

* Replace class contract call native (#1115)

* add last native version

* add failing test

* fix test

* easier merge

* fix test

---------

Co-authored-by: Edgar Luque <git@edgarluque.com>
* Added cairo native flag

* Added cairo_native as dependency

* Partial progress

* Progress

* Partial progress

* Point to newly created branch on cairo native

* Use updated version of cairo native and make test pass

* Run test with storage_write and storage_read with cairo native

* Tidy up code

* Start unhardcoding stuff

* Handle return values

* Tidy up code a little

* Added sierra programs cache

* Add impl for emit_event and send_l1_message

* Fix tests

* Install LLVM on CI

* Test

* Test CI

* Fix lint step

* Save work in progress

* Unhardcode calldata and entry point

* Unhardcode more stuff

* Fix test

* Add basic implementation for call_contract

* Add call to get_name to integration test

* Make call_contract impl compile

* Fix test

* Pass the correct amount of builtins for every function

* Improve test legibility

* Write call_contract test skeleton

* Finish writing test, still bugs to fix

* implement get_execution_info, make increase_allowance work

* More debugging

* Basic test for call_contract working

* More progress on testing ERC20

* More progress on test

* Add caller and callee contracts

* Fix call_contract test after merge

* Fix callee address in tests

* Polish some details

* Remove use_cairo_native from TransactionExecutionContext

* Write test skeleton

* Add test contracts

* Fix tests

* Readd deleted contracts

* Echo contract test passing

* Update cairo compiler to version 2.2.0

* Calling another contract with events test is passing

* Fix failing tests

* Remove internal_calls field TODO in CallInfo returned by native_execute

* Add event_emitter contract

* Add cairo vm execution to the erc20 test for comparison

* Add simple implementation for panics in native execution

* Add some documentation in code

* Assert equality between events, accessed_storage_keys and l1_l2 messages between native and vm runs

* Add event_emitter contract

* Remove print

* Remove comments

* Move native syscall handler to its own file

* Add felt decode to string when program panics

* Make cairo native an optional dependency behind a feature

* Move execution result to cairo native

* Add a README section explaining how to setup cairo native

* Fix some clippy issues

* Fix test compilation

* CI test

* Revert "CI test"

This reverts commit 4631e5e.

* CI test

* Test

* Test

* Address comment about multiple cfgs

* Remove unnecessary clone

* Test

* Test

* Switch to special workflow for native integration tests

* Fix workflow

* Fix stuff after merge.

* Fix clippy warnings.

* Fix after merge.

* Fix comments.

* Fix `Makefile`.

* Remove unused import.

* WIP: Implementing get_block_hash syscall

* Fix stuff.

* Use transactional state.

* update cairo native to llvm 17 and remove nightly requirement

* update ci

* upd ci

* try to fix ci

* use ubuntu on native

* try to fix ci

* not needed?

* fix ci

* update cairo native

* fix nightly usage

* try to fix ci

* dont need a transactional state reader, simply clone the state reader

* try to fix ci

* format

* fix again

* fix if

* values

* force rebuild

* make cache track cairo 2 version to trigger rebuilds

* try no restore key

* make get_hash_test syscall work with native and vm

* update readme

* implement get_block_hash on vm

* fmt

* fix tests on ci

* update cairo native commit

* fix more tests on ci

* fix cairo native interface

* try ci without cache

* checout earlier

* fix ci clippy

* test rpc reader execution

* try ci without cache

* setup rustup home

* make param passing to cairo native not obscure

* try

* try again

* remove large packages

* remove large dirs

* remove android too

* polly is needed

* needs sudo

* fix cov

* fix test for now

* format

* cleanup ci file

* use pyenv if available

* nightly not needed in readme

* add .sierra as generated to gitattributes

* fix gitattributes

* add casm too

* implement get_block_hash_native

* remove debug

* add vm execution

* merge

* add less code

* fix syscall

* fmt

* update native to last version

* correctly insert sierra class into cache test

* update latest native version

* remove comments

---------

Co-authored-by: Esteban Dimitroff Hódi <esteban.dimitroff@lambdaclass.com>
Co-authored-by: Javier Chatruc <jrchatruc@gmail.com>
Co-authored-by: Mariano Nicolini <mariano.nicolini.91@gmail.com>
Co-authored-by: Esteve Soler Arderiu <esteve.soler@fratilia.com>
Co-authored-by: toni-calvin <antonio.calvin@lambdaclass.com>
Co-authored-by: Edgar Luque <git@edgarluque.com>
* replace println by tracing::debug

* replace MLIR with Cairo Native

* fmt

---------

Co-authored-by: juanbono <juan.bono@lambdaclass.com>
* Remove explicit and implicit unwraps in RpcCallInfo deserialization

* Handle errors in RpcState::new_infura

* push RpcStateError

* Progress

* Remove all unwraps from rpc code

* Adapt tests

* Clippy

* Unify RpcError & RpcStateError

* Guard potential panicks + fmt

* clippy
@fguthmann fguthmann force-pushed the rpc_state_reader-add-test-calling-contract-uses-keccak-testnet branch from 2533375 to 5a438c5 Compare November 9, 2023 08:51
@fguthmann fguthmann changed the title Add a test calling a contract that uses keccak in testnet submodule to latest commit Add a test calling a contract that uses keccak in testnet submodule Nov 16, 2023
fannyguthmann added 3 commits November 16, 2023 12:58
@fguthmann fguthmann marked this pull request as draft November 17, 2023 13:03
@fguthmann fguthmann marked this pull request as ready for review November 17, 2023 13:06
@@ -612,3 +611,47 @@ fn starknet_in_rust_test_case_tx_skip_nonce_check(hash: &str, block_number: u64,
}
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is great! But we need to remove the corelib files and the scarb related files.

Copy link
Collaborator

@juanbono juanbono left a comment

Choose a reason for hiding this comment

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

The test is ok. But the rest of the files are not needed. We only need the contract that executes keccak. So you have to remove the corelib files, the Scarb.toml, the cairo 2 3 directory and other files.

@fguthmann fguthmann requested a review from juanbono November 17, 2023 15:18
src/lib.cairo Outdated
@@ -0,0 +1,6 @@
fn fib(a: felt252, b: felt252, n: felt252) -> felt252 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please remove this one too

@pefontana pefontana enabled auto-merge November 17, 2023 20:33
@pefontana pefontana added this pull request to the merge queue Nov 17, 2023
Merged via the queue into main with commit 5763f6b Nov 17, 2023
@pefontana pefontana deleted the rpc_state_reader-add-test-calling-contract-uses-keccak-testnet branch November 17, 2023 21:02
fguthmann added a commit that referenced this pull request Nov 20, 2023
…1110)

* Updated submodule to latest commit

* wip

* Added a usage target to makefile (#1069)

* Added a usage target to makefile

* Fixed typo

* Implement `NativeSyscallHandler::deploy` (#1106)

* wip

* Minor improvements + add test

* Improve make clippy

* Clippy + fmt

* Update error messages

* Add failure flag test

* Fix typo

* Apply suggestions + run formatter

* Add llvm setup so we can run clippy with `cairo-native` feature

* Fix

* Remove todo

* Use a proper class_hash

* Fix test assertion

---------

Co-authored-by: Juan Bono <juanbono94@gmail.com>

* update cairo native to use gas consumed (#1102)

* update cairo native to use gas consumed

* gas consumed

* update native rev

* fix gas consumed

* remove comments

* fixes

---------

Co-authored-by: Juan Bono <juanbono94@gmail.com>

* Save `SierraProgram` + `ContractEntryPoints` instead of `SierraContractClass` in `CompiledProgram` (#1112)

* Save Program + EntryPoints instead of ContractClass

* clippy

* `get_execution_info`test (#1067)

* Added cairo native flag

* Added cairo_native as dependency

* Partial progress

* Progress

* Partial progress

* Point to newly created branch on cairo native

* Use updated version of cairo native and make test pass

* Run test with storage_write and storage_read with cairo native

* Tidy up code

* Start unhardcoding stuff

* Handle return values

* Tidy up code a little

* Added sierra programs cache

* Add impl for emit_event and send_l1_message

* Fix tests

* Install LLVM on CI

* Test

* Test CI

* Fix lint step

* Save work in progress

* Unhardcode calldata and entry point

* Unhardcode more stuff

* Fix test

* Add basic implementation for call_contract

* Add call to get_name to integration test

* Make call_contract impl compile

* Fix test

* Pass the correct amount of builtins for every function

* Improve test legibility

* Write call_contract test skeleton

* Finish writing test, still bugs to fix

* implement get_execution_info, make increase_allowance work

* More debugging

* Basic test for call_contract working

* More progress on testing ERC20

* More progress on test

* Add caller and callee contracts

* Fix call_contract test after merge

* Fix callee address in tests

* Polish some details

* Remove use_cairo_native from TransactionExecutionContext

* Write test skeleton

* Add test contracts

* Fix tests

* Readd deleted contracts

* Echo contract test passing

* Update cairo compiler to version 2.2.0

* Calling another contract with events test is passing

* Fix failing tests

* Remove internal_calls field TODO in CallInfo returned by native_execute

* Add event_emitter contract

* Add cairo vm execution to the erc20 test for comparison

* Add simple implementation for panics in native execution

* Add some documentation in code

* Assert equality between events, accessed_storage_keys and l1_l2 messages between native and vm runs

* Add event_emitter contract

* Remove print

* Remove comments

* Move native syscall handler to its own file

* Add felt decode to string when program panics

* Make cairo native an optional dependency behind a feature

* Move execution result to cairo native

* Add a README section explaining how to setup cairo native

* Fix some clippy issues

* Fix test compilation

* CI test

* Revert "CI test"

This reverts commit 4631e5e.

* CI test

* Test

* Test

* Address comment about multiple cfgs

* Remove unnecessary clone

* Test

* Test

* Switch to special workflow for native integration tests

* Fix workflow

* Fix stuff after merge.

* Fix clippy warnings.

* Fix after merge.

* Fix comments.

* Fix `Makefile`.

* Remove unused import.

* Use transactional state.

* update cairo native to llvm 17 and remove nightly requirement

* update ci

* upd ci

* try to fix ci

* use ubuntu on native

* try to fix ci

* not needed?

* fix ci

* update cairo native

* fix nightly usage

* try to fix ci

* dont need a transactional state reader, simply clone the state reader

* try to fix ci

* format

* fix again

* fix if

* values

* force rebuild

* make cache track cairo 2 version to trigger rebuilds

* try no restore key

* Added get_execution_info test

* mend

* fix test + update native latest

* add deleted test

* mend

* delete unused struct

---------

Co-authored-by: Javier Chatruc <jrchatruc@gmail.com>
Co-authored-by: Mariano Nicolini <mariano.nicolini.91@gmail.com>
Co-authored-by: Esteve Soler Arderiu <esteve.soler@fratilia.com>
Co-authored-by: Edgar Luque <git@edgarluque.com>
Co-authored-by: toni-calvin <antonio.calvin@lambdaclass.com>

* Cairo native: Implement library_call syscall (#1074)

* cairo-native initial implementation of library call

* rebase

* clippy

* fix

* library call test

* suggestion

* Replace class native (#1105)

* update cairo native to use gas consumed

* implement native replace class syscall

* gas consumed

* add test

* update native rev

* add failing test

* fix gas consumed

* remove comments

* minor changes

* update cairo-native dependency

* improve test

* update latest native version

* use add sierra contract to cache method

* update latest native version

* Replace class contract call native (#1115)

* add last native version

* add failing test

* fix test

* easier merge

* fix test

---------

Co-authored-by: Edgar Luque <git@edgarluque.com>

* `get_block_hash` syscall native (#1048)

* Added cairo native flag

* Added cairo_native as dependency

* Partial progress

* Progress

* Partial progress

* Point to newly created branch on cairo native

* Use updated version of cairo native and make test pass

* Run test with storage_write and storage_read with cairo native

* Tidy up code

* Start unhardcoding stuff

* Handle return values

* Tidy up code a little

* Added sierra programs cache

* Add impl for emit_event and send_l1_message

* Fix tests

* Install LLVM on CI

* Test

* Test CI

* Fix lint step

* Save work in progress

* Unhardcode calldata and entry point

* Unhardcode more stuff

* Fix test

* Add basic implementation for call_contract

* Add call to get_name to integration test

* Make call_contract impl compile

* Fix test

* Pass the correct amount of builtins for every function

* Improve test legibility

* Write call_contract test skeleton

* Finish writing test, still bugs to fix

* implement get_execution_info, make increase_allowance work

* More debugging

* Basic test for call_contract working

* More progress on testing ERC20

* More progress on test

* Add caller and callee contracts

* Fix call_contract test after merge

* Fix callee address in tests

* Polish some details

* Remove use_cairo_native from TransactionExecutionContext

* Write test skeleton

* Add test contracts

* Fix tests

* Readd deleted contracts

* Echo contract test passing

* Update cairo compiler to version 2.2.0

* Calling another contract with events test is passing

* Fix failing tests

* Remove internal_calls field TODO in CallInfo returned by native_execute

* Add event_emitter contract

* Add cairo vm execution to the erc20 test for comparison

* Add simple implementation for panics in native execution

* Add some documentation in code

* Assert equality between events, accessed_storage_keys and l1_l2 messages between native and vm runs

* Add event_emitter contract

* Remove print

* Remove comments

* Move native syscall handler to its own file

* Add felt decode to string when program panics

* Make cairo native an optional dependency behind a feature

* Move execution result to cairo native

* Add a README section explaining how to setup cairo native

* Fix some clippy issues

* Fix test compilation

* CI test

* Revert "CI test"

This reverts commit 4631e5e.

* CI test

* Test

* Test

* Address comment about multiple cfgs

* Remove unnecessary clone

* Test

* Test

* Switch to special workflow for native integration tests

* Fix workflow

* Fix stuff after merge.

* Fix clippy warnings.

* Fix after merge.

* Fix comments.

* Fix `Makefile`.

* Remove unused import.

* WIP: Implementing get_block_hash syscall

* Fix stuff.

* Use transactional state.

* update cairo native to llvm 17 and remove nightly requirement

* update ci

* upd ci

* try to fix ci

* use ubuntu on native

* try to fix ci

* not needed?

* fix ci

* update cairo native

* fix nightly usage

* try to fix ci

* dont need a transactional state reader, simply clone the state reader

* try to fix ci

* format

* fix again

* fix if

* values

* force rebuild

* make cache track cairo 2 version to trigger rebuilds

* try no restore key

* make get_hash_test syscall work with native and vm

* update readme

* implement get_block_hash on vm

* fmt

* fix tests on ci

* update cairo native commit

* fix more tests on ci

* fix cairo native interface

* try ci without cache

* checout earlier

* fix ci clippy

* test rpc reader execution

* try ci without cache

* setup rustup home

* make param passing to cairo native not obscure

* try

* try again

* remove large packages

* remove large dirs

* remove android too

* polly is needed

* needs sudo

* fix cov

* fix test for now

* format

* cleanup ci file

* use pyenv if available

* nightly not needed in readme

* add .sierra as generated to gitattributes

* fix gitattributes

* add casm too

* implement get_block_hash_native

* remove debug

* add vm execution

* merge

* add less code

* fix syscall

* fmt

* update native to last version

* correctly insert sierra class into cache test

* update latest native version

* remove comments

---------

Co-authored-by: Esteban Dimitroff Hódi <esteban.dimitroff@lambdaclass.com>
Co-authored-by: Javier Chatruc <jrchatruc@gmail.com>
Co-authored-by: Mariano Nicolini <mariano.nicolini.91@gmail.com>
Co-authored-by: Esteve Soler Arderiu <esteve.soler@fratilia.com>
Co-authored-by: toni-calvin <antonio.calvin@lambdaclass.com>
Co-authored-by: Edgar Luque <git@edgarluque.com>

* Add logging to syscalls (#1111)

* replace println by tracing::debug

* replace MLIR with Cairo Native

* fmt

---------

Co-authored-by: juanbono <juan.bono@lambdaclass.com>

* Add error handling to `RpcState` (#1107)

* Remove explicit and implicit unwraps in RpcCallInfo deserialization

* Handle errors in RpcState::new_infura

* push RpcStateError

* Progress

* Remove all unwraps from rpc code

* Adapt tests

* Clippy

* Unify RpcError & RpcStateError

* Guard potential panicks + fmt

* clippy

* Convert my_contract/target from a submodule to a regular directory

* Add my_contract/target files

* added test that check fees and return data

* Add Keccak_contract folder

* add test price and retdata

* add test to check retdata and fee

* wip

* wip

* wip

* wip

* wip

* corrected format

* removed unused files

* Merge remote-tracking branch 'origin/rpc_state_reader-add-test-calling-contract-uses-keccak-testnet'

---------

Co-authored-by: fannyguthmann <fanny.guthmann@post.idc.ac.il>
Co-authored-by: Iñaki Garay <igarai@gmail.com>
Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>
Co-authored-by: Juan Bono <juanbono94@gmail.com>
Co-authored-by: Edgar <git@edgarluque.com>
Co-authored-by: ElFantasma <esteban.dimitroff@lambdaclass.com>
Co-authored-by: Javier Chatruc <jrchatruc@gmail.com>
Co-authored-by: Mariano Nicolini <mariano.nicolini.91@gmail.com>
Co-authored-by: Esteve Soler Arderiu <esteve.soler@fratilia.com>
Co-authored-by: toni-calvin <antonio.calvin@lambdaclass.com>
Co-authored-by: juanbono <juan.bono@lambdaclass.com>
Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RPCStateReader] Add a test calling a contract that uses keccak in testnet
7 participants