-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add ContractAddress type #159
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
base: main
Are you sure you want to change the base?
Conversation
bea90b3
to
02d6946
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small comments
@gabrielbosio do you have an opinion about the points I highlighted in the issue description? |
It depends if we want to migrate the |
@dorimedini-starkware you are maintaining the sequencer repo? |
no reason I can think of, but this suggested implementation differs from ours in several ways, like:
|
|
all in all I have no issue with this addition; it may take time for us to migrate to this new type though |
@dorimedini-starkware so do you want this crate to also add a |
I guess it would make the transition less painful, so sure. |
@dorimedini-starkware going back to point using derive_more::Display, or manual impl end up being the same. So no worries here Now regarding |
feature = "parity-scale-codec", | ||
derive(parity_scale_codec::Encode, parity_scale_codec::Decode) | ||
)] | ||
pub struct RegularContractAddress(ContractAddress); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses that are not 0x0 and 0x1. Most users facing application code should never interact with the protocol special addresses. If they do, it is because of a bug.
It can be enforced at the type level this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds super confusing, why not add just a regular ContractAddress and have specific functions to create 0x1 etc etc ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or go the other way around and create a type ReservedContractAddresses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dorimedini-starkware thanks for the head ups. Those are not mention on the doc https://docs.starknet.io/learn/protocol/state#special-addresses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xLucqs the use case I envision is more the opposite of what you are describing.
I'm writing rust code that allows users to interact with some contracts deployed on chain.
By using RegularContractAddress
instead of ContractAddress
, I can guarantee that a bug where I send money to 0x0
or 0x1
due to some badly initialized value, or corrupted json deserialization, will never happen.
A good use case would be: any code that references a user account should use the most restrictive type of the two.
why not add just a regular ContractAddress and have specific functions to create 0x1
This is a good quality of like improvment (hardcoded const for reserved addresses). I will add it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dorimedini-starkware thanks for the head ups. Those are not mention on the doc https://docs.starknet.io/learn/protocol/state#special-addresses
yeah, we should probably link to blockifier versioned constants for this. 0x3 is reserved without use ATM, but it is possible we will also use 0x3 and even 0x4 in the future. versioned constants should be the point of truth
the point was to get a |
67dd9f2
to
0f3e898
Compare
/// https://docs.starknet.io/learn/protocol/state#special-addresses | ||
/// https://github.com/starkware-libs/sequencer/blob/ecd4779abef7bf345938a69f18ef70b6239d3a50/crates/blockifier/resources/blockifier_versioned_constants_0_15_0.json#L92-L97 | ||
pub fn is_regular_contract_address(&self) -> bool { | ||
self > &Felt::THREE && self < &PATRICIA_KEY_UPPER_BOUND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe hard-coding Felt::THREE
as the lower bound isn't ideal, consider defining RegularContractAddress::LOWER_BOUND
or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dorimedini-starkware
Can you explain this to me too:
https://github.com/starkware-libs/starknet-api/blob/91fcc564b125c16ada9d956dcbfa2628415ca011/src/core.rs#L120C1-L121C101
It makes it look like the max contract address is not PATRICIA_KEY_UPPER_BOUND
, but PATRICIA_KEY_UPPER_BOUND
- 256.
Can you confirm this? And give me an explanation on why so that I can add it to the impl and doc in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dorimedini-starkware Do you have infos on this?
794750f
to
0ec371c
Compare
0ec371c
to
6143570
Compare
6143570
to
1a3ea40
Compare
Add a
ContractAddress
wrapper type that guarantee the felt it contains is a valid starknet contract address.Contain some quality of like function for string conversion
Not a breaking change
Discussion:
@xJonathanLEI suggested we add ClassHash too
I chose to exclude addresses 0x0 and 0x1 from the normal ContractAddress flow. You can still build them with the unchecked one. Should we add constant ContractAddress::ZERO and ContractAddress::ONE to make those special case more explicit?
Do we want to allow them at all? Is there a risk to make some API unusable downstream if those value are entierly excluded?