Skip to content

Commit

Permalink
fix: comment out serialization/deserialization of source locations (#590
Browse files Browse the repository at this point in the history
)

* fix: comment out serialization/deserialization of source locations

* fix serialization test

* apply suggested changes

* rewrite comment
  • Loading branch information
mFragaBA authored Apr 10, 2024
1 parent 9830b5a commit e5eb189
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 9 additions & 5 deletions objects/src/accounts/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::crypto::merkle::SimpleSmt;
// ================================================================================================

/// Default serialization options for account code AST.
const MODULE_SERDE_OPTIONS: AstSerdeOptions = AstSerdeOptions::new(true);
const MODULE_SERDE_OPTIONS: AstSerdeOptions = AstSerdeOptions::new(false);

/// The depth of the Merkle tree that is used to commit to the account's public interface.
pub const PROCEDURE_TREE_DEPTH: u8 = 8;
Expand Down Expand Up @@ -157,8 +157,8 @@ impl Eq for AccountCode {}

impl Serializable for AccountCode {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
// debug info (this includes module imports and source locations) is not serialized with account code
self.module.write_into(target, MODULE_SERDE_OPTIONS);
self.module.write_source_locations(target);
// since the number of procedures is guaranteed to be between 1 and 256, we can store the
// number as a single byte - but we do have to subtract 1 to store 256 as 255.
target.write_u8((self.procedures.len() - 1) as u8);
Expand All @@ -168,8 +168,8 @@ impl Serializable for AccountCode {

impl Deserializable for AccountCode {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let mut module = ModuleAst::read_from(source, MODULE_SERDE_OPTIONS)?;
module.load_source_locations(source)?;
// debug info (this includes module imports and source locations) is not serialized with account code
let module = ModuleAst::read_from(source, MODULE_SERDE_OPTIONS)?;
let num_procedures = (source.read_u8()? as usize) + 1;
let procedures = source.read_many::<Digest>(num_procedures)?;

Expand Down Expand Up @@ -218,13 +218,17 @@ mod tests {
";

// build account code from source
let module = ModuleAst::parse(source).unwrap();
let mut module = ModuleAst::parse(source).unwrap();
// clears are needed since they're not serialized for account code
module.clear_imports();
module.clear_locations();
let assembler = Assembler::default();
let code1 = AccountCode::new(module, &assembler).unwrap();

// serialize and deserialize the code; make sure deserialized version matches the original
let bytes = code1.to_bytes();
let code2 = AccountCode::read_from_bytes(&bytes).unwrap();

assert_eq!(code1, code2)
}
}
5 changes: 4 additions & 1 deletion objects/src/accounts/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ mod tests {
push.1 push.2 add
end
";
let module = ModuleAst::parse(source).unwrap();
let mut module = ModuleAst::parse(source).unwrap();
// clears are needed since imports and source locations are not serialized for account code
module.clear_locations();
module.clear_imports();
let assembler = Assembler::default();
let code = AccountCode::new(module, &assembler).unwrap();

Expand Down

0 comments on commit e5eb189

Please sign in to comment.