-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add owner policy #872
base: master
Are you sure you want to change the base?
Add owner policy #872
Conversation
@@ -622,6 +624,12 @@ fn get_transaction_fields() { | |||
op::eq(0x10, 0x10, 0x11), | |||
op::and(0x20, 0x20, 0x10), | |||
|
|||
op::movi(0x19, 0x00), | |||
op::movi(0x11, owner_idx as Immediate18), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question for me to understand: why Immediate18
? By looking at the specs and the implementation of GTF
, I would expect Immediate12
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know I just followed the existing pattern. Maybe @Dentosal knows
@@ -622,6 +624,12 @@ fn get_transaction_fields() { | |||
op::eq(0x10, 0x10, 0x11), | |||
op::and(0x20, 0x20, 0x10), | |||
|
|||
op::movi(0x19, 0x00), | |||
op::movi(0x11, owner_idx as Immediate18), | |||
op::gtf_args(0x10, 0x19, GTFArgs::PolicyOwner), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another question for me to understand here.
I guess the PolicyOwner
field is taken from the transaction included in the frame pointer. What is the value of the register 0x19
here used for? From the specs i can infer that it is related to the part of the field that we want to read, but it is not clear if this is the start or end offset or something else.
Anyway, not related to this PR (also probably this value is ignored since I'd expect the owner value to be fixed size).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above I jsut copy pasted the existing. cc @Dentosal
Another question for me to understand: |
Co-authored-by: Andrea Cerone <22031682+acerone85@users.noreply.github.com>
…into add_owner_policy
The motivation is explained here : FuelLabs/fuel-specs#617 but in other word the smart contract sometimes wants to be able to know who is the caller (partially because dev are use to EVM |
@@ -133,6 +133,8 @@ pub enum ValidityError { | |||
TransactionInputsMax, | |||
TransactionOutputsMax, | |||
TransactionWitnessesMax, | |||
TransactionOwnerIndexDoesntExist, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a nit:
TransactionOwnerIndexDoesntExist, | |
TransactionOwnerIndexOutOfBounds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with that. Changed.
fuel-tx/src/transaction/validity.rs
Outdated
if owner >= tx.inputs().len() { | ||
Err(ValidityError::TransactionOwnerIndexDoesntExist)? | ||
} | ||
// SAFETY: `owner` is guaranteed to be a valid index because it was checked above. | ||
if !&tx.inputs()[owner].input_owner().is_some() { | ||
Err(ValidityError::TransactionOwnerInputHasNoOwner)? | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid manual safety check with something like:
if tx
.inputs()
.get(owner)
.and_then(|input| input.input_owner())
.is_none()
{
return Err(ValidityError::TransactionOwnerInputHasNoOwner);
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I will change that. (not the whole code to mentionned because otherwise we will loose the two different errors)
@@ -321,6 +322,24 @@ where | |||
Ok(()) | |||
} | |||
|
|||
pub(crate) fn check_owner<T>(tx: &T) -> Result<(), ValidityError> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think adding some UTs to this function makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really think so it's well tested with the other tests and it's not a practice we currently have for validation rules. I don't find this one more sensible or difficult to understand.
I marked this PR as a Draft for now until we resolved https://forum.fuel.network/t/proposal-for-note-inputs/7094 proposal=) |
FuelLabs/fuel-specs#617
Checklist
Before requesting review
After merging, notify other teams
[Add or remove entries as needed]