-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validation: validate anchors depending on layer1 chain
- Loading branch information
1 parent
8eeae44
commit b6d754d
Showing
12 changed files
with
437 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// RGB Core Library: consensus layer for RGB smart contracts. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Written in 2019-2023 by | ||
// Dr Maxim Orlovsky <orlovsky@lnp-bp.org> | ||
// | ||
// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. | ||
// Copyright (C) 2019-2023 Dr Maxim Orlovsky. All rights reserved. | ||
// | ||
// 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 bp::dbc; | ||
use commit_verify::mpc; | ||
use commit_verify::mpc::{Message, ProtocolId}; | ||
|
||
use crate::{TransitionBundle, LIB_NAME_RGB}; | ||
|
||
#[derive(Clone, Eq, PartialEq, Debug)] | ||
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] | ||
#[strict_type(lib = LIB_NAME_RGB)] | ||
#[cfg_attr( | ||
feature = "serde", | ||
derive(Serialize, Deserialize), | ||
serde(crate = "serde_crate", rename_all = "camelCase") | ||
)] | ||
pub struct AnchoredBundle { | ||
pub anchor: Anchor, | ||
pub bundle: TransitionBundle, | ||
} | ||
|
||
#[derive(Clone, Eq, PartialEq, Debug)] | ||
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] | ||
#[strict_type(lib = LIB_NAME_RGB, tags = custom, dumb = Self::Bitcoin(strict_dumb!()))] | ||
#[cfg_attr( | ||
feature = "serde", | ||
derive(Serialize, Deserialize), | ||
serde(crate = "serde_crate", rename_all = "camelCase") | ||
)] | ||
#[non_exhaustive] | ||
pub enum Anchor { | ||
#[strict_type(tag = 0x00)] | ||
Bitcoin(dbc::Anchor<mpc::MerkleProof>), | ||
|
||
#[strict_type(tag = 0x01)] | ||
Liquid(dbc::Anchor<mpc::MerkleProof>), | ||
} | ||
|
||
impl Anchor { | ||
pub fn layer1(&self) -> Layer1 { | ||
match self { | ||
Anchor::Bitcoin(_) => Layer1::Bitcoin, | ||
Anchor::Liquid(_) => Layer1::Liquid, | ||
} | ||
} | ||
|
||
/// Verifies that the anchor commits to the given message under the given | ||
/// protocol. | ||
pub fn convolve( | ||
&self, | ||
protocol_id: impl Into<ProtocolId>, | ||
message: Message, | ||
) -> Result<mpc::Commitment, mpc::InvalidProof> { | ||
match self { | ||
Anchor::Bitcoin(anchor) | Anchor::Liquid(anchor) => { | ||
anchor.mpc_proof.convolve(protocol_id.into(), message) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display)] | ||
#[display(lowercase)] | ||
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] | ||
#[strict_type(lib = LIB_NAME_RGB, tags = repr, into_u8, try_from_u8)] | ||
#[cfg_attr( | ||
feature = "serde", | ||
derive(Serialize, Deserialize), | ||
serde(crate = "serde_crate", rename_all = "camelCase") | ||
)] | ||
#[repr(u8)] | ||
#[non_exhaustive] | ||
pub enum Layer1 { | ||
#[strict_type(dumb)] | ||
Bitcoin = 0, | ||
Liquid = 1, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.