Skip to content

Commit

Permalink
Fix missed case of propagating new constant variable
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Apr 11, 2023
1 parent 26af0e7 commit 6ba22de
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
1 change: 0 additions & 1 deletion console/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub trait Network:
/// The number of blocks per epoch (1 hour).
const NUM_BLOCKS_PER_EPOCH: u32 = 1 << 8; // 256 blocks == ~1 hour


/// The maximum recursive depth of a value and/or entry.
/// Note: This value must be strictly less than u8::MAX.
const MAX_DATA_DEPTH: usize = 32;
Expand Down
4 changes: 3 additions & 1 deletion synthesizer/src/process/stack/finalize_types/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ impl<N: Network> FinalizeTypes<N> {
}

// Ensure the operand types match the record entry types.
for (operand, (entry_name, entry_type)) in operands.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record_type.entries()) {
for (operand, (entry_name, entry_type)) in
operands.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record_type.entries())
{
match entry_type {
EntryType::Constant(plaintext_type)
| EntryType::Public(plaintext_type)
Expand Down
4 changes: 3 additions & 1 deletion synthesizer/src/process/stack/register_types/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ impl<N: Network> RegisterTypes<N> {
}

// Ensure the operand types match the record entry types.
for (operand, (entry_name, entry_type)) in operands.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record_type.entries()) {
for (operand, (entry_name, entry_type)) in
operands.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record_type.entries())
{
match entry_type {
EntryType::Constant(plaintext_type)
| EntryType::Public(plaintext_type)
Expand Down
31 changes: 20 additions & 11 deletions synthesizer/src/program/instruction/operation/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ impl<N: Network> Cast<N> {

// Initialize the record entries.
let mut entries = IndexMap::new();
for (entry, (entry_name, entry_type)) in inputs.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record_type.entries()) {
for (entry, (entry_name, entry_type)) in
inputs.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record_type.entries())
{
// Compute the register type.
let register_type = RegisterType::from(ValueType::from(*entry_type));
// Retrieve the plaintext value from the entry.
Expand Down Expand Up @@ -234,8 +236,12 @@ impl<N: Network> Cast<N> {
registers.store_circuit(stack, &self.destination, circuit::Value::Plaintext(struct_))
}
RegisterType::Record(record_name) => {
// Ensure the operands length is at least 1.
ensure!(inputs.len() >= 1, "Casting to a record requires at least 1 operand");
// Ensure the operands length is at least the minimum.
ensure!(
inputs.len() >= N::MIN_RECORD_ENTRIES,
"Casting to a record requires at least {} operand",
N::MIN_RECORD_ENTRIES
);

// Retrieve the struct and ensure it is defined in the program.
let record_type = stack.program().get_record(&record_name)?;
Expand All @@ -257,7 +263,9 @@ impl<N: Network> Cast<N> {

// Initialize the record entries.
let mut entries = IndexMap::new();
for (entry, (entry_name, entry_type)) in inputs.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record_type.entries()) {
for (entry, (entry_name, entry_type)) in
inputs.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record_type.entries())
{
// Compute the register type.
let register_type = RegisterType::from(ValueType::from(*entry_type));
// Retrieve the plaintext value from the entry.
Expand Down Expand Up @@ -346,20 +354,21 @@ impl<N: Network> Cast<N> {
let record = stack.program().get_record(&record_name)?;

// Ensure the input types length is at least the minimum.
ensure!(input_types.len() >= 2, "Casting to a record requires at least two operands");
ensure!(
input_types.len() >= N::MIN_RECORD_ENTRIES,
"Casting to a record requires at least {} operands",
N::MIN_RECORD_ENTRIES
);
// Ensure the first input type is an address.
ensure!(
input_types[0] == RegisterType::Plaintext(PlaintextType::Literal(LiteralType::Address)),
"Casting to a record requires the first operand to be an address"
);
// Ensure the second input type is a u64.
ensure!(
input_types[1] == RegisterType::Plaintext(PlaintextType::Literal(LiteralType::U64)),
"Casting to a record requires the second operand to be a u64"
);

// Ensure the input types match the record.
for (input_type, (_, entry_type)) in input_types.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record.entries()) {
for (input_type, (_, entry_type)) in
input_types.iter().skip(N::MIN_RECORD_ENTRIES).zip_eq(record.entries())
{
match input_type {
// Ensure the plaintext type matches the entry type.
RegisterType::Plaintext(plaintext_type) => match entry_type {
Expand Down

0 comments on commit 6ba22de

Please sign in to comment.