@@ -40,12 +40,14 @@ forall ty callvalueCheckStatus . class ty:ExecMethod {
40
40
}
41
41
42
42
// If fn matches the provided args/ret types, then we can execute any method
43
- forall name args rets fn callvalueCheckStatus . fn:Invokable (args,ret) => instance Method (name,args,rets,fn):ExecMethod {
44
- function exec (m : Method (name,args,rets,fn), pstatus : Proxy (callvalueCheckStatus)) {
43
+ forall name args rets fn callvalueCheckStatus
44
+ . fn:invokable (args,ret)
45
+ => instance Method (name,Proxy (args),rets,fn):ExecMethod {
46
+ function exec (m : Method (name,Proxy (args),rets,fn), pstatus : Proxy (callvalueCheckStatus)) -> () {
45
47
match m {
46
- | Method (nm,args ,rets,fn) =>
48
+ | Method (nm,pargs ,rets,fn) =>
47
49
// check callvalue
48
- MethodLevelCallvalueCheck.checkCallvalue (Proxy : Proxy (Method (name,args,rets,fn)), pstatus);
50
+ MethodLevelCallvalueCheck.checkCallvalue (Proxy : Proxy (Method (name,Proxy ( args) ,rets,fn)), pstatus);
49
51
50
52
// check we have enough calldata for the head of args
51
53
// abi decode args from calldata
@@ -59,12 +61,12 @@ forall name args rets fn callvalueCheckStatus . fn:Invokable(args,ret) => instan
59
61
}
60
62
61
63
// If fn matches the provided args/ret types, then we can execute any fallback
62
- forall args rets fn callvalueCheckStatus . fn:Invokable (args,ret) => instance Fallback (args, rets,fn):ExecMethod {
63
- function exec (fb : Fallback (args, rets,fn), pstatus : Proxy (callvalueCheckStatus)) {
64
+ forall args rets fn callvalueCheckStatus . fn:invokable (args,ret) => instance Fallback (Proxy ( args), Proxy ( rets) ,fn):ExecMethod {
65
+ function exec (fb : Fallback (Proxy ( args), Proxy ( rets) ,fn), pstatus : Proxy (callvalueCheckStatus)) -> ( ) {
64
66
match fb {
65
67
| Fallback (args, rets, fn) =>
66
68
// check callvalue
67
- MethodLevelCallvalueCheck.checkCallvalue (Proxy : Proxy (Fallback (args, rets,fn)), pstatus);
69
+ MethodLevelCallvalueCheck.checkCallvalue (Proxy : Proxy (Fallback (Proxy ( args), Proxy ( rets) ,fn)), pstatus);
68
70
69
71
// check we have enough calldata for the head of args
70
72
// abi decode args from calldata
@@ -87,7 +89,7 @@ forall ty callvalueCheckStatus . class ty:RunDispatch {
87
89
// We can dispatch to a single executable method with a known selector
88
90
// TODO: do we need this instance?
89
91
forall m callvalueCheckStatus . m:ExecMethod, m:Selector => instance m:RunDispatch {
90
- function go (method : m, pstatus : Proxy (callvalueCheckStatus)) {
92
+ function go (method : m, pstatus : Proxy (callvalueCheckStatus)) -> () {
91
93
match selector_matches (Proxy : Proxy (m)) {
92
94
| True => ExecMethod.exec (method, pstatus);
93
95
| False => return ();
@@ -97,7 +99,7 @@ forall m callvalueCheckStatus . m:ExecMethod, m:Selector => instance m:RunDispat
97
99
98
100
// We can dispatch to a tuple of executable methods with a known selector
99
101
forall n m callvalueCheckStatus . n:ExecMethod, n:Selector, m:ExecMethod, m:Selector => instance (n,m):RunDispatch {
100
- function go (methods : (n,m), pstatus : Proxy (callvalueCheckStatus)) {
102
+ function go (methods : (n,m), pstatus : Proxy (callvalueCheckStatus)) -> () {
101
103
match methods {
102
104
| (method_n, method_m) =>
103
105
match selector_matches (Proxy : Proxy (n)) {
@@ -113,7 +115,7 @@ forall n m callvalueCheckStatus . n:ExecMethod, n:Selector, m:ExecMethod, m:Sele
113
115
114
116
// Recursive instance
115
117
forall n m callvalueCheckStatus . n:ExecMethod, n:Selector, m:RunDispatch => instance (n,m):RunDispatch {
116
- function go (methods : (n,m), pstatus : Proxy (callvalueCheckStatus)) {
118
+ function go (methods : (n,m), pstatus : Proxy (callvalueCheckStatus)) -> () {
117
119
match methods {
118
120
| (method_n, rest) =>
119
121
match selector_matches (Proxy : Proxy (n)) {
@@ -160,11 +162,12 @@ forall ty ret . class ty:TopLevelCallvalueCheck(ret) {
160
162
}
161
163
162
164
forall methods . default instance methods:TopLevelCallvalueCheck (CallvalueUnchecked) {
163
- function checkCallvalue (prx) { return Proxy : Proxy (CallvalueUnchecked); }
165
+ function checkCallvalue (prx : Proxy (methods)) -> Proxy (CallvalueUnchecked)
166
+ { return Proxy : Proxy (CallvalueUnchecked); }
164
167
}
165
168
166
169
forall methods . methods:AllNonPayable => instance methods:TopLevelCallvalueCheck (CallvalueChecked) {
167
- function checkCallvalue (prx) {
170
+ function checkCallvalue (prx : Proxy (methods)) -> Proxy (CallvalueUnchecked ) {
168
171
assembly {
169
172
if gt (callvalue (), 0 ) {
170
173
mstore (0 ,0x2 )
@@ -181,11 +184,11 @@ forall ty status . class ty:MethodLevelCallvalueCheck {
181
184
}
182
185
183
186
forall method status . default instance method:MethodLevelCallvalueCheck {
184
- function checkCallvalue (pty : Proxy (method), pstatus : Proxy (status)) { }
187
+ function checkCallvalue (pty : Proxy (method), pstatus : Proxy (status)) -> () { }
185
188
}
186
189
187
190
forall method status . method:NonPayable, status:MethodsMustCheckCalldata => instance method:MethodLevelCallvalueCheck {
188
- function checkCallvalue (pty : Proxy (method), pstatus : Proxy (status)) {
191
+ function checkCallvalue (pty : Proxy (method), pstatus : Proxy (status)) -> () {
189
192
assembly {
190
193
if gt (callvalue (), 0 ) {
191
194
mstore (0 , 0x1 );
@@ -199,12 +202,12 @@ forall method status . method:NonPayable, status:MethodsMustCheckCalldata => ins
199
202
200
203
// Describes how to execute a given contract
201
204
forall c . class c:RunContract {
202
- function exec (v : c);
205
+ function exec (v : c) -> () ;
203
206
}
204
207
205
208
// If we have a dispatch for the contracts methods, and we know how to execute it's fallback, then we can define an entrypoint
206
209
forall methods fallback . methods:RunDispatch, fallback :ExecMethod => instance Contract (methods, fallback ):RunContract {
207
- function exec (c : Contract (methods, fallback )) {
210
+ function exec (c : Contract (methods, fallback )) -> () {
208
211
match c {
209
212
| Contract (ms, fb) =>
210
213
// set free memory pointer to the output of memoryguard
@@ -222,7 +225,10 @@ forall methods fallback . methods:RunDispatch, fallback:ExecMethod => instance C
222
225
}
223
226
224
227
match haveSelector {
225
- | 0 => assembly { revert (0 ,0 ); }
228
+ | 0 => assembly {
229
+ mstore (0 ,0xff )
230
+ revert (0 ,1 )
231
+ }
226
232
| _ =>
227
233
// dispatch to method based on selector
228
234
RunDispatch.go (ms, callvalueChecked);
0 commit comments