Get rid of RawValue

It is not needed anymore
This commit is contained in:
Ivan Boldyrev 2024-02-07 17:30:46 +01:00
parent e0e69f9afe
commit 78c4576862
10 changed files with 20 additions and 96 deletions

View File

@ -24,7 +24,6 @@ use air_interpreter_data::CanonCidAggregate;
use air_interpreter_data::CanonResultCidAggregate;
use air_interpreter_data::CidInfo;
use air_interpreter_data::CidTracker;
use air_interpreter_data::RawValue;
use air_interpreter_data::ServiceResultCidAggregate;
use air_interpreter_data::TracePos;
use polyplets::SecurityTetraplet;
@ -33,7 +32,7 @@ use std::rc::Rc;
#[derive(Debug, Default, Clone)]
pub struct ExecutionCidState {
pub value_tracker: CidTracker<RawValue>,
pub value_tracker: CidTracker<JValue>,
pub tetraplet_tracker: CidTracker<SecurityTetraplet>,
pub canon_element_tracker: CidTracker<CanonCidAggregate>,
pub canon_result_tracker: CidTracker<CanonResultCidAggregate>,
@ -73,8 +72,7 @@ impl ExecutionCidState {
tetraplet: RcSecurityTetraplet,
argument_hash: Rc<str>,
) -> Result<CID<ServiceResultCidAggregate>, UncatchableError> {
let vm_value = RawValue::from_value(value);
let value_cid = self.value_tracker.track_raw_value(vm_value);
let value_cid = self.value_tracker.track_value(value)?;
let tetraplet_cid = self.tetraplet_tracker.track_value(tetraplet)?;
let service_result_agg = ServiceResultCidAggregate::new(value_cid, argument_hash, tetraplet_cid);
@ -87,8 +85,7 @@ impl ExecutionCidState {
&mut self,
canon_value: &ValueAggregate,
) -> Result<CID<CanonCidAggregate>, UncatchableError> {
let vm_value = RawValue::from_value(canon_value.get_result().clone());
let value_cid = self.value_tracker.track_raw_value(vm_value);
let value_cid = self.value_tracker.track_value(canon_value.get_result().clone())?;
let tetraplet = self.tetraplet_tracker.track_value(canon_value.get_tetraplet())?;
let canon_value_aggregate = CanonCidAggregate::new(value_cid, tetraplet, canon_value.get_provenance());
@ -97,11 +94,11 @@ impl ExecutionCidState {
.map_err(UncatchableError::from)
}
pub(crate) fn get_value_by_cid(&self, cid: &CID<RawValue>) -> Result<JValue, UncatchableError> {
pub(crate) fn get_value_by_cid(&self, cid: &CID<JValue>) -> Result<JValue, UncatchableError> {
self.value_tracker
.get(cid)
.map(|v| (*v).clone())
.ok_or_else(|| UncatchableError::ValueForCidNotFound("value", cid.get_inner()))
.map(|vm_value| vm_value.get_value())
}
pub(crate) fn get_tetraplet_by_cid(

View File

@ -96,7 +96,7 @@ fn test_attack_replace_value() {
PreparationError::CidStoreVerificationError(
CidVerificationError::ValueMismatch {
// fragile: it is OK if this exact string changes on compiler upgrade
type_name: "air_interpreter_data::raw_value::RawValue",
type_name: "air_interpreter_value::JValue",
cid_repr: "bagaaihrayhxgqijfajraxivb7hxwshhbsdqk4j5zyqypb54zggmn5v7mmwxq".into(),
}
.into()

View File

@ -17,7 +17,6 @@
use air::interpreter_data::ExecutedState;
use air::ExecutionCidState;
use air::UncatchableError::*;
use air_interpreter_data::RawValue;
use air_interpreter_data::ValueRef;
use air_test_framework::AirScriptExecutor;
use air_test_utils::prelude::*;
@ -140,9 +139,7 @@ fn malformed_call_service_failed() {
// Craft an artificial incorrect error result
let value = json!("error");
let value_cid = cid_state
.value_tracker
.track_raw_value(RawValue::from_value(value.clone()));
let value_cid = cid_state.value_tracker.track_value(value.clone());
let tetraplet = SecurityTetraplet::literal_tetraplet(peer_id);
let tetraplet_cid = cid_state.tetraplet_tracker.track_value(tetraplet).unwrap();
let service_result_agg = ServiceResultCidAggregate {

View File

@ -19,9 +19,9 @@ use crate::CidStoreVerificationError;
use crate::CanonCidAggregate;
use crate::CanonResultCidAggregate;
use crate::RawValue;
use crate::ServiceResultCidAggregate;
use air_interpreter_value::JValue;
use polyplets::SecurityTetraplet;
use serde::Deserialize;
use serde::Serialize;
@ -40,7 +40,7 @@ use serde::Serialize;
#[archive(check_bytes)]
pub struct CidInfo {
/// Map CID to value.
pub value_store: CidStore<RawValue>,
pub value_store: CidStore<JValue>,
/// Map CID to a tetraplet.
pub tetraplet_store: CidStore<SecurityTetraplet>,
@ -68,7 +68,7 @@ impl CidInfo {
}
fn verify_value_store(&self) -> Result<(), CidStoreVerificationError> {
self.value_store.verify_raw_value()
self.value_store.verify()
}
fn verify_tetraplet_store(&self) -> Result<(), CidStoreVerificationError> {

View File

@ -15,7 +15,6 @@
*/
use crate::JValue;
use crate::RawValue;
use air_interpreter_cid::value_to_json_cid;
use air_interpreter_cid::verify_value;
@ -82,15 +81,6 @@ impl<Val: Serialize> CidStore<Val> {
}
}
impl CidStore<RawValue> {
pub fn verify_raw_value(&self) -> Result<(), CidStoreVerificationError> {
for (cid, value) in &self.0 {
verify_value(cid, value)?;
}
Ok(())
}
}
#[derive(ThisError, Debug)]
pub enum CidStoreVerificationError {
#[error(transparent)]
@ -146,15 +136,6 @@ impl<Val: Serialize> CidTracker<Val> {
}
}
impl CidTracker<RawValue> {
pub fn track_raw_value(&mut self, value: impl Into<Rc<RawValue>>) -> CID<RawValue> {
let value = value.into();
let cid = value_to_json_cid(&*value).expect("TODO refcator");
self.cids.insert(cid.clone(), value);
cid
}
}
impl<Val> Default for CidTracker<Val> {
fn default() -> Self {
Self {

View File

@ -19,7 +19,6 @@ mod se_de;
use crate::GenerationIdx;
use crate::JValue;
use crate::RawValue;
use crate::TracePos;
use air_interpreter_cid::CID;
@ -156,7 +155,7 @@ impl CallServiceFailed {
#[archive(check_bytes)]
/// A proof of service result execution result.
pub struct ServiceResultCidAggregate {
pub value_cid: CID<RawValue>,
pub value_cid: CID<JValue>,
/// Hash of the call arguments.
pub argument_hash: Rc<str>,
/// The tetraplet of the call result.
@ -268,7 +267,7 @@ pub struct CanonResultCidAggregate {
)]
#[archive(check_bytes)]
pub struct CanonCidAggregate {
pub value: CID<RawValue>,
pub value: CID<JValue>,
pub tetraplet: CID<SecurityTetraplet>,
pub provenance: Provenance,
}

View File

@ -15,7 +15,6 @@
*/
use super::*;
use crate::RawValue;
impl ParResult {
pub fn new(left_size: u32, right_size: u32) -> Self {
@ -123,7 +122,7 @@ impl CanonResultCidAggregate {
impl CanonCidAggregate {
pub fn new(
value: CID<RawValue>,
value: CID<JValue>,
tetraplet: CID<SecurityTetraplet>,
provenance: Provenance,
) -> Self {
@ -137,7 +136,7 @@ impl CanonCidAggregate {
impl ServiceResultCidAggregate {
pub fn new(
value_cid: CID<RawValue>,
value_cid: CID<JValue>,
argument_hash: Rc<str>,
tetraplet_cid: CID<SecurityTetraplet>,
) -> Self {

View File

@ -31,7 +31,6 @@ mod cid_store;
mod executed_state;
mod generation_idx;
mod interpreter_data;
mod raw_value;
mod rkyv;
mod trace;
mod trace_pos;
@ -41,7 +40,6 @@ pub use cid_store::*;
pub use executed_state::*;
pub use generation_idx::*;
pub use interpreter_data::*;
pub use raw_value::*;
pub use trace::*;
pub use trace_pos::*;

View File

@ -1,45 +0,0 @@
/*
* Copyright 2023 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::JValue;
use serde::Deserialize;
use serde::Serialize;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(transparent)]
#[derive(::rkyv::Archive, ::rkyv::Serialize, ::rkyv::Deserialize)]
#[archive(check_bytes)]
pub struct RawValue {
value: JValue,
}
impl RawValue {
pub fn from_value(value: impl Into<JValue>) -> Self {
let value = value.into();
Self { value }
}
pub fn get_value(&self) -> JValue {
self.value.clone()
}
}
impl From<JValue> for RawValue {
fn from(value: JValue) -> Self {
Self::from_value(value)
}
}

View File

@ -36,7 +36,6 @@ use air_interpreter_cid::CID;
use air_interpreter_data::CanonCidAggregate;
use air_interpreter_data::GenerationIdx;
use air_interpreter_data::Provenance;
use air_interpreter_data::RawValue;
use air_interpreter_data::ServiceResultCidAggregate;
use avm_server::SecurityTetraplet;
use serde::Deserialize;
@ -49,9 +48,8 @@ pub fn simple_value_aggregate_cid(
cid_state: &mut ExecutionCidState,
) -> CID<ServiceResultCidAggregate> {
let value = result.into();
let vm_value = RawValue::from_value(value);
let value_cid = cid_state.value_tracker.track_raw_value(vm_value);
let value_cid = cid_state.value_tracker.track_value(value).unwrap();
let tetraplet = SecurityTetraplet::default();
let tetraplet_cid = cid_state.tetraplet_tracker.track_value(tetraplet).unwrap();
let service_result_agg = ServiceResultCidAggregate {
@ -72,8 +70,7 @@ pub fn value_aggregate_cid(
cid_state: &mut ExecutionCidState,
) -> CID<ServiceResultCidAggregate> {
let value = result.into();
let vm_value = RawValue::from_value(value);
let value_cid = cid_state.value_tracker.track_raw_value(vm_value);
let value_cid = cid_state.value_tracker.track_value(value).unwrap();
let tetraplet_cid = cid_state.tetraplet_tracker.track_value(tetraplet).unwrap();
let arguments = JValue::array(args);
@ -175,9 +172,10 @@ pub fn canon_tracked(
.values
.iter()
.map(|value| {
let vm_value = RawValue::from_value(value.result.clone());
let value_cid = cid_state.value_tracker.track_raw_value(vm_value);
let value_cid = cid_state
.value_tracker
.track_value(value.result.clone())
.unwrap();
let tetraplet_cid = cid_state
.tetraplet_tracker
.track_value(value.tetraplet.clone())?;