forked from ProvableHQ/snarkVM
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ProvableHQ#1217 from AleoHQ/feat/coinbase-map
Adds puzzle commitments to `BlockStore`, adds serializers on `PuzzleCommitment`
- Loading branch information
Showing
19 changed files
with
446 additions
and
86 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
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
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
56 changes: 56 additions & 0 deletions
56
synthesizer/src/coinbase_puzzle/helpers/puzzle_commitment/bytes.rs
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,56 @@ | ||
// Copyright (C) 2019-2022 Aleo Systems Inc. | ||
// This file is part of the snarkVM library. | ||
|
||
// The snarkVM 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 snarkVM 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 snarkVM library. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use super::*; | ||
|
||
impl<N: Network> FromBytes for PuzzleCommitment<N> { | ||
/// Reads the puzzle commitment from the buffer. | ||
fn read_le<R: Read>(mut reader: R) -> IoResult<Self> { | ||
let commitment = KZGCommitment::read_le(&mut reader)?; | ||
|
||
Ok(Self::new(commitment)) | ||
} | ||
} | ||
|
||
impl<N: Network> ToBytes for PuzzleCommitment<N> { | ||
/// Writes the puzzle commitment to the buffer. | ||
fn write_le<W: Write>(&self, mut writer: W) -> IoResult<()> { | ||
self.commitment.write_le(&mut writer) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use console::network::Testnet3; | ||
|
||
type CurrentNetwork = Testnet3; | ||
|
||
#[test] | ||
fn test_bytes() -> Result<()> { | ||
let mut rng = TestRng::default(); | ||
// Sample a new puzzle commitment. | ||
let expected = PuzzleCommitment::<CurrentNetwork>::new(KZGCommitment(rng.gen())); | ||
|
||
// Check the byte representation. | ||
let expected_bytes = expected.to_bytes_le()?; | ||
assert_eq!(expected_bytes.len(), 48); | ||
assert_eq!(expected, PuzzleCommitment::read_le(&expected_bytes[..])?); | ||
assert!(PuzzleCommitment::<CurrentNetwork>::read_le(&expected_bytes[1..]).is_err()); | ||
|
||
Ok(()) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
synthesizer/src/coinbase_puzzle/helpers/puzzle_commitment/mod.rs
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,50 @@ | ||
// Copyright (C) 2019-2022 Aleo Systems Inc. | ||
// This file is part of the snarkVM library. | ||
|
||
// The snarkVM 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 snarkVM 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 snarkVM library. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
mod bytes; | ||
mod serialize; | ||
mod string; | ||
|
||
use super::*; | ||
|
||
/// A coinbase puzzle commitment to a polynomial. | ||
#[derive(Copy, Clone, Eq, PartialEq, Hash)] | ||
pub struct PuzzleCommitment<N: Network> { | ||
/// The commitment for the solution. | ||
commitment: KZGCommitment<<N as Environment>::PairingCurve>, | ||
} | ||
|
||
impl<N: Network> PuzzleCommitment<N> { | ||
/// Initializes a new instance of the puzzle commitment. | ||
pub const fn new(commitment: KZGCommitment<<N as Environment>::PairingCurve>) -> Self { | ||
Self { commitment } | ||
} | ||
} | ||
|
||
impl<N: Network> From<KZGCommitment<<N as Environment>::PairingCurve>> for PuzzleCommitment<N> { | ||
/// Initializes a new instance of the puzzle commitment. | ||
fn from(commitment: KZGCommitment<<N as Environment>::PairingCurve>) -> Self { | ||
Self::new(commitment) | ||
} | ||
} | ||
|
||
impl<N: Network> Deref for PuzzleCommitment<N> { | ||
type Target = KZGCommitment<<N as Environment>::PairingCurve>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.commitment | ||
} | ||
} |
Oops, something went wrong.