Skip to content
This repository was archived by the owner on Aug 17, 2026. It is now read-only.
Open
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
9 changes: 5 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- name: Install Toolchain
run: |
rustup update stable && rustup default stable
rustup target add wasm32-unknown-unknown
- uses: taiki-e/install-action@sccache
- uses: taiki-e/install-action@nextest
- uses: foundry-rs/foundry-toolchain@v1

Expand Down
15 changes: 10 additions & 5 deletions compiler/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Zink compiler

use crate::{parser::Parser, Artifact, Config, Error, Result};
use std::collections::HashMap;
use zabi::Abi;
use zingen::{
wasm::{self, Env},
Expand All @@ -11,7 +12,7 @@ use zingen::{
#[derive(Default)]
pub struct Compiler {
/// ABIs of the compiled contract.
pub(crate) abi: Vec<Abi>,
pub(crate) abi: HashMap<String, Abi>,
/// EVM bytecode buffer.
pub(crate) buffer: Buffer,
/// Compiler configuration.
Expand Down Expand Up @@ -59,7 +60,7 @@ impl Compiler {

tracing::debug!("code length: {}", buffer.len());
Ok(Artifact {
abi,
abi: abi.into_values().collect(),
config,
runtime_bytecode: buffer.to_vec(),
})
Expand All @@ -73,7 +74,9 @@ impl Compiler {
let env = parser.env.clone();

if !self.config.dispatcher {
self.abi.append(&mut env.load_abis(&selectors)?);
for abi in env.load_abis(&selectors)? {
self.abi.insert(abi.name.clone(), abi);
}
return Ok(());
}

Expand All @@ -84,7 +87,9 @@ impl Compiler {
return Err(Error::BufferOverflow(self.buffer.len()));
}

self.abi.append(&mut dispatcher.abi);
for abi in dispatcher.abi {
self.abi.insert(abi.name.clone(), abi);
}
Ok(())
}

Expand Down Expand Up @@ -124,6 +129,6 @@ impl Compiler {
/// Get abi from env and function index
fn abi(&self, env: &Env, index: u32) -> Option<Abi> {
let name = env.exports.get(&index)?;
self.abi.iter().find(|a| name == &a.name).cloned()
self.abi.get(name).cloned()
}
}
36 changes: 36 additions & 0 deletions zink/examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,42 @@ mod tests {
assert_eq!(info.logs[0].topics()[0].to_vec(), value4.bytes32().to_vec());
}
}

#[test]
fn test_log_abi() {
let contract = Contract::search("log")
.unwrap()
.compile()
.expect("failed to compile");
let abi = contract.artifact.abi;

assert_eq!(abi.len(), 5);

let test_log0 = abi.iter().find(|a| a.name == "test_log0").unwrap();
assert_eq!(test_log0.inputs.len(), 0);

let test_log1 = abi.iter().find(|a| a.name == "test_log1").unwrap();
assert_eq!(test_log1.inputs.len(), 1);
assert_eq!(test_log1.inputs[0].ty.to_string(), "uint256");

let test_log2 = abi.iter().find(|a| a.name == "test_log2").unwrap();
assert_eq!(test_log2.inputs.len(), 2);
assert_eq!(test_log2.inputs[0].ty.to_string(), "uint256");
assert_eq!(test_log2.inputs[1].ty.to_string(), "uint256");

let test_log3 = abi.iter().find(|a| a.name == "test_log3").unwrap();
assert_eq!(test_log3.inputs.len(), 3);
assert_eq!(test_log3.inputs[0].ty.to_string(), "uint256");
assert_eq!(test_log3.inputs[1].ty.to_string(), "uint256");
assert_eq!(test_log3.inputs[2].ty.to_string(), "uint256");

let test_log4 = abi.iter().find(|a| a.name == "test_log4").unwrap();
assert_eq!(test_log4.inputs.len(), 4);
assert_eq!(test_log4.inputs[0].ty.to_string(), "uint256");
assert_eq!(test_log4.inputs[1].ty.to_string(), "uint256");
assert_eq!(test_log4.inputs[2].ty.to_string(), "uint256");
assert_eq!(test_log4.inputs[3].ty.to_string(), "uint256");
}
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down
Loading