Skip to content

Commit

Permalink
remove verifyingContract from stark sig (#626)
Browse files Browse the repository at this point in the history
* remove verifyingContract from stark sig auth; rename starkEIP712 to SNIP12

* remove remaining occurences of StarkEIP712

* update comment in SNIP12

* fix DOMAIN_TYPEHASH constant
  • Loading branch information
pscott authored Aug 7, 2024
1 parent 56b6868 commit a135ae7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
18 changes: 9 additions & 9 deletions starknet/src/authenticators/stark_sig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod StarkSigAuthenticator {
use starknet::{ContractAddress, info};
use sx::interfaces::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{Strategy, IndexedStrategy, UserAddress, Choice};
use sx::utils::StarkEIP712;
use sx::utils::SNIP12;

#[storage]
struct Storage {
Expand All @@ -102,8 +102,8 @@ mod StarkSigAuthenticator {
) {
assert(!self._used_salts.read((author, salt)), 'Salt Already Used');

let state = StarkEIP712::unsafe_new_contract_state();
StarkEIP712::InternalImpl::verify_propose_sig(
let state = SNIP12::unsafe_new_contract_state();
SNIP12::InternalImpl::verify_propose_sig(
@state,
signature,
space,
Expand Down Expand Up @@ -136,8 +136,8 @@ mod StarkSigAuthenticator {
) {
// No need to check salts here, as double voting is prevented by the space itself.

let state = StarkEIP712::unsafe_new_contract_state();
StarkEIP712::InternalImpl::verify_vote_sig(
let state = SNIP12::unsafe_new_contract_state();
SNIP12::InternalImpl::verify_vote_sig(
@state,
signature,
space,
Expand Down Expand Up @@ -170,8 +170,8 @@ mod StarkSigAuthenticator {
) {
assert(!self._used_salts.read((author, salt)), 'Salt Already Used');

let state = StarkEIP712::unsafe_new_contract_state();
StarkEIP712::InternalImpl::verify_update_proposal_sig(
let state = SNIP12::unsafe_new_contract_state();
SNIP12::InternalImpl::verify_update_proposal_sig(
@state,
signature,
space,
Expand All @@ -191,7 +191,7 @@ mod StarkSigAuthenticator {
}
#[constructor]
fn constructor(ref self: ContractState, name: felt252, version: felt252) {
let mut state = StarkEIP712::unsafe_new_contract_state();
StarkEIP712::InternalImpl::initializer(ref state, name, version);
let mut state = SNIP12::unsafe_new_contract_state();
SNIP12::InternalImpl::initializer(ref state, name, version);
}
}
5 changes: 3 additions & 2 deletions starknet/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mod voting_strategies {
mod merkle_whitelist;
use merkle_whitelist::MerkleWhitelistVotingStrategy;
}

mod proposal_validation_strategies {
mod proposition_power;
use proposition_power::PropositionPowerProposalValidationStrategy;
Expand Down Expand Up @@ -152,8 +153,8 @@ mod utils {
mod single_slot_proof;
use single_slot_proof::SingleSlotProof;

mod stark_eip712;
use stark_eip712::StarkEIP712;
mod snip12;
use snip12::SNIP12;

mod struct_hash;
use struct_hash::StructHash;
Expand Down
4 changes: 2 additions & 2 deletions starknet/src/utils/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const INDEXED_STRATEGY_TYPEHASH_LOW: u128 = 0x1d011b57ff63174d8f2b064ab6ce9cc6;

const STARKNET_MESSAGE: felt252 = 'StarkNet Message';

// StarknetKeccak('StarkNetDomain(name:felt252,version:felt252,chainId:felt252,verifyingContract:ContractAddress)')
const DOMAIN_TYPEHASH: felt252 = 0xa9974a36dee531bbc36aad5eeab4ade4df5ad388a296bb14d28ad4e9bf2164;
// StarknetKeccak('StarkNetDomain(name:felt252,version:felt252,chainId:felt252)')
const DOMAIN_TYPEHASH: felt252 = 0x27652a980b9a4920425c858386f09477bb210dea95169abd576f5ef7c9d5ca2;

// H('Propose(space:ContractAddress,author:ContractAddress,metadataUri:felt*,executionStrategy:Strategy,
// userProposalValidationParams:felt*,salt:felt252)Strategy(address:felt252,params:felt*)')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// EIP712 style typed data signing implementation.
/// SNIP12 style typed data signing implementation.
/// See here for more info: https://community.starknet.io/t/snip-off-chain-signatures-a-la-eip712/98029
#[starknet::contract]
mod StarkEIP712 {
mod SNIP12 {
use starknet::ContractAddress;
use openzeppelin::account::interface::{AccountABIDispatcher, AccountABIDispatcherTrait};
use sx::types::{Strategy, IndexedStrategy, Choice};
Expand Down Expand Up @@ -154,7 +154,6 @@ mod StarkEIP712 {
name.serialize(ref encoded_data);
version.serialize(ref encoded_data);
starknet::get_tx_info().unbox().chain_id.serialize(ref encoded_data);
starknet::get_contract_address().serialize(ref encoded_data);
encoded_data.span().struct_hash()
}

Expand Down
1 change: 0 additions & 1 deletion tests/stark-sig-auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ describe('Starknet Signature Authenticator', function () {
name: 'sx-sn',
version: '0.1.0',
chainId: '0x534e5f474f45524c49', // devnet id
verifyingContract: starkSigAuthenticator.address,
};

// Dumping the Starknet state so it can be loaded at the same point for each test
Expand Down
1 change: 0 additions & 1 deletion tests/stark-sig-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export const domainTypes = {
{ name: 'name', type: 'felt252' },
{ name: 'version', type: 'felt252' },
{ name: 'chainId', type: 'felt252' },
{ name: 'verifyingContract', type: 'ContractAddress' },
],
};

Expand Down

0 comments on commit a135ae7

Please sign in to comment.