-
Notifications
You must be signed in to change notification settings - Fork 113
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
Bug fix: StateMap::Keys are not consistent across platforms #804
Conversation
This PR removes our StateMap key encoding based on std::Hash, which was not consistent across platforms. Instead, this PR introduces the `EncodeLike<Ref, Target>` trait which marks that Ref can be encoded like Target by the implementing codec. This PR also removes the SingletonKey type, which required special handling in codecs. Instead, of using this placeholder, this PR implements auxiliary methods on the working set for dealing with singletons
Codecov Report
... and 1 file with indirect coverage changes 📢 Have feedback on the report? Share it here. |
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.
Looks good! I left two comments that are more potential future improvements than something to be done now
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.
Looks good, but it also removes support for having different codecs for keys and values by using StateValueCodec
everywhere, which can't differentiate between keys and values.
I left a few other minor comments, otherwise LGTM!
Add risc0-adapter to packages_to_publish.txt Signed-off-by: Filippo Costa <filippo@sovlabs.io> Allow modules to query token names (#821) * Add public function for fetching token names * Add test coverage * lint fix keypair/private_key discrepancy for sov-cli (#811) * fix keypair/private_key discrepancy * formatting * changes to use consistent format * README changes * linting fixes * remove checked in rollup_config.toml * fix token address in git workflow --------- Co-authored-by: dubbelosix <dub@006.com> Initializes pending block on begin slot + genesis block (#803) * Initialize pending_block in begin_slot_hook properly * add timestamp handling * simplify unwrap * simplify basefee calculation, genesis block will be handled in genesis * Initialize genesis block * improvements * fix tests * add tests * fix test * Add expect * Move to lazy_static global test_config * simplify * fix * one more fix Add missing derive to BcsCodec (#823) Bug fix: StateMap::Keys are not consistent across platforms (#804) * Bug fix: Introduce EncodeLike trait. This PR removes our StateMap key encoding based on std::Hash, which was not consistent across platforms. Instead, this PR introduces the `EncodeLike<Ref, Target>` trait which marks that Ref can be encoded like Target by the implementing codec. This PR also removes the SingletonKey type, which required special handling in codecs. Instead, of using this placeholder, this PR implements auxiliary methods on the working set for dealing with singletons * Remove rollup config changes * fix test: qualify conversion * Add missing bounds for fuzzing * fix docs * clarify zsts in comment * allow separate codecs for keys/values * Split key and value codecs * Fix fuzzing feature * Introduce StateCodec trait to allow EncodeLike with SplitCodec * add doc comments * Fix fuzz and test targets * Fix test * fix docs Fix Cargo.lock, packages_to_publish.txt Signed-off-by: Filippo Costa <filippo@sovlabs.io> Update Cargo.lock Signed-off-by: Filippo Costa <filippo@sovlabs.io> Update Cargo.lock Signed-off-by: Filippo Costa <filippo@sovlabs.io>
Add risc0-adapter to packages_to_publish.txt Signed-off-by: Filippo Costa <filippo@sovlabs.io> Allow modules to query token names (#821) * Add public function for fetching token names * Add test coverage * lint fix keypair/private_key discrepancy for sov-cli (#811) * fix keypair/private_key discrepancy * formatting * changes to use consistent format * README changes * linting fixes * remove checked in rollup_config.toml * fix token address in git workflow --------- Co-authored-by: dubbelosix <dub@006.com> Initializes pending block on begin slot + genesis block (#803) * Initialize pending_block in begin_slot_hook properly * add timestamp handling * simplify unwrap * simplify basefee calculation, genesis block will be handled in genesis * Initialize genesis block * improvements * fix tests * add tests * fix test * Add expect * Move to lazy_static global test_config * simplify * fix * one more fix Add missing derive to BcsCodec (#823) Bug fix: StateMap::Keys are not consistent across platforms (#804) * Bug fix: Introduce EncodeLike trait. This PR removes our StateMap key encoding based on std::Hash, which was not consistent across platforms. Instead, this PR introduces the `EncodeLike<Ref, Target>` trait which marks that Ref can be encoded like Target by the implementing codec. This PR also removes the SingletonKey type, which required special handling in codecs. Instead, of using this placeholder, this PR implements auxiliary methods on the working set for dealing with singletons * Remove rollup config changes * fix test: qualify conversion * Add missing bounds for fuzzing * fix docs * clarify zsts in comment * allow separate codecs for keys/values * Split key and value codecs * Fix fuzzing feature * Introduce StateCodec trait to allow EncodeLike with SplitCodec * add doc comments * Fix fuzz and test targets * Fix test * fix docs Fix Cargo.lock, packages_to_publish.txt Signed-off-by: Filippo Costa <filippo@sovlabs.io> Update Cargo.lock Signed-off-by: Filippo Costa <filippo@sovlabs.io> Update Cargo.lock Signed-off-by: Filippo Costa <filippo@sovlabs.io>
* Bug fix: Introduce EncodeLike trait. This PR removes our StateMap key encoding based on std::Hash, which was not consistent across platforms. Instead, this PR introduces the `EncodeLike<Ref, Target>` trait which marks that Ref can be encoded like Target by the implementing codec. This PR also removes the SingletonKey type, which required special handling in codecs. Instead, of using this placeholder, this PR implements auxiliary methods on the working set for dealing with singletons * Remove rollup config changes * fix test: qualify conversion * Add missing bounds for fuzzing * fix docs * clarify zsts in comment * allow separate codecs for keys/values * Split key and value codecs * Fix fuzzing feature * Introduce StateCodec trait to allow EncodeLike with SplitCodec * add doc comments * Fix fuzz and test targets * Fix test * fix docs
Description
This PR removes our StateMap key encoding based on std::Hash, which was not consistent across platforms. This caused the demo-prover to fail, since the generated witness used different storage keys than the guest execution. To fix this issue without sacrificing flexibility. PR introduces the
EncodeLike<Ref, Target>
trait which marks that Ref can be encoded like Target by the implementing codec.This PR also removes the SingletonKey type, which required special handling in codecs. Instead, of using this placeholder, this PR implements auxiliary methods on the working set for dealing with singletons.
Update: September 07, 2023
After discussion with @neysofu, we decided that it was desirable to allow implementers to use different codecs for keys and values.
The new design is as follows:
All three of our state storage types (
StateMap
,StateKey
, andStateVec
) are defined with an associatedStateCodec
, which delegates to its ownKeyCodec
andValueCodec
as appropriate. This allows us to avoid introducing an extra generic in theState*
types, while allowing separate key and value codecs.This PR also introduces the
SplitCodec<KC, VC>
type which allows anyone to combine aKeyCodec
andValueCodec
into aStateCodec
. The current trait design allows thisSplitCodec
to directly inherit the functionality of its associated key and value codecs rather. Without theStateCodec
trait, this would be not be feasible. Instead,SplitCodec
would have to try to blanket impl theKeyCodec
andValueCodec
traits, which is not always possible without specialization.Future Work
This design leaves room for an additional
EncodeValueLike
trait to be implemented in the future if desired. Such a trait would could allow the storage of borrowed types, potentially removing some unnecessaryclone
s.Linked Issues
Testing
I ran the demo-rollup before on the same input before and after introducing this fix:
Before
After
Docs
Describe where this code is documented. If it changes a documented interface, have the docs been updated?