Skip to content

Commit

Permalink
Merge pull request #599 from 0xPolygonMiden/next
Browse files Browse the repository at this point in the history
v0.2.1 release
  • Loading branch information
bobbinth authored Apr 11, 2024
2 parents 7ab15df + 0407305 commit e5df312
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 26 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## 0.2.0
## 0.2.1 (2024-04-12)

* [BREAKING] Return a reference to `NoteMetadata` from output notes (#593).
* Add more type conversions for `NoteType` (#597).
* Fix note input padding for expected output notes (#598).

## 0.2.0 (2024-04-11)

* [BREAKING] Implement support for public accounts (#481, #485, #538).
* [BREAKING] Implement support for public notes (#515, #540, #572).
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion miden-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miden-lib"
version = "0.2.0"
version = "0.2.1"
description = "Standard library of the Miden rollup"
readme = "README.md"
categories = ["no-std"]
Expand Down
3 changes: 2 additions & 1 deletion miden-tx/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ impl<A: AdviceProvider> TransactionHost<A> {
return Err(TransactionKernelError::MalformedRecipientData(data.to_vec()));
}
let inputs_hash = Digest::new([data[0], data[1], data[2], data[3]]);
let inputs_key = NoteInputs::commitment_to_key(inputs_hash);
let script_hash = Digest::new([data[4], data[5], data[6], data[7]]);
let serial_num = [data[8], data[9], data[10], data[11]];
let input_els = self.adv_provider.get_mapped_values(&inputs_hash);
let input_els = self.adv_provider.get_mapped_values(&inputs_key);
let script_data = self.adv_provider.get_mapped_values(&script_hash).unwrap_or(&[]);

let inputs = NoteInputs::new(input_els.map(|e| e.to_vec()).unwrap_or_default())
Expand Down
2 changes: 1 addition & 1 deletion miden-tx/tests/integration/scripts/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn prove_faucet_contract_mint_fungible_asset_succeeds() {
assert_eq!(created_note.id(), id);
assert_eq!(
created_note.metadata(),
NoteMetadata::new(faucet_account.id(), NoteType::OffChain, tag, ZERO).unwrap()
&NoteMetadata::new(faucet_account.id(), NoteType::OffChain, tag, ZERO).unwrap()
);
}

Expand Down
2 changes: 1 addition & 1 deletion objects/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miden-objects"
version = "0.2.0"
version = "0.2.1"
description = "Core components of the Miden rollup"
readme = "README.md"
categories = ["no-std"]
Expand Down
18 changes: 16 additions & 2 deletions objects/src/notes/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use alloc::vec::Vec;

use super::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Digest, Felt, Hasher, NoteError,
Serializable, WORD_SIZE, ZERO,
Serializable, Word, WORD_SIZE, ZERO,
};
use crate::MAX_INPUTS_PER_NOTE;
use crate::{MAX_INPUTS_PER_NOTE, ONE};

// NOTE INPUTS
// ================================================================================================
Expand Down Expand Up @@ -79,6 +79,20 @@ impl NoteInputs {
pub fn to_vec(&self) -> Vec<Felt> {
self.values.to_vec()
}

// UTILITIES
// --------------------------------------------------------------------------------------------

/// Returns the key under which the raw (un-padded inputs) are located in the advice map.
///
/// TODO: eventually, this should go away. for now we need it because note inputs for input
/// notes are padded, while note inputs for expected output notes are not. switching to a
/// different padding scheme (e.g., RPX) would eliminate the need to have two different keys.
pub fn commitment_to_key(commitment: Digest) -> Digest {
let mut key: Word = commitment.into();
key[3] += ONE;
key.into()
}
}

impl PartialEq for NoteInputs {
Expand Down
49 changes: 43 additions & 6 deletions objects/src/notes/note_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,64 @@ pub enum NoteType {
Public = PUBLIC,
}

// CONVERSIONS FROM NOTE TYPE
// ================================================================================================

impl From<NoteType> for Felt {
fn from(id: NoteType) -> Self {
Felt::new(id as u64)
}
}

impl TryFrom<Felt> for NoteType {
// CONVERSIONS INTO NOTE TYPE
// ================================================================================================

impl TryFrom<u8> for NoteType {
type Error = NoteError;

fn try_from(value: Felt) -> Result<Self, Self::Error> {
let value = value.as_int();
let note_type: u8 = value.try_into().map_err(|_| NoteError::InvalidNoteTypeValue(value))?;
match note_type {
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
OFF_CHAIN => Ok(NoteType::OffChain),
ENCRYPTED => Ok(NoteType::Encrypted),
PUBLIC => Ok(NoteType::Public),
_ => Err(NoteError::InvalidNoteTypeValue(value)),
_ => Err(NoteError::InvalidNoteTypeValue(value.into())),
}
}
}

impl TryFrom<u16> for NoteType {
type Error = NoteError;

fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(value as u64)
}
}

impl TryFrom<u32> for NoteType {
type Error = NoteError;

fn try_from(value: u32) -> Result<Self, Self::Error> {
Self::try_from(value as u64)
}
}

impl TryFrom<u64> for NoteType {
type Error = NoteError;

fn try_from(value: u64) -> Result<Self, Self::Error> {
let value: u8 = value.try_into().map_err(|_| NoteError::InvalidNoteTypeValue(value))?;
value.try_into()
}
}

impl TryFrom<Felt> for NoteType {
type Error = NoteError;

fn try_from(value: Felt) -> Result<Self, Self::Error> {
value.as_int().try_into()
}
}

// SERIALIZATION
// ================================================================================================

Expand Down
6 changes: 3 additions & 3 deletions objects/src/transaction/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ impl OutputNote {
}

/// Note's metadata.
pub fn metadata(&self) -> NoteMetadata {
pub fn metadata(&self) -> &NoteMetadata {
match self {
OutputNote::Public(note) => *note.metadata(),
OutputNote::Private(note) => *note.metadata(),
OutputNote::Public(note) => note.metadata(),
OutputNote::Private(note) => note.metadata(),
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions objects/src/transaction/tx_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use vm_processor::AdviceMap;
use super::{Digest, Felt, Word};
use crate::{
assembly::{Assembler, AssemblyContext, ProgramAst},
notes::{Note, NoteId},
notes::{Note, NoteId, NoteInputs},
vm::CodeBlock,
TransactionScriptError,
};
Expand Down Expand Up @@ -71,18 +71,21 @@ impl TransactionArgs {
///
/// The map is extended with the following keys:
///
/// - recipient |-> recipient details (inputs_hash, script_hash, serial_num)
/// - intputs_hash |-> inputs
/// - script_hash |-> script
/// - recipient |-> recipient details (inputs_hash, script_hash, serial_num).
/// - inputs_key |-> inputs, where inputs_key is computed by taking note inputs commitment and
/// adding ONE to its most significant element.
/// - script_hash |-> script.
///
pub fn add_expected_output_note(&mut self, note: &Note) {
let recipient = note.recipient();
let inputs = note.inputs();
let script = note.script();
let script_encoded: Vec<Felt> = script.into();

let inputs_key = NoteInputs::commitment_to_key(inputs.commitment());

self.advice_map.insert(recipient.digest(), recipient.to_elements());
self.advice_map.insert(inputs.commitment(), inputs.to_padded_values());
self.advice_map.insert(inputs_key, inputs.to_vec());
self.advice_map.insert(script.hash(), script_encoded);
}

Expand All @@ -91,7 +94,8 @@ impl TransactionArgs {
/// The map is extended with the following keys:
///
/// - recipient |-> recipient details (inputs_hash, script_hash, serial_num)
/// - intputs_hash |-> inputs
/// - inputs_key |-> inputs, where inputs_key is computed by taking note inputs commitment and
/// adding ONE to its most significant element.
/// - script_hash |-> script
///
pub fn extend_expected_output_notes<T>(&mut self, notes: T)
Expand Down

0 comments on commit e5df312

Please sign in to comment.