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

Pack proposal struct #363

Merged
merged 14 commits into from
Oct 20, 2022
Merged

Pack proposal struct #363

merged 14 commits into from
Oct 20, 2022

Conversation

Orland0x
Copy link
Contributor

@Orland0x Orland0x commented Oct 5, 2022

closes #184

Reduces cost to create a proposal by nearly 30% for the vanilla setup

contracts/starknet/lib/felt_utils.cairo Outdated Show resolved Hide resolved
contracts/starknet/lib/voting.cairo Outdated Show resolved Hide resolved
max_end_timestamp: felt,
// timestamps contains the following packed into a single felt (each one is 32 bit):
// snapshot_timestamp, start_timestamp, min_end_timestamp, max_end_timestamp
timestamps: felt,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use a TyepAlias here maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how do you mean?

Copy link
Contributor

@pscott pscott Oct 19, 2022

Choose a reason for hiding this comment

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

the type here is felt but we can use TypeAlias (see here) to have something like:

using PackedTimestamps = (inner: felt)

and then we could use timestamps: PackedTimestamps

this way the reader understands that it's a "special" felt :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

something like PackedTimestamps = (packed_timestamps : felt); seems a little unnecessary. Its an internal value that users wont ever need to interact with directly anyway so i think its okay to keep it a felt.

Copy link
Contributor

Choose a reason for hiding this comment

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

Your choice :) I guess it's just the Rust way of thinking that got me wanting this. I find it much cleaner to have a type wrapper for this packedTimestamp. If I'm reading the code and I see this felt I will be thinking "what the fuck?". If I read the code and I see it's a special type (that just wraps a felt, but it doesn't matter), I will understand more what it is. But honestly it's a detail :)

Copy link
Contributor Author

@Orland0x Orland0x Oct 19, 2022

Choose a reason for hiding this comment

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

I just tried and we would need to do all sorts of casting to make it work as the lib uses felts. It would make more sense to have a generic type in the FeltUtils lib, a type like 4x32BitPacked . then use timestamps: 4x32BitPacked in the proposal struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay tried doing this and I cant get it to compile. I dont think type aliases can be used for return values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lets just stick to felts for the time being I think

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed

@Orland0x Orland0x merged commit fef974a into develop Oct 20, 2022
@Orland0x Orland0x deleted the pack_proposal_struct branch November 25, 2022 13:33
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.

Felt packing inside Proposal Struct
2 participants