Set a fixed fee transferred to the caller for publication

Avoids the risk of the gas used by the contract exceeding the gas presumed to
be used (causing an insolvency).
This commit is contained in:
Luke Parker
2024-09-20 00:20:05 -04:00
parent ec9211fd84
commit bc1bbf9951
5 changed files with 28 additions and 54 deletions

View File

@@ -18,7 +18,7 @@ use crate::{output::OutputId, machine::ClonableTransctionMachine};
#[derive(Clone, PartialEq, Debug)]
pub(crate) enum Action {
SetKey { chain_id: U256, nonce: u64, key: PublicKey },
Batch { chain_id: U256, nonce: u64, coin: Coin, fee_per_gas: U256, outs: Vec<(Address, U256)> },
Batch { chain_id: U256, nonce: u64, coin: Coin, fee: U256, outs: Vec<(Address, U256)> },
}
#[derive(Clone, PartialEq, Eq, Debug)]
@@ -36,11 +36,11 @@ impl Action {
Action::SetKey { chain_id, nonce, key } => {
Router::update_serai_key_message(*chain_id, *nonce, key)
}
Action::Batch { chain_id, nonce, coin, fee_per_gas, outs } => Router::execute_message(
Action::Batch { chain_id, nonce, coin, fee, outs } => Router::execute_message(
*chain_id,
*nonce,
*coin,
*fee_per_gas,
*fee,
OutInstructions::from(outs.as_ref()),
),
}
@@ -51,10 +51,9 @@ impl Action {
Self::SetKey { chain_id: _, nonce, key } => {
Executed::SetKey { nonce: *nonce, key: key.eth_repr() }
}
Self::Batch { nonce, .. } => Executed::Batch {
nonce: *nonce,
message_hash: keccak256(self.message()),
},
Self::Batch { nonce, .. } => {
Executed::Batch { nonce: *nonce, message_hash: keccak256(self.message()) }
}
})
}
}
@@ -106,9 +105,9 @@ impl SignableTransaction for Action {
1 => {
let coin = Coin::read(reader)?;
let mut fee_per_gas = [0; 32];
reader.read_exact(&mut fee_per_gas)?;
let fee_per_gas = U256::from_le_bytes(fee_per_gas);
let mut fee = [0; 32];
reader.read_exact(&mut fee)?;
let fee = U256::from_le_bytes(fee);
let mut outs_len = [0; 4];
reader.read_exact(&mut outs_len)?;
@@ -124,7 +123,7 @@ impl SignableTransaction for Action {
outs.push((address, amount));
}
Action::Batch { chain_id, nonce, coin, fee_per_gas, outs }
Action::Batch { chain_id, nonce, coin, fee, outs }
}
_ => unreachable!(),
})
@@ -137,12 +136,12 @@ impl SignableTransaction for Action {
writer.write_all(&nonce.to_le_bytes())?;
writer.write_all(&key.eth_repr())
}
Self::Batch { chain_id, nonce, coin, fee_per_gas, outs } => {
Self::Batch { chain_id, nonce, coin, fee, outs } => {
writer.write_all(&[1])?;
writer.write_all(&chain_id.as_le_bytes())?;
writer.write_all(&nonce.to_le_bytes())?;
coin.write(writer)?;
writer.write_all(&fee_per_gas.as_le_bytes())?;
writer.write_all(&fee.as_le_bytes())?;
writer.write_all(&u32::try_from(outs.len()).unwrap().to_le_bytes())?;
for (address, amount) in outs {
borsh::BorshSerialize::serialize(address, writer)?;