git.delta.rocks / unique-network / refs/commits / 82bedeffe28d

difftreelog

fix evm sponsoring allowlist handling

Yaroslav Bolyukin2021-11-18parent: #dd1406b.patch.diff
in: master

2 files changed

modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
5959
60 fn allowed(&self, contract_address: address, user: address) -> Result<bool> {60 fn allowed(&self, contract_address: address, user: address) -> Result<bool> {
61 self.0.consume_sload()?;61 self.0.consume_sload()?;
62 Ok(<Pallet<T>>::allowed(contract_address, user, true))62 Ok(<Pallet<T>>::allowed(contract_address, user)
63 || !<AllowlistEnabled<T>>::get(contract_address))
63 }64 }
6465
65 fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {66 fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {
113 value: sp_core::U256,114 value: sp_core::U256,
114 ) -> Option<PrecompileOutput> {115 ) -> Option<PrecompileOutput> {
115 // TODO: Extract to another OnMethodCall handler116 // TODO: Extract to another OnMethodCall handler
116 if !<Pallet<T>>::allowed(*target, *source, true) {117 if <AllowlistEnabled<T>>::get(target) && !<Pallet<T>>::allowed(*target, *source) {
117 return Some(PrecompileOutput {118 return Some(PrecompileOutput {
118 exit_status: ExitReason::Revert(ExitRevert::Reverted),119 exit_status: ExitReason::Revert(ExitRevert::Reverted),
119 cost: 0,120 cost: 0,
151pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);152pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);
152impl<T: Config> SponsorshipHandler<H160, (H160, Vec<u8>)> for HelpersContractSponsoring<T> {153impl<T: Config> SponsorshipHandler<H160, (H160, Vec<u8>)> for HelpersContractSponsoring<T> {
153 fn get_sponsor(who: &H160, call: &(H160, Vec<u8>)) -> Option<H160> {154 fn get_sponsor(who: &H160, call: &(H160, Vec<u8>)) -> Option<H160> {
154 if <SelfSponsoring<T>>::get(&call.0) && <Pallet<T>>::allowed(call.0, *who, false) {155 if !<SelfSponsoring<T>>::get(&call.0) {
156 return None;
157 }
158 if !<Pallet<T>>::allowed(call.0, *who) {
159 return None;
160 }
155 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;161 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
162
156 if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {163 if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {
157 let rate_limit = <SponsoringRateLimit<T>>::get(&call.0);164 let limit = <SponsoringRateLimit<T>>::get(&call.0);
165
158 let limit_time = last_tx_block + rate_limit;166 let timeout = last_tx_block + limit.into();
159167 if block_number < timeout {
160 if block_number > limit_time {168 return None;
161 <SponsorBasket<T>>::insert(&call.0, who, block_number);169 }
162 return Some(call.0);
163 }
164 } else {170 }
171
165 <SponsorBasket<T>>::insert(&call.0, who, block_number);172 <SponsorBasket<T>>::insert(&call.0, who, block_number);
173
166 return Some(call.0);174 Some(call.0)
167 }
168 }
169 None
170 }175 }
171}176}
172177
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
76 <SponsoringRateLimit<T>>::insert(contract, rate_limit);76 <SponsoringRateLimit<T>>::insert(contract, rate_limit);
77 }77 }
7878
79 /// Default is returned if allowlist is disabled
80 pub fn allowed(contract: H160, user: H160, default: bool) -> bool {79 pub fn allowed(contract: H160, user: H160) -> bool {
81 if !<AllowlistEnabled<T>>::get(contract) {
82 return default;
83 }
84 <Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user80 <Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user
85 }81 }
8682