Skip to content

Commit

Permalink
v0.7.1 (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauroToscano committed Sep 23, 2024
2 parents ce5c9e7 + 0d29b1a commit ff72fae
Show file tree
Hide file tree
Showing 6 changed files with 2,768 additions and 2,456 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ OS := $(shell uname -s)
CONFIG_FILE?=config-files/config.yaml
AGG_CONFIG_FILE?=config-files/config-aggregator.yaml

OPERATOR_VERSION=v0.7.0
OPERATOR_VERSION=v0.7.1

ifeq ($(OS),Linux)
BUILD_ALL_FFI = $(MAKE) build_all_ffi_linux
Expand Down
83 changes: 70 additions & 13 deletions batcher/aligned-sdk/src/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,30 +218,38 @@ impl Eip712 for NoncedVerificationData {
}

fn struct_hash(&self) -> Result<[u8; 32], Self::Error> {
//EIP requires big endian for u256
let mut nonce_bytes = [0u8; 32];
self.nonce.to_big_endian(&mut nonce_bytes);

let mut max_fee_bytes = [0u8; 32];
self.max_fee.to_big_endian(&mut max_fee_bytes);

// This hashes the data of the task the user wants solved
// This is the data that is the leaf on the batch merkle tree
let verification_data_hash =
VerificationCommitmentBatch::hash_data(&self.verification_data.clone().into());

let mut hasher = Keccak256::new();

// As per the EIP, first we generate the type hash
// hashStruct(s : 𝕊) = keccak256(typeHash ‖ encodeData(s))
hasher.update(NONCED_VERIFICATION_DATA_TYPE);
let nonced_verification_data_type_hash = hasher.finalize_reset();
let type_hash = hasher.finalize_reset();

let mut nonce_bytes = [0u8; 32];
self.nonce.to_big_endian(&mut nonce_bytes);
// Then hash is resetted, so we start hashing the second term of the encodedData(s)
hasher.update(verification_data_hash);
hasher.update(nonce_bytes);
let nonce_hash = hasher.finalize_reset();

let mut max_fee_bytes = [0u8; 32];
self.max_fee.to_big_endian(&mut max_fee_bytes);
hasher.update(max_fee_bytes);
let max_fee_hash = hasher.finalize_reset();
let encoded_data_hash = hasher.finalize_reset();

hasher.update(nonced_verification_data_type_hash.as_slice());
hasher.update(verification_data_hash.as_slice());
hasher.update(nonce_hash.as_slice());
hasher.update(max_fee_hash.as_slice());
// Now we do the actual final
// keccak256(typeHash ‖ encodeData(s))
hasher.update(type_hash);
hasher.update(encoded_data_hash);
let hash_struct = hasher.finalize_reset();

Ok(hasher.finalize().into())
Ok(hash_struct.into())
}
}

Expand All @@ -266,6 +274,7 @@ impl ClientMessage {
/// The signature of the message is verified, and when it correct, the
/// recovered address from the signature is returned.
pub fn verify_signature(&self) -> Result<Address, VerifySignatureError> {
// Recovers the address from the signed data
let recovered = self.signature.recover_typed_data(&self.verification_data)?;

let hashed_data = self.verification_data.encode_eip712()?;
Expand Down Expand Up @@ -329,3 +338,51 @@ pub enum Chain {
Holesky,
HoleskyStage,
}

#[cfg(test)]
mod tests {
use ethers::signers::LocalWallet;
use std::str::FromStr;

use super::*;

#[tokio::test]
async fn eip_712_recovers_same_address_as_signed() {
const ANVIL_PRIVATE_KEY: &str =
"2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6"; // Anvil address 9
let wallet = LocalWallet::from_str(ANVIL_PRIVATE_KEY).expect("Failed to create wallet");

let proof = [42, 42, 42, 42].to_vec();
let pub_input = Some([32, 32, 32, 32].to_vec());
let verification_key = Some([8, 8, 8, 8].to_vec());
let proving_system = ProvingSystemId::Groth16Bn254;

let verification_data = VerificationData {
proving_system,
proof,
pub_input,
verification_key,
vm_program_code: None,
proof_generator_addr: wallet.address(),
};

let nonced_verification_data = NoncedVerificationData::new(
verification_data,
1.into(),
2.into(),
3.into(),
wallet.address(),
);

let signed_data = wallet
.sign_typed_data(&nonced_verification_data)
.await
.unwrap();

let recovered_address = signed_data
.recover_typed_data(&nonced_verification_data)
.unwrap();

assert_eq!(recovered_address, wallet.address())
}
}

Large diffs are not rendered by default.

5,124 changes: 2,689 additions & 2,435 deletions contracts/scripts/anvil/state/eigenlayer-deployed-anvil-state.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions contracts/src/core/BatcherPaymentService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,16 @@ contract BatcherPaymentService is
revert InvalidMaxFee(signatureData.maxFee, feePerProof);
}

bytes32 structHash = keccak256(
bytes32 encodedDataHash = keccak256(
abi.encode(
noncedVerificationDataTypeHash,
leaf,
keccak256(abi.encodePacked(signatureData.nonce)),
keccak256(abi.encodePacked(signatureData.maxFee))
signatureData.nonce,
signatureData.maxFee
)
);

bytes32 structHash = keccak256(abi.encode(noncedVerificationDataTypeHash, encodedDataHash));

bytes32 hash = _hashTypedDataV4(structHash);

address signer = ECDSA.recover(hash, signatureData.signature);
Expand Down
4 changes: 2 additions & 2 deletions docs/operator_guides/0_running_an_operator.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Register as an Aligned operator in testnet

> **CURRENT VERSION:**
> Aligned Operator [v0.7.0](https://github.com/yetanotherco/aligned_layer/releases/tag/v0.7.0)
> Aligned Operator [v0.7.1](https://github.com/yetanotherco/aligned_layer/releases/tag/v0.7.1)
> **IMPORTANT:**
> You must be [whitelisted](https://docs.google.com/forms/d/e/1FAIpQLSdH9sgfTz4v33lAvwj6BvYJGAeIshQia3FXz36PFfF-WQAWEQ/viewform) to become an Aligned operator.
Expand All @@ -26,7 +26,7 @@ Minimum hardware requirements:
To start with, clone the Aligned repository and move inside it

```bash
git clone https://github.com/yetanotherco/aligned_layer.git --branch v0.7.0
git clone https://github.com/yetanotherco/aligned_layer.git --branch v0.7.1
cd aligned_layer
```

Expand Down

0 comments on commit ff72fae

Please sign in to comment.