-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rewrite programs using new packed transaction repr
- Loading branch information
Showing
22 changed files
with
179 additions
and
510 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,53 @@ | ||
#![no_std] | ||
#![feature(test)] | ||
extern crate test; | ||
|
||
use core::ops::Deref; | ||
|
||
use test::Bencher; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
#[repr(transparent)] | ||
pub struct Hash([u8; 32]); | ||
|
||
impl Deref for Hash { | ||
type Target = [u8; 32]; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
#[bench] | ||
fn bench_validate(b: &mut Bencher) { | ||
let transaction = Transaction { | ||
manifest: Manifest { | ||
programs: ProgramSet { | ||
validate: VALIDATE_ID.into(), | ||
}, | ||
}, | ||
inputs: Inputs { | ||
parents: [[0; 32].into(); 4], | ||
indexes: [0, 1, 2, 3], | ||
asset_ids: [1, 2, 3, 1], | ||
amounts: [100, 200, 300, 400], | ||
program_id: [[0; 32].into(); 4], | ||
data: [u32::MAX; 4], | ||
}, | ||
outputs: Outputs { | ||
asset_ids: [1, 2, 3, 1], | ||
amounts: [150, 200, 300, 350], | ||
program_id: [[0; 32].into(); 4], | ||
data: [u32::MAX; 4], | ||
}, | ||
data: [0; 256 * 8], | ||
assets: [ | ||
[1; 32].into(), | ||
[2; 32].into(), | ||
[3; 32].into(), | ||
[0; 32].into(), | ||
], | ||
}; | ||
|
||
b.iter(|| validate(&transaction)); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
#![no_std] | ||
|
||
use mugraph_core::programs::validate; | ||
use risc0_zkvm::guest::env; | ||
|
||
fn main() { | ||
validate(&env::read()); | ||
env::write(&env::cycle_count()); | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,3 @@ pub mod error; | |
pub mod programs; | ||
pub mod types; | ||
pub mod util; | ||
pub mod wallet; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
mod apply; | ||
mod compose; | ||
mod validate; | ||
|
||
pub use self::{apply::*, compose::*}; | ||
pub use self::validate::*; |
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,35 @@ | ||
use crate::types::*; | ||
|
||
#[inline(always)] | ||
#[no_mangle] | ||
pub fn validate(transaction: &Transaction) { | ||
let mut amounts = [0u64; 4]; | ||
|
||
for i in 0..4 { | ||
assert_ne!(transaction.inputs.amounts[i], 0); | ||
|
||
let index = transaction | ||
.assets | ||
.iter() | ||
.position(|a| a[0] == transaction.inputs.asset_ids[i]) | ||
.unwrap_or(0); | ||
|
||
amounts[index] = amounts[index] | ||
.checked_add(transaction.inputs.amounts[i]) | ||
.unwrap(); | ||
} | ||
|
||
for i in 0..4 { | ||
let index = transaction | ||
.assets | ||
.iter() | ||
.position(|a| a[0] == transaction.outputs.asset_ids[i]) | ||
.unwrap_or(0); | ||
|
||
amounts[index] = amounts[index] | ||
.checked_sub(transaction.outputs.amounts[i]) | ||
.unwrap(); | ||
} | ||
|
||
assert_eq!(amounts, amounts); | ||
} |
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.