Skip to content
Merged
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
5 changes: 1 addition & 4 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,7 @@ pub async fn run(args: Arguments, shutdown_controller: ShutdownController) {
web3.clone(),
quoter.clone(),
Box::new(custom_ethflow_order_parser),
DomainSeparator::new(
chain_id,
eth.contracts().settlement().address().into_legacy(),
),
DomainSeparator::new(chain_id, *eth.contracts().settlement().address()),
eth.contracts().settlement().address().into_legacy(),
eth.contracts().trampoline().clone(),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
doctest = false

[dependencies]
alloy = { workspace = true }
alloy = { workspace = true, features = ["sol-types"] }
anyhow = { workspace = true }
app-data = { workspace = true }
bigdecimal = { workspace = true }
Expand Down
41 changes: 12 additions & 29 deletions crates/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ pub mod trade;
use {
alloy::primitives::Address,
const_hex::{FromHex, FromHexError},
primitive_types::H160,
std::{fmt, sync::LazyLock},
web3::{
ethabi::{Token, encode},
signing,
},
std::fmt,
};

pub type AuctionId = i64;
Expand Down Expand Up @@ -116,36 +111,24 @@ impl std::fmt::Debug for DomainSeparator {
}

impl DomainSeparator {
pub fn new(chain_id: u64, contract_address: H160) -> Self {
/// The EIP-712 domain name used for computing the domain separator.
static DOMAIN_NAME: LazyLock<[u8; 32]> =
LazyLock::new(|| signing::keccak256(b"Gnosis Protocol"));

/// The EIP-712 domain version used for computing the domain separator.
static DOMAIN_VERSION: LazyLock<[u8; 32]> = LazyLock::new(|| signing::keccak256(b"v2"));

/// The EIP-712 domain type used computing the domain separator.
static DOMAIN_TYPE_HASH: LazyLock<[u8; 32]> = LazyLock::new(|| {
signing::keccak256(
b"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)",
)
});
let abi_encode_string = encode(&[
Token::Uint((*DOMAIN_TYPE_HASH).into()),
Token::Uint((*DOMAIN_NAME).into()),
Token::Uint((*DOMAIN_VERSION).into()),
Token::Uint(chain_id.into()),
Token::Address(contract_address),
]);
pub fn new(chain_id: u64, contract_address: Address) -> Self {
let domain = alloy::sol_types::Eip712Domain {
name: Some("Gnosis Protocol".into()),
version: Some("v2".into()),
chain_id: Some(alloy::primitives::U256::from(chain_id)),
verifying_contract: Some(contract_address),
salt: None,
};

DomainSeparator(signing::keccak256(abi_encode_string.as_slice()))
DomainSeparator(domain.separator().into())
}
}

#[cfg(test)]
mod tests {
use {
super::*,
alloy::primitives::address,
hex_literal::hex,
std::{cmp::Ordering, str::FromStr},
};
Expand All @@ -162,7 +145,7 @@ mod tests {

#[test]
fn domain_separator_sepolia() {
let contract_address: H160 = hex!("9008D19f58AAbD9eD0D60971565AA8510560ab41").into(); // new deployment
let contract_address = address!("9008D19f58AAbD9eD0D60971565AA8510560ab41"); // new deployment
let chain_id: u64 = 11155111;
let domain_separator_sepolia = DomainSeparator::new(chain_id, contract_address);
// domain separator is taken from Sepolia deployment at address
Expand Down
5 changes: 2 additions & 3 deletions crates/orderbook/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ pub async fn run(args: Arguments) {
verify_deployed_contract_constants(&settlement_contract, chain_id)
.await
.expect("Deployed contract constants don't match the ones in this binary");
let domain_separator =
DomainSeparator::new(chain_id, settlement_contract.address().into_legacy());
let domain_separator = DomainSeparator::new(chain_id, *settlement_contract.address());
let postgres_write =
Postgres::try_new(args.db_write_url.as_str()).expect("failed to create database");

Expand Down Expand Up @@ -590,7 +589,7 @@ async fn verify_deployed_contract_constants(
.0,
);

let domain_separator = DomainSeparator::new(chain_id, contract.address().into_legacy());
let domain_separator = DomainSeparator::new(chain_id, *contract.address());
if !bytecode.contains(&const_hex::encode(domain_separator.0)) {
return Err(anyhow!("Bytecode did not contain domain separator"));
}
Expand Down
Loading