Skip to content

Commit 695bb5d

Browse files
authored
Merge pull request #175 from argotorg/mbenke/fix-dispatch2
Fixes to dispatch
2 parents f40ec31 + 03b122f commit 695bb5d

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

std/dispatch.sol

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ forall ty callvalueCheckStatus . class ty:ExecMethod {
4040
}
4141

4242
// 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)) -> () {
4547
match m {
46-
| Method(nm,args,rets,fn) =>
48+
| Method(nm,pargs,rets,fn) =>
4749
// 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);
4951

5052
// check we have enough calldata for the head of args
5153
// abi decode args from calldata
@@ -59,12 +61,12 @@ forall name args rets fn callvalueCheckStatus . fn:Invokable(args,ret) => instan
5961
}
6062

6163
// 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)) -> () {
6466
match fb {
6567
| Fallback(args, rets, fn) =>
6668
// check callvalue
67-
MethodLevelCallvalueCheck.checkCallvalue(Proxy : Proxy(Fallback(args,rets,fn)), pstatus);
69+
MethodLevelCallvalueCheck.checkCallvalue(Proxy : Proxy(Fallback(Proxy(args),Proxy(rets),fn)), pstatus);
6870

6971
// check we have enough calldata for the head of args
7072
// abi decode args from calldata
@@ -87,7 +89,7 @@ forall ty callvalueCheckStatus . class ty:RunDispatch {
8789
// We can dispatch to a single executable method with a known selector
8890
// TODO: do we need this instance?
8991
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)) -> () {
9193
match selector_matches(Proxy : Proxy(m)) {
9294
| True => ExecMethod.exec(method, pstatus);
9395
| False => return ();
@@ -97,7 +99,7 @@ forall m callvalueCheckStatus . m:ExecMethod, m:Selector => instance m:RunDispat
9799

98100
// We can dispatch to a tuple of executable methods with a known selector
99101
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)) -> () {
101103
match methods {
102104
| (method_n, method_m) =>
103105
match selector_matches(Proxy : Proxy(n)) {
@@ -113,7 +115,7 @@ forall n m callvalueCheckStatus . n:ExecMethod, n:Selector, m:ExecMethod, m:Sele
113115

114116
// Recursive instance
115117
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)) -> () {
117119
match methods {
118120
| (method_n, rest) =>
119121
match selector_matches(Proxy : Proxy(n)) {
@@ -160,11 +162,12 @@ forall ty ret . class ty:TopLevelCallvalueCheck(ret) {
160162
}
161163

162164
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); }
164167
}
165168

166169
forall methods . methods:AllNonPayable => instance methods:TopLevelCallvalueCheck(CallvalueChecked) {
167-
function checkCallvalue(prx) {
170+
function checkCallvalue(prx : Proxy(methods)) -> Proxy(CallvalueUnchecked) {
168171
assembly {
169172
if gt(callvalue(), 0) {
170173
mstore(0,0x2)
@@ -181,11 +184,11 @@ forall ty status . class ty:MethodLevelCallvalueCheck {
181184
}
182185

183186
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)) -> () { }
185188
}
186189

187190
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)) -> () {
189192
assembly {
190193
if gt(callvalue(), 0) {
191194
mstore(0, 0x1);
@@ -199,12 +202,12 @@ forall method status . method:NonPayable, status:MethodsMustCheckCalldata => ins
199202

200203
// Describes how to execute a given contract
201204
forall c . class c:RunContract {
202-
function exec(v : c);
205+
function exec(v : c) -> ();
203206
}
204207

205208
// If we have a dispatch for the contracts methods, and we know how to execute it's fallback, then we can define an entrypoint
206209
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)) -> () {
208211
match c {
209212
| Contract(ms, fb) =>
210213
// set free memory pointer to the output of memoryguard
@@ -222,7 +225,10 @@ forall methods fallback . methods:RunDispatch, fallback:ExecMethod => instance C
222225
}
223226

224227
match haveSelector {
225-
| 0 => assembly { revert(0,0); }
228+
| 0 => assembly {
229+
mstore(0,0xff)
230+
revert(0,1)
231+
}
226232
| _ =>
227233
// dispatch to method based on selector
228234
RunDispatch.go(ms, callvalueChecked);

0 commit comments

Comments
 (0)