Skip to content

Commit

Permalink
Merge branch 'main' into ism-integrartion
Browse files Browse the repository at this point in the history
  • Loading branch information
JordyRo1 committed May 13, 2024
2 parents f79c05a + 8c39481 commit 094ef99
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 9 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: release

on:
push:
tags:
- 'v*.*.*'

jobs:
artifact:
permissions:
contents: write
pull-requests: write
name: artifact
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
- name: Build contracts
run: scarb build
- name: Archive contracts
run: |
mkdir -p filtered_artifacts
find ./target/dev -type f -name '*.contract_class.json' -exec cp {} filtered_artifacts/ \;
- name: Generate checksums
run: |
cd filtered_artifacts
for file in *; do
sha256sum "$file" > "$file.sha256"
md5sum "$file" > "$file.md5"
done
- name: Build artifact zip
run: |
cd filtered_artifacts
zip -r ../hyperlane-starknet-${{ github.ref_name }}.zip .
cd ..
sha256sum hyperlane-starknet-${{ github.ref_name }}.zip > hyperlane-starknet-${{ github.ref_name }}.CHECKSUM
md5sum hyperlane-starknet-${{ github.ref_name }}.zip > hyperlane-starknet-${{ github.ref_name }}.CHECKSUM.MD5
- name: Find zip files
run: |
find ./filtered_artifacts -type f -name '*.zip' -exec echo "::set-output name=zip_files::{}" \;
id: find_zip_files

- name: Release Artifact
uses: softprops/action-gh-release@v1
with:
files: |
hyperlane-starknet-${{ github.ref_name }}.zip
hyperlane-starknet-${{ github.ref_name }}.CHECKSUM
hyperlane-starknet-${{ github.ref_name }}.CHECKSUM.MD5
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: tests
on:
push:
pull_request:
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
- uses: foundry-rs/setup-snfoundry@v3
- run: scarb fmt --check
- run: scarb build
- run: snforge test
34 changes: 26 additions & 8 deletions src/contracts/libs/message.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use alexandria_bytes::{Bytes, BytesTrait, BytesStore};
use core::keccak::keccak_u256s_be_inputs;
use core::poseidon::poseidon_hash_span;
use hyperlane_starknet::utils::keccak256::reverse_endianness;
use starknet::{ContractAddress, contract_address_const};

pub const HYPERLANE_VERSION: u8 = 3;


#[derive(Serde, starknet::Store, Drop, Clone)]
pub struct Message {
Expand All @@ -15,8 +18,14 @@ pub struct Message {
pub body: Bytes,
}


#[generate_trait]
pub impl MessageImpl of MessageTrait {
/// Generate a default empty message
///
/// # Returns
///
/// * An empty message structure
fn default() -> Message {
Message {
version: 3_u8,
Expand All @@ -29,19 +38,28 @@ pub impl MessageImpl of MessageTrait {
}
}

fn format_message(message: Message) -> u256 {
let sender: felt252 = message.sender.into();
let recipient: felt252 = message.recipient.into();
/// Format an input message, using reverse keccak big endian
///
/// # Arguments
///
/// * `_message` - Message to hash
///
/// # Returns
///
/// * u256 representing the hash of the message
fn format_message(_message: Message) -> u256 {
let sender: felt252 = _message.sender.into();
let recipient: felt252 = _message.recipient.into();

let mut input: Array<u256> = array![
message.version.into(),
message.origin.into(),
_message.version.into(),
_message.origin.into(),
sender.into(),
message.destination.into(),
_message.destination.into(),
recipient.into(),
message.body.size().into()
_message.body.size().into()
];
let mut message_data = message.body.data();
let mut message_data = _message.body.data();
loop {
match message_data.pop_front() {
Option::Some(data) => { input.append(data.into()); },
Expand Down
15 changes: 14 additions & 1 deletion src/utils/keccak256.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
use core::integer::u128_byte_reverse;

/// Reverse the endianness of an u256
pub fn reverse_endianness(value: u256) -> u256 {
let new_low = u128_byte_reverse(value.high);
let new_high = u128_byte_reverse(value.low);
u256 { low: new_low, high: new_high }
}


#[cfg(test)]
mod tests {
use super::reverse_endianness;
#[test]
fn test_reverse_endianness() {
let big_endian_number: u256 = u256 { high: 0x12345678, low: 0 };
let expected_result: u256 = u256 { high: 0, low: 0x78563412000000000000000000000000 };
assert(
reverse_endianness(big_endian_number) == expected_result, 'Failed to realise reverse'
);
}
}

0 comments on commit 094ef99

Please sign in to comment.