Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pintc/src/asm_gen/asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ impl<'a> AsmBuilder<'a> {
}

match kind {
ExternalIntrinsic::PanicIf => asm.push(PNCIF),

ExternalIntrinsic::RecoverSECP256k1 => asm.push(RSECP),

ExternalIntrinsic::Sha256 => asm.extend([PUSH(3), SHL, SHA2]),
Expand Down
8 changes: 8 additions & 0 deletions pintc/src/expr/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub enum ExternalIntrinsic {
// Returns the address of a predicate in the same contract
AddressOf,

// Panics if supplied condition is `true`
PanicIf,

// Recovers the public key from a secp256k1 signature.
RecoverSECP256k1,

Expand All @@ -75,6 +78,7 @@ impl Display for ExternalIntrinsic {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::AddressOf => write!(f, "__address_of"),
Self::PanicIf => write!(f, "__panic_if"),
Self::RecoverSECP256k1 => write!(f, "__recover_secp256k1"),
Self::Sha256 => write!(f, "__sha256"),
Self::SizeOf => write!(f, "__size_of"),
Expand All @@ -92,6 +96,9 @@ impl ExternalIntrinsic {
Self::AddressOf => vec![
string(), // path to a predicate in the contract
],
Self::PanicIf => vec![
r#bool(), // path to a predicate in the contract
],
Self::RecoverSECP256k1 => vec![
b256(), // data hash
tuple(vec![b256(), b256(), int()]), // signature
Expand All @@ -116,6 +123,7 @@ impl ExternalIntrinsic {
pub fn ty(&self) -> Type {
match self {
Self::AddressOf => b256(),
Self::PanicIf => any(),
Self::RecoverSECP256k1 => tuple(vec![b256(), int()]),
Self::Sha256 => b256(),
Self::SizeOf => int(),
Expand Down
1 change: 1 addition & 0 deletions pintc/src/parser/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ impl<'a> ParserContext<'a> {
kind: (
match &name.name[..] {
"__address_of" => IntrinsicKind::External(ExternalIntrinsic::AddressOf),
"__panic_if" => IntrinsicKind::External(ExternalIntrinsic::PanicIf),
"__recover_secp256k1" => {
IntrinsicKind::External(ExternalIntrinsic::RecoverSECP256k1)
}
Expand Down
5 changes: 1 addition & 4 deletions pintc/src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,7 @@ fn storage_types() {
// Multi dimensional vectors are not yet supported
check(
&run_parser!(storage_var_type, "int[][]"),
expect_test::expect![[r#"
expected `?`, found `[`
@18..19: expected `?`
"#]],
expect_test::expect!["int[][]"],
);
}

Expand Down
9 changes: 5 additions & 4 deletions pintc/src/pint_parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,12 @@ MapType: Type = {
}
}

// This only allows single dimensional vectors for the time being
VectorType: Type = {
<l:@L> <ty:TypeAtom> "[" "]" <r:@R> => Type::Vector {
ty: Box::new(ty),
span: (context.span_from)(l, r),
<l:@L> <ty:TypeAtom> <ranges: ("[" "]")+> <r:@R> => {
ranges.iter().rev().fold(ty, |acc, _| Type::Vector {
ty: Box::new(acc),
span: (context.span_from)(l, r),
})
}
}

Expand Down
9 changes: 2 additions & 7 deletions pintc/src/predicate/transform.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
mod legalize;
mod lower;
mod unroll;
mod validate;

use crate::error::{ErrorEmitted, Handler};
use legalize::legalize_vector_accesses;
use lower::{
coalesce_prime_ops, lower_aliases, lower_array_ranges, lower_casts, lower_ifs,
lower_imm_accesses, lower_ins, lower_matches, lower_storage_accesses,
Expand Down Expand Up @@ -80,11 +78,8 @@ impl super::Contract {
// (e.g., `option::none`) from Expr::Path to Expr::UnionVariant.
lower_union_variant_paths(&mut self);

// Insert OOB checks for storage vector accesses
let _ = legalize_vector_accesses(handler, &mut self);

// Lower all storage accesses to __storage_get and __storage_get_extern intrinsics. Also
// add constraints on mutable keys
// Lower all storage accesses to storage intrinsics (`__pre_state`, `__pre_state_extern`,
// `_post_state`, and `__post_state_extern`). Also add constraints on mutable keys
let _ = lower_storage_accesses(handler, &mut self);

// Ensure that the final contract is indeed final
Expand Down
289 changes: 0 additions & 289 deletions pintc/src/predicate/transform/legalize.rs

This file was deleted.

Loading
Loading