mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-30 23:33:27 +03:00
output bytes update
This commit is contained in:
parent
80d5c87b8a
commit
da52984385
@ -47,7 +47,7 @@ version = "1.0.8"
|
||||
|
||||
[dependencies.leo-asg]
|
||||
path = "../asg"
|
||||
version = "1.0.7"
|
||||
version = "1.0.8"
|
||||
|
||||
[dependencies.snarkvm-curves]
|
||||
version = "0.0.2"
|
||||
|
@ -15,7 +15,8 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::errors::ValueError;
|
||||
use leo_ast::{Error as FormattedError, Span, Type};
|
||||
use leo_asg::{AsgConvertError, Type};
|
||||
use leo_ast::{Error as FormattedError, Span};
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
@ -26,6 +27,9 @@ pub enum OutputBytesError {
|
||||
|
||||
#[error("{}", _0)]
|
||||
ValueError(#[from] ValueError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
AsgConvertError(#[from] AsgConvertError),
|
||||
}
|
||||
|
||||
impl OutputBytesError {
|
||||
@ -33,6 +37,7 @@ impl OutputBytesError {
|
||||
match self {
|
||||
OutputBytesError::Error(error) => error.set_path(path),
|
||||
OutputBytesError::ValueError(error) => error.set_path(path),
|
||||
OutputBytesError::AsgConvertError(_error) => (),
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +51,7 @@ impl OutputBytesError {
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn mismatched_output_types(left: Type, right: Type, span: Span) -> Self {
|
||||
pub fn mismatched_output_types(left: &Type, right: &Type, span: Span) -> Self {
|
||||
let message = format!(
|
||||
"Mismatched types. Expected register output type `{}`, found type `{}`.",
|
||||
left, right
|
||||
|
@ -91,7 +91,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
|
||||
let span = function.span.clone().unwrap_or_default();
|
||||
let result_value = self.enforce_function(cs, function, None, &arguments)?;
|
||||
let output_bytes = OutputBytes::new_from_constrained_value(registers, result_value, span)?;
|
||||
let output_bytes = OutputBytes::new_from_constrained_value(&self.asg, registers, result_value, span)?;
|
||||
|
||||
Ok(output_bytes)
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{errors::OutputBytesError, ConstrainedValue, GroupType, REGISTERS_VARIABLE_NAME};
|
||||
use leo_asg::Program;
|
||||
use leo_ast::{Parameter, Registers, Span};
|
||||
|
||||
use snarkvm_models::curves::{Field, PrimeField};
|
||||
@ -31,6 +32,7 @@ impl OutputBytes {
|
||||
}
|
||||
|
||||
pub fn new_from_constrained_value<F: Field + PrimeField, G: GroupType<F>>(
|
||||
program: &Program,
|
||||
registers: &Registers,
|
||||
value: ConstrainedValue<F, G>,
|
||||
span: Span,
|
||||
@ -65,13 +67,13 @@ impl OutputBytes {
|
||||
let name = parameter.variable.name;
|
||||
|
||||
// Check register type == return value type.
|
||||
let register_type = parameter.type_;
|
||||
let register_type = program.borrow().scope.borrow().resolve_ast_type(¶meter.type_)?;
|
||||
let return_value_type = value.to_type(&span)?;
|
||||
|
||||
if !register_type.eq_flat(&return_value_type) {
|
||||
if !register_type.is_assignable_from(&return_value_type) {
|
||||
return Err(OutputBytesError::mismatched_output_types(
|
||||
register_type,
|
||||
return_value_type,
|
||||
®ister_type,
|
||||
&return_value_type,
|
||||
span,
|
||||
));
|
||||
}
|
||||
|
@ -1,3 +1,19 @@
|
||||
// Copyright (C) 2019-2020 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::CoreCircuit;
|
||||
|
@ -1,3 +1,19 @@
|
||||
// Copyright (C) 2019-2020 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
pub mod blake2s;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user