Skip to content

Commit

Permalink
fix: remove unwrap which is causing panics closes #1073
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Dec 26, 2024
1 parent 1f1ca4f commit 3e2ca75
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- **aiken-project**: The `aiken.toml` file no longer supports `v1` and `v2` for the plutus version field. @rvcas
- **aiken-project**: `Error::TomlLoading` now looks much better - [see](https://github.com/aiken-lang/aiken/issues/1032#issuecomment-2562122101). @rvcas

### Fixed

- **aiken**: Fixed the panic error when using `aiken uplc decode` on cbor encoded flat bytes. @rvcas

## v1.1.9 - 2024-12-13

### Added
Expand Down
26 changes: 13 additions & 13 deletions crates/aiken/src/cmd/uplc/decode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use miette::IntoDiagnostic;
use miette::{Context, IntoDiagnostic};
use std::{path::PathBuf, println};
use uplc::ast::{DeBruijn, Name, NamedDeBruijn, Program};

Expand Down Expand Up @@ -39,16 +39,14 @@ pub fn exec(
std::fs::read(&input).into_diagnostic()?
};

let pretty_uplc = match from {
let program: Program<Name> = match from {
Format::Name => {
let program: Program<Name> = if cbor {
if cbor {
let mut flat_buffer = Vec::new();
Program::from_cbor(&bytes, &mut flat_buffer).into_diagnostic()?
} else {
Program::from_flat(&bytes).into_diagnostic()?
};

program.to_pretty()
}
}
Format::NamedDebruijn => {
let program: Program<NamedDeBruijn> = if cbor {
Expand All @@ -58,9 +56,10 @@ pub fn exec(
Program::from_flat(&bytes).into_diagnostic()?
};

let program: Program<Name> = program.try_into().unwrap();

program.to_pretty()
program
.try_into()
.into_diagnostic()
.context("failed to decode, maybe try `--cbor`")?
}
Format::Debruijn => {
let program: Program<DeBruijn> = if cbor {
Expand All @@ -70,13 +69,14 @@ pub fn exec(
Program::from_flat(&bytes).into_diagnostic()?
};

let program: Program<Name> = program.try_into().unwrap();

program.to_pretty()
program
.try_into()
.into_diagnostic()
.context("failed to decode, maybe try `--cbor`")?
}
};

println!("{pretty_uplc}");
println!("{}", program.to_pretty());

Ok(())
}
7 changes: 6 additions & 1 deletion crates/uplc/src/debruijn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,12 @@ impl Converter {

fn get_unique(&mut self, index: &DeBruijn) -> Result<Unique, Error> {
for scope in self.levels.iter().rev() {
let index = Level(self.current_level.0 - index.inner());
let index = Level(
self.current_level
.0
.checked_sub(index.inner())
.ok_or(Error::FreeIndex(*index))?,
);

if let Some(unique) = scope.get_right(&index) {
return Ok(*unique);
Expand Down
2 changes: 1 addition & 1 deletion examples/gift_card/plutus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"plutusVersion": "v3",
"compiler": {
"name": "Aiken",
"version": "v1.1.6+18054ee"
"version": "v1.1.9+2217206"
},
"license": "Apache-2.0"
},
Expand Down

0 comments on commit 3e2ca75

Please sign in to comment.