Skip to content

Commit

Permalink
Merge pull request #2479 from eqlabs/krisztian/backport-cairo0-class-…
Browse files Browse the repository at this point in the history
…size-limit

Backport Cairo 0 class size limit checks to v0.15.3
  • Loading branch information
kkovaacs authored Jan 10, 2025
2 parents a88f518 + 56641bc commit 70ad7dd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ More expansive patch notes and explanations may be found in the specific [pathfi
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed

- Cairo 0 class definition size is now capped at 4 MiB.

## [0.15.2] - 2024-12-04

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions crates/common/src/class_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use serde_with::serde_as;

use crate::{ByteCodeOffset, EntryPoint};

pub const CLASS_DEFINITION_MAX_ALLOWED_SIZE: u64 = 4 * 1024 * 1024;

#[derive(Debug, Deserialize, Dummy)]
pub enum ClassDefinition<'a> {
Sierra(Sierra<'a>),
Expand Down
4 changes: 2 additions & 2 deletions crates/p2p/src/client/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,10 @@ impl TryFromDto<p2p_proto::class::Cairo0Class> for CairoDefinition {
let abi = dto.abi;

let compressed_program = base64::decode(dto.program)?;
let mut gzip_decoder =
flate2::read::GzDecoder::new(std::io::Cursor::new(compressed_program));
let gzip_decoder = flate2::read::GzDecoder::new(std::io::Cursor::new(compressed_program));
let mut program = Vec::new();
gzip_decoder
.take(pathfinder_common::class_definition::CLASS_DEFINITION_MAX_ALLOWED_SIZE)
.read_to_end(&mut program)
.context("Decompressing program JSON")?;

Expand Down
3 changes: 2 additions & 1 deletion crates/rpc/src/types/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ impl CairoContractClass {

pub fn serialize_to_json(&self) -> anyhow::Result<Vec<u8>> {
// decode program
let mut decompressor =
let decompressor =
flate2::read::GzDecoder::new(Cursor::new(base64::decode(&self.program).unwrap()));
let mut program = Vec::new();
decompressor
.take(pathfinder_common::class_definition::CLASS_DEFINITION_MAX_ALLOWED_SIZE)
.read_to_end(&mut program)
.context("Decompressing program")?;

Expand Down

0 comments on commit 70ad7dd

Please sign in to comment.